Screenshot directory is now configurable. (requested in #4)

- Directory must already exist if a non-default location is used.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2014-07-18 00:56:37 -04:00
parent edf40e11fd
commit 2380b11f48
2 changed files with 30 additions and 13 deletions

View File

@ -436,24 +436,23 @@ public class Utils {
// TODO: should this be threaded? // TODO: should this be threaded?
try { try {
// create the screenshot directory // create the screenshot directory
if (!Options.SCREENSHOT_DIR.isDirectory()) { File dir = Options.getScreenshotDir();
if (!Options.SCREENSHOT_DIR.mkdir()) if (!dir.isDirectory()) {
if (!dir.mkdir())
return false; return false;
} }
// create file name // create file name
SimpleDateFormat date = new SimpleDateFormat("yyyyMMdd_HHmmss"); SimpleDateFormat date = new SimpleDateFormat("yyyyMMdd_HHmmss");
String file = date.format(new Date()); File file = new File(dir, String.format("screenshot_%s.%s",
date.format(new Date()), Options.getScreenshotFormat()));
SoundController.playSound(SoundController.SOUND_SHUTTER); SoundController.playSound(SoundController.SOUND_SHUTTER);
// copy the screen // copy the screen
Image screen = new Image(container.getWidth(), container.getHeight()); Image screen = new Image(container.getWidth(), container.getHeight());
container.getGraphics().copyArea(screen, 0, 0); container.getGraphics().copyArea(screen, 0, 0);
ImageOut.write(screen, String.format("%s%sscreenshot_%s.%s", ImageOut.write(screen, file.getAbsolutePath(), false);
Options.SCREENSHOT_DIR.getName(), File.separator,
file, Options.getScreenshotFormat()), false
);
screen.destroy(); screen.destroy();
} catch (SlickException e) { } catch (SlickException e) {
Log.warn("Failed to take a screenshot.", e); Log.warn("Failed to take a screenshot.", e);

View File

@ -57,11 +57,6 @@ public class Options extends BasicGameState {
* Temporary folder for file conversions, auto-deleted upon successful exit. * Temporary folder for file conversions, auto-deleted upon successful exit.
*/ */
public static final File TMP_DIR = new File(".opsu_tmp/"); public static final File TMP_DIR = new File(".opsu_tmp/");
/**
* Directory for screenshots (created when needed).
*/
public static final File SCREENSHOT_DIR = new File("Screenshots/");
/** /**
* File for logging errors. * File for logging errors.
@ -92,6 +87,11 @@ public class Options extends BasicGameState {
*/ */
private static File oszDir; private static File oszDir;
/**
* The screenshot directory (created when needed).
*/
private static File screenshotDir;
/** /**
* The current skin directory (for user skins). * The current skin directory (for user skins).
*/ */
@ -1186,7 +1186,7 @@ public class Options extends BasicGameState {
/** /**
* Returns the OSZ archive directory. * Returns the OSZ archive directory.
* If invalid, this will return the root directory. * If invalid, this will create and return a "SongPacks" directory.
* @return the OSZ archive directory * @return the OSZ archive directory
*/ */
public static File getOSZDir() { public static File getOSZDir() {
@ -1198,6 +1198,19 @@ public class Options extends BasicGameState {
return oszDir; return oszDir;
} }
/**
* Returns the screenshot directory.
* If invalid, this will return a "Screenshot" directory.
* @return the screenshot directory
*/
public static File getScreenshotDir() {
if (screenshotDir != null && screenshotDir.isDirectory())
return screenshotDir;
screenshotDir = new File("Screenshots/");
return screenshotDir;
}
/** /**
* Returns the current skin directory. * Returns the current skin directory.
* If invalid, this will create a "Skins" folder in the root directory. * If invalid, this will create a "Skins" folder in the root directory.
@ -1242,6 +1255,9 @@ public class Options extends BasicGameState {
case "OSZDirectory": case "OSZDirectory":
oszDir = new File(value); oszDir = new File(value);
break; break;
case "ScreenshotDirectory":
screenshotDir = new File(value);
break;
case "Skin": case "Skin":
skinDir = new File(value); skinDir = new File(value);
break; break;
@ -1385,6 +1401,8 @@ public class Options extends BasicGameState {
writer.newLine(); writer.newLine();
writer.write(String.format("OSZDirectory = %s", getOSZDir().getAbsolutePath())); writer.write(String.format("OSZDirectory = %s", getOSZDir().getAbsolutePath()));
writer.newLine(); writer.newLine();
writer.write(String.format("ScreenshotDirectory = %s", getScreenshotDir().getAbsolutePath()));
writer.newLine();
writer.write(String.format("Skin = %s", getSkinDir().getAbsolutePath())); writer.write(String.format("Skin = %s", getSkinDir().getAbsolutePath()));
writer.newLine(); writer.newLine();
writer.write(String.format("Port = %d", port)); writer.write(String.format("Port = %d", port));