Created
June 28, 2017 13:33
-
-
Save MaanooAk/755991f7365dd2863b11317fe2ae0113 to your computer and use it in GitHub Desktop.
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
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