-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
adam
committed
Mar 21, 2024
1 parent
3d2d6b5
commit 96dc726
Showing
8 changed files
with
142 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
common/src/main/java/com/adamcalculator/dynamicpack/status/StatusChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.adamcalculator.dynamicpack.status; | ||
|
||
import com.adamcalculator.dynamicpack.Mod; | ||
import com.adamcalculator.dynamicpack.util.Out; | ||
import com.adamcalculator.dynamicpack.util.Urls; | ||
import org.json.JSONObject; | ||
|
||
public class StatusChecker { | ||
private static final String URL = "https://adamcalculator.github.io/DynamicPack/dynamicpack.status.v1.json"; | ||
|
||
|
||
private static boolean isUpdateAvailable = false; | ||
private static boolean isFormatActual = true; | ||
private static boolean isSafe = true; | ||
private static boolean isChecked = false; | ||
|
||
public static void check() throws Exception { | ||
Out.println("Checking status..."); | ||
String s = Urls.parseContent(URL, 1024 * 1024 * 128); | ||
JSONObject j = new JSONObject(s); | ||
JSONObject lat = j.getJSONObject("latest_version"); | ||
isUpdateAvailable = lat.getLong("build") > Mod.VERSION_BUILD; | ||
isSafe = lat.getLong("safe") <= Mod.VERSION_BUILD; | ||
isFormatActual = lat.getLong("format") <= Mod.VERSION_BUILD; | ||
|
||
isChecked = true; | ||
Out.println(String.format("Status checked! isSafe=%s, isFormatActual=%s, isUpdateAvailable=%s", isSafe, isFormatActual, isUpdateAvailable)); | ||
} | ||
|
||
public static boolean isBlockUpdating(String remoteType) { | ||
if (remoteType.equals("modrinth")) { | ||
return false; | ||
} | ||
return !isSafe(); | ||
} | ||
|
||
|
||
public static boolean isModUpdateAvailable() { | ||
return isUpdateAvailable; | ||
} | ||
|
||
public static boolean isSafe() { | ||
return isSafe; | ||
} | ||
|
||
public static boolean isFormatActual() { | ||
return isFormatActual; | ||
} | ||
|
||
public static boolean isChecked() { | ||
return isChecked; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters