Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacOS custom dir support #164

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -183,7 +186,7 @@ public static void setSwingLookAndFeel() {
} catch (Throwable e) {
}
}

private static File getFileChooseDefaultDir() {
JFileChooser chooser = new JFileChooser();
FileSystemView fsv = chooser.getFileSystemView();
Expand All @@ -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"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
latestUrl=http://update.skcraft.com/quark/launcher/latest.json