diff --git a/Common/customskinloader/loader/JsonAPILoader.java b/Common/customskinloader/loader/JsonAPILoader.java index 18a2cec..fadb80c 100644 --- a/Common/customskinloader/loader/JsonAPILoader.java +++ b/Common/customskinloader/loader/JsonAPILoader.java @@ -65,7 +65,7 @@ public class JsonAPILoader implements ProfileLoader.IProfileLoader { } json=IOUtils.toString(new FileInputStream(jsonFile)); }else{ - HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(jsonUrl).setUserAgent(ssp.userAgent).setPayload(type.jsonAPI.getPayload(ssp))); + HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(jsonUrl).setCacheTime(60).setUserAgent(ssp.userAgent).setPayload(type.jsonAPI.getPayload(ssp))); json=responce.content; } if(json==null||json.equals("")){ diff --git a/Common/customskinloader/loader/LegacyLoader.java b/Common/customskinloader/loader/LegacyLoader.java index b3e4127..1ddcadf 100644 --- a/Common/customskinloader/loader/LegacyLoader.java +++ b/Common/customskinloader/loader/LegacyLoader.java @@ -30,7 +30,7 @@ public class LegacyLoader implements ProfileLoader.IProfileLoader { if(skinFile.exists()&&skinFile.isFile()) profile.skinUrl=HttpTextureUtil.getLocalLegacyFakeUrl(skin, HttpTextureUtil.getHash(skin, skinFile.length(), skinFile.lastModified())); }else{ - HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(skin).setUserAgent(ssp.userAgent).setLoadContent(false)); + HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(skin).setUserAgent(ssp.userAgent).setLoadContent(false).setCacheTime(60)); if(responce.success) profile.skinUrl=HttpTextureUtil.getLegacyFakeUrl(skin); } @@ -43,7 +43,7 @@ public class LegacyLoader implements ProfileLoader.IProfileLoader { if(capeFile.exists()&&capeFile.isFile()) profile.capeUrl=HttpTextureUtil.getLocalLegacyFakeUrl(cape, HttpTextureUtil.getHash(cape, capeFile.length(), capeFile.lastModified())); }else{ - HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(cape).setUserAgent(ssp.userAgent).setLoadContent(false)); + HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(cape).setUserAgent(ssp.userAgent).setLoadContent(false).setCacheTime(60)); if(responce.success) profile.capeUrl=HttpTextureUtil.getLegacyFakeUrl(cape); } @@ -55,7 +55,7 @@ public class LegacyLoader implements ProfileLoader.IProfileLoader { if(elytraFile.exists()&&elytraFile.isFile()) profile.elytraUrl=HttpTextureUtil.getLocalLegacyFakeUrl(elytra, HttpTextureUtil.getHash(elytra, elytraFile.length(), elytraFile.lastModified())); }else{ - HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(elytra).setUserAgent(ssp.userAgent).setLoadContent(false)); + HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(elytra).setUserAgent(ssp.userAgent).setLoadContent(false).setCacheTime(60)); if(responce.success) profile.elytraUrl=HttpTextureUtil.getLegacyFakeUrl(elytra); } diff --git a/Common/customskinloader/utils/HttpRequestUtil.java b/Common/customskinloader/utils/HttpRequestUtil.java index 52c3eb3..4e2f689 100644 --- a/Common/customskinloader/utils/HttpRequestUtil.java +++ b/Common/customskinloader/utils/HttpRequestUtil.java @@ -151,6 +151,7 @@ public class HttpRequestUtil { cacheInfo.expire=getExpire(c,request.cacheTime); FileUtils.write(cacheInfoFile, CustomSkinLoader.GSON.toJson(cacheInfo)); } + CustomSkinLoader.logger.info("Saved to cache (Length: "+request.cacheFile.length()+" , Path: '"+request.cacheFile.getAbsolutePath()+"' , Expire: "+cacheInfo.expire+")"); } if(!request.loadContent) return responce; @@ -187,13 +188,12 @@ public class HttpRequestUtil { } return responce; } - private final static Pattern MAX_AGE_PATTERN = Pattern.compile("max-age=(\\d+)"); + private final static Pattern MAX_AGE_PATTERN = Pattern.compile("(\\d+)"); private static long getExpire(HttpURLConnection connection,int cacheTime){ String cacheControl=connection.getHeaderField("Cache-Control"); if(StringUtils.isNotEmpty(cacheControl)){ - cacheControl=cacheControl.replaceAll(" ", ""); Matcher m=MAX_AGE_PATTERN.matcher(cacheControl); - if(m!=null && m.matches()) + if(m!=null && (m.matches()||m.find())) return TimeUtil.getUnixTimestamp(Long.parseLong(m.group(0))); } long expires=connection.getExpiration(); diff --git a/Common/customskinloader/utils/HttpTextureUtil.java b/Common/customskinloader/utils/HttpTextureUtil.java index a39a7e0..7dcfeda 100644 --- a/Common/customskinloader/utils/HttpTextureUtil.java +++ b/Common/customskinloader/utils/HttpTextureUtil.java @@ -35,9 +35,11 @@ public class HttpTextureUtil { } if(fakeUrl.startsWith(LOCAL_LEGACY_MARK)){ fakeUrl=fakeUrl.replaceFirst(LOCAL_LEGACY_MARK, ""); - info.url=fakeUrl; - info.hash=DigestUtils.sha1Hex(info.url);; - info.cacheFile=HttpTextureUtil.getCacheFile(info.hash); + String[] t=fakeUrl.split(",",2); + if(t.length!=2) + return info; + info.cacheFile=new File(CustomSkinLoader.DATA_DIR,t[1]); + info.hash=t[0]; return info; } if(fakeUrl.startsWith(LOCAL_MARK)){ @@ -48,12 +50,9 @@ public class HttpTextureUtil { } if(fakeUrl.startsWith(LEGACY_MARK)){ fakeUrl=fakeUrl.replaceFirst(LEGACY_MARK, ""); - String[] t=fakeUrl.split(",",2); - if(t.length!=2) - return info; - info.url=t[1]; - info.hash=t[0]; - info.cacheFile=getCacheFile(info.hash); + info.url=fakeUrl; + info.hash=DigestUtils.sha1Hex(info.url);; + info.cacheFile=HttpTextureUtil.getCacheFile(info.hash); return info; } return info; diff --git a/Common/customskinloader/utils/MinecraftUtil.java b/Common/customskinloader/utils/MinecraftUtil.java index 977c9a0..8ccd987 100644 --- a/Common/customskinloader/utils/MinecraftUtil.java +++ b/Common/customskinloader/utils/MinecraftUtil.java @@ -54,11 +54,11 @@ public class MinecraftUtil { for(String version:getMinecraftVersions()){ Matcher m = null; try{ - m=MINECRAFT_VERSION_PATTERN.matcher(version); + m=MINECRAFT_VERSION_PATTERN.matcher(" "+version+" "); }catch(Exception e){ e.printStackTrace(); } - if(m==null || !m.matches()) + if(m==null || (!m.matches() && !m.find())) continue; minecraftMainVersion=m.group(0); break;