From d4e7c99a1a4696327a8d19d2ed015d6680e13510 Mon Sep 17 00:00:00 2001
From: tobias <tobias.ullerich@icloud.com>
Date: Wed, 27 Jul 2016 21:41:21 +0200
Subject: [PATCH] Fixed file existing issues

---
 PlayWall/src/de/tobias/playpad/PlayPadMain.java       |  3 +--
 .../de/tobias/playpad/project/ProjectReference.java   | 11 ++++++++---
 .../de/tobias/playpad/settings/ProfileReference.java  |  4 ++++
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/PlayWall/src/de/tobias/playpad/PlayPadMain.java b/PlayWall/src/de/tobias/playpad/PlayPadMain.java
index 429036da..a399f856 100644
--- a/PlayWall/src/de/tobias/playpad/PlayPadMain.java
+++ b/PlayWall/src/de/tobias/playpad/PlayPadMain.java
@@ -190,7 +190,6 @@ public class PlayPadMain extends Application implements LocalizationDelegate, Pr
 		}
 
 		ViewController.create(LaunchDialog.class, stage);
-
 	}
 
 	@Override
@@ -256,7 +255,7 @@ public class PlayPadMain extends Application implements LocalizationDelegate, Pr
 	private void setupPlugins(Path pluginPath) throws IOException, MalformedURLException {
 		// Delete old plugins
 		impl.deletePlugins();
-		
+
 		// Load Plugins
 		impl.loadPlugin(pluginPath.toUri());
 	}
diff --git a/PlayWallCore/src/de/tobias/playpad/project/ProjectReference.java b/PlayWallCore/src/de/tobias/playpad/project/ProjectReference.java
index 8dd9ff1d..44724c67 100644
--- a/PlayWallCore/src/de/tobias/playpad/project/ProjectReference.java
+++ b/PlayWallCore/src/de/tobias/playpad/project/ProjectReference.java
@@ -147,9 +147,10 @@ public class ProjectReference implements Displayable {
 
 	public static void loadProjects() throws DocumentException, IOException {
 		Path path = ApplicationUtils.getApplication().getPath(PathType.CONFIGURATION, FILE_NAME);
-		XMLHandler<ProjectReference> loader = new XMLHandler<>(path);
-		projects = loader.loadElements(PROJECT_ELEMENT, new ProjectReferenceSerializer());
-
+		if (Files.exists(path)) {
+			XMLHandler<ProjectReference> loader = new XMLHandler<>(path);
+			projects = loader.loadElements(PROJECT_ELEMENT, new ProjectReferenceSerializer());
+		}
 		loadedProjectOverview = true;
 	}
 
@@ -161,6 +162,10 @@ public class ProjectReference implements Displayable {
 		handler.saveElements(PROJECT_ELEMENT, projects, new ProjectReferenceSerializer());
 
 		Path path = ApplicationUtils.getApplication().getPath(PathType.CONFIGURATION, FILE_NAME);
+		if (Files.notExists(path)) {
+			Files.createDirectories(path.getParent());
+			Files.createFile(path);
+		}
 		XMLHandler.save(path, document);
 	}
 
diff --git a/PlayWallCore/src/de/tobias/playpad/settings/ProfileReference.java b/PlayWallCore/src/de/tobias/playpad/settings/ProfileReference.java
index 9eaf5a15..ba3a13d0 100644
--- a/PlayWallCore/src/de/tobias/playpad/settings/ProfileReference.java
+++ b/PlayWallCore/src/de/tobias/playpad/settings/ProfileReference.java
@@ -272,6 +272,10 @@ public class ProfileReference implements Displayable {
 		handler.saveElements(PROFILE_ELEMENT, profiles, new ProfileReferenceSerializer());
 
 		Path path = ApplicationUtils.getApplication().getPath(PathType.CONFIGURATION, FILE_NAME);
+		if (Files.notExists(path)) {
+			Files.createDirectories(path.getParent());
+			Files.createFile(path);
+		}
 		XMLHandler.save(path, document);
 	}
 
-- 
GitLab