mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-18 16:09:17 +00:00
Cache Auto Clean
This commit is contained in:
1 parent
a7f52365ca
commit
2f141bd565
9 files changed
+130
-10
No files matched your search
@@ -11,17 +11,26 @@ import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import customskinloader.CustomSkinLoader;
|
||||
import customskinloader.loader.ProfileLoader;
|
||||
import customskinloader.utils.HttpUtil0;
|
||||
|
||||
public class Config {
|
||||
//Program
|
||||
public String version;
|
||||
public boolean enable=true;
|
||||
public SkinSiteProfile[] loadlist;
|
||||
|
||||
//Function
|
||||
public boolean enableSkull=true;
|
||||
public boolean enableDynamicSkull=true;
|
||||
public boolean enableTransparentSkin=true;
|
||||
public boolean ignoreHttpsCertificate=false;
|
||||
|
||||
//Cache
|
||||
public int cacheExpiry=10;
|
||||
public boolean enableUpdateSkull=false;
|
||||
public boolean enableLocalProfileCache=false;
|
||||
public SkinSiteProfile[] loadlist;
|
||||
public boolean enableCacheAutoClean=false;
|
||||
|
||||
|
||||
//Init config
|
||||
public Config(SkinSiteProfile[] loadlist){
|
||||
@@ -31,16 +40,26 @@ public class Config {
|
||||
|
||||
public static Config loadConfig0() {
|
||||
Config config=loadConfig();
|
||||
|
||||
//Init program
|
||||
config.loadExtraList();
|
||||
config.initLocalFolder();
|
||||
if(config.ignoreHttpsCertificate)
|
||||
HttpUtil0.ignoreHttpsCertificate();
|
||||
|
||||
//Output config
|
||||
CustomSkinLoader.logger.info("Enable:"+config.enable+
|
||||
", EnableSkull:"+config.enableSkull+
|
||||
", EnableDynamicSkull:"+config.enableDynamicSkull+
|
||||
", EnableTranSkin:"+config.enableTransparentSkin+
|
||||
", IgnoreHttpsCertificate:"+config.ignoreHttpsCertificate+
|
||||
", CacheExpiry:"+config.cacheExpiry+
|
||||
", enableUpdateSkull:"+config.enableUpdateSkull+
|
||||
", LocalProfileCache:"+config.enableLocalProfileCache+
|
||||
", EnableUpdateSkull:"+config.enableUpdateSkull+
|
||||
", EnableLocalProfileCache:"+config.enableLocalProfileCache+
|
||||
", EnableCacheAutoClean:"+config.enableCacheAutoClean+
|
||||
", LoadList:"+(config.loadlist==null?0:config.loadlist.length));
|
||||
|
||||
//Check config version
|
||||
float floatVersion=0f;
|
||||
float configVersion=0f;
|
||||
try{
|
||||
@@ -54,6 +73,7 @@ public class Config {
|
||||
config.version=CustomSkinLoader.CustomSkinLoader_VERSION;
|
||||
writeConfig(config,true);
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ public class JsonAPILoader implements ProfileLoader.IProfileLoader {
|
||||
|
||||
public interface IJsonAPI {
|
||||
public String toJsonUrl(String root,String username);
|
||||
public String getPayload();
|
||||
public String getPayload(SkinSiteProfile ssp);
|
||||
public UserProfile toUserProfile(String root,String json,boolean local);
|
||||
public String getName();
|
||||
}
|
||||
@@ -32,7 +32,7 @@ public class JsonAPILoader implements ProfileLoader.IProfileLoader {
|
||||
public String msg;
|
||||
}
|
||||
public static enum Type{
|
||||
CustomSkinAPI(new CustomSkinAPI()),UniSkinAPI(new UniSkinAPI());
|
||||
CustomSkinAPI(new CustomSkinAPI()),CustomSkinAPIPlus(new CustomSkinAPIPlus()),UniSkinAPI(new UniSkinAPI());
|
||||
public IJsonAPI jsonAPI;
|
||||
private Type(IJsonAPI jsonAPI){
|
||||
this.jsonAPI=jsonAPI;
|
||||
@@ -62,7 +62,7 @@ public class JsonAPILoader implements ProfileLoader.IProfileLoader {
|
||||
}
|
||||
json=IOUtils.toString(new FileInputStream(jsonFile));
|
||||
}else{
|
||||
json=HttpUtil0.readHttp(jsonUrl,ssp.userAgent,type.jsonAPI.getPayload());
|
||||
json=HttpUtil0.readHttp(jsonUrl,ssp.userAgent,type.jsonAPI.getPayload(ssp));
|
||||
}
|
||||
if(json==null||json.equals("")){
|
||||
CustomSkinLoader.logger.info("Profile not found.");
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.util.Set;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import customskinloader.CustomSkinLoader;
|
||||
import customskinloader.config.SkinSiteProfile;
|
||||
import customskinloader.loader.JsonAPILoader.IJsonAPI;
|
||||
import customskinloader.profile.ModelManager0;
|
||||
import customskinloader.profile.ModelManager0.Model;
|
||||
@@ -80,7 +81,7 @@ public class CustomSkinAPI implements IJsonAPI {
|
||||
public String elytra;
|
||||
}
|
||||
@Override
|
||||
public String getPayload() {
|
||||
public String getPayload(SkinSiteProfile ssp) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package customskinloader.loader.jsonapi;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import customskinloader.CustomSkinLoader;
|
||||
import customskinloader.config.SkinSiteProfile;
|
||||
import customskinloader.loader.JsonAPILoader;
|
||||
import customskinloader.loader.JsonAPILoader.IJsonAPI;
|
||||
import customskinloader.profile.UserProfile;
|
||||
import customskinloader.utils.MinecraftUtil;
|
||||
|
||||
public class CustomSkinAPIPlus implements IJsonAPI {
|
||||
|
||||
@Override
|
||||
public String toJsonUrl(String root, String username) {
|
||||
return JsonAPILoader.Type.CustomSkinAPI.jsonAPI.toJsonUrl(root, username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPayload(SkinSiteProfile ssp) {
|
||||
return new Gson().toJson(new CustomSkinAPIPlusPayload());
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserProfile toUserProfile(String root, String json, boolean local) {
|
||||
return JsonAPILoader.Type.CustomSkinAPI.jsonAPI.toUserProfile(root, json, local);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "CustomSKinAPIPlus";
|
||||
}
|
||||
|
||||
public static class CustomSkinAPIPlusPayload{
|
||||
public static String gameVersion = MinecraftUtil.getMinecraftMainVersion();//minecraft version
|
||||
public static String modVersion = CustomSkinLoader.CustomSkinLoader_FULL_VERSION;//mod version
|
||||
public String serverAddress = MinecraftUtil.isLanServer()?null:MinecraftUtil.getServerAddress();//ip:port
|
||||
}
|
||||
public static class CustomSkinAPIPlusPrivacy{
|
||||
public static boolean gameVersion;
|
||||
public static boolean modVersion;
|
||||
public static boolean serverAddress;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import java.util.Map;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import customskinloader.CustomSkinLoader;
|
||||
import customskinloader.config.SkinSiteProfile;
|
||||
import customskinloader.loader.JsonAPILoader.IJsonAPI;
|
||||
import customskinloader.profile.ModelManager0;
|
||||
import customskinloader.profile.UserProfile;
|
||||
@@ -68,7 +69,7 @@ public class UniSkinAPI implements IJsonAPI {
|
||||
public String cape;
|
||||
}
|
||||
@Override
|
||||
public String getPayload() {
|
||||
public String getPayload(SkinSiteProfile ssp) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
|
||||
@@ -18,6 +18,13 @@ public class HttpTextureUtil {
|
||||
LOCAL_MARK="(LOCAL)",
|
||||
LOCAL_LEGACY_MARK="(LOCAL_LEGACY)";
|
||||
public static File defaultCacheDir;
|
||||
public static void initDefaultCacheDir(){
|
||||
if(CustomSkinLoader.config.enableCacheAutoClean && !CustomSkinLoader.config.enableLocalProfileCache && defaultCacheDir!=null){
|
||||
defaultCacheDir.delete();
|
||||
defaultCacheDir.mkdirs();
|
||||
}
|
||||
}
|
||||
|
||||
public static HttpTextureInfo toHttpTextureInfo(String fakeUrl){
|
||||
HttpTextureInfo info=new HttpTextureInfo();
|
||||
if(fakeUrl.startsWith("http")){
|
||||
|
||||
@@ -7,8 +7,16 @@ import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import org.apache.commons.io.Charsets;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
@@ -141,4 +149,30 @@ public class HttpUtil0 {
|
||||
public static boolean isLocal(String url){
|
||||
return url==null? false : !url.startsWith("http");
|
||||
}
|
||||
|
||||
//From: http://blog.csdn.net/xiyushiyi/article/details/46685387
|
||||
public static void ignoreHttpsCertificate(){
|
||||
HostnameVerifier doNotVerify = new HostnameVerifier() {
|
||||
|
||||
public boolean verify(String hostname, SSLSession session) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return new X509Certificate[] {};
|
||||
}
|
||||
public void checkClientTrusted(X509Certificate[] chain, String authType){}
|
||||
public void checkServerTrusted(X509Certificate[] chain, String authType){}
|
||||
}};
|
||||
|
||||
try {
|
||||
SSLContext sc = SSLContext.getInstance("TLS");
|
||||
sc.init(null, trustAllCerts, new java.security.SecureRandom());
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
||||
HttpsURLConnection.setDefaultHostnameVerifier(doNotVerify);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,6 +66,19 @@ public class MinecraftUtil {
|
||||
return minecraftMainVersion;
|
||||
}
|
||||
|
||||
public static String getServerAddress(){
|
||||
net.minecraft.client.multiplayer.ServerData data=net.minecraft.client.Minecraft.getMinecraft().getCurrentServerData();
|
||||
if(data==null)//Single Player
|
||||
return null;
|
||||
return data.serverIP;
|
||||
}
|
||||
public static boolean isLanServer(){
|
||||
net.minecraft.client.multiplayer.ServerData data=net.minecraft.client.Minecraft.getMinecraft().getCurrentServerData();
|
||||
if(data==null)//Single Player
|
||||
return true;
|
||||
return data.isOnLAN();
|
||||
}
|
||||
|
||||
private final static Pattern MINECRAFT_CORE_FILE_PATTERN = Pattern.compile("^(.*?)/versions/([^\\/\\\\]*?)/([^\\/\\\\]*?).jar$");
|
||||
private static void testProbe(){
|
||||
minecraftVersion.clear();
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
name=CustomSkinLoader
|
||||
group=customskinloader
|
||||
version=14.5
|
||||
version=14.6
|
||||
dev_version=
|
||||
#RELEASE: snapshot=0
|
||||
snapshot=0
|
||||
snapshot=1
|
||||
Reference in new issue
Block a user