mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-16 23:37:14 -04:00
alt: print the reason why renaming version failed
This commit is contained in:
parent
1c865e3d8d
commit
97e8ff91ea
@ -30,13 +30,16 @@ import org.jackhuang.hmcl.event.RemoveVersionEvent;
|
|||||||
import org.jackhuang.hmcl.event.RenameVersionEvent;
|
import org.jackhuang.hmcl.event.RenameVersionEvent;
|
||||||
import org.jackhuang.hmcl.mod.ModManager;
|
import org.jackhuang.hmcl.mod.ModManager;
|
||||||
import org.jackhuang.hmcl.task.Task;
|
import org.jackhuang.hmcl.task.Task;
|
||||||
|
import org.jackhuang.hmcl.util.Lang;
|
||||||
import org.jackhuang.hmcl.util.ToStringBuilder;
|
import org.jackhuang.hmcl.util.ToStringBuilder;
|
||||||
import org.jackhuang.hmcl.util.gson.JsonUtils;
|
import org.jackhuang.hmcl.util.gson.JsonUtils;
|
||||||
import org.jackhuang.hmcl.util.io.FileUtils;
|
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.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;
|
||||||
@ -154,28 +157,32 @@ public class DefaultGameRepository implements GameRepository {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Version fromVersion = getVersion(from);
|
Version fromVersion = getVersion(from);
|
||||||
File fromDir = getVersionRoot(from);
|
Path fromDir = getVersionRoot(from).toPath();
|
||||||
File toDir = getVersionRoot(to);
|
Path toDir = getVersionRoot(to).toPath();
|
||||||
if (!fromDir.renameTo(toDir))
|
Files.move(fromDir, toDir);
|
||||||
return false;
|
|
||||||
|
|
||||||
File toJson = new File(toDir, to + ".json");
|
Path fromJson = toDir.resolve(from + ".json");
|
||||||
File toJar = new File(toDir, to + ".jar");
|
Path fromJar = toDir.resolve(from + ".jar");
|
||||||
|
Path toJson = toDir.resolve(to + ".json");
|
||||||
|
Path toJar = toDir.resolve(to + ".jar");
|
||||||
|
|
||||||
if (!new File(toDir, from + ".json").renameTo(toJson)
|
try {
|
||||||
|| !new File(toDir, from + ".jar").renameTo(toJar)) {
|
Files.move(fromJson, toJson);
|
||||||
|
Files.move(fromJar, toJar);
|
||||||
|
} catch (IOException e) {
|
||||||
// recovery
|
// recovery
|
||||||
toJson.renameTo(new File(toDir, from + ".json"));
|
Lang.ignoringException(() -> Files.move(toJson, fromJson));
|
||||||
toJar.renameTo(new File(toDir, from + ".jar"));
|
Lang.ignoringException(() -> Files.move(toJar, fromJar));
|
||||||
toDir.renameTo(fromDir);
|
Lang.ignoringException(() -> Files.move(toDir, fromDir));
|
||||||
return false;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fromVersion.getId().equals(fromVersion.getJar()))
|
if (fromVersion.getId().equals(fromVersion.getJar()))
|
||||||
fromVersion = fromVersion.setJar(null);
|
fromVersion = fromVersion.setJar(null);
|
||||||
FileUtils.writeText(toJson, 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 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