|
25 | 25 | import org.jackhuang.hmcl.download.game.GameAssetDownloadTask; |
26 | 26 | import org.jackhuang.hmcl.game.GameDirectoryType; |
27 | 27 | import org.jackhuang.hmcl.game.GameRepository; |
| 28 | +import org.jackhuang.hmcl.game.HMCLGameRepository; |
28 | 29 | import org.jackhuang.hmcl.game.LauncherHelper; |
29 | 30 | import org.jackhuang.hmcl.mod.RemoteMod; |
30 | 31 | import org.jackhuang.hmcl.setting.*; |
@@ -126,7 +127,7 @@ public static void deleteVersion(Profile profile, String version) { |
126 | 127 |
|
127 | 128 | public static CompletableFuture<String> renameVersion(Profile profile, String version) { |
128 | 129 | return Controllers.prompt(i18n("version.manage.rename.message"), (newName, resolve, reject) -> { |
129 | | - if (!FileUtils.isNameValid(newName)) { |
| 130 | + if (!HMCLGameRepository.isValidVersionId(newName)) { |
130 | 131 | reject.accept(i18n("install.new_game.malformed")); |
131 | 132 | return; |
132 | 133 | } |
@@ -157,20 +158,26 @@ public static void duplicateVersion(Profile profile, String version) { |
157 | 158 | new PromptDialogPane.Builder(i18n("version.manage.duplicate.prompt"), (res, resolve, reject) -> { |
158 | 159 | String newVersionName = ((PromptDialogPane.Builder.StringQuestion) res.get(1)).getValue(); |
159 | 160 | 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 | + } |
160 | 165 | Task.runAsync(() -> profile.getRepository().duplicateVersion(version, newVersionName, copySaves)) |
161 | 166 | .thenComposeAsync(profile.getRepository().refreshVersionsAsync()) |
162 | 167 | .whenComplete(Schedulers.javafx(), (result, exception) -> { |
163 | 168 | if (exception == null) { |
164 | 169 | resolve.run(); |
165 | 170 | } else { |
166 | 171 | reject.accept(StringUtils.getStackTrace(exception)); |
167 | | - profile.getRepository().removeVersionFromDisk(newVersionName); |
| 172 | + if (!profile.getRepository().versionIdConflicts(newVersionName)) { |
| 173 | + profile.getRepository().removeVersionFromDisk(newVersionName); |
| 174 | + } |
168 | 175 | } |
169 | 176 | }).start(); |
170 | 177 | }) |
171 | 178 | .addQuestion(new PromptDialogPane.Builder.HintQuestion(i18n("version.manage.duplicate.confirm"))) |
172 | 179 | .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)))) |
174 | 181 | .addQuestion(new PromptDialogPane.Builder.BooleanQuestion(i18n("version.manage.duplicate.duplicate_save"), false))); |
175 | 182 | } |
176 | 183 |
|
|
0 commit comments