Repository: faforever/downlords-faf-client
Issue: Exception when cache/theme folders are missing

Please create the following directories before using them:
C:\\ProgramData\\FAForever\\themes
C:\\ProgramData\\FAForever\\cache

Also, we should fix updateTaskbarProgress in MainController.java crashing when the taskBarList hasn't been created yet.


Changed files:
src/main/java/com/faforever/client/theme/ThemeServiceImpl.java, src/main/java/com/faforever/client/main/MainController.java

diff --git a/src/main/java/com/faforever/client/main/MainController.java b/src/main/java/com/faforever/client/main/MainController.java
index 3b54fbc4..d4368528 100644
--- a/src/main/java/com/faforever/client/main/MainController.java
+++ b/src/main/java/com/faforever/client/main/MainController.java
@@ -307,7 +307,7 @@ public class MainController implements OnChoseGameDirectoryListener {
    */
   @SuppressWarnings("unchecked")
   private void updateTaskbarProgress(@Nullable Double progress) {
-    if (taskBarRelatedPointer == null) {
+    if (taskBarRelatedPointer == null || taskBarList == null) {
       return;
     }
     threadPoolExecutor.execute(() -> {
diff --git a/src/main/java/com/faforever/client/theme/ThemeServiceImpl.java b/src/main/java/com/faforever/client/theme/ThemeServiceImpl.java
index cd18a8cc..b5bb8502 100644
--- a/src/main/java/com/faforever/client/theme/ThemeServiceImpl.java
+++ b/src/main/java/com/faforever/client/theme/ThemeServiceImpl.java
@@ -179,6 +179,14 @@ public class ThemeServiceImpl implements ThemeService {
     noCatch(() -> watchKeys.put(directory, directory.register(watchService, ENTRY_MODIFY, ENTRY_CREATE, ENTRY_DELETE)));
   }
 
+  private void reloadStylesheet() {
+    String styleSheet = getSceneStyleSheet();
+
+    logger.debug("Changes detected, reloading stylesheet: {}", styleSheet);
+    scenes.forEach(scene -> setStyleSheet(scene, styleSheet));
+    webViews.forEach(webView -> setStyleSheet(webView, getWebViewStyleSheet()));
+  }
+
   @Override
   public String getThemeFile(String relativeFile) {
     Path externalFile = getThemeDirectory(currentTheme.get()).resolve(relativeFile);
@@ -188,14 +196,6 @@ public class ThemeServiceImpl implements ThemeService {
     return noCatch(() -> externalFile.toUri().toURL().toString());
   }
 
-  private void reloadStylesheet() {
-    String styleSheet = getSceneStyleSheet();
-
-    logger.debug("Changes detected, reloading stylesheet: {}", styleSheet);
-    scenes.forEach(scene -> setStyleSheet(scene, styleSheet));
-    webViews.forEach(webView -> setStyleSheet(webView, getWebViewStyleSheet()));
-  }
-
   private void setStyleSheet(Scene scene, String styleSheet) {
     Platform.runLater(() -> scene.getStylesheets().setAll(styleSheet));
   }
@@ -211,8 +211,6 @@ public class ThemeServiceImpl implements ThemeService {
   }
 
 
-
-
   @Override
   public void setTheme(Theme theme) {
     stopWatchingTheme(theme);
@@ -247,6 +245,7 @@ public class ThemeServiceImpl implements ThemeService {
     themesByFolderName.clear();
     themesByFolderName.put(DEFAULT_THEME_NAME, DEFAULT_THEME);
     noCatch(() -> {
+      Files.createDirectories(preferencesService.getThemesDirectory());
       try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(preferencesService.getThemesDirectory())) {
         directoryStream.forEach(this::addThemeDirectory);
       }
@@ -273,7 +272,10 @@ public class ThemeServiceImpl implements ThemeService {
   private void setStyleSheet(WebView webView, String styleSheetUrl) {
     // Always copy to a new file since WebView locks the loaded one
     Path cacheDirectory = preferencesService.getCacheDirectory();
+
     noCatch(() -> {
+      Files.createDirectories(cacheDirectory);
+
       Path tempStyleSheet = Files.createTempFile(cacheDirectory, "style-webview", ".css");
       Files.delete(tempStyleSheet);