diff --git a/launcher-bootstrap/src/main/java/com/skcraft/launcher/Bootstrap.java b/launcher-bootstrap/src/main/java/com/skcraft/launcher/Bootstrap.java index 463245efc..0221e8dcd 100644 --- a/launcher-bootstrap/src/main/java/com/skcraft/launcher/Bootstrap.java +++ b/launcher-bootstrap/src/main/java/com/skcraft/launcher/Bootstrap.java @@ -20,6 +20,9 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; import java.util.*; import java.util.logging.Level; @@ -183,7 +186,7 @@ public static void setSwingLookAndFeel() { } catch (Throwable e) { } } - + private static File getFileChooseDefaultDir() { JFileChooser chooser = new JFileChooser(); FileSystemView fsv = chooser.getFileSystemView(); @@ -194,6 +197,21 @@ private File getUserLauncherDir() { String osName = System.getProperty("os.name").toLowerCase(); if (osName.contains("win")) { return new File(getFileChooseDefaultDir(), getProperties().getProperty("homeFolderWindows")); + } else if (osName.contains("mac") && getProperties().getProperty("homeFolderMac") != null) { + // this scope can be replaced with: return new File(getFileChooseDefaultDir(), getProperties().getProperty("homeFolderMac")); + File macHomeFolder = new File(getFileChooseDefaultDir(), getProperties().getProperty("homeFolderMac")); + try { + if (!macHomeFolder.exists()) { + File standartHomeFolder = new File(System.getProperty("user.home"), getProperties().getProperty("homeFolder")); + if (standartHomeFolder.exists()) { + log.info("Found launcher directory at the wrong place... Moving " + standartHomeFolder.getAbsolutePath() + " to " + macHomeFolder.getAbsolutePath() + "..."); + Files.move(Paths.get(standartHomeFolder.getPath()), Paths.get(macHomeFolder.getPath()), StandardCopyOption.REPLACE_EXISTING); + } + } + } catch (IOException e) { + log.log(Level.WARNING, "Error occurred while moving the directory. Creating and using new laucher directory (" + macHomeFolder.getAbsolutePath() + ").", e); + } + return macHomeFolder; } else { return new File(System.getProperty("user.home"), getProperties().getProperty("homeFolder")); } diff --git a/launcher-bootstrap/src/main/resources/com/skcraft/launcher/bootstrap.properties b/launcher-bootstrap/src/main/resources/com/skcraft/launcher/bootstrap.properties index 8609369f7..c0f4d259e 100644 --- a/launcher-bootstrap/src/main/resources/com/skcraft/launcher/bootstrap.properties +++ b/launcher-bootstrap/src/main/resources/com/skcraft/launcher/bootstrap.properties @@ -5,6 +5,7 @@ # homeFolderWindows=Example Launcher +homeFolderMac=Library/Application Support/ExampleLauncher homeFolder=.examplelauncher launcherClass=com.skcraft.launcher.Launcher -latestUrl=http://update.skcraft.com/quark/launcher/latest.json \ No newline at end of file +latestUrl=http://update.skcraft.com/quark/launcher/latest.json