From f730935622d33da4e168f18f7bcc927997cd9772 Mon Sep 17 00:00:00 2001 From: yugecin Date: Sat, 21 Jan 2017 01:16:27 +0100 Subject: [PATCH] use the new errorhandler & bubble notifs --- src/itdelatrisu/opsu/GameImage.java | 16 +++++--- src/itdelatrisu/opsu/Options.java | 20 ++++++---- src/itdelatrisu/opsu/Utils.java | 24 +++++++----- src/itdelatrisu/opsu/audio/MultiClip.java | 4 +- .../opsu/audio/MusicController.java | 15 +++++--- .../opsu/audio/SoundController.java | 12 +++--- .../opsu/beatmap/BeatmapParser.java | 26 +++++++++---- .../opsu/beatmap/BeatmapSetList.java | 7 ++-- .../opsu/beatmap/BeatmapWatchService.java | 9 +++-- src/itdelatrisu/opsu/beatmap/OszUnpacker.java | 9 +++-- src/itdelatrisu/opsu/db/BeatmapDB.java | 38 +++++++++---------- src/itdelatrisu/opsu/db/DBController.java | 6 +-- src/itdelatrisu/opsu/db/ScoreDB.java | 20 +++++----- src/itdelatrisu/opsu/downloads/Download.java | 10 +++-- .../opsu/downloads/DownloadNode.java | 5 ++- src/itdelatrisu/opsu/downloads/Updater.java | 4 +- .../downloads/servers/BloodcatServer.java | 4 +- .../opsu/downloads/servers/HexideServer.java | 4 +- .../opsu/downloads/servers/MengSkyServer.java | 4 +- .../downloads/servers/MnetworkServer.java | 4 +- .../downloads/servers/OsuMirrorServer.java | 4 +- .../downloads/servers/YaSOnlineServer.java | 6 +-- .../opsu/render/CurveRenderState.java | 2 +- .../opsu/render/FrameBufferCache.java | 1 + src/itdelatrisu/opsu/replay/Replay.java | 10 +++-- .../opsu/replay/ReplayImporter.java | 17 ++++++--- src/itdelatrisu/opsu/skins/SkinLoader.java | 7 +++- .../opsu/states/DownloadsMenu.java | 1 - src/itdelatrisu/opsu/states/MainMenu.java | 10 +++-- src/itdelatrisu/opsu/ui/Cursor.java | 5 +-- src/itdelatrisu/opsu/ui/UI.java | 16 -------- src/yugecin/opsudance/OpsuDance.java | 8 ++-- .../opsudance/core/DisplayContainer.java | 2 + .../core/errorhandling/ErrorHandler.java | 12 +++++- .../opsudance/core/events/EventBus.java | 4 ++ 35 files changed, 199 insertions(+), 147 deletions(-) diff --git a/src/itdelatrisu/opsu/GameImage.java b/src/itdelatrisu/opsu/GameImage.java index cd1dd463..17efa2de 100644 --- a/src/itdelatrisu/opsu/GameImage.java +++ b/src/itdelatrisu/opsu/GameImage.java @@ -27,7 +27,11 @@ import java.util.List; import org.newdawn.slick.Animation; import org.newdawn.slick.Image; import org.newdawn.slick.SlickException; +import org.newdawn.slick.util.Log; import org.newdawn.slick.util.ResourceLoader; +import yugecin.opsudance.core.errorhandling.ErrorHandler; +import yugecin.opsudance.core.events.EventBus; +import yugecin.opsudance.events.BubbleNotificationEvent; import yugecin.opsudance.utils.SlickUtil; /** @@ -706,7 +710,9 @@ public enum GameImage { return; } - ErrorHandler.error(String.format("Could not find default image '%s'.", filename), null, false); + String err = String.format("Could not find default image '%s'.", filename); + Log.warn(err); + EventBus.instance.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED)); } /** @@ -765,7 +771,7 @@ public enum GameImage { img = img.getScaledCopy(0.5f); list.add(img); } catch (SlickException e) { - ErrorHandler.error(String.format("Failed to set image '%s'.", name), null, false); + EventBus.instance.post(new BubbleNotificationEvent(String.format("Failed to set image '%s'.", name), BubbleNotificationEvent.COMMONCOLOR_RED)); break; } } @@ -779,7 +785,7 @@ public enum GameImage { img = img.getScaledCopy(0.5f); list.add(img); } catch (SlickException e) { - ErrorHandler.error(String.format("Failed to set image '%s'.", name), null, false); + EventBus.instance.post(new BubbleNotificationEvent(String.format("Failed to set image '%s'.", name), BubbleNotificationEvent.COMMONCOLOR_RED)); break; } } @@ -806,7 +812,7 @@ public enum GameImage { img = img.getScaledCopy(0.5f); return img; } catch (SlickException e) { - ErrorHandler.error(String.format("Failed to set image '%s'.", filename), null, false); + EventBus.instance.post(new BubbleNotificationEvent(String.format("Failed to set image '%s'.", filename), BubbleNotificationEvent.COMMONCOLOR_RED)); } } } @@ -851,7 +857,7 @@ public enum GameImage { skinImages = null; } } catch (SlickException e) { - ErrorHandler.error(String.format("Failed to destroy beatmap skin images for '%s'.", this.name()), e, true); + ErrorHandler.error(String.format("Failed to destroy beatmap skin images for '%s'.", this.name()), e).show(); } } diff --git a/src/itdelatrisu/opsu/Options.java b/src/itdelatrisu/opsu/Options.java index 03a8c772..e095c5d2 100644 --- a/src/itdelatrisu/opsu/Options.java +++ b/src/itdelatrisu/opsu/Options.java @@ -60,6 +60,8 @@ import com.sun.jna.platform.win32.Win32Exception; import com.sun.jna.platform.win32.WinReg; import yugecin.opsudance.*; import yugecin.opsudance.core.DisplayContainer; +import yugecin.opsudance.core.errorhandling.ErrorHandler; +import yugecin.opsudance.core.events.EventBus; import yugecin.opsudance.events.BubbleNotificationEvent; import yugecin.opsudance.movers.factories.ExgonMoverFactory; import yugecin.opsudance.movers.factories.QuadraticBezierMoverFactory; @@ -197,7 +199,7 @@ public class Options { } File dir = new File(rootPath, "opsu"); if (!dir.isDirectory() && !dir.mkdir()) - ErrorHandler.error(String.format("Failed to create configuration folder at '%s/opsu'.", rootPath), null, false); + ErrorHandler.error(String.format("Failed to create configuration folder at '%s/opsu'.", rootPath), new Exception("empty")).preventReport().show(); return dir; } else return workingDir; @@ -1785,7 +1787,7 @@ public class Options { // use default directory beatmapDir = BEATMAP_DIR; if (!beatmapDir.isDirectory() && !beatmapDir.mkdir()) - ErrorHandler.error(String.format("Failed to create beatmap directory at '%s'.", beatmapDir.getAbsolutePath()), null, false); + EventBus.instance.post(new BubbleNotificationEvent(String.format("Failed to create beatmap directory at '%s'.", beatmapDir.getAbsolutePath()), BubbleNotificationEvent.COMMONCOLOR_RED)); return beatmapDir; } @@ -1800,7 +1802,7 @@ public class Options { oszDir = new File(DATA_DIR, "SongPacks/"); if (!oszDir.isDirectory() && !oszDir.mkdir()) - ErrorHandler.error(String.format("Failed to create song packs directory at '%s'.", oszDir.getAbsolutePath()), null, false); + EventBus.instance.post(new BubbleNotificationEvent(String.format("Failed to create song packs directory at '%s'.", oszDir.getAbsolutePath()), BubbleNotificationEvent.COMMONCOLOR_RED)); return oszDir; } @@ -1815,7 +1817,7 @@ public class Options { replayImportDir = new File(DATA_DIR, "ReplayImport/"); if (!replayImportDir.isDirectory() && !replayImportDir.mkdir()) - ErrorHandler.error(String.format("Failed to create replay import directory at '%s'.", replayImportDir.getAbsolutePath()), null, false); + EventBus.instance.post(new BubbleNotificationEvent(String.format("Failed to create replay import directory at '%s'.", replayImportDir.getAbsolutePath()), BubbleNotificationEvent.COMMONCOLOR_RED)); return replayImportDir; } @@ -1865,7 +1867,7 @@ public class Options { // use default directory skinRootDir = SKIN_ROOT_DIR; if (!skinRootDir.isDirectory() && !skinRootDir.mkdir()) - ErrorHandler.error(String.format("Failed to create skins directory at '%s'.", skinRootDir.getAbsolutePath()), null, false); + EventBus.instance.post(new BubbleNotificationEvent(String.format("Failed to create skins directory at '%s'.", skinRootDir.getAbsolutePath()), BubbleNotificationEvent.COMMONCOLOR_RED)); return skinRootDir; } @@ -1998,7 +2000,9 @@ public class Options { } GameOption.DANCE_HIDE_WATERMARK.setValue(false); } catch (IOException e) { - ErrorHandler.error(String.format("Failed to read file '%s'.", OPTIONS_FILE.getAbsolutePath()), e, false); + String err = String.format("Failed to read file '%s'.", OPTIONS_FILE.getAbsolutePath()); + Log.error(err, e); + EventBus.instance.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED)); } } @@ -2027,7 +2031,9 @@ public class Options { } writer.close(); } catch (IOException e) { - ErrorHandler.error(String.format("Failed to write to file '%s'.", OPTIONS_FILE.getAbsolutePath()), e, false); + String err = String.format("Failed to write to file '%s'.", OPTIONS_FILE.getAbsolutePath()); + Log.error(err, e); + EventBus.instance.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED)); } } } diff --git a/src/itdelatrisu/opsu/Utils.java b/src/itdelatrisu/opsu/Utils.java index a66e320d..746a5e68 100644 --- a/src/itdelatrisu/opsu/Utils.java +++ b/src/itdelatrisu/opsu/Utils.java @@ -73,6 +73,9 @@ import org.newdawn.slick.util.Log; import com.sun.jna.platform.FileUtils; import yugecin.opsudance.core.DisplayContainer; +import yugecin.opsudance.core.errorhandling.ErrorHandler; +import yugecin.opsudance.core.events.EventBus; +import yugecin.opsudance.events.BubbleNotificationEvent; /** * Contains miscellaneous utilities. @@ -245,14 +248,14 @@ public class Utils { // create the screenshot directory File dir = Options.getScreenshotDir(); if (!dir.isDirectory() && !dir.mkdir()) { - ErrorHandler.error(String.format("Failed to create screenshot directory at '%s'.", dir.getAbsolutePath()), null, false); + EventBus.instance.post(new BubbleNotificationEvent(String.format("Failed to create screenshot directory at '%s'.", dir.getAbsolutePath()), BubbleNotificationEvent.COMMONCOLOR_RED)); return; } // create file name SimpleDateFormat date = new SimpleDateFormat("yyyyMMdd_HHmmss"); - final File file = new File(dir, String.format("screenshot_%s.%s", - date.format(new Date()), Options.getScreenshotFormat())); + final String fileName = String.format("screenshot_%s.%s", date.format(new Date()), Options.getScreenshotFormat()); + final File file = new File(dir, fileName); SoundController.playSound(SoundEffect.SHUTTER); @@ -279,8 +282,9 @@ public class Utils { } } ImageIO.write(image, Options.getScreenshotFormat(), file); + EventBus.instance.post(new BubbleNotificationEvent("Created " + fileName, BubbleNotificationEvent.COMMONCOLOR_PURPLE)); } catch (Exception e) { - ErrorHandler.error("Failed to take a screenshot.", e, true); + ErrorHandler.error("Failed to take a screenshot.", e).show(); } } }.start(); @@ -429,7 +433,7 @@ public class Utils { try { json = new JSONObject(s); } catch (JSONException e) { - ErrorHandler.error("Failed to create JSON object.", e, true); + ErrorHandler.error("Failed to create JSON object.", e).show(); } } return json; @@ -448,7 +452,7 @@ public class Utils { try { json = new JSONArray(s); } catch (JSONException e) { - ErrorHandler.error("Failed to create JSON array.", e, true); + ErrorHandler.error("Failed to create JSON array.", e).show(); } } return json; @@ -490,7 +494,7 @@ public class Utils { result.append(String.format("%02x", b)); return result.toString(); } catch (NoSuchAlgorithmException | IOException e) { - ErrorHandler.error("Failed to calculate MD5 hash.", e, true); + ErrorHandler.error("Failed to calculate MD5 hash.", e).show(); } return null; } @@ -514,7 +518,7 @@ public class Utils { * @return true if JAR, false if file */ public static boolean isJarRunning() { - return Opsu.class.getResource(String.format("%s.class", Opsu.class.getSimpleName())).toString().startsWith("jar:"); + return Utils.class.getResource(String.format("%s.class", Utils.class.getSimpleName())).toString().startsWith("jar:"); } /** @@ -526,7 +530,7 @@ public class Utils { return null; try { - return new JarFile(new File(Opsu.class.getProtectionDomain().getCodeSource().getLocation().toURI()), false); + return new JarFile(new File(Utils.class.getProtectionDomain().getCodeSource().getLocation().toURI()), false); } catch (URISyntaxException | IOException e) { Log.error("Could not determine the JAR file.", e); return null; @@ -539,7 +543,7 @@ public class Utils { */ public static File getRunningDirectory() { try { - return new File(Opsu.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()); + return new File(Utils.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()); } catch (URISyntaxException e) { Log.error("Could not get the running directory.", e); return null; diff --git a/src/itdelatrisu/opsu/audio/MultiClip.java b/src/itdelatrisu/opsu/audio/MultiClip.java index 3193aac7..d314815f 100644 --- a/src/itdelatrisu/opsu/audio/MultiClip.java +++ b/src/itdelatrisu/opsu/audio/MultiClip.java @@ -1,6 +1,6 @@ package itdelatrisu.opsu.audio; -import itdelatrisu.opsu.ErrorHandler; +import yugecin.opsudance.core.errorhandling.ErrorHandler; import java.io.IOException; import java.util.Iterator; @@ -194,7 +194,7 @@ public class MultiClip { try { audioIn.close(); } catch (IOException e) { - ErrorHandler.error(String.format("Could not close AudioInputStream for MultiClip %s.", name), e, true); + ErrorHandler.error(String.format("Could not close AudioInputStream for MultiClip %s.", name), e).show(); } } } diff --git a/src/itdelatrisu/opsu/audio/MusicController.java b/src/itdelatrisu/opsu/audio/MusicController.java index ba4ec00a..e8c6a0ad 100644 --- a/src/itdelatrisu/opsu/audio/MusicController.java +++ b/src/itdelatrisu/opsu/audio/MusicController.java @@ -18,7 +18,6 @@ package itdelatrisu.opsu.audio; -import itdelatrisu.opsu.ErrorHandler; import itdelatrisu.opsu.Options; import itdelatrisu.opsu.beatmap.Beatmap; import itdelatrisu.opsu.beatmap.BeatmapParser; @@ -44,8 +43,12 @@ import org.newdawn.slick.MusicListener; import org.newdawn.slick.SlickException; import org.newdawn.slick.openal.Audio; import org.newdawn.slick.openal.SoundStore; +import org.newdawn.slick.util.Log; import org.newdawn.slick.util.ResourceLoader; import org.tritonus.share.sampled.file.TAudioFileFormat; +import yugecin.opsudance.core.errorhandling.ErrorHandler; +import yugecin.opsudance.core.events.EventBus; +import yugecin.opsudance.events.BubbleNotificationEvent; /** * Controller for all music. @@ -152,7 +155,9 @@ public class MusicController { }); playAt(position, loop); } catch (Exception e) { - ErrorHandler.error(String.format("Could not play track '%s'.", file.getName()), e, false); + String err = String.format("Could not play track '%s'.", file.getName()); + Log.error(err, e); + EventBus.instance.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED)); } } @@ -496,9 +501,7 @@ public class MusicController { trackLoader.interrupt(); try { trackLoader.join(); - } catch (InterruptedException e) { - ErrorHandler.error(null, e, true); - } + } catch (InterruptedException ignored) { } } trackLoader = null; @@ -575,7 +578,7 @@ public class MusicController { player = null; } catch (Exception e) { - ErrorHandler.error("Failed to destroy OpenAL.", e, true); + ErrorHandler.error("Failed to destroy OpenAL.", e).show(); } } diff --git a/src/itdelatrisu/opsu/audio/SoundController.java b/src/itdelatrisu/opsu/audio/SoundController.java index 7db7f608..10e8e850 100644 --- a/src/itdelatrisu/opsu/audio/SoundController.java +++ b/src/itdelatrisu/opsu/audio/SoundController.java @@ -18,7 +18,6 @@ package itdelatrisu.opsu.audio; -import itdelatrisu.opsu.ErrorHandler; import itdelatrisu.opsu.Options; import itdelatrisu.opsu.audio.HitSound.SampleSet; import itdelatrisu.opsu.beatmap.HitObject; @@ -41,6 +40,9 @@ import javax.sound.sampled.LineUnavailableException; import org.newdawn.slick.SlickException; import org.newdawn.slick.util.ResourceLoader; +import yugecin.opsudance.core.errorhandling.ErrorHandler; +import yugecin.opsudance.core.events.EventBus; +import yugecin.opsudance.events.BubbleNotificationEvent; /** * Controller for all (non-music) sound components. @@ -99,7 +101,7 @@ public class SoundController { AudioInputStream audioIn = AudioSystem.getAudioInputStream(url); return loadClip(ref, audioIn, isMP3); } catch (Exception e) { - ErrorHandler.error(String.format("Failed to load file '%s'.", ref), e, true); + ErrorHandler.error(String.format("Failed to load file '%s'.", ref), e).show(); return null; } } @@ -214,7 +216,7 @@ public class SoundController { // menu and game sounds for (SoundEffect s : SoundEffect.values()) { if ((currentFileName = getSoundFileName(s.getFileName())) == null) { - ErrorHandler.error(String.format("Could not find sound file '%s'.", s.getFileName()), null, false); + EventBus.instance.post(new BubbleNotificationEvent("Could not find sound file " + s.getFileName(), BubbleNotificationEvent.COLOR_ORANGE)); continue; } MultiClip newClip = loadClip(currentFileName, currentFileName.endsWith(".mp3")); @@ -233,7 +235,7 @@ public class SoundController { for (HitSound s : HitSound.values()) { String filename = String.format("%s-%s", ss.getName(), s.getFileName()); if ((currentFileName = getSoundFileName(filename)) == null) { - ErrorHandler.error(String.format("Could not find hit sound file '%s'.", filename), null, false); + EventBus.instance.post(new BubbleNotificationEvent("Could not find hit sound file " + filename, BubbleNotificationEvent.COLOR_ORANGE)); continue; } MultiClip newClip = loadClip(currentFileName, false); @@ -277,7 +279,7 @@ public class SoundController { try { clip.start(volume, listener); } catch (LineUnavailableException e) { - ErrorHandler.error(String.format("Could not start a clip '%s'.", clip.getName()), e, true); + ErrorHandler.error(String.format("Could not start a clip '%s'.", clip.getName()), e).show(); } } } diff --git a/src/itdelatrisu/opsu/beatmap/BeatmapParser.java b/src/itdelatrisu/opsu/beatmap/BeatmapParser.java index 3e3fa4f1..97e6442a 100644 --- a/src/itdelatrisu/opsu/beatmap/BeatmapParser.java +++ b/src/itdelatrisu/opsu/beatmap/BeatmapParser.java @@ -18,7 +18,6 @@ package itdelatrisu.opsu.beatmap; -import itdelatrisu.opsu.ErrorHandler; import itdelatrisu.opsu.Options; import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.db.BeatmapDB; @@ -35,6 +34,9 @@ import java.util.Map; import org.newdawn.slick.Color; import org.newdawn.slick.util.Log; +import yugecin.opsudance.core.errorhandling.ErrorHandler; +import yugecin.opsudance.core.events.EventBus; +import yugecin.opsudance.events.BubbleNotificationEvent; /** * Parser for beatmaps. @@ -243,9 +245,11 @@ public class BeatmapParser { } map.timingPoints.trimToSize(); } catch (IOException e) { - ErrorHandler.error(String.format("Failed to read file '%s'.", map.getFile().getAbsolutePath()), e, false); + String err = String.format("Failed to read file '%s'.", map.getFile().getAbsolutePath()); + Log.error(err, e); + EventBus.instance.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED)); } catch (NoSuchAlgorithmException e) { - ErrorHandler.error("Failed to get MD5 hash stream.", e, true); + ErrorHandler.error("Failed to get MD5 hash stream.", e).show(); // retry without MD5 hasNoMD5Algorithm = true; @@ -646,9 +650,11 @@ public class BeatmapParser { if (md5stream != null) beatmap.md5Hash = md5stream.getMD5(); } catch (IOException e) { - ErrorHandler.error(String.format("Failed to read file '%s'.", file.getAbsolutePath()), e, false); + String err = String.format("Failed to read file '%s'.", file.getAbsolutePath()); + Log.error(err, e); + EventBus.instance.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED)); } catch (NoSuchAlgorithmException e) { - ErrorHandler.error("Failed to get MD5 hash stream.", e, true); + ErrorHandler.error("Failed to get MD5 hash stream.", e).show(); // retry without MD5 hasNoMD5Algorithm = true; @@ -727,7 +733,9 @@ public class BeatmapParser { } beatmap.timingPoints.trimToSize(); } catch (IOException e) { - ErrorHandler.error(String.format("Failed to read file '%s'.", beatmap.getFile().getAbsolutePath()), e, false); + String err = String.format("Failed to read file '%s'.", beatmap.getFile().getAbsolutePath()); + Log.error(err, e); + EventBus.instance.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED)); } } @@ -803,9 +811,11 @@ public class BeatmapParser { // check that all objects were parsed if (objectIndex != beatmap.objects.length) ErrorHandler.error(String.format("Parsed %d objects for beatmap '%s', %d objects expected.", - objectIndex, beatmap.toString(), beatmap.objects.length), null, true); + objectIndex, beatmap.toString(), beatmap.objects.length), new Exception("no")).show(); } catch (IOException e) { - ErrorHandler.error(String.format("Failed to read file '%s'.", beatmap.getFile().getAbsolutePath()), e, false); + String err = String.format("Failed to read file '%s'.", beatmap.getFile().getAbsolutePath()); + Log.error(err, e); + EventBus.instance.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED)); } } diff --git a/src/itdelatrisu/opsu/beatmap/BeatmapSetList.java b/src/itdelatrisu/opsu/beatmap/BeatmapSetList.java index dc9471ce..eda1338a 100644 --- a/src/itdelatrisu/opsu/beatmap/BeatmapSetList.java +++ b/src/itdelatrisu/opsu/beatmap/BeatmapSetList.java @@ -18,11 +18,12 @@ package itdelatrisu.opsu.beatmap; -import itdelatrisu.opsu.ErrorHandler; import itdelatrisu.opsu.Options; import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.audio.MusicController; import itdelatrisu.opsu.db.BeatmapDB; +import yugecin.opsudance.core.events.EventBus; +import yugecin.opsudance.events.BubbleNotificationEvent; import java.io.File; import java.io.IOException; @@ -215,7 +216,7 @@ public class BeatmapSetList { try { Utils.deleteToTrash(dir); } catch (IOException e) { - ErrorHandler.error("Could not delete song group.", e, true); + EventBus.instance.post(new BubbleNotificationEvent("Could not delete song group", BubbleNotificationEvent.COLOR_ORANGE)); } if (ws != null) ws.resume(); @@ -270,7 +271,7 @@ public class BeatmapSetList { try { Utils.deleteToTrash(file); } catch (IOException e) { - ErrorHandler.error("Could not delete song.", e, true); + EventBus.instance.post(new BubbleNotificationEvent("Could not delete song", BubbleNotificationEvent.COLOR_ORANGE)); } if (ws != null) ws.resume(); diff --git a/src/itdelatrisu/opsu/beatmap/BeatmapWatchService.java b/src/itdelatrisu/opsu/beatmap/BeatmapWatchService.java index 8399cc22..f864c2ad 100644 --- a/src/itdelatrisu/opsu/beatmap/BeatmapWatchService.java +++ b/src/itdelatrisu/opsu/beatmap/BeatmapWatchService.java @@ -18,7 +18,6 @@ package itdelatrisu.opsu.beatmap; -import itdelatrisu.opsu.ErrorHandler; import itdelatrisu.opsu.Options; import java.io.IOException; @@ -42,6 +41,8 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import org.newdawn.slick.util.Log; +import yugecin.opsudance.core.events.EventBus; +import yugecin.opsudance.events.BubbleNotificationEvent; /* * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. @@ -96,7 +97,8 @@ public class BeatmapWatchService { ws = new BeatmapWatchService(); ws.register(Options.getBeatmapDir().toPath()); } catch (IOException e) { - ErrorHandler.error("An I/O exception occurred while creating the watch service.", e, true); + Log.error("Could not create watch service", e); + EventBus.instance.post(new BubbleNotificationEvent("Could not create watch service", BubbleNotificationEvent.COMMONCOLOR_RED)); return; } @@ -117,8 +119,9 @@ public class BeatmapWatchService { ws.service.shutdownNow(); ws = null; } catch (IOException e) { + Log.error("An I/O exception occurred while closing the previous watch service.", e); + EventBus.instance.post(new BubbleNotificationEvent("An I/O exception occurred while closing the previous watch service.", BubbleNotificationEvent.COMMONCOLOR_RED)); ws = null; - ErrorHandler.error("An I/O exception occurred while closing the previous watch service.", e, true); } } diff --git a/src/itdelatrisu/opsu/beatmap/OszUnpacker.java b/src/itdelatrisu/opsu/beatmap/OszUnpacker.java index 5b9c1071..e1e40f41 100644 --- a/src/itdelatrisu/opsu/beatmap/OszUnpacker.java +++ b/src/itdelatrisu/opsu/beatmap/OszUnpacker.java @@ -18,7 +18,6 @@ package itdelatrisu.opsu.beatmap; -import itdelatrisu.opsu.ErrorHandler; import itdelatrisu.opsu.Options; import java.io.File; @@ -28,6 +27,9 @@ import java.util.List; import net.lingala.zip4j.core.ZipFile; import net.lingala.zip4j.exception.ZipException; +import org.newdawn.slick.util.Log; +import yugecin.opsudance.core.events.EventBus; +import yugecin.opsudance.events.BubbleNotificationEvent; /** * Unpacker for OSZ (ZIP) archives. @@ -97,8 +99,9 @@ public class OszUnpacker { ZipFile zipFile = new ZipFile(file); zipFile.extractAll(dest.getAbsolutePath()); } catch (ZipException e) { - ErrorHandler.error(String.format("Failed to unzip file %s to dest %s.", - file.getAbsolutePath(), dest.getAbsolutePath()), e, false); + String err = String.format("Failed to unzip file %s to dest %s.", file.getAbsolutePath(), dest.getAbsolutePath()); + Log.error(err, e); + EventBus.instance.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED)); } } diff --git a/src/itdelatrisu/opsu/db/BeatmapDB.java b/src/itdelatrisu/opsu/db/BeatmapDB.java index 2dbb1e2f..e6e0e4d5 100644 --- a/src/itdelatrisu/opsu/db/BeatmapDB.java +++ b/src/itdelatrisu/opsu/db/BeatmapDB.java @@ -18,7 +18,6 @@ package itdelatrisu.opsu.db; -import itdelatrisu.opsu.ErrorHandler; import itdelatrisu.opsu.Options; import itdelatrisu.opsu.beatmap.Beatmap; import itdelatrisu.opsu.beatmap.BeatmapParser; @@ -35,6 +34,7 @@ import java.util.List; import java.util.Map; import org.newdawn.slick.util.Log; +import yugecin.opsudance.core.errorhandling.ErrorHandler; /** * Handles connections and queries with the cached beatmap database. @@ -110,7 +110,7 @@ public class BeatmapDB { try { updateSizeStmt = connection.prepareStatement("REPLACE INTO info (key, value) VALUES ('size', ?)"); } catch (SQLException e) { - ErrorHandler.error("Failed to prepare beatmap statements.", e, true); + ErrorHandler.error("Failed to prepare beatmap statements.", e).show(); } // retrieve the cache size @@ -132,7 +132,7 @@ public class BeatmapDB { updatePlayStatsStmt = connection.prepareStatement("UPDATE beatmaps SET playCount = ?, lastPlayed = ? WHERE dir = ? AND file = ?"); setFavoriteStmt = connection.prepareStatement("UPDATE beatmaps SET favorite = ? WHERE dir = ? AND file = ?"); } catch (SQLException e) { - ErrorHandler.error("Failed to prepare beatmap statements.", e, true); + ErrorHandler.error("Failed to prepare beatmap statements.", e).show(); } } @@ -170,7 +170,7 @@ public class BeatmapDB { 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); + ErrorHandler.error("Coudl not create beatmap database.", e).show(); } } @@ -222,7 +222,7 @@ public class BeatmapDB { ps.close(); } } catch (SQLException e) { - ErrorHandler.error("Failed to update beatmap database.", e, true); + ErrorHandler.error("Failed to update beatmap database.", e).show(); } } @@ -240,7 +240,7 @@ public class BeatmapDB { } rs.close(); } catch (SQLException e) { - ErrorHandler.error("Could not get beatmap cache size.", e, true); + ErrorHandler.error("Could not get beatmap cache size.", e).show(); } } @@ -255,7 +255,7 @@ public class BeatmapDB { updateSizeStmt.setString(1, Integer.toString(Math.max(cacheSize, 0))); updateSizeStmt.executeUpdate(); } catch (SQLException e) { - ErrorHandler.error("Could not update beatmap cache size.", e, true); + ErrorHandler.error("Could not update beatmap cache size.", e).show(); } } @@ -273,7 +273,7 @@ public class BeatmapDB { cacheSize = 0; updateCacheSize(); } catch (SQLException e) { - ErrorHandler.error("Could not drop beatmap database.", e, true); + ErrorHandler.error("Could not drop beatmap database.", e).show(); } createDatabase(); } @@ -291,7 +291,7 @@ public class BeatmapDB { cacheSize += insertStmt.executeUpdate(); updateCacheSize(); } catch (SQLException e) { - ErrorHandler.error("Failed to add beatmap to database.", e, true); + ErrorHandler.error("Failed to add beatmap to database.", e).show(); } } @@ -344,7 +344,7 @@ public class BeatmapDB { // update cache size updateCacheSize(); } catch (SQLException e) { - ErrorHandler.error("Failed to add beatmaps to database.", e, true); + ErrorHandler.error("Failed to add beatmaps to database.", e).show(); } } @@ -432,7 +432,7 @@ public class BeatmapDB { } rs.close(); } catch (SQLException e) { - ErrorHandler.error("Failed to load Beatmap from database.", e, true); + ErrorHandler.error("Failed to load Beatmap from database.", e).show(); } } @@ -495,7 +495,7 @@ public class BeatmapDB { } rs.close(); } catch (SQLException e) { - ErrorHandler.error("Failed to load beatmaps from database.", e, true); + ErrorHandler.error("Failed to load beatmaps from database.", e).show(); } } @@ -596,7 +596,7 @@ public class BeatmapDB { rs.close(); return map; } catch (SQLException e) { - ErrorHandler.error("Failed to get last modified map from database.", e, true); + ErrorHandler.error("Failed to get last modified map from database.", e).show(); return null; } } @@ -616,7 +616,7 @@ public class BeatmapDB { cacheSize -= deleteMapStmt.executeUpdate(); updateCacheSize(); } catch (SQLException e) { - ErrorHandler.error("Failed to delete beatmap entry from database.", e, true); + ErrorHandler.error("Failed to delete beatmap entry from database.", e).show(); } } @@ -633,7 +633,7 @@ public class BeatmapDB { cacheSize -= deleteGroupStmt.executeUpdate(); updateCacheSize(); } catch (SQLException e) { - ErrorHandler.error("Failed to delete beatmap group entry from database.", e, true); + ErrorHandler.error("Failed to delete beatmap group entry from database.", e).show(); } } @@ -652,7 +652,7 @@ public class BeatmapDB { setStarsStmt.executeUpdate(); } catch (SQLException e) { ErrorHandler.error(String.format("Failed to save star rating '%.4f' for beatmap '%s' in database.", - beatmap.starRating, beatmap.toString()), e, true); + beatmap.starRating, beatmap.toString()), e).show(); } } @@ -672,7 +672,7 @@ public class BeatmapDB { updatePlayStatsStmt.executeUpdate(); } catch (SQLException e) { ErrorHandler.error(String.format("Failed to update play statistics for beatmap '%s' in database.", - beatmap.toString()), e, true); + beatmap.toString()), e).show(); } } @@ -691,7 +691,7 @@ public class BeatmapDB { setFavoriteStmt.executeUpdate(); } catch (SQLException e) { ErrorHandler.error(String.format("Failed to update favorite status for beatmap '%s' in database.", - beatmap.toString()), e, true); + beatmap.toString()), e).show(); } } @@ -711,7 +711,7 @@ public class BeatmapDB { connection.close(); connection = null; } catch (SQLException e) { - ErrorHandler.error("Failed to close beatmap database.", e, true); + ErrorHandler.error("Failed to close beatmap database.", e).show(); } } } diff --git a/src/itdelatrisu/opsu/db/DBController.java b/src/itdelatrisu/opsu/db/DBController.java index aebd414b..61e0d5ca 100644 --- a/src/itdelatrisu/opsu/db/DBController.java +++ b/src/itdelatrisu/opsu/db/DBController.java @@ -18,7 +18,7 @@ package itdelatrisu.opsu.db; -import itdelatrisu.opsu.ErrorHandler; +import yugecin.opsudance.core.errorhandling.ErrorHandler; import java.sql.Connection; import java.sql.DriverManager; @@ -39,7 +39,7 @@ public class DBController { try { Class.forName("org.sqlite.JDBC"); } catch (ClassNotFoundException e) { - ErrorHandler.error("Could not load sqlite-JDBC driver.", e, true); + ErrorHandler.error("Could not load sqlite-JDBC driver.", e).show(); } // initialize the databases @@ -65,7 +65,7 @@ public class DBController { return DriverManager.getConnection(String.format("jdbc:sqlite:%s", path)); } catch (SQLException e) { // if the error message is "out of memory", it probably means no database file is found - ErrorHandler.error(String.format("Could not connect to database: '%s'.", path), e, true); + ErrorHandler.error(String.format("Could not connect to database: '%s'.", path), e).show(); return null; } } diff --git a/src/itdelatrisu/opsu/db/ScoreDB.java b/src/itdelatrisu/opsu/db/ScoreDB.java index babf1841..6fa86910 100644 --- a/src/itdelatrisu/opsu/db/ScoreDB.java +++ b/src/itdelatrisu/opsu/db/ScoreDB.java @@ -18,10 +18,10 @@ package itdelatrisu.opsu.db; -import itdelatrisu.opsu.ErrorHandler; import itdelatrisu.opsu.Options; import itdelatrisu.opsu.ScoreData; import itdelatrisu.opsu.beatmap.Beatmap; +import yugecin.opsudance.core.errorhandling.ErrorHandler; import java.sql.Connection; import java.sql.PreparedStatement; @@ -124,7 +124,7 @@ public class ScoreDB { // TODO: extra playerName checks not needed if name is guaranteed not null ); } catch (SQLException e) { - ErrorHandler.error("Failed to prepare score statements.", e, true); + ErrorHandler.error("Failed to prepare score statements.", e).show(); } } @@ -157,7 +157,7 @@ public class ScoreDB { sql = String.format("INSERT OR IGNORE INTO info(key, value) VALUES('version', %d)", DATABASE_VERSION); stmt.executeUpdate(sql); } catch (SQLException e) { - ErrorHandler.error("Could not create score database.", e, true); + ErrorHandler.error("Could not create score database.", e).show(); } } @@ -209,7 +209,7 @@ public class ScoreDB { ps.close(); } } catch (SQLException e) { - ErrorHandler.error("Failed to update score database.", e, true); + ErrorHandler.error("Failed to update score database.", e).show(); } } @@ -227,7 +227,7 @@ public class ScoreDB { insertStmt.setString(19, data.playerName); insertStmt.executeUpdate(); } catch (SQLException e) { - ErrorHandler.error("Failed to save score to database.", e, true); + ErrorHandler.error("Failed to save score to database.", e).show(); } } @@ -247,7 +247,7 @@ public class ScoreDB { deleteScoreStmt.setString(21, data.playerName); deleteScoreStmt.executeUpdate(); } catch (SQLException e) { - ErrorHandler.error("Failed to delete score from database.", e, true); + ErrorHandler.error("Failed to delete score from database.", e).show(); } } @@ -267,7 +267,7 @@ public class ScoreDB { deleteSongStmt.setString(5, beatmap.version); deleteSongStmt.executeUpdate(); } catch (SQLException e) { - ErrorHandler.error("Failed to delete scores from database.", e, true); + ErrorHandler.error("Failed to delete scores from database.", e).show(); } } @@ -335,7 +335,7 @@ public class ScoreDB { } rs.close(); } catch (SQLException e) { - ErrorHandler.error("Failed to read scores from database.", e, true); + ErrorHandler.error("Failed to read scores from database.", e).show(); return null; } return getSortedArray(list); @@ -377,7 +377,7 @@ public class ScoreDB { map.put(version, getSortedArray(list)); rs.close(); } catch (SQLException e) { - ErrorHandler.error("Failed to read scores from database.", e, true); + ErrorHandler.error("Failed to read scores from database.", e).show(); return null; } return map; @@ -406,7 +406,7 @@ public class ScoreDB { connection.close(); connection = null; } catch (SQLException e) { - ErrorHandler.error("Failed to close score database.", e, true); + ErrorHandler.error("Failed to close score database.", e).show(); } } } diff --git a/src/itdelatrisu/opsu/downloads/Download.java b/src/itdelatrisu/opsu/downloads/Download.java index 58818490..218533d3 100644 --- a/src/itdelatrisu/opsu/downloads/Download.java +++ b/src/itdelatrisu/opsu/downloads/Download.java @@ -18,7 +18,6 @@ package itdelatrisu.opsu.downloads; -import itdelatrisu.opsu.ErrorHandler; import itdelatrisu.opsu.Utils; import java.io.File; @@ -35,6 +34,9 @@ import java.nio.file.Path; import java.nio.file.StandardCopyOption; import org.newdawn.slick.util.Log; +import yugecin.opsudance.core.errorhandling.ErrorHandler; +import yugecin.opsudance.core.events.EventBus; +import yugecin.opsudance.events.BubbleNotificationEvent; /** * File download. @@ -142,7 +144,7 @@ public class Download { this.url = new URL(remoteURL); } catch (MalformedURLException e) { this.status = Status.ERROR; - ErrorHandler.error(String.format("Bad download URL: '%s'", remoteURL), e, true); + ErrorHandler.error(String.format("Bad download URL: '%s'", remoteURL), e).show(); return; } this.localPath = localPath; @@ -215,7 +217,7 @@ public class Download { else if (redirectCount > MAX_REDIRECTS) error = String.format("Download for URL '%s' is attempting too many redirects (over %d).", base.toString(), MAX_REDIRECTS); if (error != null) { - ErrorHandler.error(error, null, false); + EventBus.instance.post(new BubbleNotificationEvent(error, BubbleNotificationEvent.COLOR_ORANGE)); throw new IOException(); } @@ -417,7 +419,7 @@ public class Download { } } catch (IOException e) { this.status = Status.ERROR; - ErrorHandler.error("Failed to cancel download.", e, true); + ErrorHandler.error("Failed to cancel download.", e).show(); } } } diff --git a/src/itdelatrisu/opsu/downloads/DownloadNode.java b/src/itdelatrisu/opsu/downloads/DownloadNode.java index 728dacf5..d8869fe4 100644 --- a/src/itdelatrisu/opsu/downloads/DownloadNode.java +++ b/src/itdelatrisu/opsu/downloads/DownloadNode.java @@ -18,7 +18,6 @@ package itdelatrisu.opsu.downloads; -import itdelatrisu.opsu.ErrorHandler; import itdelatrisu.opsu.GameImage; import itdelatrisu.opsu.Options; import itdelatrisu.opsu.Utils; @@ -35,6 +34,8 @@ import java.io.File; import org.newdawn.slick.Color; import org.newdawn.slick.Graphics; import org.newdawn.slick.Image; +import yugecin.opsudance.core.events.EventBus; +import yugecin.opsudance.events.BubbleNotificationEvent; /** * Node containing song data and a Download object. @@ -402,7 +403,7 @@ public class DownloadNode { public void drawDownload(Graphics g, float position, int id, boolean hover) { Download download = this.download; // in case clearDownload() is called asynchronously if (download == null) { - ErrorHandler.error("Trying to draw download information for button without Download object.", null, false); + EventBus.instance.post(new BubbleNotificationEvent("Trying to draw download information for button without Download object", BubbleNotificationEvent.COLOR_ORANGE)); return; } diff --git a/src/itdelatrisu/opsu/downloads/Updater.java b/src/itdelatrisu/opsu/downloads/Updater.java index 307b8e54..fbd607ea 100644 --- a/src/itdelatrisu/opsu/downloads/Updater.java +++ b/src/itdelatrisu/opsu/downloads/Updater.java @@ -18,7 +18,6 @@ package itdelatrisu.opsu.downloads; -import itdelatrisu.opsu.ErrorHandler; import itdelatrisu.opsu.Options; import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.downloads.Download.DownloadListener; @@ -38,6 +37,7 @@ 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.errorhandling.ErrorHandler; /** * Handles automatic program updates. @@ -298,7 +298,7 @@ public class Updater { pb.start(); } catch (IOException e) { status = Status.INTERNAL_ERROR; - ErrorHandler.error("Failed to start new process.", e, true); + ErrorHandler.error("Failed to start new process.", e).show(); } } } diff --git a/src/itdelatrisu/opsu/downloads/servers/BloodcatServer.java b/src/itdelatrisu/opsu/downloads/servers/BloodcatServer.java index 335982e9..d86a4579 100644 --- a/src/itdelatrisu/opsu/downloads/servers/BloodcatServer.java +++ b/src/itdelatrisu/opsu/downloads/servers/BloodcatServer.java @@ -18,7 +18,6 @@ package itdelatrisu.opsu.downloads.servers; -import itdelatrisu.opsu.ErrorHandler; import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.downloads.DownloadNode; @@ -34,6 +33,7 @@ import java.util.Date; import org.json.JSONArray; import org.json.JSONObject; +import yugecin.opsudance.core.errorhandling.ErrorHandler; /** * Download server: http://bloodcat.com/osu/ @@ -97,7 +97,7 @@ public class BloodcatServer extends DownloadServer { resultCount++; this.totalResults = resultCount; } catch (MalformedURLException | UnsupportedEncodingException e) { - ErrorHandler.error(String.format("Problem loading result list for query '%s'.", query), e, true); + ErrorHandler.error(String.format("Problem loading result list for query '%s'.", query), e).show(); } return nodes; } diff --git a/src/itdelatrisu/opsu/downloads/servers/HexideServer.java b/src/itdelatrisu/opsu/downloads/servers/HexideServer.java index e9b7c683..f0c6cb7d 100644 --- a/src/itdelatrisu/opsu/downloads/servers/HexideServer.java +++ b/src/itdelatrisu/opsu/downloads/servers/HexideServer.java @@ -18,7 +18,6 @@ package itdelatrisu.opsu.downloads.servers; -import itdelatrisu.opsu.ErrorHandler; import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.downloads.DownloadNode; @@ -30,6 +29,7 @@ import java.net.URLEncoder; import org.json.JSONArray; import org.json.JSONObject; +import yugecin.opsudance.core.errorhandling.ErrorHandler; /** * Download server: https://osu.hexide.com/ @@ -128,7 +128,7 @@ public class HexideServer extends DownloadServer { // all results at once; this approach just gets pagination correct. this.totalResults = arr.length() + resultIndex; } catch (MalformedURLException | UnsupportedEncodingException e) { - ErrorHandler.error(String.format("Problem loading result list for query '%s'.", query), e, true); + ErrorHandler.error(String.format("Problem loading result list for query '%s'.", query), e).show(); } return nodes; } diff --git a/src/itdelatrisu/opsu/downloads/servers/MengSkyServer.java b/src/itdelatrisu/opsu/downloads/servers/MengSkyServer.java index 1c72dff5..a2e298a4 100644 --- a/src/itdelatrisu/opsu/downloads/servers/MengSkyServer.java +++ b/src/itdelatrisu/opsu/downloads/servers/MengSkyServer.java @@ -18,7 +18,6 @@ package itdelatrisu.opsu.downloads.servers; -import itdelatrisu.opsu.ErrorHandler; import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.downloads.DownloadNode; @@ -30,6 +29,7 @@ import java.net.URLEncoder; import org.json.JSONArray; import org.json.JSONObject; +import yugecin.opsudance.core.errorhandling.ErrorHandler; /** * Download server: http://osu.mengsky.net/ @@ -101,7 +101,7 @@ public class MengSkyServer extends DownloadServer { resultCount = 1 + (pageTotal - 1) * PAGE_LIMIT; this.totalResults = resultCount; } catch (MalformedURLException | UnsupportedEncodingException e) { - ErrorHandler.error(String.format("Problem loading result list for query '%s'.", query), e, true); + ErrorHandler.error(String.format("Problem loading result list for query '%s'.", query), e).show(); } return nodes; } diff --git a/src/itdelatrisu/opsu/downloads/servers/MnetworkServer.java b/src/itdelatrisu/opsu/downloads/servers/MnetworkServer.java index 4341512a..e9c2e3c6 100644 --- a/src/itdelatrisu/opsu/downloads/servers/MnetworkServer.java +++ b/src/itdelatrisu/opsu/downloads/servers/MnetworkServer.java @@ -18,9 +18,9 @@ package itdelatrisu.opsu.downloads.servers; -import itdelatrisu.opsu.ErrorHandler; import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.downloads.DownloadNode; +import yugecin.opsudance.core.errorhandling.ErrorHandler; import java.io.IOException; import java.io.UnsupportedEncodingException; @@ -120,7 +120,7 @@ public class MnetworkServer extends DownloadServer { // store total result count this.totalResults = nodes.length; } catch (MalformedURLException | UnsupportedEncodingException e) { - ErrorHandler.error(String.format("Problem loading result list for query '%s'.", query), e, true); + ErrorHandler.error(String.format("Problem loading result list for query '%s'.", query), e).show(); } return nodes; } diff --git a/src/itdelatrisu/opsu/downloads/servers/OsuMirrorServer.java b/src/itdelatrisu/opsu/downloads/servers/OsuMirrorServer.java index 834f2b9f..435eee2f 100644 --- a/src/itdelatrisu/opsu/downloads/servers/OsuMirrorServer.java +++ b/src/itdelatrisu/opsu/downloads/servers/OsuMirrorServer.java @@ -18,7 +18,6 @@ package itdelatrisu.opsu.downloads.servers; -import itdelatrisu.opsu.ErrorHandler; import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.downloads.DownloadNode; @@ -36,6 +35,7 @@ import java.util.TimeZone; import org.json.JSONArray; import org.json.JSONObject; +import yugecin.opsudance.core.errorhandling.ErrorHandler; /** * Download server: http://loli.al/ @@ -123,7 +123,7 @@ public class OsuMirrorServer extends DownloadServer { else this.totalResults = maxServerID; } catch (MalformedURLException | UnsupportedEncodingException e) { - ErrorHandler.error(String.format("Problem loading result list for query '%s'.", query), e, true); + ErrorHandler.error(String.format("Problem loading result list for query '%s'.", query), e).show(); } return nodes; } diff --git a/src/itdelatrisu/opsu/downloads/servers/YaSOnlineServer.java b/src/itdelatrisu/opsu/downloads/servers/YaSOnlineServer.java index 3d25459a..9e13dc58 100644 --- a/src/itdelatrisu/opsu/downloads/servers/YaSOnlineServer.java +++ b/src/itdelatrisu/opsu/downloads/servers/YaSOnlineServer.java @@ -17,7 +17,6 @@ */ package itdelatrisu.opsu.downloads.servers; -import itdelatrisu.opsu.ErrorHandler; import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.downloads.DownloadNode; @@ -34,6 +33,7 @@ import java.util.Iterator; import java.util.List; import org.json.JSONObject; +import yugecin.opsudance.core.errorhandling.ErrorHandler; /** * Download server: http://osu.yas-online.net/ @@ -114,7 +114,7 @@ public class YaSOnlineServer extends DownloadServer { String downloadLink = item.getString("downloadLink"); return String.format(DOWNLOAD_FETCH_URL, downloadLink); } catch (MalformedURLException | UnsupportedEncodingException e) { - ErrorHandler.error(String.format("Problem retrieving download URL for beatmap '%d'.", beatmapSetID), e, true); + ErrorHandler.error(String.format("Problem retrieving download URL for beatmap '%d'.", beatmapSetID), e).show(); return null; } finally { Utils.setSSLCertValidation(true); @@ -186,7 +186,7 @@ public class YaSOnlineServer extends DownloadServer { else this.totalResults = maxServerID; } catch (MalformedURLException | UnsupportedEncodingException e) { - ErrorHandler.error(String.format("Problem loading result list for query '%s'.", query), e, true); + ErrorHandler.error(String.format("Problem loading result list for query '%s'.", query), e).show(); } finally { Utils.setSSLCertValidation(true); } diff --git a/src/itdelatrisu/opsu/render/CurveRenderState.java b/src/itdelatrisu/opsu/render/CurveRenderState.java index a70846b6..9ca3a33e 100644 --- a/src/itdelatrisu/opsu/render/CurveRenderState.java +++ b/src/itdelatrisu/opsu/render/CurveRenderState.java @@ -96,7 +96,7 @@ public class CurveRenderState { */ public static void shutdown() { staticState.shutdown(); - FrameBufferCache.shutdown(); + //FrameBufferCache.shutdown(); } /** diff --git a/src/itdelatrisu/opsu/render/FrameBufferCache.java b/src/itdelatrisu/opsu/render/FrameBufferCache.java index c27a80cb..bf1a96aa 100644 --- a/src/itdelatrisu/opsu/render/FrameBufferCache.java +++ b/src/itdelatrisu/opsu/render/FrameBufferCache.java @@ -128,6 +128,7 @@ public class FrameBufferCache { *

* This is necessary for cases when the game gets restarted with a * different resolution without closing the process. + * // TODO d do we still need this */ public static void shutdown() { FrameBufferCache fbcInstance = FrameBufferCache.getInstance(); diff --git a/src/itdelatrisu/opsu/replay/Replay.java b/src/itdelatrisu/opsu/replay/Replay.java index 6f2d9fb4..5ee6e271 100644 --- a/src/itdelatrisu/opsu/replay/Replay.java +++ b/src/itdelatrisu/opsu/replay/Replay.java @@ -18,7 +18,6 @@ package itdelatrisu.opsu.replay; -import itdelatrisu.opsu.ErrorHandler; import itdelatrisu.opsu.Options; import itdelatrisu.opsu.ScoreData; import itdelatrisu.opsu.Utils; @@ -45,6 +44,9 @@ import org.apache.commons.compress.compressors.lzma.LZMACompressorInputStream; import org.newdawn.slick.util.Log; import lzma.streams.LzmaOutputStream; +import yugecin.opsudance.core.errorhandling.ErrorHandler; +import yugecin.opsudance.core.events.EventBus; +import yugecin.opsudance.events.BubbleNotificationEvent; /** * Captures osu! replay data. @@ -273,7 +275,7 @@ public class Replay { File dir = Options.getReplayDir(); if (!dir.isDirectory()) { if (!dir.mkdir()) { - ErrorHandler.error("Failed to create replay directory.", null, false); + EventBus.instance.post(new BubbleNotificationEvent("Failed to create replay directory.", BubbleNotificationEvent.COMMONCOLOR_RED)); return; } } @@ -343,7 +345,7 @@ public class Replay { compressedOut.write(bytes); } catch (IOException e) { // possible OOM: https://github.com/jponge/lzma-java/issues/9 - ErrorHandler.error("LZMA compression failed (possible out-of-memory error).", e, true); + ErrorHandler.error("LZMA compression failed (possible out-of-memory error).", e).show(); } compressedOut.close(); bout.close(); @@ -357,7 +359,7 @@ public class Replay { writer.close(); } catch (IOException e) { - ErrorHandler.error("Could not save replay data.", e, true); + ErrorHandler.error("Could not save replay data.", e).show(); } } }.start(); diff --git a/src/itdelatrisu/opsu/replay/ReplayImporter.java b/src/itdelatrisu/opsu/replay/ReplayImporter.java index 22e4a7dd..ee901143 100644 --- a/src/itdelatrisu/opsu/replay/ReplayImporter.java +++ b/src/itdelatrisu/opsu/replay/ReplayImporter.java @@ -18,7 +18,7 @@ package itdelatrisu.opsu.replay; -import itdelatrisu.opsu.ErrorHandler; +import com.sun.deploy.security.EnhancedJarVerifier; import itdelatrisu.opsu.Options; import itdelatrisu.opsu.beatmap.Beatmap; import itdelatrisu.opsu.beatmap.BeatmapSetList; @@ -31,6 +31,8 @@ import java.nio.file.Files; import java.nio.file.StandardCopyOption; import org.newdawn.slick.util.Log; +import yugecin.opsudance.core.events.EventBus; +import yugecin.opsudance.events.BubbleNotificationEvent; /** * Importer for replay files. @@ -70,7 +72,9 @@ public class ReplayImporter { File replayDir = Options.getReplayDir(); if (!replayDir.isDirectory()) { if (!replayDir.mkdir()) { - ErrorHandler.error(String.format("Failed to create replay directory '%s'.", replayDir.getAbsolutePath()), null, false); + String err = String.format("Failed to create replay directory '%s'.", replayDir.getAbsolutePath()); + Log.error(err); + EventBus.instance.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED)); return; } } @@ -83,7 +87,9 @@ public class ReplayImporter { r.loadHeader(); } catch (IOException e) { moveToFailedDirectory(file); - ErrorHandler.error(String.format("Failed to import replay '%s'. The replay file could not be parsed.", file.getName()), e, false); + String err = String.format("Failed to import replay '%s'. The replay file could not be parsed.", file.getName()); + Log.error(err, e); + EventBus.instance.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED)); continue; } Beatmap beatmap = BeatmapSetList.get().getBeatmapFromHash(r.beatmapHash); @@ -100,8 +106,9 @@ public class ReplayImporter { } } else { moveToFailedDirectory(file); - ErrorHandler.error(String.format("Failed to import replay '%s'. The associated beatmap could not be found.", file.getName()), null, false); - continue; + String err = String.format("Failed to import replay '%s'. The associated beatmap could not be found.", file.getName()); + Log.error(err); + EventBus.instance.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED)); } } diff --git a/src/itdelatrisu/opsu/skins/SkinLoader.java b/src/itdelatrisu/opsu/skins/SkinLoader.java index b7ac04ec..5c9be6e6 100644 --- a/src/itdelatrisu/opsu/skins/SkinLoader.java +++ b/src/itdelatrisu/opsu/skins/SkinLoader.java @@ -18,7 +18,6 @@ package itdelatrisu.opsu.skins; -import itdelatrisu.opsu.ErrorHandler; import itdelatrisu.opsu.GameImage; import itdelatrisu.opsu.Utils; @@ -32,6 +31,8 @@ import java.util.LinkedList; import org.newdawn.slick.Color; import org.newdawn.slick.util.Log; +import yugecin.opsudance.core.events.EventBus; +import yugecin.opsudance.events.BubbleNotificationEvent; /** * Loads skin configuration files. @@ -290,7 +291,9 @@ public class SkinLoader { } } } catch (IOException e) { - ErrorHandler.error(String.format("Failed to read file '%s'.", skinFile.getAbsolutePath()), e, false); + String err = String.format("Failed to read file '%s'.", skinFile.getAbsolutePath()); + Log.error(err, e); + EventBus.instance.post(new BubbleNotificationEvent(err, BubbleNotificationEvent.COMMONCOLOR_RED)); } return skin; diff --git a/src/itdelatrisu/opsu/states/DownloadsMenu.java b/src/itdelatrisu/opsu/states/DownloadsMenu.java index 718be4dd..83a31bf6 100644 --- a/src/itdelatrisu/opsu/states/DownloadsMenu.java +++ b/src/itdelatrisu/opsu/states/DownloadsMenu.java @@ -19,7 +19,6 @@ package itdelatrisu.opsu.states; import itdelatrisu.opsu.GameImage; -import itdelatrisu.opsu.Opsu; import itdelatrisu.opsu.Options; import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.audio.MusicController; diff --git a/src/itdelatrisu/opsu/states/MainMenu.java b/src/itdelatrisu/opsu/states/MainMenu.java index a56418fe..a099e037 100644 --- a/src/itdelatrisu/opsu/states/MainMenu.java +++ b/src/itdelatrisu/opsu/states/MainMenu.java @@ -18,7 +18,6 @@ package itdelatrisu.opsu.states; -import itdelatrisu.opsu.ErrorHandler; import itdelatrisu.opsu.GameImage; import itdelatrisu.opsu.Options; import itdelatrisu.opsu.Utils; @@ -46,10 +45,13 @@ import org.newdawn.slick.Color; import org.newdawn.slick.Graphics; import org.newdawn.slick.Image; import org.newdawn.slick.Input; +import org.newdawn.slick.util.Log; import yugecin.opsudance.core.DisplayContainer; +import yugecin.opsudance.core.events.EventBus; import yugecin.opsudance.core.inject.InstanceContainer; import yugecin.opsudance.core.state.BaseOpsuState; import yugecin.opsudance.core.state.OpsuState; +import yugecin.opsudance.events.BubbleNotificationEvent; /** * "Main Menu" state. @@ -570,7 +572,8 @@ public class MainMenu extends BaseOpsuState { } catch (UnsupportedOperationException e) { UI.sendBarNotification("The repository web page could not be opened."); } catch (IOException e) { - ErrorHandler.error("Could not browse to repository URI.", e, false); + Log.error("could not browse to repo", e); + displayContainer.eventBus.post(new BubbleNotificationEvent("Could not browse to repo", BubbleNotificationEvent.COLOR_ORANGE)); } return true; } @@ -581,7 +584,8 @@ public class MainMenu extends BaseOpsuState { } catch (UnsupportedOperationException e) { UI.sendBarNotification("The repository web page could not be opened."); } catch (IOException e) { - ErrorHandler.error("Could not browse to repository URI.", e, false); + Log.error("could not browse to repo", e); + displayContainer.eventBus.post(new BubbleNotificationEvent("Could not browse to repo", BubbleNotificationEvent.COLOR_ORANGE)); } return true; } diff --git a/src/itdelatrisu/opsu/ui/Cursor.java b/src/itdelatrisu/opsu/ui/Cursor.java index c3025ab7..1b7894c3 100644 --- a/src/itdelatrisu/opsu/ui/Cursor.java +++ b/src/itdelatrisu/opsu/ui/Cursor.java @@ -18,9 +18,7 @@ package itdelatrisu.opsu.ui; -import itdelatrisu.opsu.ErrorHandler; import itdelatrisu.opsu.GameImage; -import itdelatrisu.opsu.Opsu; import itdelatrisu.opsu.Options; import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.audio.MusicController; @@ -37,6 +35,7 @@ import org.newdawn.slick.*; import org.newdawn.slick.state.StateBasedGame; import yugecin.opsudance.Dancer; import yugecin.opsudance.core.DisplayContainer; +import yugecin.opsudance.core.errorhandling.ErrorHandler; /** * Updates and draws the cursor. @@ -91,7 +90,7 @@ public class Cursor { IntBuffer tmp = BufferUtils.createIntBuffer(min * min); emptyCursor = new org.lwjgl.input.Cursor(min, min, min/2, min/2, 1, tmp, null); } catch (LWJGLException e) { - ErrorHandler.error("Failed to create hidden cursor.", e, true); + ErrorHandler.error("Failed to create hidden cursor.", e).show(); } } diff --git a/src/itdelatrisu/opsu/ui/UI.java b/src/itdelatrisu/opsu/ui/UI.java index 1afed82e..8c5d5a10 100644 --- a/src/itdelatrisu/opsu/ui/UI.java +++ b/src/itdelatrisu/opsu/ui/UI.java @@ -18,7 +18,6 @@ package itdelatrisu.opsu.ui; -import itdelatrisu.opsu.ErrorHandler; import itdelatrisu.opsu.GameImage; import itdelatrisu.opsu.Options; import itdelatrisu.opsu.Utils; @@ -455,19 +454,4 @@ public class UI { Colors.WHITE_ALPHA.a = oldAlphaW; } - /** - * Shows a confirmation dialog (used before exiting the game). - * @param message the message to display - * @return true if user selects "yes", false otherwise - */ - public static boolean showExitConfirmation(String message) { - try { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } catch (Exception e) { - ErrorHandler.error("Could not set system look and feel for exit confirmation.", e, true); - } - int n = JOptionPane.showConfirmDialog(null, message, "Warning", - JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); - return (n != JOptionPane.YES_OPTION); - } } diff --git a/src/yugecin/opsudance/OpsuDance.java b/src/yugecin/opsudance/OpsuDance.java index 04b04054..2fa43c60 100644 --- a/src/yugecin/opsudance/OpsuDance.java +++ b/src/yugecin/opsudance/OpsuDance.java @@ -23,7 +23,6 @@ import itdelatrisu.opsu.beatmap.BeatmapWatchService; import itdelatrisu.opsu.db.DBController; import itdelatrisu.opsu.downloads.DownloadList; import itdelatrisu.opsu.downloads.Updater; -import itdelatrisu.opsu.render.CurveRenderState; import itdelatrisu.opsu.states.Splash; import org.newdawn.slick.util.Log; import yugecin.opsudance.core.DisplayContainer; @@ -78,7 +77,6 @@ public class OpsuDance { DBController.closeConnections(); DownloadList.get().cancelAllDownloads(); Utils.deleteDirectory(Options.TEMP_DIR); - CurveRenderState.shutdown(); if (!Options.isWatchServiceEnabled()) { BeatmapWatchService.destroy(); } @@ -89,7 +87,7 @@ public class OpsuDance { container.setup(); container.resume(); } catch (Exception e) { - ErrorHandler.error("could not initialize GL", e).preventContinue().show(); + ErrorHandler.error("could not initialize GL", e).allowTerminate().preventContinue().show(); return false; } Exception caughtException = null; @@ -100,7 +98,7 @@ public class OpsuDance { } container.teardown(); container.pause(); - return caughtException != null && ErrorHandler.error("update/render error", caughtException).show().shouldIgnoreAndContinue(); + return caughtException != null && ErrorHandler.error("update/render error", caughtException).allowTerminate().show().shouldIgnoreAndContinue(); } private void initDatabase() { @@ -174,7 +172,7 @@ public class OpsuDance { } private void errorAndExit(String errstr) { - ErrorHandler.error(errstr, new Throwable()).preventContinue().show(); + ErrorHandler.error(errstr, new Throwable()).allowTerminate().preventContinue().show(); System.exit(1); } diff --git a/src/yugecin/opsudance/core/DisplayContainer.java b/src/yugecin/opsudance/core/DisplayContainer.java index 4385de56..4e7f6308 100644 --- a/src/yugecin/opsudance/core/DisplayContainer.java +++ b/src/yugecin/opsudance/core/DisplayContainer.java @@ -24,6 +24,7 @@ import itdelatrisu.opsu.audio.MusicController; import itdelatrisu.opsu.beatmap.Beatmap; import itdelatrisu.opsu.downloads.DownloadList; import itdelatrisu.opsu.downloads.Updater; +import itdelatrisu.opsu.render.CurveRenderState; import itdelatrisu.opsu.ui.Fonts; import org.lwjgl.Sys; import org.lwjgl.openal.AL; @@ -222,6 +223,7 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen GameImage.destroyImages(); GameData.Grade.destroyImages(); Beatmap.destroyBackgroundImageCache(); + CurveRenderState.shutdown(); Display.destroy(); } diff --git a/src/yugecin/opsudance/core/errorhandling/ErrorHandler.java b/src/yugecin/opsudance/core/errorhandling/ErrorHandler.java index 163a1940..99321ba4 100644 --- a/src/yugecin/opsudance/core/errorhandling/ErrorHandler.java +++ b/src/yugecin/opsudance/core/errorhandling/ErrorHandler.java @@ -52,6 +52,7 @@ public class ErrorHandler { private boolean preventContinue; private boolean preventReport; private boolean ignoreAndContinue; + private boolean allowTerminate; public ErrorHandler(DisplayContainer displayContainer) { this.displayContainer = displayContainer; @@ -95,6 +96,11 @@ public class ErrorHandler { return this; } + public ErrorHandler allowTerminate() { + allowTerminate = true; + return this; + } + public ErrorHandler preventContinue() { preventContinue = true; return this; @@ -127,7 +133,9 @@ public class ErrorHandler { Object[] messageComponents = new Object[] { message, new JScrollPane(textArea), createViewLogButton(), createReportButton() }; String[] buttons; - if (preventContinue) { + if (!allowTerminate && !preventContinue) { + buttons = new String[] { "Ignore & continue" }; + } else if (preventContinue) { buttons = new String[] { "Terminate" }; } else { buttons = new String[] { "Terminate", "Ignore & continue" }; @@ -145,7 +153,7 @@ public class ErrorHandler { null, buttons, buttons[buttons.length - 1]); - ignoreAndContinue = result == 1; + ignoreAndContinue = !allowTerminate || result == 1; frame.dispose(); return this; diff --git a/src/yugecin/opsudance/core/events/EventBus.java b/src/yugecin/opsudance/core/events/EventBus.java index 51f142a3..5bdf6c98 100644 --- a/src/yugecin/opsudance/core/events/EventBus.java +++ b/src/yugecin/opsudance/core/events/EventBus.java @@ -22,10 +22,14 @@ import java.util.*; @SuppressWarnings("unchecked") public class EventBus { + @Deprecated + public static EventBus instance; // TODO get rid of this + private final List subscribers; public EventBus() { subscribers = new LinkedList<>(); + instance = this; } public void subscribe(Class eventType, EventListener eventListener) {