Skip to content
This repository was archived by the owner on Mar 5, 2023. It is now read-only.

Commit 081e579

Browse files
committed
Fix mods tab when invalid json
1 parent 7a480fd commit 081e579

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

project/vcmi-app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ android {
1010
minSdk 21
1111
targetSdk 31
1212
versionCode 1
13-
versionName "0.99"
13+
versionName "1.1"
1414
setProperty("archivesBaseName", "vcmi")
1515

1616
externalNativeBuild {

project/vcmi-app/src/main/java/eu/vcmi/vcmi/mods/VCMIModsRepo.java

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,32 @@ protected ServerResponse<List<VCMIMod>> doInBackground(final String... params)
5151
final JSONArray names = jsonContent.names();
5252
for (int i = 0; i < names.length(); ++i)
5353
{
54-
String name = names.getString(i);
55-
JSONObject modDownloadData = jsonContent.getJSONObject(name);
56-
57-
if(modDownloadData.has("mod"))
54+
try
5855
{
59-
String modFileAddress = modDownloadData.getString("mod");
60-
ServerResponse<List<VCMIMod>> modFile = sendRequest(modFileAddress);
56+
String name = names.getString(i);
57+
JSONObject modDownloadData = jsonContent.getJSONObject(name);
6158

62-
if (!modFile.isValid())
59+
if(modDownloadData.has("mod"))
6360
{
64-
continue;
65-
}
61+
String modFileAddress = modDownloadData.getString("mod");
62+
ServerResponse<List<VCMIMod>> modFile = sendRequest(modFileAddress);
63+
64+
if (!modFile.isValid())
65+
{
66+
continue;
67+
}
6668

67-
JSONObject modJson = new JSONObject(modFile.mRawContent);
68-
mods.add(VCMIMod.buildFromRepoJson(name, modJson, modDownloadData));
69+
JSONObject modJson = new JSONObject(modFile.mRawContent);
70+
mods.add(VCMIMod.buildFromRepoJson(name, modJson, modDownloadData));
71+
}
72+
else
73+
{
74+
mods.add(VCMIMod.buildFromRepoJson(name, modDownloadData, modDownloadData));
75+
}
6976
}
70-
else
77+
catch (JSONException e)
7178
{
72-
mods.add(VCMIMod.buildFromRepoJson(name, modDownloadData, modDownloadData));
79+
Log.e(this, "Could not parse the response as json", e);
7380
}
7481
}
7582
serverResponse.mContent = mods;

0 commit comments

Comments
 (0)