From fb7a6f93273a56560ac74c4924b61bc0444ed831 Mon Sep 17 00:00:00 2001 From: Volcano Date: Sat, 16 Mar 2019 21:44:35 +0100 Subject: [PATCH] Update --- .classpath | 6 ++ .project | 17 ++++++ .settings/org.eclipse.jdt.core.prefs | 11 ++++ bin/autoupdater/Updater.class | Bin 0 -> 3781 bytes src/autoupdater/Updater.java | 82 +++++++++++++++++++++++++++ 5 files changed, 116 insertions(+) create mode 100644 .classpath create mode 100644 .project create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 bin/autoupdater/Updater.class create mode 100644 src/autoupdater/Updater.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..329c16d --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + UnturnedNPCCreatorAutoupdater + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/bin/autoupdater/Updater.class b/bin/autoupdater/Updater.class new file mode 100644 index 0000000000000000000000000000000000000000..9059abd4418d5450a36af1b13fbc0f1cf6868f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hNxgJ$6Cg?g(Um}<+gQ?Na(~3ASQ##v8S?smx#h$x_GmD?8v}qytOJn3xuw-w6k}H%9 zn?cgGZD~5ncMX3nHNK^-n2`)yuAP*MVRW^4A>5@v#5SJTmApDuusKzsnlsIt1vw9u z&1)$|s$n&sYbX)nTku`gRzTe)PbJK!G5`v!MF#W z*o-DL;x25Vt=sv}!d7ZE)6yNZdM8iQ?L0qsAj|i8wBlV}hCGw)K{vCp%X zr8TAwU&qtjp;k2F8~7#@+r%9s_!gP87Xf@5-{I&%Oye0m%lS#(kiLuWkz+~j{T!ZW zOygwO_wfTV?r}=^qjx!aLFsbO;s`(FJ~If<6Mza0Khj7|p`kA@j}8R=4;se3zoQy> za9ynt|Hz1VpHwfyv}0p^nLSIFASWNjhdQNV8tcvUgh ziWl&DXVolf6;Vln6N*%C#5=36&;MHuf2SDv)XUt>&uSm)Io?k{4zRcmGKcpuZ->x^ zZf4+q!qm$vZ676i(Z%^89N~TO0iFUejPQMmyhvfl%jQWICZoXbnGaRCWB3F9$SBwG ziuEVvrh=9$aShk`jL@1tQhPmvw}?lS9pr7iLo{MU>d&-N&0Mc8j#TEF5cn_JG+Y$_ bK|sS_-bbT`%Ni^VQ#XjAz~3lUfxrI`9q7@q literal 0 HcmV?d00001 diff --git a/src/autoupdater/Updater.java b/src/autoupdater/Updater.java new file mode 100644 index 0000000..bd93fa6 --- /dev/null +++ b/src/autoupdater/Updater.java @@ -0,0 +1,82 @@ +package autoupdater; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class Updater { + + static final String FILE_URL = "https://api.github.com/repos/volcanocookies/unturnednpccreator/releases/latest"; + static final String FILE_NAME = "Unturned NPC Creator.exe"; + + public static void main(String[] args) { + //Delete old program + File oldVersion = new File(args[0]); + oldVersion.delete(); + + //Get latest version + try { + Matcher matcher = Pattern.compile("\"browser_download_url\":\"(https://github.com/VolcanoCookies/UnturnedNPCCreator/releases/download/[^\"]*)\"").matcher(getText(FILE_URL)); + if(matcher.find()) { + System.out.println(matcher.group(1)); + } + } catch (IOException e1) { + e1.printStackTrace(); + } + try (BufferedInputStream in = new BufferedInputStream(new URL(FILE_URL).openStream()); + FileOutputStream fileOutputStream = new FileOutputStream(FILE_NAME)) { + byte dataBuffer[] = new byte[1024]; + int bytesRead; + while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) { + fileOutputStream.write(dataBuffer, 0, bytesRead); + } + } catch (IOException e) { + // handle exception + e.printStackTrace(); + } + + //Start the new version + try { + new ProcessBuilder(oldVersion.getAbsolutePath().substring(0, oldVersion.getAbsolutePath().lastIndexOf("\\")) + "\\" + FILE_NAME).start(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + static String getText(String url) throws IOException { + HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); + //add headers to the connection, or check the status if desired.. + + // handle error response code it occurs + int responseCode = connection.getResponseCode(); + InputStream inputStream; + if (200 <= responseCode && responseCode <= 299) { + inputStream = connection.getInputStream(); + } else { + inputStream = connection.getErrorStream(); + } + + BufferedReader in = new BufferedReader( + new InputStreamReader( + inputStream)); + + StringBuilder response = new StringBuilder(); + String currentLine; + + while ((currentLine = in.readLine()) != null) + response.append(currentLine); + + in.close(); + + return response.toString(); + } +}