This repository has been archived by the owner on Apr 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
92a597f
commit fb7a6f9
Showing
5 changed files
with
116 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
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,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>UnturnedNPCCreatorAutoupdater</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
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,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 |
Binary file not shown.
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,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(); | ||
} | ||
} |