From 3bd9bbdafda419fa4a791558cb70d7747b82e88d Mon Sep 17 00:00:00 2001 From: Jeffrey Han Date: Thu, 12 Mar 2015 02:38:43 -0400 Subject: [PATCH] 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 --- src/itdelatrisu/opsu/Opsu.java | 4 +++ src/itdelatrisu/opsu/db/OsuDB.java | 17 +++++++---- src/itdelatrisu/opsu/downloads/Updater.java | 33 ++++++++++++++++++++- src/itdelatrisu/opsu/states/MainMenu.java | 15 ++++++---- 4 files changed, 57 insertions(+), 12 deletions(-) diff --git a/src/itdelatrisu/opsu/Opsu.java b/src/itdelatrisu/opsu/Opsu.java index c8487dc4..078e791d 100644 --- a/src/itdelatrisu/opsu/Opsu.java +++ b/src/itdelatrisu/opsu/Opsu.java @@ -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 diff --git a/src/itdelatrisu/opsu/db/OsuDB.java b/src/itdelatrisu/opsu/db/OsuDB.java index a76869d2..c2b76e83 100644 --- a/src/itdelatrisu/opsu/db/OsuDB.java +++ b/src/itdelatrisu/opsu/db/OsuDB.java @@ -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); } diff --git a/src/itdelatrisu/opsu/downloads/Updater.java b/src/itdelatrisu/opsu/downloads/Updater.java index 759472a2..c70a48ff 100644 --- a/src/itdelatrisu/opsu/downloads/Updater.java +++ b/src/itdelatrisu/opsu/downloads/Updater.java @@ -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; diff --git a/src/itdelatrisu/opsu/states/MainMenu.java b/src/itdelatrisu/opsu/states/MainMenu.java index 18b6ee3c..832593c9 100644 --- a/src/itdelatrisu/opsu/states/MainMenu.java +++ b/src/itdelatrisu/opsu/states/MainMenu.java @@ -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