mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-28 03:15:47 +00:00
Auto create local skin folder
This commit is contained in:
1 parent
9a85d18f22
commit
7cf42be31c
11 files changed
+112
-49
No files matched your search
@@ -118,7 +118,7 @@ public class SkinManager
|
||||
{
|
||||
final Map<Type, MinecraftProfileTexture> map = Maps.<Type, MinecraftProfileTexture>newHashMap();
|
||||
|
||||
//CustomSkinLoader Begin (User Skin/Cape Part)
|
||||
//CustomSkinLoader Begin (User Profile Part)
|
||||
if(customskinloader.CustomSkinLoader.config.enable){
|
||||
map.putAll(customskinloader.CustomSkinLoader.loadProfile(profile));
|
||||
}else{
|
||||
@@ -132,15 +132,12 @@ public class SkinManager
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
if (map.containsKey(Type.SKIN))
|
||||
{
|
||||
SkinManager.this.loadSkin((MinecraftProfileTexture)map.get(Type.SKIN), Type.SKIN, skinAvailableCallback);
|
||||
}
|
||||
|
||||
if (map.containsKey(Type.CAPE))
|
||||
{
|
||||
SkinManager.this.loadSkin((MinecraftProfileTexture)map.get(Type.CAPE), Type.CAPE, skinAvailableCallback);
|
||||
//CustomSkinLoader Begin (Loading Task)
|
||||
for(Type type:Type.values()){
|
||||
if(map.containsKey(type))
|
||||
SkinManager.this.loadSkin((MinecraftProfileTexture)map.get(type), type, skinAvailableCallback);
|
||||
}
|
||||
//CustomSkinLoader End
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public class SkinManager
|
||||
{
|
||||
final Map<Type, MinecraftProfileTexture> map = Maps.<Type, MinecraftProfileTexture>newHashMap();
|
||||
|
||||
//CustomSkinLoader Begin (User Skin/Cape Part)
|
||||
//CustomSkinLoader Begin (User Profile Part)
|
||||
if(customskinloader.CustomSkinLoader.config.enable){
|
||||
map.putAll(customskinloader.CustomSkinLoader.loadProfile(profile));
|
||||
}else{
|
||||
@@ -132,15 +132,12 @@ public class SkinManager
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
if (map.containsKey(Type.SKIN))
|
||||
{
|
||||
SkinManager.this.loadSkin((MinecraftProfileTexture)map.get(Type.SKIN), Type.SKIN, skinAvailableCallback);
|
||||
}
|
||||
|
||||
if (map.containsKey(Type.CAPE))
|
||||
{
|
||||
SkinManager.this.loadSkin((MinecraftProfileTexture)map.get(Type.CAPE), Type.CAPE, skinAvailableCallback);
|
||||
//CustomSkinLoader Begin (Loading Task)
|
||||
for(Type type:Type.values()){
|
||||
if(map.containsKey(type))
|
||||
SkinManager.this.loadSkin((MinecraftProfileTexture)map.get(type), type, skinAvailableCallback);
|
||||
}
|
||||
//CustomSkinLoader End
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public class SkinManager
|
||||
{
|
||||
final Map<Type, MinecraftProfileTexture> map = Maps.<Type, MinecraftProfileTexture>newHashMap();
|
||||
|
||||
//CustomSkinLoader Begin (User Skin/Cape Part)
|
||||
//CustomSkinLoader Begin (User Profile Part)
|
||||
if(customskinloader.CustomSkinLoader.config.enable){
|
||||
map.putAll(customskinloader.CustomSkinLoader.loadProfile(profile));
|
||||
}else{
|
||||
@@ -132,15 +132,12 @@ public class SkinManager
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
if (map.containsKey(Type.SKIN))
|
||||
{
|
||||
SkinManager.this.loadSkin((MinecraftProfileTexture)map.get(Type.SKIN), Type.SKIN, skinAvailableCallback);
|
||||
}
|
||||
|
||||
if (map.containsKey(Type.CAPE))
|
||||
{
|
||||
SkinManager.this.loadSkin((MinecraftProfileTexture)map.get(Type.CAPE), Type.CAPE, skinAvailableCallback);
|
||||
//CustomSkinLoader Begin (Loading Task)
|
||||
for(Type type:Type.values()){
|
||||
if(map.containsKey(type))
|
||||
SkinManager.this.loadSkin((MinecraftProfileTexture)map.get(type), type, skinAvailableCallback);
|
||||
}
|
||||
//CustomSkinLoader End
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ public class CustomSkinLoader {
|
||||
Logger logger=new Logger(LOG_FILE);
|
||||
logger.info("CustomSkinLoader "+CustomSkinLoader_FULL_VERSION);
|
||||
logger.info("DataDir: "+DATA_DIR.getAbsolutePath());
|
||||
logger.info("Minecraft: "+MinecraftUtil.getMinecraftVersion());
|
||||
logger.info("Minecraft: "+MinecraftUtil.getMinecraftMainVersion()+"("+MinecraftUtil.getMinecraftVersionText()+")");
|
||||
return logger;
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ public class Config {
|
||||
public static Config loadConfig0() {
|
||||
Config config=loadConfig();
|
||||
config.loadExtraList();
|
||||
config.initLocalFolder();
|
||||
CustomSkinLoader.logger.info("Enable:"+config.enable+
|
||||
", EnableSkull:"+config.enableSkull+
|
||||
", EnableTranSkin:"+config.enableTransparentSkin+
|
||||
@@ -40,12 +41,14 @@ public class Config {
|
||||
", LocalProfileCache:"+config.enableLocalProfileCache+
|
||||
", LoadList:"+(config.loadlist==null?0:config.loadlist.length));
|
||||
float floatVersion=0f;
|
||||
float configVersion=0f;
|
||||
try{
|
||||
floatVersion=Float.parseFloat(CustomSkinLoader.CustomSkinLoader_VERSION);
|
||||
configVersion=Float.parseFloat(config.version);
|
||||
}catch (Exception e){
|
||||
CustomSkinLoader.logger.warning("Exception occurs while parsing version: "+e.toString());
|
||||
}
|
||||
if(config.version==null||floatVersion-Float.parseFloat(config.version)>0.01){
|
||||
if(config.version==null||floatVersion < configVersion){
|
||||
CustomSkinLoader.logger.info("Config File is out of date: "+config.version);
|
||||
config.version=CustomSkinLoader.CustomSkinLoader_VERSION;
|
||||
writeConfig(config,true);
|
||||
@@ -121,6 +124,15 @@ public class Config {
|
||||
writeConfig(this,true);
|
||||
}
|
||||
}
|
||||
|
||||
private void initLocalFolder(){
|
||||
for(SkinSiteProfile ssp:this.loadlist){
|
||||
ProfileLoader.IProfileLoader loader=ProfileLoader.LOADERS.get(ssp.type.toLowerCase());
|
||||
if(loader==null)
|
||||
continue;
|
||||
loader.initLocalFolder(ssp);
|
||||
}
|
||||
}
|
||||
|
||||
private static Config initConfig() {
|
||||
Config config=new Config(CustomSkinLoader.DEFAULT_LOAD_LIST);
|
||||
|
||||
@@ -77,4 +77,12 @@ public class JsonAPILoader implements ProfileLoader.IProfileLoader {
|
||||
public String getName() {
|
||||
return type.jsonAPI.getName();
|
||||
}
|
||||
@Override
|
||||
public void initLocalFolder(SkinSiteProfile ssp) {
|
||||
if(HttpUtil0.isLocal(ssp.root)){
|
||||
File f=new File(ssp.root);
|
||||
if(!f.exists())
|
||||
f.mkdirs();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,4 +72,20 @@ public class LegacyLoader implements ProfileLoader.IProfileLoader {
|
||||
public String getName() {
|
||||
return "Legacy";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initLocalFolder(SkinSiteProfile ssp) {
|
||||
if(HttpUtil0.isLocal(ssp.skin))
|
||||
initFolder(ssp.skin);
|
||||
if(HttpUtil0.isLocal(ssp.cape))
|
||||
initFolder(ssp.cape);
|
||||
if(HttpUtil0.isLocal(ssp.elytra))
|
||||
initFolder(ssp.elytra);
|
||||
}
|
||||
private void initFolder(String target){
|
||||
String file=target.replaceAll(USERNAME_REGEX, "init");
|
||||
File folder=new File(CustomSkinLoader.DATA_DIR,file).getParentFile();
|
||||
if(folder!=null&&!folder.exists())
|
||||
folder.mkdirs();
|
||||
}
|
||||
}
|
||||
@@ -91,4 +91,8 @@ public class MojangAPILoader implements ProfileLoader.IProfileLoader {
|
||||
public String getName() {
|
||||
return "MojangAPI";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initLocalFolder(SkinSiteProfile ssp) {
|
||||
}
|
||||
}
|
||||
@@ -28,5 +28,6 @@ public class ProfileLoader {
|
||||
public UserProfile loadProfile(SkinSiteProfile ssp,GameProfile gameProfile) throws Exception;
|
||||
public boolean compare(SkinSiteProfile ssp0,SkinSiteProfile ssp1);
|
||||
public String getName();
|
||||
public void initLocalFolder(SkinSiteProfile ssp);
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,10 @@ public class ClassTransformer implements IClassTransformer {
|
||||
ModSystemTweaker.logger.info(url.toString()+" : SKIP (core file).");
|
||||
continue;
|
||||
}
|
||||
if(MinecraftUtil.isLibraryFile(url)){
|
||||
ModSystemTweaker.logger.info(url.toString()+" : SKIP (library file).");
|
||||
continue;
|
||||
}
|
||||
File file = new File(url.toURI());
|
||||
if(file==null||!file.isFile()){
|
||||
ModSystemTweaker.logger.info(url.toString()+" : EXCEPTION (file not found).");
|
||||
|
||||
@@ -4,9 +4,12 @@ import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* MinecraftUtil for mcp version.
|
||||
* It is the only class in package 'customskinloader' which has differences in mcp/non-mcp version.
|
||||
@@ -21,32 +24,51 @@ public class MinecraftUtil {
|
||||
}
|
||||
|
||||
public static File minecraftDataFolder=null;
|
||||
private static final String MINECRAFT_DATA_FOLDER=".minecraft";
|
||||
public static File getMinecraftDataDir(){
|
||||
if(minecraftDataFolder!=null)
|
||||
return minecraftDataFolder;
|
||||
testProbe();
|
||||
if(minecraftDataFolder!=null)
|
||||
return minecraftDataFolder;
|
||||
File temp=new File("");
|
||||
if(temp.getAbsolutePath().endsWith(MINECRAFT_DATA_FOLDER))
|
||||
return temp;
|
||||
File temp0=new File(MINECRAFT_DATA_FOLDER);
|
||||
if(temp0.exists())
|
||||
return temp0;
|
||||
return temp;
|
||||
return new File("");
|
||||
}
|
||||
|
||||
private static String minecraftVersion=null;
|
||||
public static String getMinecraftVersion(){
|
||||
if(minecraftVersion!=null)
|
||||
private static ArrayList<String> minecraftVersion=new ArrayList<String>();
|
||||
private static String minecraftMainVersion=null;
|
||||
private final static Pattern MINECRAFT_VERSION_PATTERN = Pattern.compile("(\\d+\\.\\d+[\\.]?\\d*)");
|
||||
public static ArrayList<String> getMinecraftVersions(){
|
||||
if(minecraftVersion!=null&&!minecraftVersion.isEmpty())
|
||||
return minecraftVersion;
|
||||
testProbe();
|
||||
return minecraftVersion;
|
||||
}
|
||||
public static String getMinecraftVersionText(){
|
||||
StringBuilder sb=new StringBuilder();
|
||||
for(String version:getMinecraftVersions())
|
||||
sb.append(version).append(" ");
|
||||
return StringUtils.trim(sb.toString());
|
||||
}
|
||||
public static String getMinecraftMainVersion(){
|
||||
if(minecraftMainVersion!=null)
|
||||
return minecraftMainVersion;
|
||||
for(String version:getMinecraftVersions()){
|
||||
Matcher m = null;
|
||||
try{
|
||||
m=MINECRAFT_VERSION_PATTERN.matcher(version);
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(m==null || !m.matches())
|
||||
continue;
|
||||
minecraftMainVersion=m.group(0);
|
||||
break;
|
||||
}
|
||||
return minecraftMainVersion;
|
||||
}
|
||||
|
||||
private final static Pattern MINECRAFT_CORE_FILE_PATTERN = Pattern.compile("^(.*?)/versions/([^\\/\\\\]*?)/([^\\/\\\\]*?).jar$");
|
||||
private static void testProbe(){
|
||||
minecraftVersion.clear();
|
||||
URLClassLoader ucl = (URLClassLoader)new MinecraftUtil().getClass().getClassLoader();
|
||||
URL urls[] = ucl.getURLs();
|
||||
for(URL url:urls){
|
||||
@@ -56,16 +78,11 @@ public class MinecraftUtil {
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(m==null)
|
||||
continue;
|
||||
if(!m.matches())
|
||||
if(m==null || !m.matches())
|
||||
continue;
|
||||
if(minecraftDataFolder==null)
|
||||
minecraftDataFolder=new File(m.group(1));
|
||||
//System.out.println(url.getPath()+" "+minecraftDataFolder.getAbsolutePath());
|
||||
if(minecraftVersion==null)
|
||||
minecraftVersion=m.group(2);
|
||||
break;
|
||||
minecraftVersion.add(m.group(2));
|
||||
}
|
||||
}
|
||||
public static boolean isCoreFile(URL url){
|
||||
@@ -76,8 +93,18 @@ public class MinecraftUtil {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
if(m==null)
|
||||
return m!=null && m.matches();
|
||||
}
|
||||
|
||||
private final static Pattern LIBRARY_FILE_PATTERN = Pattern.compile("^(.*?)/libraries/(.*?)/([^\\/\\\\]*?).jar$");
|
||||
public static boolean isLibraryFile(URL url){
|
||||
Matcher m = null;
|
||||
try{
|
||||
m=LIBRARY_FILE_PATTERN.matcher(URLDecoder.decode(url.getPath(),"UTF-8"));
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
return m.matches();
|
||||
}
|
||||
return m!=null && m.matches();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user