got rid of dependency injection, it doesn't add anything at this point and only slows down things and makes a mess. Also some refactoring.
This commit is contained in:
@@ -35,26 +35,18 @@ import java.util.Properties;
|
||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||
import org.newdawn.slick.util.Log;
|
||||
import org.newdawn.slick.util.ResourceLoader;
|
||||
import yugecin.opsudance.core.Constants;
|
||||
import yugecin.opsudance.core.errorhandling.ErrorHandler;
|
||||
import yugecin.opsudance.core.events.EventBus;
|
||||
import yugecin.opsudance.core.inject.Inject;
|
||||
import yugecin.opsudance.events.BarNotificationEvent;
|
||||
import yugecin.opsudance.options.Configuration;
|
||||
|
||||
import static yugecin.opsudance.core.InstanceContainer.*;
|
||||
|
||||
/**
|
||||
* Handles automatic program updates.
|
||||
*/
|
||||
public class Updater {
|
||||
|
||||
@Inject
|
||||
private Configuration config;
|
||||
|
||||
private static Updater updater;
|
||||
|
||||
public static Updater get() {
|
||||
return updater;
|
||||
}
|
||||
|
||||
/** The exit confirmation message. */
|
||||
public static final String EXIT_CONFIRMATION = "An opsu! update is being downloaded.\nAre you sure you want to quit opsu!?";
|
||||
|
||||
@@ -95,7 +87,7 @@ public class Updater {
|
||||
* Returns the status description.
|
||||
*/
|
||||
public String getDescription() { return description; }
|
||||
};
|
||||
}
|
||||
|
||||
/** The current updater status. */
|
||||
private Status status;
|
||||
@@ -119,10 +111,8 @@ public class Updater {
|
||||
return currentVersion.getMajorVersion() + "." + currentVersion.getMinorVersion() + "." + currentVersion.getIncrementalVersion();
|
||||
}
|
||||
|
||||
@Inject
|
||||
public Updater() {
|
||||
status = Status.INITIAL;
|
||||
updater = this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,7 +135,7 @@ public class Updater {
|
||||
Date date = null;
|
||||
try {
|
||||
Properties props = new Properties();
|
||||
props.load(ResourceLoader.getResourceAsStream(config.VERSION_FILE));
|
||||
props.load(ResourceLoader.getResourceAsStream(Constants.VERSION_FILE));
|
||||
String build = props.getProperty("build.date");
|
||||
if (build == null || build.equals("${timestamp}") || build.equals("${maven.build.timestamp}"))
|
||||
date = new Date();
|
||||
@@ -214,16 +204,16 @@ public class Updater {
|
||||
|
||||
// get current version
|
||||
Properties props = new Properties();
|
||||
props.load(ResourceLoader.getResourceAsStream(config.VERSION_FILE));
|
||||
props.load(ResourceLoader.getResourceAsStream(Constants.VERSION_FILE));
|
||||
if ((currentVersion = getVersion(props)) == null)
|
||||
return;
|
||||
|
||||
// get latest version
|
||||
String s = null;
|
||||
try {
|
||||
s = Utils.readDataFromUrl(new URL(config.VERSION_REMOTE));
|
||||
s = Utils.readDataFromUrl(new URL(Constants.VERSION_REMOTE));
|
||||
} catch (UnknownHostException e) {
|
||||
Log.warn(String.format("Check for updates failed. Please check your internet connection, or your connection to %s.", config.VERSION_REMOTE));
|
||||
Log.warn(String.format("Check for updates failed. Please check your internet connection, or your connection to %s.", Constants.VERSION_REMOTE));
|
||||
}
|
||||
if (s == null) {
|
||||
status = Status.CONNECTION_ERROR;
|
||||
|
||||
Reference in New Issue
Block a user