diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/Versions.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/Versions.java index 239f0857f..e28998cde 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/Versions.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/Versions.java @@ -60,8 +60,12 @@ public class Versions { } public static CompletableFuture renameVersion(Profile profile, String version) { - return Controllers.prompt(i18n("version.manage.rename.message"), (res, resolve, reject) -> { - if (profile.getRepository().renameVersion(version, res)) { + return Controllers.prompt(i18n("version.manage.rename.message"), (newName, resolve, reject) -> { + if (!OperatingSystem.isNameValid(newName)) { + reject.accept(i18n("install.new_game.malformed")); + return; + } + if (profile.getRepository().renameVersion(version, newName)) { profile.getRepository().refreshVersionsAsync().start(); resolve.run(); } else { diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/game/DefaultGameRepository.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/game/DefaultGameRepository.java index 072a8ee87..730cb0347 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/game/DefaultGameRepository.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/game/DefaultGameRepository.java @@ -38,8 +38,8 @@ import org.jackhuang.hmcl.util.io.FileUtils; import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.InvalidPathException; import java.nio.file.Path; -import java.nio.file.StandardCopyOption; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -181,7 +181,7 @@ public class DefaultGameRepository implements GameRepository { fromVersion = fromVersion.setJar(null); FileUtils.writeText(toJson.toFile(), JsonUtils.GSON.toJson(fromVersion.setId(to))); return true; - } catch (IOException | JsonParseException | VersionNotFoundException e) { + } catch (IOException | JsonParseException | VersionNotFoundException | InvalidPathException e) { LOG.log(Level.WARNING, "Unable to rename version " + from + " to " + to, e); return false; }