Skip to content

Commit

Permalink
v1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
RizlimDev authored and RizlimDev committed Sep 4, 2018
1 parent 3030f3e commit af774e2
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 1 deletion.
4 changes: 4 additions & 0 deletions PoE-Addon-Manager-Launcher.iml
Expand Up @@ -16,5 +16,9 @@
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.6" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: org.kohsuke:github-api:1.93" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.7" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.7" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:1.4" level="project" />
</component>
</module>
7 changes: 6 additions & 1 deletion pom.xml
Expand Up @@ -6,7 +6,7 @@

<groupId>RizlimDev</groupId>
<artifactId>PoE-Addon-Manager-Launcher</artifactId>
<version>1.1</version>
<version>1.2</version>

<dependencies>
<dependency>
Expand All @@ -19,6 +19,11 @@
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.kohsuke</groupId>
<artifactId>github-api</artifactId>
<version>1.93</version>
</dependency>
</dependencies>

<build>
Expand Down
73 changes: 73 additions & 0 deletions src/main/java/GUI/LauncherUI_Controller.java
Expand Up @@ -9,6 +9,7 @@
import javafx.scene.text.Text;
import javafx.stage.Stage;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
Expand All @@ -32,11 +33,77 @@ public class LauncherUI_Controller implements Initializable
*/
public void initialize(URL location, ResourceBundle resources)
{
cleanUp();
daemon_progress();
daemon_checker();
daemon_launch();
}

private void runMostRecentVersion()
{

Runtime runtime = Runtime.getRuntime();
try
{
runtime.exec("java -jar " + mr_jar.getPath());
} catch (IOException e)
{
e.printStackTrace();
}

Stage s = LauncherUI.stage;
Platform.runLater(() -> s.close());

}

private boolean isNewer(String _old, String _new)
{
_old = _old.replace("b", "");
_old = _old.replace(".jar", "");
_new = _new.replace("b", "");
_new =_new.replace(".jar", "");

int num_old = Integer.parseInt(_old);
int num_new = Integer.parseInt(_new);

return num_new > num_old;
}

private File mr_jar;
private void cleanUp()
{
File f = new File(Data.getINSTANCE().getProgram_path());
if (f.exists())
{
if (f.isDirectory())
{
File[] files = f.listFiles();
File most_recent_jar = new File("b0.jar");
for (File file : files)
{
if (file.getName().contains(".jar"))
{
if (isNewer(most_recent_jar.getName(), file.getName()))
{
most_recent_jar = file;
}
}
}
mr_jar = most_recent_jar;
for (File file : files)
{
if (file.getName().contains(".jar"))
{
if (!file.getName().equals(most_recent_jar.getName()))
{
file.delete();
}
}
}
}
}
}

/**
* This daemon will terminate the launcher and launch the core program.
*/
Expand Down Expand Up @@ -90,6 +157,12 @@ private void daemon_checker()
// Create Releases Array
Data.setStatus("Accessing github for releases");
ArrayList<Release> releases = UpdateCheckerClient.getINSTANCE().getReleases();
if (releases == null)
{
Data.setStatus("Can't connect to the GitHub API using installed version.");
runMostRecentVersion();
return;
}

Data.setStatus("Got all " + releases.size() + " releases!");

Expand Down
22 changes: 22 additions & 0 deletions src/main/java/Helper/UpdateCheckerClient.java
Expand Up @@ -3,6 +3,7 @@
import GUI.Data;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.kohsuke.github.GitHub;

import java.io.File;
import java.io.IOException;
Expand All @@ -13,6 +14,7 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;

/**
Expand Down Expand Up @@ -79,6 +81,12 @@ public void downloadUpdate(Release most_recent)
*/
public ArrayList<Release> getReleases()
{
if (!canCheckGithub())
{
return null;
}


ArrayList<Release> releases = new ArrayList<>();
try
{
Expand All @@ -103,4 +111,18 @@ public ArrayList<Release> getReleases()
}
return releases;
}

private boolean canCheckGithub()
{
try
{
GitHub github = GitHub.connectAnonymously();
return github.getRateLimit().remaining > 0;
}
catch (IOException e)
{
e.printStackTrace();
}
return false;
}
}

0 comments on commit af774e2

Please sign in to comment.