aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
diff options
context:
space:
mode:
authorMoulberry <james.jenour@student.scotch.wa.edu.au>2020-10-18 21:01:11 +1100
committerMoulberry <james.jenour@student.scotch.wa.edu.au>2020-10-18 21:01:11 +1100
commita0402708801b525145d01d0f4da17f0ba9d93455 (patch)
treece0b58df707388449558073df3aa9492efaf8978 /src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
parent275fe45caa8eb1048914d864aafae21f3f3a1157 (diff)
downloadnotenoughupdates-a0402708801b525145d01d0f4da17f0ba9d93455.tar.gz
notenoughupdates-a0402708801b525145d01d0f4da17f0ba9d93455.tar.bz2
notenoughupdates-a0402708801b525145d01d0f4da17f0ba9d93455.zip
1.4
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
index c0932fcf..c78885c3 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
@@ -69,6 +69,8 @@ public class NEUManager {
private HashMap<String, Set<String>> usagesMap = new HashMap<>();
+ public String latestRepoCommit = null;
+
public File configLocation;
public File repoLocation;
public File configFile;
@@ -92,7 +94,7 @@ public class NEUManager {
repoLocation.mkdir();
this.itemRenameFile = new File(configLocation, "itemRename.json");
- try { itemRenameJson = getJsonFromFile(itemRenameFile); } catch(IOException ignored) {}
+ itemRenameJson = getJsonFromFile(itemRenameFile);
if(itemRenameJson == null) {
itemRenameJson = new JsonObject();
}
@@ -144,13 +146,13 @@ public class NEUManager {
/**
* Parses a file in to a JsonObject.
*/
- public JsonObject getJsonFromFile(File file) throws IOException {
+ public JsonObject getJsonFromFile(File file) {
try {
InputStream in = new FileInputStream(file);
BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
JsonObject json = gson.fromJson(reader, JsonObject.class);
return json;
- } catch(Exception e) { e.printStackTrace(); return null; }
+ } catch(Exception e) { return null; }
}
public void resetRepo() {
@@ -210,18 +212,18 @@ public class NEUManager {
JsonObject currentCommitJSON = getJsonFromFile(new File(configLocation, "currentCommit.json"));
- String latestCommit = null;
+ latestRepoCommit = null;
try(Reader inReader = new InputStreamReader(new URL(GIT_COMMITS_URL).openStream())) {
JsonObject commits = gson.fromJson(inReader, JsonObject.class);
- latestCommit = commits.get("sha").getAsString();
+ latestRepoCommit = commits.get("sha").getAsString();
} catch (Exception e) {
e.printStackTrace();
}
- if(latestCommit == null || latestCommit.isEmpty()) return;
+ if(latestRepoCommit == null || latestRepoCommit.isEmpty()) return;
if(new File(configLocation, "repo").exists() && new File(configLocation, "repo/items").exists()) {
- if(currentCommitJSON != null && currentCommitJSON.get("sha").getAsString().equals(latestCommit)) {
+ if(currentCommitJSON != null && currentCommitJSON.get("sha").getAsString().equals(latestRepoCommit)) {
dialog.setVisible(false);
return;
}
@@ -330,9 +332,9 @@ public class NEUManager {
}*/
}
- if(currentCommitJSON == null || !currentCommitJSON.get("sha").getAsString().equals(latestCommit)) {
+ if(currentCommitJSON == null || !currentCommitJSON.get("sha").getAsString().equals(latestRepoCommit)) {
JsonObject newCurrentCommitJSON = new JsonObject();
- newCurrentCommitJSON.addProperty("sha", latestCommit);
+ newCurrentCommitJSON.addProperty("sha", latestRepoCommit);
try {
writeJson(newCurrentCommitJSON, new File(configLocation, "currentCommit.json"));
} catch (IOException e) {
@@ -447,7 +449,7 @@ public class NEUManager {
}
}
}
- } catch(IOException e) {
+ } catch(Exception e) {
e.printStackTrace();
}
}