mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-17 07:47:57 -04:00
fix: crash when renaming game version
This commit is contained in:
parent
43de254a98
commit
383de6cb2e
@ -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 {
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user