mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-19 00:19:16 +00:00
Add: MinecraftCapesAPI
This commit is contained in:
1 parent
46b8635e10
commit
f50640139a
3 files changed
+242
-70
No files matched your search
@@ -8,76 +8,100 @@ import org.apache.commons.io.FilenameUtils;
|
||||
import customskinloader.CustomSkinLoader;
|
||||
|
||||
public class HttpTextureUtil {
|
||||
public static class HttpTextureInfo{
|
||||
public String url="";
|
||||
public static class HttpTextureInfo {
|
||||
public String url = "";
|
||||
public File cacheFile;
|
||||
public String hash;
|
||||
}
|
||||
private static final String
|
||||
LEGACY_MARK="(LEGACY)",
|
||||
LOCAL_MARK="(LOCAL)",
|
||||
LOCAL_LEGACY_MARK="(LOCAL_LEGACY)";
|
||||
|
||||
private static final String
|
||||
LEGACY_MARK = "(LEGACY)",
|
||||
LOCAL_MARK = "(LOCAL)",
|
||||
LOCAL_LEGACY_MARK = "(LOCAL_LEGACY)",
|
||||
BASE64_MARK = "(BASE64)";
|
||||
public static File defaultCacheDir;
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
public static void cleanCacheDir(){
|
||||
if(defaultCacheDir!=null){
|
||||
public static void cleanCacheDir() {
|
||||
if (defaultCacheDir != null) {
|
||||
defaultCacheDir.delete();
|
||||
defaultCacheDir.mkdirs();
|
||||
}
|
||||
}
|
||||
public static File getCacheDir(){
|
||||
return defaultCacheDir==null?new File(MinecraftUtil.getMinecraftDataDir(),"assets/skins"):defaultCacheDir;
|
||||
|
||||
public static File getCacheDir() {
|
||||
return defaultCacheDir == null ? new File(MinecraftUtil.getMinecraftDataDir(), "assets/skins") : defaultCacheDir;
|
||||
}
|
||||
|
||||
public static HttpTextureInfo toHttpTextureInfo(String fakeUrl){
|
||||
HttpTextureInfo info=new HttpTextureInfo();
|
||||
if(fakeUrl.startsWith("http")){
|
||||
info.url=fakeUrl;
|
||||
info.hash=FilenameUtils.getBaseName(fakeUrl);
|
||||
info.cacheFile=getCacheFile(info.hash);
|
||||
|
||||
public static HttpTextureInfo toHttpTextureInfo(String fakeUrl) {
|
||||
HttpTextureInfo info = new HttpTextureInfo();
|
||||
if (fakeUrl.startsWith("http")) {
|
||||
info.url = fakeUrl;
|
||||
info.hash = FilenameUtils.getBaseName(fakeUrl);
|
||||
info.cacheFile = getCacheFile(info.hash);
|
||||
return info;
|
||||
}
|
||||
if(fakeUrl.startsWith(LOCAL_LEGACY_MARK)){
|
||||
fakeUrl=fakeUrl.replace(LOCAL_LEGACY_MARK, "");
|
||||
String[] t=fakeUrl.split(",",2);
|
||||
if(t.length!=2)
|
||||
if (fakeUrl.startsWith(LOCAL_LEGACY_MARK)) {
|
||||
fakeUrl = fakeUrl.replace(LOCAL_LEGACY_MARK, "");
|
||||
String[] t = fakeUrl.split(",", 2);
|
||||
if (t.length != 2)
|
||||
return info;
|
||||
info.cacheFile=new File(CustomSkinLoader.DATA_DIR,t[1]);
|
||||
info.hash=t[0];
|
||||
info.cacheFile = new File(CustomSkinLoader.DATA_DIR, t[1]);
|
||||
info.hash = t[0];
|
||||
return info;
|
||||
}
|
||||
if(fakeUrl.startsWith(LOCAL_MARK)){
|
||||
fakeUrl=fakeUrl.replace(LOCAL_MARK, "");
|
||||
info.cacheFile=new File(CustomSkinLoader.DATA_DIR,fakeUrl);
|
||||
info.hash=FilenameUtils.getBaseName(fakeUrl);
|
||||
if (fakeUrl.startsWith(LOCAL_MARK)) {
|
||||
fakeUrl = fakeUrl.replace(LOCAL_MARK, "");
|
||||
info.cacheFile = new File(CustomSkinLoader.DATA_DIR, fakeUrl);
|
||||
info.hash = FilenameUtils.getBaseName(fakeUrl);
|
||||
return info;
|
||||
}
|
||||
if(fakeUrl.startsWith(LEGACY_MARK)){
|
||||
fakeUrl=fakeUrl.replace(LEGACY_MARK, "");
|
||||
info.url=fakeUrl;
|
||||
info.hash=DigestUtils.sha1Hex(info.url);
|
||||
if (fakeUrl.startsWith(LEGACY_MARK)) {
|
||||
fakeUrl = fakeUrl.replace(LEGACY_MARK, "");
|
||||
info.url = fakeUrl;
|
||||
info.hash = DigestUtils.sha1Hex(info.url);
|
||||
info.cacheFile = HttpRequestUtil.getCacheFile(info.hash);
|
||||
return info;
|
||||
}
|
||||
//Base64 fake url format: `(BASE64)${hash}`
|
||||
if (fakeUrl.startsWith(BASE64_MARK)) {
|
||||
fakeUrl = fakeUrl.replace(BASE64_MARK, "");
|
||||
info.hash = fakeUrl;
|
||||
info.cacheFile = HttpRequestUtil.getCacheFile(info.hash);
|
||||
return info;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
public static String getLegacyFakeUrl(String url){
|
||||
return LEGACY_MARK+url;
|
||||
public static String getLegacyFakeUrl(String url) {
|
||||
return LEGACY_MARK + url;
|
||||
}
|
||||
public static String getLocalFakeUrl(String path){
|
||||
return LOCAL_MARK+path;
|
||||
|
||||
public static String getLocalFakeUrl(String path) {
|
||||
return LOCAL_MARK + path;
|
||||
}
|
||||
public static String getLocalLegacyFakeUrl(String path,String hash){
|
||||
return LOCAL_LEGACY_MARK+hash+","+path;
|
||||
|
||||
public static String getLocalLegacyFakeUrl(String path, String hash) {
|
||||
return LOCAL_LEGACY_MARK + hash + "," + path;
|
||||
}
|
||||
public static String getHash(String url,long size,long lastModified){
|
||||
return DigestUtils.sha1Hex(size+url+lastModified);
|
||||
|
||||
public static String getBase64FakeUrl(String hash) {
|
||||
return BASE64_MARK + hash;
|
||||
}
|
||||
public static File getCacheFile(String hash){
|
||||
return getCacheFile(defaultCacheDir,hash);
|
||||
|
||||
public static String getHash(String url, long size, long lastModified) {
|
||||
return DigestUtils.sha1Hex(size + url + lastModified);
|
||||
}
|
||||
|
||||
public static String getHash(String base64) {
|
||||
return DigestUtils.sha1Hex(base64);
|
||||
}
|
||||
|
||||
public static File getCacheFile(String hash) {
|
||||
return getCacheFile(defaultCacheDir, hash);
|
||||
}
|
||||
|
||||
public static File getCacheFile(File cacheDir, String hash) {
|
||||
return new File(new File(cacheDir, hash.length() > 2 ? hash.substring(0, 2) : "xx"), hash);
|
||||
}
|
||||
public static File getCacheFile(File cacheDir,String hash){
|
||||
return new File(new File(cacheDir,hash.length()>2?hash.substring(0,2):"xx"), hash);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user