mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-11 12:56:53 -04:00
modpack update
This commit is contained in:
parent
3bdaaddcd8
commit
005589955c
@ -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);
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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<String> callback) throws IOException {
|
||||
public static void unzip(File zipFileName, File extPlace, Predicate<String> 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();
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user