fix: crash when renaming game version

This commit is contained in:
huanghongxun 2020-04-23 08:12:19 +08:00
parent 43de254a98
commit 383de6cb2e
2 changed files with 8 additions and 4 deletions

View File

@ -60,8 +60,12 @@ public class Versions {
} }
public static CompletableFuture<String> renameVersion(Profile profile, String version) { public static CompletableFuture<String> renameVersion(Profile profile, String version) {
return Controllers.prompt(i18n("version.manage.rename.message"), (res, resolve, reject) -> { return Controllers.prompt(i18n("version.manage.rename.message"), (newName, resolve, reject) -> {
if (profile.getRepository().renameVersion(version, res)) { if (!OperatingSystem.isNameValid(newName)) {
reject.accept(i18n("install.new_game.malformed"));
return;
}
if (profile.getRepository().renameVersion(version, newName)) {
profile.getRepository().refreshVersionsAsync().start(); profile.getRepository().refreshVersionsAsync().start();
resolve.run(); resolve.run();
} else { } else {

View File

@ -38,8 +38,8 @@ import org.jackhuang.hmcl.util.io.FileUtils;
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.InvalidPathException;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -181,7 +181,7 @@ public class DefaultGameRepository implements GameRepository {
fromVersion = fromVersion.setJar(null); fromVersion = fromVersion.setJar(null);
FileUtils.writeText(toJson.toFile(), JsonUtils.GSON.toJson(fromVersion.setId(to))); FileUtils.writeText(toJson.toFile(), JsonUtils.GSON.toJson(fromVersion.setId(to)));
return true; 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); LOG.log(Level.WARNING, "Unable to rename version " + from + " to " + to, e);
return false; return false;
} }