2626import org .jackhuang .hmcl .game .*;
2727import org .jackhuang .hmcl .mod .RemoteMod ;
2828import org .jackhuang .hmcl .setting .*;
29- import org .jackhuang .hmcl .task .*;
29+ import org .jackhuang .hmcl .task .FileDownloadTask ;
30+ import org .jackhuang .hmcl .task .Schedulers ;
31+ import org .jackhuang .hmcl .task .Task ;
32+ import org .jackhuang .hmcl .task .TaskExecutor ;
3033import org .jackhuang .hmcl .ui .Controllers ;
3134import org .jackhuang .hmcl .ui .FXUtils ;
3235import org .jackhuang .hmcl .ui .account .CreateAccountPane ;
5053import java .util .concurrent .CompletableFuture ;
5154import java .util .function .Consumer ;
5255
53- import static org .jackhuang .hmcl .util .logging .Logger .LOG ;
5456import static org .jackhuang .hmcl .util .i18n .I18n .i18n ;
57+ import static org .jackhuang .hmcl .util .logging .Logger .LOG ;
5558
5659public final class Versions {
5760 private Versions () {
@@ -124,10 +127,6 @@ public static void deleteVersion(Profile profile, String version) {
124127
125128 public static CompletableFuture <String > renameVersion (Profile profile , String version ) {
126129 return Controllers .prompt (i18n ("version.manage.rename.message" ), (newName , resolve , reject ) -> {
127- if (!HMCLGameRepository .isValidVersionId (newName )) {
128- reject .accept (i18n ("install.new_game.malformed" ));
129- return ;
130- }
131130 if (profile .getRepository ().renameVersion (version , newName )) {
132131 resolve .run ();
133132 profile .getRepository ().refreshVersionsAsync ()
@@ -139,7 +138,8 @@ public static CompletableFuture<String> renameVersion(Profile profile, String ve
139138 } else {
140139 reject .accept (i18n ("version.manage.rename.fail" ));
141140 }
142- }, version );
141+ }, version , new Validator (i18n ("install.new_game.malformed" ), HMCLGameRepository ::isValidVersionId ),
142+ new Validator (i18n ("install.new_game.already_exists" ), newVersionName -> !profile .getRepository ().versionIdConflicts (newVersionName )));
143143 }
144144
145145 public static void exportVersion (Profile profile , String version ) {
@@ -155,10 +155,6 @@ public static void duplicateVersion(Profile profile, String version) {
155155 new PromptDialogPane .Builder (i18n ("version.manage.duplicate.prompt" ), (res , resolve , reject ) -> {
156156 String newVersionName = ((PromptDialogPane .Builder .StringQuestion ) res .get (1 )).getValue ();
157157 boolean copySaves = ((PromptDialogPane .Builder .BooleanQuestion ) res .get (2 )).getValue ();
158- if (!HMCLGameRepository .isValidVersionId (newVersionName )) {
159- reject .accept (i18n ("install.new_game.malformed" ));
160- return ;
161- }
162158 Task .runAsync (() -> profile .getRepository ().duplicateVersion (version , newVersionName , copySaves ))
163159 .thenComposeAsync (profile .getRepository ().refreshVersionsAsync ())
164160 .whenComplete (Schedulers .javafx (), (result , exception ) -> {
@@ -174,6 +170,7 @@ public static void duplicateVersion(Profile profile, String version) {
174170 })
175171 .addQuestion (new PromptDialogPane .Builder .HintQuestion (i18n ("version.manage.duplicate.confirm" )))
176172 .addQuestion (new PromptDialogPane .Builder .StringQuestion (null , version ,
173+ new Validator (i18n ("install.new_game.malformed" ), HMCLGameRepository ::isValidVersionId ),
177174 new Validator (i18n ("install.new_game.already_exists" ), newVersionName -> !profile .getRepository ().versionIdConflicts (newVersionName ))))
178175 .addQuestion (new PromptDialogPane .Builder .BooleanQuestion (i18n ("version.manage.duplicate.duplicate_save" ), false )));
179176 }
0 commit comments