From 1cd7dc367441a94fbc0a35656fa73b341b5c3d41 Mon Sep 17 00:00:00 2001 From: Moresteck Date: Wed, 16 Oct 2024 13:30:54 +0000 Subject: [PATCH] Added some sanity checks to assets-related methods --- .../java/uk/betacraft/legacyfix/LegacyFixLauncher.java | 4 +++- .../java/uk/betacraft/legacyfix/util/AssetUtils.java | 10 +++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/uk/betacraft/legacyfix/LegacyFixLauncher.java b/src/main/java/uk/betacraft/legacyfix/LegacyFixLauncher.java index 0169215..0f2321e 100644 --- a/src/main/java/uk/betacraft/legacyfix/LegacyFixLauncher.java +++ b/src/main/java/uk/betacraft/legacyfix/LegacyFixLauncher.java @@ -131,7 +131,9 @@ public static String getAssetsDir() { } public static String getAssetIndexPath() { - String assetIndex = getValue("assetIndex", "empty"); + String assetIndex = getValue("assetIndex", null); + if (assetIndex == null) + return null; return new File(getAssetsDir(), "indexes/" + assetIndex + ".json").getAbsolutePath(); } diff --git a/src/main/java/uk/betacraft/legacyfix/util/AssetUtils.java b/src/main/java/uk/betacraft/legacyfix/util/AssetUtils.java index d9b57fd..ba4eb26 100644 --- a/src/main/java/uk/betacraft/legacyfix/util/AssetUtils.java +++ b/src/main/java/uk/betacraft/legacyfix/util/AssetUtils.java @@ -23,7 +23,11 @@ public class AssetUtils { public static List assets = new LinkedList(); public static JSONObject getAssetIndex() throws FileNotFoundException { - return new JSONObject(new JSONTokener(new InputStreamReader(new FileInputStream(LegacyFixLauncher.getAssetIndexPath())))).getJSONObject("objects"); + String assetIndexPath = LegacyFixLauncher.getAssetIndexPath(); + if (assetIndexPath == null) + return new JSONObject(); + + return new JSONObject(new JSONTokener(new InputStreamReader(new FileInputStream(assetIndexPath)))).getJSONObject("objects"); } public static String generateTxtIndex() { @@ -35,10 +39,10 @@ public static String generateTxtIndex() { initAssets(assetIndex); for (AssetObject assetObject : assets) { - txtIndex.append("\n").append(assetObject.key).append(",").append(assetObject.size).append(",0"); + txtIndex.append(assetObject.key).append(",").append(assetObject.size).append(",0").append("\n"); } - return txtIndex.substring(1); + return txtIndex.toString(); } catch (Throwable t) { LFLogger.error("generateTxtIndex", t); return "";