Proposal: two new Sys methods for user directories

Started by aldacron, February 02, 2007, 11:11:45

Previous topic - Next topic

aldacron

In light of Vista's restrictions on who can write where, and in order to provide a consistent interface across platforms (including older versions of Windows), I think it would be helpful to add two new methods to the Sys class:

getSaveDir()
getSharedDir()

The user directory is the place to store saved games, profiles and anything related to a specific user. The shared directory is the place to store hi-score tables or anything else that is shared between users. This thread at IndieGamer made me realize that there's really no good way to do this in Java. In a thread here, Matzon said that getting the path to "My Documents" doesn't make sense on Mac or Linux, basically implying that such functionality doesn't belong in LWJGL. But I think the functionality above does make sense across all platforms.

getSaveDir would return "C:\Users\<user>\Saved Games\" on Vista (the preferred path), and either "My Documents\My Games" or CSIDL_APPDATA ("C:\Documents and Settings\username\Application Data\") on older versions of Windows. getSharedDir would return the path for CSIDL_COMMON_APPDATA on Win2K and later (C:\ProgramData\ on Vista, and "C:\Documents and Settings\All Users\Application Data\" on 2K/XP), and whatever is appropriate on older versions.

getSaveDir would obviously return the home directory on Linux and whatever is appropriate on Mac. getSharedDir would also return the appropriate locations. I don't use either platform so I have no idea what those are. If there is not equivalent directory then it should just return "./".

This seems like a sensible addition to me and would allow users of LWJGL to easily write data to the appropriate location regardless of platform. Otherwise, we'd have to resort to hacks, custom JNI code, or write to the wrong folders. I know it's possible to get the home directory through system properties, but that doesn't help on Windows. Nor does it help in getting the shared app directory. When you throw different languages into the mix, where the folder names are no longer in English, it's a necessity to go through the Win32 API to get to the proper locations.




Matzon

I basically agree - however, this is of course for LWJGL 1.1

numberR

personally, i want Java to handle this instead of LWJGL.

let's say new version of Windows came out and now it uses different directory for saving personal stuff for some reason. Then, LWJGL needs to update to reflect that. I don't think that's LWJGL's job though.

oNyx


aldacron


mot

Hello.

http://lwjgl.org/forum/index.php/topic,1956.0.html
http://code.google.com/p/winfoldersjava/

Check the second link for a brief explanation of why System.getProperty("user.home") is not that good a solution.

Quotelet's say new version of Windows came out and now it uses different directory for saving personal stuff for some reason. Then, LWJGL needs to update to reflect that. I don't think that's LWJGL's job though.

SHGetSpecialFolderPath is part of the Windows API and it always returns the correct location, so no updates are necessary.

erikd

I'd still rather see this implemented as a new standard system property in java (just like user.home), than in LWJGL only.
It's not really something that fits a gaming library imho.

bobjob

Quote from: Matzon on February 02, 2007, 12:47:00
I basically agree - however, this is of course for LWJGL 1.1

rapped 2 here theres gonna be another lwjgl  ;D
sry wot was the forums topic again  ;)

Orangy Tang

Sneaky bump. ;D This functionally would be a really good addition IMHO.

Matzon


elias

I'm not keen on catering for a single platform (only the windows platform need native code for this seemingly simple task), however, I'm inclined to agreeing with the original poster. A few issues though:

1. I don't think getSharedDir is worthy of inclusion, since the shared folder concept is only  supported on windows, afaik.
2. getSaveDir should probably take a application id String argument, so that getSaveDir("TribalTrouble") could be transformed to ~/.TribalTrouble on linux (note the leading dot).
(3. Naming - getSaveDir() -> getLocalApplicationDirectory(String application_id)?)

- elias

elias

4. I'd prefer not to use the c:\Users\<user>\Saved Games dir, since games could store more than saved games in their directory and since it's a vista specific feature.

- elias