From 005589955c01bb0a6da44e95b85e7dc68dfc36d5 Mon Sep 17 00:00:00 2001 From: huangyuhui Date: Sat, 23 Jan 2016 19:49:12 +0800 Subject: [PATCH] modpack update --- .../core/launch/DefaultGameLauncher.java | 2 +- .../launcher/core/mod/ModpackManager.java | 18 +++++++- .../utils/system/Compressor.java | 45 ++----------------- .../hellominecraft/launcher/I18N.properties | 2 +- .../launcher/I18N_en.properties | 2 +- .../launcher/I18N_zh.properties | 2 +- .../launcher/I18N_zh_CN.properties | 2 +- 7 files changed, 26 insertions(+), 47 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/launch/DefaultGameLauncher.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/launch/DefaultGameLauncher.java index 8ce6ee03f..c61fbf5c9 100755 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/launch/DefaultGameLauncher.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/launch/DefaultGameLauncher.java @@ -57,7 +57,7 @@ public class DefaultGameLauncher extends GameLauncher { for (int i = 0; i < value.decompressFiles.length; i++) try { String[] rules = value.extractRules[i]; - Compressor.unzip(value.decompressFiles[i], value.decompressTo, t -> !StrUtils.startsWithOne(rules, t)); + Compressor.unzip(value.decompressFiles[i], value.decompressTo, t -> !StrUtils.startsWithOne(rules, t), false); } catch (IOException ex) { HMCLog.err("Unable to decompress library file: " + value.decompressFiles[i] + " to " + value.decompressTo, ex); } diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/mod/ModpackManager.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/mod/ModpackManager.java index 83faab522..b7caec4b6 100644 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/mod/ModpackManager.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/mod/ModpackManager.java @@ -69,6 +69,14 @@ public final class ModpackManager { oldFile.renameTo(newFile); } + File preVersion = new File(versions, id), preVersionRenamed = null; + if (preVersion.exists()) { + String preId = id + "-" + System.currentTimeMillis(); + preVersion.renameTo(preVersionRenamed = new File(versions, preId)); + new File(preVersionRenamed, id + ".json").renameTo(new File(preVersionRenamed, preId + ".json")); + new File(preVersionRenamed, id + ".jar").renameTo(new File(preVersionRenamed, preId + ".jar")); + } + try { AtomicInteger b = new AtomicInteger(0); HMCLog.log("Decompressing modpack"); @@ -76,7 +84,7 @@ public final class ModpackManager { if (t.equals("minecraft/pack.json")) b.incrementAndGet(); return true; - }); + }, true); if (b.get() < 1) throw new FileNotFoundException(C.i18n("modpack.incorrect_format.no_json")); File nowFile = new File(versions, id); @@ -91,6 +99,14 @@ public final class ModpackManager { FileUtils.writeStringToFile(json, C.gsonPrettyPrinting.toJson(mv)); json.renameTo(new File(nowFile, id + ".json")); + if (preVersionRenamed != null) { + File presaves = new File(preVersionRenamed, "saves"); + File saves = new File(nowFile, "saves"); + if (presaves.exists()) { + FileUtils.deleteDirectory(saves); + FileUtils.copyDirectory(presaves, saves); + } + } } finally { FileUtils.deleteDirectoryQuietly(oldFile); if (newFile != null) diff --git a/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/system/Compressor.java b/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/system/Compressor.java index ed8e4741d..bb1b4646c 100755 --- a/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/system/Compressor.java +++ b/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/system/Compressor.java @@ -140,7 +140,7 @@ public class Compressor { } public static void unzip(File zipFileName, File extPlace) throws IOException { - unzip(zipFileName, extPlace, null); + unzip(zipFileName, extPlace, null, true); } /** @@ -153,7 +153,7 @@ public class Compressor { * * @throws java.io.IOException 解压失败或无法写入 */ - public static void unzip(File zipFileName, File extPlace, Predicate callback) throws IOException { + public static void unzip(File zipFileName, File extPlace, Predicate callback, boolean ignoreExistsFile) throws IOException { extPlace.mkdirs(); try (ZipInputStream zipFile = new ZipInputStream(new FileInputStream(zipFileName))) { if (zipFileName.exists()) { @@ -182,6 +182,8 @@ public class Compressor { if (!subdir.exists()) subdir.mkdir(); } + if (ignoreExistsFile && new File(strtemp).exists()) + continue; try (FileOutputStream fos = new FileOutputStream(strtemp); BufferedOutputStream bos = new BufferedOutputStream(fos)) { int c; while ((c = zipFile.read()) != -1) @@ -192,43 +194,4 @@ public class Compressor { } } } - - /** - * 将zip1合并到zip2里面,即保留zip2 - * - * @param destFile zip1 - * @param srcFile zip2 - * - * @throws java.io.IOException 无法写入或读取 - *//* - * public static void merge(File destFile, File srcFile) throws IOException - * { - * try (ZipOutputStream os = new ZipOutputStream(new - * FileOutputStream(destFile))) { - * if (destFile.exists()) { - * File extPlace = new File(IOUtils.currentDir(), "HMCL-MERGE-TEMP"); - * unzip(srcFile, extPlace); - * ZipFile zipFile = new ZipFile(srcFile); - * if (srcFile.exists()) { - * String gbkPath;//, strtemp, strPath; - * //strPath = extPlace.getAbsolutePath(); - * java.util.Enumeration e = zipFile.entries(); - * while (e.hasMoreElements()) { - * ZipEntry zipEnt = (ZipEntry) e.nextElement(); - * //gbkPath = zipEnt.getName(); - * if (zipEnt.isDirectory()) { - * //strtemp = strPath + File.separator + gbkPath; - * } else { - * gbkPath = zipEnt.getName(); - * //strtemp = strPath + File.separator + gbkPath; - * os.putNextEntry(zipEnt); - * os.write(gbkPath.getBytes("UTF-8")); - * } - * } - * } - * } - * os.closeEntry(); - * } - * } - */ } diff --git a/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N.properties b/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N.properties index b6ba0af7b..9b5c5ac46 100755 --- a/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N.properties +++ b/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N.properties @@ -209,7 +209,7 @@ settings.choose_gamedir=\u9009\u62e9\u6e38\u620f\u8def\u5f84 settings.failed_load=\u8bbe\u7f6e\u6587\u4ef6\u52a0\u8f7d\u5931\u8d25\uff0c\u53ef\u80fd\u662f\u5347\u7ea7\u4e86\u542f\u52a8\u5668\u6216\u88ab\u4eba\u5de5\u4fee\u6539\u9020\u6210\u9519\u8bef\uff0c\u662f\u5426\u6e05\u9664\uff1f modpack=\u6574\u5408\u5305 -modpack.choose=\u9009\u62e9\u8981\u5bfc\u5165\u7684\u6e38\u620f\u6574\u5408\u5305\u6587\u4ef6 +modpack.choose=\u9009\u62e9\u8981\u5bfc\u5165\u7684\u6e38\u620f\u6574\u5408\u5305\u6587\u4ef6\uff0c\u5982\u679c\u60a8\u5e0c\u671b\u66f4\u65b0\u6574\u5408\u5305\uff0c\u8bf7\u8f93\u5165\u8981\u66f4\u65b0\u7684\u7248\u672c\u540d modpack.install.task=\u5bfc\u5165\u6574\u5408\u5305 modpack.install_error=\u5b89\u88c5\u5931\u8d25\uff0c\u53ef\u80fd\u662f\u6574\u5408\u5305\u683c\u5f0f\u4e0d\u6b63\u786e\u6216\u64cd\u4f5c\u6587\u4ef6\u5931\u8d25 modpack.save=\u9009\u62e9\u8981\u5bfc\u51fa\u5230\u7684\u6e38\u620f\u6574\u5408\u5305\u4f4d\u7f6e diff --git a/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N_en.properties b/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N_en.properties index bc7319036..66160fb7b 100755 --- a/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N_en.properties +++ b/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N_en.properties @@ -209,7 +209,7 @@ settings.choose_gamedir=Choose Game Directory settings.failed_load=Failed to load settings file. Remove it? modpack=Mod pack -modpack.choose=Choose a modpack zip file which you want to import. +modpack.choose=Choose a modpack zip file which you want to import. If you want to update the modpack, please enter the version you want to update. modpack.install.task=Import the modpack modpack.install_error=Failed to install the modpack, maybe the modpack file is incorrect or failed to manage files. modpack.save=Choose a location which you want to export the game files to. diff --git a/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N_zh.properties b/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N_zh.properties index ef9c72a7e..9f2a1b35b 100755 --- a/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N_zh.properties +++ b/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N_zh.properties @@ -209,7 +209,7 @@ settings.choose_gamedir=\u9009\u62e9\u6e38\u620f\u8def\u5f84 settings.failed_load=\u8a2d\u5b9a\u6587\u4ef6\u52a0\u8f09\u5931\u6557\uff0c\u53ef\u80fd\u662f\u5347\u7d1a\u4e86\u555f\u52d5\u5668\u6216\u88ab\u4eba\u5de5\u4fee\u6539\u9020\u6210\u932f\u8aa4\uff0c\u662f\u5426\u6e05\u9664\uff1f modpack=\u61f6\u4eba\u5305 -modpack.choose=\u9078\u64c7\u8981\u5c0e\u5165\u7684\u904a\u6232\u61f6\u4eba\u5305\u6587\u4ef6 +modpack.choose=\u9078\u64c7\u8981\u5c0e\u5165\u7684\u904a\u6232\u61f6\u4eba\u5305\u6587\u4ef6\uff0c\u5982\u679c\u60a8\u5e0c\u671b\u66f4\u65b0\u6574\u5408\u5305\uff0c\u8bf7\u8f93\u5165\u8981\u66f4\u65b0\u7684\u7248\u672c\u540d modpack.install.task=\u5c0e\u5165\u61f6\u4eba\u5305 modpack.install_error=\u5b89\u88dd\u5931\u6557\uff0c\u53ef\u80fd\u662f\u6574\u5408\u5305\u683c\u5f0f\u4e0d\u6b63\u78ba\u6216\u64cd\u4f5c\u6587\u4ef6\u5931\u6557 modpack.save=\u9078\u64c7\u8981\u5c0e\u51fa\u5230\u7684\u904a\u6232\u61f6\u4eba\u5305\u4f4d\u7f6e diff --git a/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N_zh_CN.properties b/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N_zh_CN.properties index bd2868fc9..c85e8d29b 100755 --- a/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N_zh_CN.properties +++ b/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N_zh_CN.properties @@ -209,7 +209,7 @@ settings.choose_gamedir=\u9009\u62e9\u6e38\u620f\u8def\u5f84 settings.failed_load=\u8bbe\u7f6e\u6587\u4ef6\u52a0\u8f7d\u5931\u8d25\uff0c\u53ef\u80fd\u662f\u5347\u7ea7\u4e86\u542f\u52a8\u5668\u6216\u88ab\u4eba\u5de5\u4fee\u6539\u9020\u6210\u9519\u8bef\uff0c\u662f\u5426\u6e05\u9664\uff1f modpack=\u6574\u5408\u5305 -modpack.choose=\u9009\u62e9\u8981\u5bfc\u5165\u7684\u6e38\u620f\u6574\u5408\u5305\u6587\u4ef6 +modpack.choose=\u9009\u62e9\u8981\u5bfc\u5165\u7684\u6e38\u620f\u6574\u5408\u5305\u6587\u4ef6\uff0c\u5982\u679c\u60a8\u5e0c\u671b\u66f4\u65b0\u6574\u5408\u5305\uff0c\u8bf7\u8f93\u5165\u8981\u66f4\u65b0\u7684\u7248\u672c\u540d modpack.install.task=\u5bfc\u5165\u6574\u5408\u5305 modpack.install_error=\u5b89\u88c5\u5931\u8d25\uff0c\u53ef\u80fd\u662f\u6574\u5408\u5305\u683c\u5f0f\u4e0d\u6b63\u786e\u6216\u64cd\u4f5c\u6587\u4ef6\u5931\u8d25 modpack.save=\u9009\u62e9\u8981\u5bfc\u51fa\u5230\u7684\u6e38\u620f\u6574\u5408\u5305\u4f4d\u7f6e