1- package xyz . qalcyo .damagetint .utils ;
1+ package net . wyvest .damagetint .updater ;
22
33import com .google .gson .JsonObject ;
44import gg .essential .api .EssentialAPI ;
55import gg .essential .api .utils .Multithreading ;
6+ import gg .essential .api .utils .WebUtil ;
7+ import gg .essential .universal .UDesktop ;
68import kotlin .Unit ;
79import net .minecraft .client .Minecraft ;
810import net .minecraftforge .fml .common .versioning .DefaultArtifactVersion ;
11+ import net .wyvest .damagetint .DamageTint ;
12+ import net .wyvest .damagetint .config .Config ;
913import org .apache .commons .lang3 .StringUtils ;
10- import org .apache .http .HttpResponse ;
11- import org .apache .http .client .methods .HttpGet ;
12- import xyz .qalcyo .damagetint .DamageTint ;
13- import xyz .qalcyo .damagetint .config .Config ;
14- import xyz .qalcyo .damagetint .gui .DownloadConfirmGui ;
1514
16- import java .awt .*;
1715import java .io .File ;
18- import java .io .FileOutputStream ;
1916import java .io .IOException ;
2017import java .util .Locale ;
2118
@@ -27,12 +24,11 @@ public class Updater {
2724 public static void update () {
2825 Multithreading .runAsync (() -> {
2926 try {
30- JsonObject latestRelease = APIUtil . getJSONResponse ("https://api.github.com/repos/Qalcyo /" + DamageTint .ID + "/releases/latest" );
27+ JsonObject latestRelease = WebUtil . fetchJSON ("https://api.github.com/repos/W-OVERFLOW /" + DamageTint .ID + "/releases/latest" ). getObject ( );
3128 latestTag = latestRelease .get ("tag_name" ).getAsString ();
3229 DefaultArtifactVersion currentVersion = new DefaultArtifactVersion (StringUtils .substringBefore (DamageTint .VER , "-" ));
3330 DefaultArtifactVersion latestVersion = new DefaultArtifactVersion (StringUtils .substringBefore (StringUtils .substringAfter (latestTag , "v" ), "-" ));
34- if (DamageTint .VER .contains ("BETA" ) || currentVersion .compareTo (latestVersion ) >= 0 ) {
35- System .out .println ("Either current version is on a beta, or the current version is the same or newer than the latest version." );
31+ if (currentVersion .compareTo (latestVersion ) >= 0 ) {
3632 return ;
3733 }
3834 updateUrl = latestRelease .get ("assets" ).getAsJsonArray ().get (0 ).getAsJsonObject ().get ("browser_download_url" ).getAsString ();
@@ -47,27 +43,22 @@ public static void update() {
4743 }
4844 });
4945 }
46+
5047 public static Unit openUpdateGui () {
51- EssentialAPI .getGuiUtil ().openScreen (new DownloadConfirmGui ( Minecraft . getMinecraft (). currentScreen ));
48+ EssentialAPI .getGuiUtil ().openScreen (new DownloadGui ( ));
5249 return Unit .INSTANCE ;
5350 }
5451
5552 public static boolean download (String url , File file ) {
5653 if (file .exists ()) return true ;
5754 url = url .replace (" " , "%20" );
58- try (FileOutputStream fileOut = new FileOutputStream (file )) {
59- HttpResponse downloadResponse = APIUtil .builder .build ().execute (new HttpGet (url ));
60- byte [] buffer = new byte [1024 ];
61-
62- int read ;
63- while ((read = downloadResponse .getEntity ().getContent ().read (buffer )) > 0 ) {
64- fileOut .write (buffer , 0 , read );
65- }
55+ try {
56+ WebUtil .downloadToFile (url , file , DamageTint .NAME + "/" + DamageTint .VER );
6657 } catch (Exception e ) {
6758 e .printStackTrace ();
6859 return false ;
6960 }
70- return true ;
61+ return file . exists () ;
7162 }
7263
7364 /**
@@ -80,7 +71,7 @@ public static void addShutdownHook() {
8071 try {
8172 String runtime = getJavaRuntime ();
8273 if (Minecraft .isRunningOnMac ) {
83- Desktop . getDesktop () .open (DamageTint .jarFile .getParentFile ());
74+ UDesktop .open (DamageTint .jarFile .getParentFile ());
8475 }
8576 File file = new File (DamageTint .modDir .getParentFile (), "Deleter-1.2.jar" );
8677 Runtime .getRuntime ()
@@ -94,15 +85,16 @@ public static void addShutdownHook() {
9485
9586 /**
9687 * Gets the current Java runtime being used.
88+ *
9789 * @link https://stackoverflow.com/a/47925649
9890 */
9991 public static String getJavaRuntime () throws IOException {
10092 String os = System .getProperty ("os.name" );
10193 String java = System .getProperty ("java.home" ) + File .separator + "bin" + File .separator +
10294 (os != null && os .toLowerCase (Locale .ENGLISH ).startsWith ("windows" ) ? "java.exe" : "java" );
10395 if (!new File (java ).isFile ()) {
104- throw new IOException ("Unable to find suitable java runtime at " + java );
96+ throw new IOException ("Unable to find suitable java runtime at " + java );
10597 }
10698 return java ;
10799 }
108- }
100+ }
0 commit comments