Skip to content

Instantly share code, notes, and snippets.

@MaanooAk
Created June 28, 2017 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaanooAk/755991f7365dd2863b11317fe2ae0113 to your computer and use it in GitHub Desktop.
Save MaanooAk/755991f7365dd2863b11317fe2ae0113 to your computer and use it in GitHub Desktop.
package com.maanoo.kickassist;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Scanner;
/**
* Check and upgrades to a new version.
*
* @author Akritas Akritidis
*/
public final class Upgrader {
private static final String location_version = "";
private static final String location_jar = "";
private Upgrader() {
}
public static boolean run() {
if (existsNewVersion()) {
return upgrade();
}
return false;
}
private static boolean existsNewVersion() {
try {
URL url = new URL(location_version);
try (Scanner in = new Scanner(url.openStream())) {
String line = in.nextLine().trim();
if (line.startsWith(Log.product) && !line.equals(Log.getFullVersion())) {
return true;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
private static boolean upgrade() {
try {
URL url = new URL(location_jar);
try (InputStream in = url.openStream()) {
Files.copy(in, ProjectPaths.FILE_KICKASSIST_JAR, StandardCopyOption.REPLACE_EXISTING);
}
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment