Skip to content

Commit

Permalink
oops.. update checker again
Browse files Browse the repository at this point in the history
  • Loading branch information
tim03we committed Jan 4, 2025
1 parent 588fa4e commit 5d0fcbb
Showing 1 changed file with 65 additions and 57 deletions.
122 changes: 65 additions & 57 deletions src/main/java/ovis/futureplots/components/util/UpdateChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,90 +82,98 @@ public void check() {
FuturePlots.getInstance().getLogger().warning("----------");
}
} else {
this.updateAvailable = true;
FuturePlots.getInstance().getLogger().warning("----------");
FuturePlots.getInstance().getLogger().warning("The release tag could not be retrieved. Is an unofficial version possibly being used?");
FuturePlots.getInstance().getLogger().warning("Newest version: " + latestReleaseTag);
FuturePlots.getInstance().getLogger().warning("Download: " + latestReleaseUrl);
FuturePlots.getInstance().getLogger().warning("----------");
FuturePlots.getInstance().getLogger().error("The release tag could not be retrieved. Is an unofficial version possibly being used?");
}
}
} catch (Exception e) {
e.printStackTrace();
}
}

private String getGitTagFromCommitHash(String commitHash) throws Exception {
String urlString = String.format(GITHUB_API_URL_TAGS);
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
private String getGitTagFromCommitHash(String commitHash) {
try {
String urlString = String.format(GITHUB_API_URL_TAGS);
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");

BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();

while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();

JsonArray tags = JsonParser.parseString(response.toString()).getAsJsonArray();
JsonArray tags = JsonParser.parseString(response.toString()).getAsJsonArray();

for (JsonElement element : tags) {
JsonObject tag = element.getAsJsonObject();
String sha = tag.getAsJsonObject("commit").get("sha").getAsString();
for (JsonElement element : tags) {
JsonObject tag = element.getAsJsonObject();
String sha = tag.getAsJsonObject("commit").get("sha").getAsString();

if (sha.equals(commitHash)) {
return tag.get("name").getAsString();
if (sha.equals(commitHash)) {
return tag.get("name").getAsString();
}
}
} catch (Exception e) {
// nothing
}

return null;
}

private String[] getLatestRelease() throws Exception {
String urlString = String.format(GITHUB_API_URL_LATEST_RELEASE);
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
private String[] getLatestRelease() {
try {
String urlString = String.format(GITHUB_API_URL_LATEST_RELEASE);
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");

BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();

while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();

JsonObject release = JsonParser.parseString(response.toString()).getAsJsonObject();
String tag = release.get("tag_name").getAsString();
String urlRelease = release.get("html_url").getAsString();
JsonObject release = JsonParser.parseString(response.toString()).getAsJsonObject();
String tag = release.get("tag_name").getAsString();
String urlRelease = release.get("html_url").getAsString();

return new String[]{tag, urlRelease};
return new String[]{tag, urlRelease};
} catch (Exception e) {
// nothing
}
return new String[]{"", ""};
}


private String getLatestCommitHash() throws Exception {
String urlString = String.format(GITHUB_API_URL_COMMITS);
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
private String getLatestCommitHash() {
try {
String urlString = String.format(GITHUB_API_URL_COMMITS);
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");

BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();

while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();

JsonArray commits = JsonParser.parseString(response.toString()).getAsJsonArray();
JsonObject latestCommit = commits.get(0).getAsJsonObject();
String latestCommitHash = latestCommit.get("sha").getAsString();
JsonArray commits = JsonParser.parseString(response.toString()).getAsJsonArray();
JsonObject latestCommit = commits.get(0).getAsJsonObject();
String latestCommitHash = latestCommit.get("sha").getAsString();

return latestCommitHash;
return latestCommitHash;
} catch (Exception e) {
// nothing
}
return null;
}
}

0 comments on commit 5d0fcbb

Please sign in to comment.