Creating a cross-platform launcher

This is good enough:


String saveFolder;

if(os.startsWith("Win")) {
    saveFolder = System.getProperty("user.home") + "/Application Data/" + gameName + "/";
}
else if(os.startsWith("linux") || os.startsWith("mac") || os.startsWith("darwin")) {
    saveFolder = System.getProperty("user.home") + "/." + gameName + "/";
}

EDIT: Apparently “Application Data” also works on Vista and 7 for backwards compatibility purposes.

Thanks again Ra4king. Everything I’ve been reading has been saying that you require administrator rights to write to appdata on windows. I haven’t experienced this issue myself because I have UAC disabled completely. But if 90% of people playing my game will be children without admin rights on their parents’ PC; and as a result they cant play the game; then I want to avoid appdata at all costs.

The idea that admin rights are required only came from a couple of stackexchange answers. So I’m not sure about the authenticity of the claim. :wink:

At this point I think I’ll roll with the appdata directories like in your code anyway; if its good enough for Ra4king and Minecraft, then its good enough for me. :slight_smile:

user.home on Linux returns “/home//”. On Linux, all folders that start with ‘.’ are automatically hidden. On Windows they are not, and this leads to cluttering of the home directory. It is best to put it in Application Data because then it’s in its proper place in Windows and out of sight.

EDIT: In no way does AppData need administrative privileges. I have UAC enabled and new File(System.getProperty(“user.home”) + “/Application Data/My Test Folder/”).mkdir() successfully creates the folder: “C:\Users<username>\AppData\Roaming\My Test Folder”

EDIT: UAC in Windows 7 is actually quite good now. It only prompts me for system-wide changes, like installations. It’s now a good second line of defense against viruses, with your AV being the first. I recommend you turn it on :wink:

Awesome. That’s really good to hear. That should be all the information I need to make this launcher work now. :slight_smile: Thanks for everything today and yesterday Ra4king.

I don’t know about XP but on Windows 7 this works great:


if(os.startsWith("Win")) {
    saveFolder = System.getenv("AppData") + "\" gameName + "\";
}

I wonder if we can use other engine like webkit to load html in java.

I know that similar ideas come up very often around here :), but what about uploading that launcher right now to github and creat some nice launcher together. A game launcher with update functionality is something which is useful for everybody.
With git everybody can branch and merge stuff together as he likes, so we would end up with perhaps some a bit different launchers, but I think this would be quite great for everybody.

I would also invest some hours into this.

JavaFX has a webkit component.

Oh wow I didn’t know there was a ‘getenv’ method. That’s basically doing %APPDATA% which resolves to the correct location for XP, Vista and 7.

Rather use IzPack in this case.

I do something more complicated to create desktop shortcuts in my own source code.

Java Web Start, IzPack and GetDown are often enough… Anyway, good luck.

Exactly ;D I managed to track down something like this for Linux-based OSes through some googlefu. Unfortunately, I didn’t have any luck with OSX. For Linux you’d do something like this:


if(os.contains("Linux")) // Can someone on a Linux distro test this part?
{
   saveFolder = System.getenv("XDG_DATA_HOME");
   if(saveFolder == null)
      saveFolder = System.getProperty("user.home") + "/.local/share";
   saveFolder += "/" + gameName + "/";
}

Apparently Linux splits config (options) and data (saves) into two separate locations, i.e. $XDG_CONFIG_HOME and $XDG_DATA_HOME. I’d probably just pick one or the other out of laziness :stuck_out_tongue:

For Linux and Mac OS X, the user.home + “.” is all you need.

The point isn’t “all you need”, the point is trying to follow the standards for whatever OS your program is running on. You could put your save in C:\Users\ZMan\GameName\player1.sv and call it good, but instead we put it in %AppData%\GameName\player1.sv because it’s cleaner and is what is expected on Windows. If you don’t care about that then ya, user.home + gameName works just fine. I was just looking for an AppData equivalent on Linux/OSX.

While we’re on the topic of standards, and expected behaviour; there’s one that I hate.

When games/applications put binary data (usually some sort of save file) in the designated documents folder. My Documents on XP, Documents on Vista/7/8, user.home/Documents on linux. And you can’t even relocate the data half the time without breaking the associated app. Its a super irritating habit that too many devs have. Thats what the %appdata% folder is for !!!

for cross platform applications, always determine the file-seperator!


String fileSeperator = System.getProperty("file.separator");

dont just use " / " or " " thingies for pathnames.

XDG_DATA_HOME and XDG_CONFIG_HOME are not correctly defined on all Linux distros, it depends on the window manager.

Ooooh, thats a great little tidbit!

Forward slash works as a separator on every single interesting platform that Java runs on, including every version of windows. You only need the separator if you’re generating names that will go into a .bat file or sent to explorer.exe or something else that deliberately doesn’t understand forward slashes.

yeah System.getProperty(“file.separator”) is pretty useless, I always just use /

or use File.separator