|
18 | 18 |
|
19 | 19 | package airsquared.blobsaver.app; |
20 | 20 |
|
| 21 | +import com.google.gson.JsonElement; |
| 22 | +import com.google.gson.JsonParser; |
21 | 23 | import com.sun.jna.Platform; |
22 | 24 | import javafx.scene.Node; |
23 | 25 | import javafx.scene.control.Alert; |
|
34 | 36 | import javafx.stage.DirectoryChooser; |
35 | 37 | import javafx.stage.Window; |
36 | 38 | import org.apache.commons.compress.archivers.zip.ZipFile; |
37 | | -import org.json.JSONObject; |
38 | | -import org.json.JSONTokener; |
39 | 39 |
|
40 | 40 | import java.io.*; |
41 | 41 | import java.net.URI; |
@@ -90,11 +90,11 @@ static void checkForUpdates(boolean forceCheck) { |
90 | 90 | executeInThreadPool(() -> _checkForUpdates(forceCheck)); |
91 | 91 | } |
92 | 92 |
|
93 | | - static final record LatestVersion(String version, String changelog) { |
| 93 | + record LatestVersion(String version, String changelog) { |
94 | 94 | static LatestVersion request() throws IOException { |
95 | | - JSONObject json = makeRequest("https://api.github.com/repos/airsquared/blobsaver/releases/latest"); |
96 | | - String tempChangelog = json.getString("body"); |
97 | | - return new LatestVersion(json.getString("tag_name"), tempChangelog.substring(tempChangelog.indexOf("Changelog"))); |
| 95 | + JsonElement json = makeRequest("https://api.github.com/repos/airsquared/blobsaver/releases/latest"); |
| 96 | + String tempChangelog = json.getAsJsonObject().get("body").getAsString(); |
| 97 | + return new LatestVersion(json.getAsJsonObject().get("tag_name").getAsString(), tempChangelog.substring(tempChangelog.indexOf("Changelog"))); |
98 | 98 | } |
99 | 99 |
|
100 | 100 | @Override |
@@ -140,9 +140,9 @@ private static void _checkForUpdates(boolean forceCheck) { |
140 | 140 | } |
141 | 141 | } |
142 | 142 |
|
143 | | - private static JSONObject makeRequest(String url) throws IOException { |
| 143 | + private static JsonElement makeRequest(String url) throws IOException { |
144 | 144 | try (var inputStream = new BufferedReader(new InputStreamReader(new URL(url).openStream()))) { |
145 | | - return new JSONObject(new JSONTokener(inputStream)); |
| 145 | + return JsonParser.parseReader(inputStream); |
146 | 146 | } |
147 | 147 | } |
148 | 148 |
|
@@ -349,16 +349,16 @@ static void runSafe(Runnable runnable) { |
349 | 349 |
|
350 | 350 | static Stream<IOSVersion> getFirmwareList(String deviceIdentifier) throws IOException { |
351 | 351 | String url = "https://api.ipsw.me/v4/device/" + deviceIdentifier; |
352 | | - return StreamSupport.stream(makeRequest(url).getJSONArray("firmwares").spliterator(), false) |
353 | | - .map(o -> (JSONObject) o) |
354 | | - .map(o -> new IOSVersion(o.getString("version"), o.getString("url"), o.getBoolean("signed"))); |
| 352 | + return StreamSupport.stream(makeRequest(url).getAsJsonObject().getAsJsonArray("firmwares").spliterator(), false) |
| 353 | + .map(JsonElement::getAsJsonObject) |
| 354 | + .map(o -> new IOSVersion(o.get("version").getAsString(), o.get("url").getAsString(), o.get("signed").getAsBoolean())); |
355 | 355 | } |
356 | 356 |
|
357 | 357 | static Stream<IOSVersion> getSignedFirmwares(String deviceIdentifier) throws IOException { |
358 | 358 | return getFirmwareList(deviceIdentifier).filter(IOSVersion::signed); |
359 | 359 | } |
360 | 360 |
|
361 | | - static final record IOSVersion(String versionString, String ipswURL, Boolean signed) { |
| 361 | + record IOSVersion(String versionString, String ipswURL, Boolean signed) { |
362 | 362 | public IOSVersion { |
363 | 363 | Objects.requireNonNull(ipswURL, "ipsw url cannot be null"); |
364 | 364 | } |
|
0 commit comments