Now steamapps.json will be remade if it is corrupt

(thanks to user Shori from [REDACTED] for reporting the bug)
This commit is contained in:
Jeddunk 2020-06-05 23:46:51 +02:00
parent 832ab8608f
commit bf0d8c576f
2 changed files with 11 additions and 1 deletions

View File

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="CheckStyle-IDEA-Module">
<option name="configuration">
<map />
</option>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" /> <output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" /> <output-test url="file://$MODULE_DIR$/target/test-classes" />

View File

@ -1,6 +1,7 @@
package util; package util;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import kong.unirest.HttpResponse; import kong.unirest.HttpResponse;
import kong.unirest.Unirest; import kong.unirest.Unirest;
@ -47,6 +48,10 @@ public class SteamAppsListCache {
System.err.println("File does not exist, trying to create steamapps.json for the first time..."); System.err.println("File does not exist, trying to create steamapps.json for the first time...");
//fileFound = false; //fileFound = false;
sync(); sync();
} catch (JsonSyntaxException e) {
System.err.println("File seems to be corrupt, trying to recreate steamapps.json...");
//fileFound = false;
sync();
} }
if (Instant.now().isAfter(list.getTimestamp().plus(Duration.ofDays(3)))) { if (Instant.now().isAfter(list.getTimestamp().plus(Duration.ofDays(3)))) {
System.err.println("List in file is not recent!"); System.err.println("List in file is not recent!");
@ -115,7 +120,7 @@ public class SteamAppsListCache {
System.out.println("Successfully saved SteamAppList to file (" + cacheFile.getAbsolutePath() + ")..."); System.out.println("Successfully saved SteamAppList to file (" + cacheFile.getAbsolutePath() + ")...");
} }
private void getListFromFile() throws FileNotFoundException { private void getListFromFile() throws FileNotFoundException, JsonSyntaxException {
System.out.println("Trying to get SteamAppList from file (" + cacheFile.getAbsolutePath() + ")..."); System.out.println("Trying to get SteamAppList from file (" + cacheFile.getAbsolutePath() + ")...");
BufferedReader fIn = new BufferedReader(new FileReader(cacheFile)); BufferedReader fIn = new BufferedReader(new FileReader(cacheFile));
String json = fIn.lines().collect(Collectors.joining()); String json = fIn.lines().collect(Collectors.joining());