fix: unable to duplicate game version.
This commit is contained in:
@@ -42,6 +42,7 @@ import org.jackhuang.hmcl.util.versioning.VersionNumber;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
@@ -137,15 +138,26 @@ public class HMCLGameRepository extends DefaultGameRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void duplicateVersion(String srcId, String dstId, boolean copySaves) throws IOException {
|
public void duplicateVersion(String srcId, String dstId, boolean copySaves) throws IOException {
|
||||||
File srcDir = getVersionRoot(srcId);
|
Path srcDir = getVersionRoot(srcId).toPath();
|
||||||
File dstDir = getVersionRoot(dstId);
|
Path dstDir = getVersionRoot(dstId).toPath();
|
||||||
|
|
||||||
if (dstDir.exists()) throw new IOException("Version exists");
|
Version fromVersion = getVersion(srcId);
|
||||||
FileUtils.copyDirectory(srcDir.toPath(), dstDir.toPath());
|
|
||||||
if (Files.exists(dstDir.toPath().resolve(srcId + ".jar"))) {
|
if (Files.exists(dstDir)) throw new IOException("Version exists");
|
||||||
Files.move(dstDir.toPath().resolve(srcId + ".jar"), dstDir.toPath().resolve(dstId + ".jar"));
|
FileUtils.copyDirectory(srcDir, dstDir);
|
||||||
|
|
||||||
|
Path fromJson = dstDir.resolve(srcId + ".json");
|
||||||
|
Path fromJar = dstDir.resolve(srcId + ".jar");
|
||||||
|
Path toJson = dstDir.resolve(dstId + ".json");
|
||||||
|
Path toJar = dstDir.resolve(dstId + ".jar");
|
||||||
|
|
||||||
|
if (Files.exists(fromJar)) {
|
||||||
|
Files.move(fromJar, toJar);
|
||||||
}
|
}
|
||||||
Files.move(dstDir.toPath().resolve(srcId + ".json"), dstDir.toPath().resolve(dstId + ".json"));
|
Files.move(fromJson, toJson);
|
||||||
|
|
||||||
|
FileUtils.writeText(toJson.toFile(), JsonUtils.GSON.toJson(fromVersion.setId(dstId)));
|
||||||
|
|
||||||
VersionSetting oldVersionSetting = getVersionSetting(srcId).clone();
|
VersionSetting oldVersionSetting = getVersionSetting(srcId).clone();
|
||||||
GameDirectoryType originalGameDirType = oldVersionSetting.getGameDirType();
|
GameDirectoryType originalGameDirType = oldVersionSetting.getGameDirType();
|
||||||
oldVersionSetting.setUsesGlobal(false);
|
oldVersionSetting.setUsesGlobal(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user