From bf0d8c576f1e0655e4508d05624752a3210d3a80 Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Fri, 5 Jun 2020 23:46:51 +0200 Subject: [PATCH] Now steamapps.json will be remade if it is corrupt (thanks to user Shori from [REDACTED] for reporting the bug) --- auto-cream-api.iml | 5 +++++ src/main/java/util/SteamAppsListCache.java | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/auto-cream-api.iml b/auto-cream-api.iml index 4599ba8..f79f6a4 100644 --- a/auto-cream-api.iml +++ b/auto-cream-api.iml @@ -1,5 +1,10 @@ + + + diff --git a/src/main/java/util/SteamAppsListCache.java b/src/main/java/util/SteamAppsListCache.java index 3e107a6..037dd52 100644 --- a/src/main/java/util/SteamAppsListCache.java +++ b/src/main/java/util/SteamAppsListCache.java @@ -1,6 +1,7 @@ package util; import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; import com.google.gson.reflect.TypeToken; import kong.unirest.HttpResponse; 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..."); //fileFound = false; 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)))) { 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() + ")..."); } - private void getListFromFile() throws FileNotFoundException { + private void getListFromFile() throws FileNotFoundException, JsonSyntaxException { System.out.println("Trying to get SteamAppList from file (" + cacheFile.getAbsolutePath() + ")..."); BufferedReader fIn = new BufferedReader(new FileReader(cacheFile)); String json = fIn.lines().collect(Collectors.joining());