New updater notification and minor OsuDB fix.

- A bar notification is now shown after opsu! updates.
- Insert the current database version into the beatmap cache upon creation (fixes the initial version check) and only update the version if necessary.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-03-12 02:38:43 -04:00
parent 87323533af
commit 3bd9bbdafd
4 changed files with 57 additions and 12 deletions

View File

@ -137,6 +137,10 @@ public class Opsu extends StateBasedGame {
// initialize databases
DBController.init();
// check if just updated
if (args.length >= 2)
Updater.get().setUpdateInfo(args[0], args[1]);
// check for updates
new Thread() {
@Override

View File

@ -127,6 +127,10 @@ public class OsuDB {
"PRAGMA locking_mode = EXCLUSIVE; " +
"PRAGMA journal_mode = WAL;";
stmt.executeUpdate(sql);
// set the version key, if empty
sql = String.format("INSERT OR IGNORE INTO info(key, value) VALUES('version', '%s')", DATABASE_VERSION);
stmt.executeUpdate(sql);
} catch (SQLException e) {
ErrorHandler.error("Could not create beatmap database.", e, true);
}
@ -145,14 +149,15 @@ public class OsuDB {
rs.close();
// if different from current version, clear the database
if (!version.equals(DATABASE_VERSION))
if (!version.equals(DATABASE_VERSION)) {
clearDatabase();
// update version
PreparedStatement ps = connection.prepareStatement("REPLACE INTO info (key, value) VALUES ('version', ?)");
ps.setString(1, DATABASE_VERSION);
ps.executeUpdate();
ps.close();
// update version
PreparedStatement ps = connection.prepareStatement("REPLACE INTO info (key, value) VALUES ('version', ?)");
ps.setString(1, DATABASE_VERSION);
ps.executeUpdate();
ps.close();
}
} catch (SQLException e) {
ErrorHandler.error("Beatmap database version checks failed.", e, true);
}

View File

@ -97,6 +97,9 @@ public class Updater {
/** The current and latest versions. */
private DefaultArtifactVersion currentVersion, latestVersion;
/** The version information if the program was just updated. */
private String updatedFromVersion, updatedToVersion;
/** The build date. */
private int buildDate = -1;
@ -148,6 +151,31 @@ public class Updater {
return buildDate;
}
/**
* Sets the version information if the program was just updated.
* @param fromVersion the previous version
* @param toVersion the new version
*/
public void setUpdateInfo(String fromVersion, String toVersion) {
this.updatedFromVersion = fromVersion;
this.updatedToVersion = toVersion;
}
/**
* Returns whether or not the program was just updated.
*/
public boolean justUpdated() { return (updatedFromVersion != null && updatedToVersion != null); }
/**
* Returns the version the program was just updated from, or null if not updated.
*/
public String updatedFromVersion() { return (justUpdated()) ? updatedFromVersion : null; }
/**
* Returns the version the program was just updated to, or null if not updated.
*/
public String updatedToVersion() { return (justUpdated()) ? updatedToVersion : null; }
/**
* Returns the version from a set of properties.
* @param props the set of properties
@ -248,7 +276,10 @@ public class Updater {
try {
// TODO: it is better to wait for the process? is this portable?
ProcessBuilder pb = new ProcessBuilder("java", "-jar", download.getLocalPath());
ProcessBuilder pb = new ProcessBuilder(
"java", "-jar", download.getLocalPath(),
currentVersion.toString(), latestVersion.toString()
);
pb.start();
} catch (IOException e) {
status = Status.INTERNAL_ERROR;

View File

@ -97,8 +97,8 @@ public class MainMenu extends BasicGameState {
/** Background alpha level (for fade-in effect). */
private float bgAlpha = 0f;
/** Whether or not an update notification was already sent. */
private boolean updateNotification = false;
/** Whether or not a notification was already sent upon entering. */
private boolean enterNotification = false;
/** Music position bar coordinates and dimensions. */
private float musicBarX, musicBarY, musicBarWidth, musicBarHeight;
@ -388,9 +388,14 @@ public class MainMenu extends BasicGameState {
public void enter(GameContainer container, StateBasedGame game)
throws SlickException {
UI.enter();
if (!updateNotification && Updater.get().getStatus() == Updater.Status.UPDATE_AVAILABLE) {
UI.sendBarNotification("An opsu! update is available.");
updateNotification = true;
if (!enterNotification) {
if (Updater.get().getStatus() == Updater.Status.UPDATE_AVAILABLE) {
UI.sendBarNotification("An opsu! update is available.");
enterNotification = true;
} else if (Updater.get().justUpdated()) {
UI.sendBarNotification("opsu! is now up to date!");
enterNotification = true;
}
}
// reset button hover states if mouse is not currently hovering over the button