Skip to content

Commit

Permalink
Clean filename build and exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
acollign committed Oct 18, 2011
1 parent f371d30 commit 5e37309
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/net/eliosoft/elios/main/Elios.java
Expand Up @@ -26,7 +26,6 @@
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.MessageFormat;
Expand Down Expand Up @@ -79,6 +78,12 @@
*/
public final class Elios {

/** Folder in which data are stored. **/
private static final String ELIOS_DATA_FOLDER = System.getProperty("user.home") + File.separator + ".elios";

/** Filename of the file used for cues list persistence. **/
private static final String CUESLIST_FILENAME = ELIOS_DATA_FOLDER + File.separator + "elios.cues";

/**
* The logger.
*/
Expand Down Expand Up @@ -337,13 +342,10 @@ public static RemoteModel createRemoteModel(Preferences prefs) {
model.setHttpPort(prefs.getInt("server.httpserver.port",
HttpServerManager.DEFAULT_HTTP_PORT));


try {
model.load(new FileInputStream(System.getProperty("user.home") + File.separator + ".elios" + File.separator + "elios.cues"));
} catch (FileNotFoundException e) {
LOGGER.warning("Can not load cues" + e.getMessage());
model.load(new FileInputStream(CUESLIST_FILENAME));
} catch (IOException e) {
LOGGER.warning("Can not load cues" + e.getMessage());
LOGGER.warning("Can not load cues " + e.getMessage());
}

return model;
Expand Down Expand Up @@ -373,18 +375,14 @@ public static void persistRemoteModel(RemoteModel model, Preferences prefs) {
prefs.putInt("server.httpserver.port", model.getHttpPort());

try {
final String directory = System.getProperty("user.home") + File.separator + ".elios";

File dir = new File(directory);
if(!dir.isDirectory()) {
dir.mkdir();
File dir = new File(ELIOS_DATA_FOLDER);
if(!dir.isDirectory()) { // create root folder if needed
dir.mkdir();
}

model.persist(new FileOutputStream(System.getProperty("user.home") + File.separator + ".elios" +File.separator + "elios.cues"));
} catch (FileNotFoundException e) {
LOGGER.warning("Can not persist current cues" + e.getMessage());
model.persist(new FileOutputStream(CUESLIST_FILENAME));
} catch (IOException e) {
LOGGER.warning("Can not persist current cues " + e.getMessage());
LOGGER.warning("Can not persist current cues : " + e.getMessage());
}

}
Expand Down

0 comments on commit 5e37309

Please sign in to comment.