Skip to content

Commit

Permalink
Show errors if any directories could not be created. (fixes #97)
Browse files Browse the repository at this point in the history
Signed-off-by: Jeffrey Han <[email protected]>
  • Loading branch information
itdelatrisu committed Jul 11, 2015
1 parent 05c7ac0 commit 4e2074e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
22 changes: 15 additions & 7 deletions src/itdelatrisu/opsu/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ private static File getXDGBaseDir(String env, String fallback) {
rootPath = String.format("%s/%s", home, fallback);
}
File dir = new File(rootPath, "opsu");
if (!dir.isDirectory())
dir.mkdir();
if (!dir.isDirectory() && !dir.mkdir())
ErrorHandler.error(String.format("Failed to create configuration folder at '%s/opsu'.", rootPath), null, false);
return dir;
} else
return new File("./");
Expand Down Expand Up @@ -357,7 +357,7 @@ public void drag(GameContainer container, int d) {
public String getValueString() { return String.format("%dms", val); }
},
DISABLE_SOUNDS ("Disable All Sound Effects", "DisableSound", "May resolve Linux sound driver issues. Requires a restart.",
(System.getProperty("os.name").toLowerCase().indexOf("linux") > -1)),
(System.getProperty("os.name").toLowerCase().contains("linux"))),
KEY_LEFT ("Left Game Key", "keyOsuLeft", "Select this option to input a key.") {
@Override
public String getValueString() { return Keyboard.getKeyName(getGameKeyLeft()); }
Expand Down Expand Up @@ -1094,7 +1094,10 @@ public static File getBeatmapDir() {
if (beatmapDir.isDirectory())
return beatmapDir;
}
beatmapDir.mkdir(); // none found, create new directory

// none found, create new directory
if (!beatmapDir.mkdir())
ErrorHandler.error(String.format("Failed to create beatmap directory at '%s'.", beatmapDir.getAbsolutePath()), null, false);
return beatmapDir;
}

Expand All @@ -1108,7 +1111,8 @@ public static File getOSZDir() {
return oszDir;

oszDir = new File(DATA_DIR, "SongPacks/");
oszDir.mkdir();
if (!oszDir.isDirectory() && !oszDir.mkdir())
ErrorHandler.error(String.format("Failed to create song packs directory at '%s'.", oszDir.getAbsolutePath()), null, false);
return oszDir;
}

Expand All @@ -1122,7 +1126,8 @@ public static File getReplayImportDir() {
return replayImportDir;

replayImportDir = new File(DATA_DIR, "ReplayImport/");
replayImportDir.mkdir();
if (!replayImportDir.isDirectory() && !replayImportDir.mkdir())
ErrorHandler.error(String.format("Failed to create replay import directory at '%s'.", replayImportDir.getAbsolutePath()), null, false);
return replayImportDir;
}

Expand Down Expand Up @@ -1167,7 +1172,10 @@ public static File getSkinRootDir() {
if (skinRootDir.isDirectory())
return skinRootDir;
}
skinRootDir.mkdir(); // none found, create new directory

// none found, create new directory
if (!skinRootDir.mkdir())
ErrorHandler.error(String.format("Failed to create skins directory at '%s'.", skinRootDir.getAbsolutePath()), null, false);
return skinRootDir;
}

Expand Down
8 changes: 3 additions & 5 deletions src/itdelatrisu/opsu/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,9 @@ public static boolean isGameKeyPressed() {
public static void takeScreenShot() {
// create the screenshot directory
File dir = Options.getScreenshotDir();
if (!dir.isDirectory()) {
if (!dir.mkdir()) {
ErrorHandler.error("Failed to create screenshot directory.", null, false);
return;
}
if (!dir.isDirectory() && !dir.mkdir()) {
ErrorHandler.error(String.format("Failed to create screenshot directory at '%s'.", dir.getAbsolutePath()), null, false);
return;
}

// create file name
Expand Down

0 comments on commit 4e2074e

Please sign in to comment.