Skip to content

Commit 0543da3

Browse files
authored
Fix #4802: 修复复制实例时使用非法实例 ID 启动器行为异常的问题 (#4805)
1 parent a74dc98 commit 0543da3

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/Versions.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.jackhuang.hmcl.download.game.GameAssetDownloadTask;
2626
import org.jackhuang.hmcl.game.GameDirectoryType;
2727
import org.jackhuang.hmcl.game.GameRepository;
28+
import org.jackhuang.hmcl.game.HMCLGameRepository;
2829
import org.jackhuang.hmcl.game.LauncherHelper;
2930
import org.jackhuang.hmcl.mod.RemoteMod;
3031
import org.jackhuang.hmcl.setting.*;
@@ -126,7 +127,7 @@ public static void deleteVersion(Profile profile, String version) {
126127

127128
public static CompletableFuture<String> renameVersion(Profile profile, String version) {
128129
return Controllers.prompt(i18n("version.manage.rename.message"), (newName, resolve, reject) -> {
129-
if (!FileUtils.isNameValid(newName)) {
130+
if (!HMCLGameRepository.isValidVersionId(newName)) {
130131
reject.accept(i18n("install.new_game.malformed"));
131132
return;
132133
}
@@ -157,20 +158,26 @@ public static void duplicateVersion(Profile profile, String version) {
157158
new PromptDialogPane.Builder(i18n("version.manage.duplicate.prompt"), (res, resolve, reject) -> {
158159
String newVersionName = ((PromptDialogPane.Builder.StringQuestion) res.get(1)).getValue();
159160
boolean copySaves = ((PromptDialogPane.Builder.BooleanQuestion) res.get(2)).getValue();
161+
if (!HMCLGameRepository.isValidVersionId(newVersionName)) {
162+
reject.accept(i18n("install.new_game.malformed"));
163+
return;
164+
}
160165
Task.runAsync(() -> profile.getRepository().duplicateVersion(version, newVersionName, copySaves))
161166
.thenComposeAsync(profile.getRepository().refreshVersionsAsync())
162167
.whenComplete(Schedulers.javafx(), (result, exception) -> {
163168
if (exception == null) {
164169
resolve.run();
165170
} else {
166171
reject.accept(StringUtils.getStackTrace(exception));
167-
profile.getRepository().removeVersionFromDisk(newVersionName);
172+
if (!profile.getRepository().versionIdConflicts(newVersionName)) {
173+
profile.getRepository().removeVersionFromDisk(newVersionName);
174+
}
168175
}
169176
}).start();
170177
})
171178
.addQuestion(new PromptDialogPane.Builder.HintQuestion(i18n("version.manage.duplicate.confirm")))
172179
.addQuestion(new PromptDialogPane.Builder.StringQuestion(null, version,
173-
new Validator(i18n("install.new_game.already_exists"), newVersionName -> !profile.getRepository().hasVersion(newVersionName))))
180+
new Validator(i18n("install.new_game.already_exists"), newVersionName -> !profile.getRepository().versionIdConflicts(newVersionName))))
174181
.addQuestion(new PromptDialogPane.Builder.BooleanQuestion(i18n("version.manage.duplicate.duplicate_save"), false)));
175182
}
176183

0 commit comments

Comments
 (0)