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 b963f2fbd..42069173d 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/game/DefaultGameRepository.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/game/DefaultGameRepository.java @@ -21,11 +21,12 @@ import com.google.gson.JsonParseException; import org.jackhuang.hmcl.event.*; import org.jackhuang.hmcl.mod.ModManager; import org.jackhuang.hmcl.task.Schedulers; -import org.jackhuang.hmcl.util.Logging; import org.jackhuang.hmcl.util.ToStringBuilder; import org.jackhuang.hmcl.util.gson.JsonUtils; import org.jackhuang.hmcl.util.io.FileUtils; +import static org.jackhuang.hmcl.util.Logging.LOG; + import java.io.File; import java.io.IOException; import java.util.*; @@ -171,13 +172,13 @@ public class DefaultGameRepository implements GameRepository { List jsons = FileUtils.listFilesByExtension(removedFile, "json"); jsons.forEach(f -> { if (!f.delete()) - Logging.LOG.warning("Unable to delete file " + f); + LOG.warning("Unable to delete file " + f); }); // remove the version from version list regardless of whether the directory was removed successfully or not. try { FileUtils.deleteDirectory(removedFile); } catch (IOException e) { - Logging.LOG.log(Level.WARNING, "Unable to remove version folder: " + file, e); + LOG.log(Level.WARNING, "Unable to remove version folder: " + file, e); } return true; } @@ -202,17 +203,23 @@ public class DefaultGameRepository implements GameRepository { // we will find the only json and rename it to correct name. if (!json.exists()) { List jsons = FileUtils.listFilesByExtension(dir, "json"); - if (jsons.size() == 1) + if (jsons.size() == 1) { + LOG.info("Renaming json file " + jsons.get(0) + " to " + json); if (!jsons.get(0).renameTo(json)) { - Logging.LOG.warning("Cannot rename json file " + jsons.get(0) + " to " + json + ", ignoring version " + id); + LOG.warning("Cannot rename json file, ignoring version " + id); return Stream.empty(); } + } else { + LOG.info("No available json file found, ignoring version " + id); + return Stream.empty(); + } } Version version; try { version = Objects.requireNonNull(readVersionJson(json)); } catch (Exception e) { + LOG.log(Level.WARNING, "Malformed version json " + id, e); // JsonSyntaxException or IOException or NullPointerException(!!) if (EventBus.EVENT_BUS.fireEvent(new GameJsonParseFailedEvent(this, json, id)) != Event.Result.ALLOW) return Stream.empty(); @@ -220,7 +227,7 @@ public class DefaultGameRepository implements GameRepository { try { version = Objects.requireNonNull(readVersionJson(json)); } catch (Exception e2) { - Logging.LOG.log(Level.SEVERE, "User corrected version json is still malformed"); + LOG.log(Level.SEVERE, "User corrected version json is still malformed", e2); return Stream.empty(); } } @@ -230,7 +237,7 @@ public class DefaultGameRepository implements GameRepository { try { FileUtils.writeText(json, JsonUtils.GSON.toJson(version)); } catch (Exception e) { - Logging.LOG.log(Level.WARNING, "Ignoring version " + id + " because wrong id " + version.getId() + " is set and cannot correct it."); + LOG.log(Level.WARNING, "Ignoring version " + id + " because wrong id " + version.getId() + " is set and cannot correct it.", e); return Stream.empty(); } } @@ -246,7 +253,7 @@ public class DefaultGameRepository implements GameRepository { EventBus.EVENT_BUS.fireEvent(new LoadedOneVersionEvent(this, resolved)) != Event.Result.DENY) versions.put(version.getId(), version); } catch (VersionNotFoundException e) { - Logging.LOG.log(Level.WARNING, "Ignoring version " + version.getId() + " because it inherits from a nonexistent version."); + LOG.log(Level.WARNING, "Ignoring version " + version.getId() + " because it inherits from a nonexistent version."); } } @@ -278,7 +285,7 @@ public class DefaultGameRepository implements GameRepository { try { return reconstructAssets(version, assetId); } catch (IOException | JsonParseException e) { - Logging.LOG.log(Level.SEVERE, "Unable to reconstruct asset directory", e); + LOG.log(Level.SEVERE, "Unable to reconstruct asset directory", e); return getAssetDirectory(version, assetId); } }