From 46f0167f721475d9049aae87233ccbfb43b54fb1 Mon Sep 17 00:00:00 2001 From: Alexander Xia Date: Wed, 3 Feb 2016 14:51:15 +0800 Subject: [PATCH] Remove GUI --- .../idv/jlchntoz/CustomSkinLoader.java | 129 +++++++++--------- .../idv/jlchntoz/CustomSkinLoader.java | 129 +++++++++--------- .../idv/jlchntoz/CustomSkinLoader.java | 129 +++++++++--------- .../idv/jlchntoz/CustomSkinLoader.java | 129 +++++++++--------- README.md | 6 +- 5 files changed, 249 insertions(+), 273 deletions(-) diff --git a/1.6.4-mcp811/src/minecraft/idv/jlchntoz/CustomSkinLoader.java b/1.6.4-mcp811/src/minecraft/idv/jlchntoz/CustomSkinLoader.java index 6283362..e6716f3 100644 --- a/1.6.4-mcp811/src/minecraft/idv/jlchntoz/CustomSkinLoader.java +++ b/1.6.4-mcp811/src/minecraft/idv/jlchntoz/CustomSkinLoader.java @@ -13,16 +13,12 @@ import java.util.HashMap; import java.util.logging.*; import java.util.regex.*; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.reflect.TypeToken; - /** * Custom skin loader mod for Minecraft. * - * @version 12th Revision 7th Subversion 2015.8.22 + * @version 12th Revision 8th Subversion 2016.2.3 * - * @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014-2015 + * @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014-2016 */ public class CustomSkinLoader { public final static String VERSION="12.7"; @@ -37,9 +33,21 @@ public class CustomSkinLoader { public final static File DATA_DIR=new File(Minecraft.getMinecraft().mcDataDir,"CustomSkinLoader"), CACHE_DIR=new File(DATA_DIR,"caches"), - LOG_FILE=new File(DATA_DIR,"CustomSkinLoader.log"); + LOG_FILE=new File(DATA_DIR,"CustomSkinLoader.log"), + SKIN_URL_FILE=new File(DATA_DIR,"skinurls.txt"), + CAPE_URL_FILE=new File(DATA_DIR,"capeurls.txt"); public final static MainLogger logger = getLogger(LOG_FILE); + public final static String[] DEFAULT_SKIN_URLS={ + "http://skins.minecraft.net/MinecraftSkins/*.png", + "http://minecrack.fr.nf/mc/skinsminecrackd/*.png", + "http://www.skinme.cc/MinecraftSkins/*.png"}; + public final static String[] DEFAULT_CAPE_URLS={ + "http://skins.minecraft.net/MinecraftCloaks/*.png", + "http://s.optifine.net/capes/*.png", + "http://minecrack.fr.nf/mc/cloaksminecrackd/*.png", + "http://www.skinme.cc:88/MinecraftCloaks/*.png"}; + private static String[] cloakURLs = null, skinURLs = null; private HttpURLConnection C = null; @@ -50,6 +58,8 @@ public class CustomSkinLoader { if(!CACHE_DIR.exists()) CACHE_DIR.mkdir(); logger.info("Get a request: "+path); + if(path.contains("NOCSL"))//Not to use CSL to load, prepared for json api + return getStream(path, false); Matcher m = newURLPattern.matcher(path); if (!m.matches())//Is not new url { @@ -223,29 +233,41 @@ public class CustomSkinLoader { private static void refreshSkinURL() { try { - skinURLs = readAllLines(DATA_DIR, "skinurls.txt"); - cloakURLs = readAllLines(DATA_DIR, "capeurls.txt"); + if(!SKIN_URL_FILE.exists()){ + logger.log(Level.INFO, "SKIN config not found, create a new one."); + SKIN_URL_FILE.createNewFile(); + } + if(!CAPE_URL_FILE.exists()){ + logger.log(Level.INFO, "CAPE config not found, create a new one."); + CAPE_URL_FILE.createNewFile(); + } + skinURLs = readAllLines(SKIN_URL_FILE); + cloakURLs = readAllLines(CAPE_URL_FILE); } catch (Exception ex) { logger.log(Level.WARNING, ex.getMessage()); } finally { if(skinURLs.length==0&&cloakURLs.length==0){ - logger.info("No skinURLs and cloak URLS found, try to show GUI."); - showGUI(); + logger.info("No skinURLs and cloak URLS found, try to init and use default settings."); + initSkinURL(); + refreshSkinURL(); }else{ logger.log(Level.INFO, "Skin URLs Refreshed. Skin count = " + skinURLs.length + ", Cloak count = " + cloakURLs.length); } } } + private static void initSkinURL(){ + //TODO Init URL List + skinURLs=DEFAULT_SKIN_URLS; + writeToFile(new File(DATA_DIR,"skinurls.txt"),parseArrayToText(skinURLs)); + cloakURLs=DEFAULT_CAPE_URLS; + writeToFile(new File(DATA_DIR,"capeurls.txt"),parseArrayToText(cloakURLs)); + } - private static String[] readAllLines(File dir, String path) { + private static String[] readAllLines(File F) { try { - File F = new File(dir, path); logger.log(Level.INFO, "Config file: " + F.getAbsolutePath()); - if (!F.exists()) { - logger.log(Level.INFO, "Config file not found."); - return new String[0]; - } else if (F.length() <= 0) { + if (F.length() <= 0) { logger.log(Level.INFO, "Config file is blank, skipped."); return new String[0]; } else { @@ -258,9 +280,9 @@ public class CustomSkinLoader { String[] re= str_replace("\r", "\n", str_replace("\r\n", "\n", new String(b))).split("\n"); for(int i=0;i=System.currentTimeMillis()-10000){ - logger.info("'download.lck' found! Download will not start."); - return false; - } - LCK.createNewFile(); - logger.info("Downloading "+remote+" to "+local.getAbsolutePath()); - URL url = new URL(remote); - URLConnection conn = url.openConnection(); - InputStream inStream = conn.getInputStream(); - FileOutputStream fs = new FileOutputStream(local); - int byteRead = 0; - byte[] buffer = new byte[1024]; - while (( byteRead = inStream.read(buffer)) != -1) { - fs.write(buffer, 0, byteRead); - } - fs.close(); - LCK.delete(); - logger.info("Download successfully!"); - return local.exists(); - }catch (Exception e) { - logger.warning(e.getMessage()); + private static boolean writeToFile(File file,String Data){ + System.out.print("Write to "+file.getAbsolutePath()+" "); + FileWriter fw=null; + try{ + fw = new FileWriter(file); + fw.write(Data,0,Data.length()); + fw.flush(); + fw.close(); + }catch(Exception ex){ + ex.printStackTrace(); + System.out.println("failed."); return false; } + System.out.println("succeed."); + return true; } + public String MD5(String str){ byte [] buf = str.getBytes(); MessageDigest md5; @@ -356,6 +350,7 @@ public class CustomSkinLoader { } return "Fail"; } + private static MainLogger getLogger(File logFile){ MainLogger mainLogger = new MainLogger(logFile); mainLogger.info("CustomSkinLoader " + VERSION); diff --git a/1.7.10-mcp908/src/minecraft/idv/jlchntoz/CustomSkinLoader.java b/1.7.10-mcp908/src/minecraft/idv/jlchntoz/CustomSkinLoader.java index f9ebfab..c2370aa 100644 --- a/1.7.10-mcp908/src/minecraft/idv/jlchntoz/CustomSkinLoader.java +++ b/1.7.10-mcp908/src/minecraft/idv/jlchntoz/CustomSkinLoader.java @@ -13,16 +13,12 @@ import java.util.HashMap; import java.util.logging.*; import java.util.regex.*; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.reflect.TypeToken; - /** * Custom skin loader mod for Minecraft. * - * @version 12th Revision 7th Subversion 2015.8.22 + * @version 12th Revision 8th Subversion 2016.2.3 * - * @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014-2015 + * @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014-2016 */ public class CustomSkinLoader { public final static String VERSION="12.7"; @@ -37,9 +33,21 @@ public class CustomSkinLoader { public final static File DATA_DIR=new File(Minecraft.getMinecraft().mcDataDir,"CustomSkinLoader"), CACHE_DIR=new File(DATA_DIR,"caches"), - LOG_FILE=new File(DATA_DIR,"CustomSkinLoader.log"); + LOG_FILE=new File(DATA_DIR,"CustomSkinLoader.log"), + SKIN_URL_FILE=new File(DATA_DIR,"skinurls.txt"), + CAPE_URL_FILE=new File(DATA_DIR,"capeurls.txt"); public final static MainLogger logger = getLogger(LOG_FILE); + public final static String[] DEFAULT_SKIN_URLS={ + "http://skins.minecraft.net/MinecraftSkins/*.png", + "http://minecrack.fr.nf/mc/skinsminecrackd/*.png", + "http://www.skinme.cc/MinecraftSkins/*.png"}; + public final static String[] DEFAULT_CAPE_URLS={ + "http://skins.minecraft.net/MinecraftCloaks/*.png", + "http://s.optifine.net/capes/*.png", + "http://minecrack.fr.nf/mc/cloaksminecrackd/*.png", + "http://www.skinme.cc:88/MinecraftCloaks/*.png"}; + private static String[] cloakURLs = null, skinURLs = null; private HttpURLConnection C = null; @@ -50,6 +58,8 @@ public class CustomSkinLoader { if(!CACHE_DIR.exists()) CACHE_DIR.mkdir(); logger.info("Get a request: "+path); + if(path.contains("NOCSL"))//Not to use CSL to load, prepared for json api + return getStream(path, false); Matcher m = newURLPattern.matcher(path); if (!m.matches())//Is not new url { @@ -223,29 +233,41 @@ public class CustomSkinLoader { private static void refreshSkinURL() { try { - skinURLs = readAllLines(DATA_DIR, "skinurls.txt"); - cloakURLs = readAllLines(DATA_DIR, "capeurls.txt"); + if(!SKIN_URL_FILE.exists()){ + logger.log(Level.INFO, "SKIN config not found, create a new one."); + SKIN_URL_FILE.createNewFile(); + } + if(!CAPE_URL_FILE.exists()){ + logger.log(Level.INFO, "CAPE config not found, create a new one."); + CAPE_URL_FILE.createNewFile(); + } + skinURLs = readAllLines(SKIN_URL_FILE); + cloakURLs = readAllLines(CAPE_URL_FILE); } catch (Exception ex) { logger.log(Level.WARNING, ex.getMessage()); } finally { if(skinURLs.length==0&&cloakURLs.length==0){ - logger.info("No skinURLs and cloak URLS found, try to show GUI."); - showGUI(); + logger.info("No skinURLs and cloak URLS found, try to init and use default settings."); + initSkinURL(); + refreshSkinURL(); }else{ logger.log(Level.INFO, "Skin URLs Refreshed. Skin count = " + skinURLs.length + ", Cloak count = " + cloakURLs.length); } } } + private static void initSkinURL(){ + //TODO Init URL List + skinURLs=DEFAULT_SKIN_URLS; + writeToFile(new File(DATA_DIR,"skinurls.txt"),parseArrayToText(skinURLs)); + cloakURLs=DEFAULT_CAPE_URLS; + writeToFile(new File(DATA_DIR,"capeurls.txt"),parseArrayToText(cloakURLs)); + } - private static String[] readAllLines(File dir, String path) { + private static String[] readAllLines(File F) { try { - File F = new File(dir, path); logger.log(Level.INFO, "Config file: " + F.getAbsolutePath()); - if (!F.exists()) { - logger.log(Level.INFO, "Config file not found."); - return new String[0]; - } else if (F.length() <= 0) { + if (F.length() <= 0) { logger.log(Level.INFO, "Config file is blank, skipped."); return new String[0]; } else { @@ -258,9 +280,9 @@ public class CustomSkinLoader { String[] re= str_replace("\r", "\n", str_replace("\r\n", "\n", new String(b))).split("\n"); for(int i=0;i=System.currentTimeMillis()-10000){ - logger.info("'download.lck' found! Download will not start."); - return false; - } - LCK.createNewFile(); - logger.info("Downloading "+remote+" to "+local.getAbsolutePath()); - URL url = new URL(remote); - URLConnection conn = url.openConnection(); - InputStream inStream = conn.getInputStream(); - FileOutputStream fs = new FileOutputStream(local); - int byteRead = 0; - byte[] buffer = new byte[1024]; - while (( byteRead = inStream.read(buffer)) != -1) { - fs.write(buffer, 0, byteRead); - } - fs.close(); - LCK.delete(); - logger.info("Download successfully!"); - return local.exists(); - }catch (Exception e) { - logger.warning(e.getMessage()); + private static boolean writeToFile(File file,String Data){ + System.out.print("Write to "+file.getAbsolutePath()+" "); + FileWriter fw=null; + try{ + fw = new FileWriter(file); + fw.write(Data,0,Data.length()); + fw.flush(); + fw.close(); + }catch(Exception ex){ + ex.printStackTrace(); + System.out.println("failed."); return false; } + System.out.println("succeed."); + return true; } + public String MD5(String str){ byte [] buf = str.getBytes(); MessageDigest md5; @@ -356,6 +350,7 @@ public class CustomSkinLoader { } return "Fail"; } + private static MainLogger getLogger(File logFile){ MainLogger mainLogger = new MainLogger(logFile); mainLogger.info("CustomSkinLoader " + VERSION); diff --git a/1.7.2-mcp903/src/minecraft/idv/jlchntoz/CustomSkinLoader.java b/1.7.2-mcp903/src/minecraft/idv/jlchntoz/CustomSkinLoader.java index f9ebfab..c2370aa 100644 --- a/1.7.2-mcp903/src/minecraft/idv/jlchntoz/CustomSkinLoader.java +++ b/1.7.2-mcp903/src/minecraft/idv/jlchntoz/CustomSkinLoader.java @@ -13,16 +13,12 @@ import java.util.HashMap; import java.util.logging.*; import java.util.regex.*; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.reflect.TypeToken; - /** * Custom skin loader mod for Minecraft. * - * @version 12th Revision 7th Subversion 2015.8.22 + * @version 12th Revision 8th Subversion 2016.2.3 * - * @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014-2015 + * @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014-2016 */ public class CustomSkinLoader { public final static String VERSION="12.7"; @@ -37,9 +33,21 @@ public class CustomSkinLoader { public final static File DATA_DIR=new File(Minecraft.getMinecraft().mcDataDir,"CustomSkinLoader"), CACHE_DIR=new File(DATA_DIR,"caches"), - LOG_FILE=new File(DATA_DIR,"CustomSkinLoader.log"); + LOG_FILE=new File(DATA_DIR,"CustomSkinLoader.log"), + SKIN_URL_FILE=new File(DATA_DIR,"skinurls.txt"), + CAPE_URL_FILE=new File(DATA_DIR,"capeurls.txt"); public final static MainLogger logger = getLogger(LOG_FILE); + public final static String[] DEFAULT_SKIN_URLS={ + "http://skins.minecraft.net/MinecraftSkins/*.png", + "http://minecrack.fr.nf/mc/skinsminecrackd/*.png", + "http://www.skinme.cc/MinecraftSkins/*.png"}; + public final static String[] DEFAULT_CAPE_URLS={ + "http://skins.minecraft.net/MinecraftCloaks/*.png", + "http://s.optifine.net/capes/*.png", + "http://minecrack.fr.nf/mc/cloaksminecrackd/*.png", + "http://www.skinme.cc:88/MinecraftCloaks/*.png"}; + private static String[] cloakURLs = null, skinURLs = null; private HttpURLConnection C = null; @@ -50,6 +58,8 @@ public class CustomSkinLoader { if(!CACHE_DIR.exists()) CACHE_DIR.mkdir(); logger.info("Get a request: "+path); + if(path.contains("NOCSL"))//Not to use CSL to load, prepared for json api + return getStream(path, false); Matcher m = newURLPattern.matcher(path); if (!m.matches())//Is not new url { @@ -223,29 +233,41 @@ public class CustomSkinLoader { private static void refreshSkinURL() { try { - skinURLs = readAllLines(DATA_DIR, "skinurls.txt"); - cloakURLs = readAllLines(DATA_DIR, "capeurls.txt"); + if(!SKIN_URL_FILE.exists()){ + logger.log(Level.INFO, "SKIN config not found, create a new one."); + SKIN_URL_FILE.createNewFile(); + } + if(!CAPE_URL_FILE.exists()){ + logger.log(Level.INFO, "CAPE config not found, create a new one."); + CAPE_URL_FILE.createNewFile(); + } + skinURLs = readAllLines(SKIN_URL_FILE); + cloakURLs = readAllLines(CAPE_URL_FILE); } catch (Exception ex) { logger.log(Level.WARNING, ex.getMessage()); } finally { if(skinURLs.length==0&&cloakURLs.length==0){ - logger.info("No skinURLs and cloak URLS found, try to show GUI."); - showGUI(); + logger.info("No skinURLs and cloak URLS found, try to init and use default settings."); + initSkinURL(); + refreshSkinURL(); }else{ logger.log(Level.INFO, "Skin URLs Refreshed. Skin count = " + skinURLs.length + ", Cloak count = " + cloakURLs.length); } } } + private static void initSkinURL(){ + //TODO Init URL List + skinURLs=DEFAULT_SKIN_URLS; + writeToFile(new File(DATA_DIR,"skinurls.txt"),parseArrayToText(skinURLs)); + cloakURLs=DEFAULT_CAPE_URLS; + writeToFile(new File(DATA_DIR,"capeurls.txt"),parseArrayToText(cloakURLs)); + } - private static String[] readAllLines(File dir, String path) { + private static String[] readAllLines(File F) { try { - File F = new File(dir, path); logger.log(Level.INFO, "Config file: " + F.getAbsolutePath()); - if (!F.exists()) { - logger.log(Level.INFO, "Config file not found."); - return new String[0]; - } else if (F.length() <= 0) { + if (F.length() <= 0) { logger.log(Level.INFO, "Config file is blank, skipped."); return new String[0]; } else { @@ -258,9 +280,9 @@ public class CustomSkinLoader { String[] re= str_replace("\r", "\n", str_replace("\r\n", "\n", new String(b))).split("\n"); for(int i=0;i=System.currentTimeMillis()-10000){ - logger.info("'download.lck' found! Download will not start."); - return false; - } - LCK.createNewFile(); - logger.info("Downloading "+remote+" to "+local.getAbsolutePath()); - URL url = new URL(remote); - URLConnection conn = url.openConnection(); - InputStream inStream = conn.getInputStream(); - FileOutputStream fs = new FileOutputStream(local); - int byteRead = 0; - byte[] buffer = new byte[1024]; - while (( byteRead = inStream.read(buffer)) != -1) { - fs.write(buffer, 0, byteRead); - } - fs.close(); - LCK.delete(); - logger.info("Download successfully!"); - return local.exists(); - }catch (Exception e) { - logger.warning(e.getMessage()); + private static boolean writeToFile(File file,String Data){ + System.out.print("Write to "+file.getAbsolutePath()+" "); + FileWriter fw=null; + try{ + fw = new FileWriter(file); + fw.write(Data,0,Data.length()); + fw.flush(); + fw.close(); + }catch(Exception ex){ + ex.printStackTrace(); + System.out.println("failed."); return false; } + System.out.println("succeed."); + return true; } + public String MD5(String str){ byte [] buf = str.getBytes(); MessageDigest md5; @@ -356,6 +350,7 @@ public class CustomSkinLoader { } return "Fail"; } + private static MainLogger getLogger(File logFile){ MainLogger mainLogger = new MainLogger(logFile); mainLogger.info("CustomSkinLoader " + VERSION); diff --git a/1.8-mcp910/src/minecraft/idv/jlchntoz/CustomSkinLoader.java b/1.8-mcp910/src/minecraft/idv/jlchntoz/CustomSkinLoader.java index f9ebfab..c2370aa 100644 --- a/1.8-mcp910/src/minecraft/idv/jlchntoz/CustomSkinLoader.java +++ b/1.8-mcp910/src/minecraft/idv/jlchntoz/CustomSkinLoader.java @@ -13,16 +13,12 @@ import java.util.HashMap; import java.util.logging.*; import java.util.regex.*; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.reflect.TypeToken; - /** * Custom skin loader mod for Minecraft. * - * @version 12th Revision 7th Subversion 2015.8.22 + * @version 12th Revision 8th Subversion 2016.2.3 * - * @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014-2015 + * @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014-2016 */ public class CustomSkinLoader { public final static String VERSION="12.7"; @@ -37,9 +33,21 @@ public class CustomSkinLoader { public final static File DATA_DIR=new File(Minecraft.getMinecraft().mcDataDir,"CustomSkinLoader"), CACHE_DIR=new File(DATA_DIR,"caches"), - LOG_FILE=new File(DATA_DIR,"CustomSkinLoader.log"); + LOG_FILE=new File(DATA_DIR,"CustomSkinLoader.log"), + SKIN_URL_FILE=new File(DATA_DIR,"skinurls.txt"), + CAPE_URL_FILE=new File(DATA_DIR,"capeurls.txt"); public final static MainLogger logger = getLogger(LOG_FILE); + public final static String[] DEFAULT_SKIN_URLS={ + "http://skins.minecraft.net/MinecraftSkins/*.png", + "http://minecrack.fr.nf/mc/skinsminecrackd/*.png", + "http://www.skinme.cc/MinecraftSkins/*.png"}; + public final static String[] DEFAULT_CAPE_URLS={ + "http://skins.minecraft.net/MinecraftCloaks/*.png", + "http://s.optifine.net/capes/*.png", + "http://minecrack.fr.nf/mc/cloaksminecrackd/*.png", + "http://www.skinme.cc:88/MinecraftCloaks/*.png"}; + private static String[] cloakURLs = null, skinURLs = null; private HttpURLConnection C = null; @@ -50,6 +58,8 @@ public class CustomSkinLoader { if(!CACHE_DIR.exists()) CACHE_DIR.mkdir(); logger.info("Get a request: "+path); + if(path.contains("NOCSL"))//Not to use CSL to load, prepared for json api + return getStream(path, false); Matcher m = newURLPattern.matcher(path); if (!m.matches())//Is not new url { @@ -223,29 +233,41 @@ public class CustomSkinLoader { private static void refreshSkinURL() { try { - skinURLs = readAllLines(DATA_DIR, "skinurls.txt"); - cloakURLs = readAllLines(DATA_DIR, "capeurls.txt"); + if(!SKIN_URL_FILE.exists()){ + logger.log(Level.INFO, "SKIN config not found, create a new one."); + SKIN_URL_FILE.createNewFile(); + } + if(!CAPE_URL_FILE.exists()){ + logger.log(Level.INFO, "CAPE config not found, create a new one."); + CAPE_URL_FILE.createNewFile(); + } + skinURLs = readAllLines(SKIN_URL_FILE); + cloakURLs = readAllLines(CAPE_URL_FILE); } catch (Exception ex) { logger.log(Level.WARNING, ex.getMessage()); } finally { if(skinURLs.length==0&&cloakURLs.length==0){ - logger.info("No skinURLs and cloak URLS found, try to show GUI."); - showGUI(); + logger.info("No skinURLs and cloak URLS found, try to init and use default settings."); + initSkinURL(); + refreshSkinURL(); }else{ logger.log(Level.INFO, "Skin URLs Refreshed. Skin count = " + skinURLs.length + ", Cloak count = " + cloakURLs.length); } } } + private static void initSkinURL(){ + //TODO Init URL List + skinURLs=DEFAULT_SKIN_URLS; + writeToFile(new File(DATA_DIR,"skinurls.txt"),parseArrayToText(skinURLs)); + cloakURLs=DEFAULT_CAPE_URLS; + writeToFile(new File(DATA_DIR,"capeurls.txt"),parseArrayToText(cloakURLs)); + } - private static String[] readAllLines(File dir, String path) { + private static String[] readAllLines(File F) { try { - File F = new File(dir, path); logger.log(Level.INFO, "Config file: " + F.getAbsolutePath()); - if (!F.exists()) { - logger.log(Level.INFO, "Config file not found."); - return new String[0]; - } else if (F.length() <= 0) { + if (F.length() <= 0) { logger.log(Level.INFO, "Config file is blank, skipped."); return new String[0]; } else { @@ -258,9 +280,9 @@ public class CustomSkinLoader { String[] re= str_replace("\r", "\n", str_replace("\r\n", "\n", new String(b))).split("\n"); for(int i=0;i=System.currentTimeMillis()-10000){ - logger.info("'download.lck' found! Download will not start."); - return false; - } - LCK.createNewFile(); - logger.info("Downloading "+remote+" to "+local.getAbsolutePath()); - URL url = new URL(remote); - URLConnection conn = url.openConnection(); - InputStream inStream = conn.getInputStream(); - FileOutputStream fs = new FileOutputStream(local); - int byteRead = 0; - byte[] buffer = new byte[1024]; - while (( byteRead = inStream.read(buffer)) != -1) { - fs.write(buffer, 0, byteRead); - } - fs.close(); - LCK.delete(); - logger.info("Download successfully!"); - return local.exists(); - }catch (Exception e) { - logger.warning(e.getMessage()); + private static boolean writeToFile(File file,String Data){ + System.out.print("Write to "+file.getAbsolutePath()+" "); + FileWriter fw=null; + try{ + fw = new FileWriter(file); + fw.write(Data,0,Data.length()); + fw.flush(); + fw.close(); + }catch(Exception ex){ + ex.printStackTrace(); + System.out.println("failed."); return false; } + System.out.println("succeed."); + return true; } + public String MD5(String str){ byte [] buf = str.getBytes(); MessageDigest md5; @@ -356,6 +350,7 @@ public class CustomSkinLoader { } return "Fail"; } + private static MainLogger getLogger(File logFile){ MainLogger mainLogger = new MainLogger(logFile); mainLogger.info("CustomSkinLoader " + VERSION); diff --git a/README.md b/README.md index 3face87..c923c87 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ MCCustomSkinLoader ================== -/* - 版权所有(C) 2013-2014 JLChnToZ xfl03 这一程序是自由软件,你可以遵照自由软件基金会出版的GNU通用公共许可证条款来修改和重新发布这一程序。或者用许可证的第三版,或者(根据你的选择)用任何更新的版本。 @@ -16,6 +14,4 @@ Copyright(C) 2013-2014 JLChnToZ xfl03 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -http://www.gnu.org/licenses/gpl.html - -*/ +GPLv3: http://www.gnu.org/licenses/gpl.html