Skip to content

Commit

Permalink
Added some sanity checks to assets-related methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Moresteck committed Oct 16, 2024
1 parent 326a9de commit 1cd7dc3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/main/java/uk/betacraft/legacyfix/LegacyFixLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/uk/betacraft/legacyfix/util/AssetUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ public class AssetUtils {
public static List<AssetObject> assets = new LinkedList<AssetObject>();

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() {
Expand All @@ -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 "";
Expand Down

0 comments on commit 1cd7dc3

Please sign in to comment.