Skip to main content
GameDev.net gamedev.net
🔒 Locked

Saving files (write permission)

Started by jamesa Mar 11, 2005 at 12:34 AM 9 replies 2.4k views
Original Post
jamesa
jamesa
Usually, user will install your game in C:\Program Files\YourFame Do our game.exe ALWAYS have write permission under that directory ? So then I can put (create) some data files there (save game). Or should I move it to user directory \My Documents\Username ? I dont like this approach btw, look not nice cluttering \My Documents Thanks.
daerid
daerid
System-wide information should go in the PRogram Files folder. More than likely you will need Administrator privileges to write to this folder.

Any user-specific data should go into the %USERPROFILE%\Application Data\Your App Name folder. The user will always have write permissions to this location.
daerid@gmail.com
mutex
mutex
Never attempt to write to Program Files, that'll really annoy people like me who allow only Administrators and SYSTEM write-access to it. I think daerid is right; by default I think users are denied write access to Program Files.

Read this for Microsoft's guidelines on data storage requirements, specifically section 3.0. To summarize, you'll want to use SHGetFolderPath with CSIDL_APPDATA to get the path to the appdata folder. From the documentation:

TCHAR szPath[MAX_PATH];if(SUCCEEDED(SHGetFolderPath(NULL,                              CSIDL_APPDATA|CSIDL_FLAG_CREATE,                              NULL,                              0,                              szPath))) {    PathAppend(szPath, TEXT("New Doc.txt"));    HANDLE hFile = CreateFile(szPath, ...);}
BTW, the path returned points directly to the Application Data folder; you'll want to store files in a folder underneath it.

If you're using .NET, you can get the path via System.Windows.Forms.Application.UserAppDataPath.

Telastyn
Telastyn
If any game programmer makes me save into my homedir, I'm going to figuratively beat them with a stick.

Given all the games I've played, I think 2 didn't save into their own directory.

In an ideal world, you'd allow the path to be configured by the user in game [ideally though a nice directory chooser], even if it defaults to the homedir.
mutex
mutex
Quote:
Original post by Telastyn
If any game programmer makes me save into my homedir, I'm going to figuratively beat them with a stick.

Given all the games I've played, I think 2 didn't save into their own directory.

In an ideal world, you'd allow the path to be configured by the user in game [ideally though a nice directory chooser], even if it defaults to the homedir.
And that's why a lot of games unnecessarily require admin privileges to run. Try running a game as a normal user. Doesn't work? Give users full read/write permissions to the game directory. I've found that in a lot of cases this is sufficient to allow the game to run under a non-privileged account. This is unnecessary when there's already a place for games to store data.

Also, a lot of applications already store data in the appdata directory (Firefox, Visual Studio, Office, OpenOffice.org, SharpReader, TortoiseSVN, as well as all recent Microsoft-published games that I've come across). Why should games be different in that aspect? I do agree that a directory chooser would be the optimal solution. Just treat saved games as any other type of user-saveable data in an application.

Apocryphiliac
Apocryphiliac
Quote:
Original post by Telastyn
If any game programmer makes me save into my homedir, I'm going to figuratively beat them with a stick.


I'm curious about your reasoning behind this. Care to explain?

I personally perfer saving to home directories: when I was younger, my brothers and I had to share the same computer for games making quicksaves dangerous (oops! I forgot to do a real save, and Nick overwrote my quicksave!), and there were some occasions when regular savegames would get overwritten as well. I would have loved to have my own account to keep my savegames safe. Also, I like the idea of being able to uninstall a game without having to surgically move my savegames to a safe place if I want to keep them. Asside from the fact that to me, it just makes sense ;~)

Of course, being able to select the directory might be "ideal," but then if Andrea and Billy use the same computer for a game, whenever Billy plays it will want to save to Andrea's directory, and vice versa (unless there's some sort of homedir checkbox). Well... unless the game saves configurations per user, but you don't want things in your homedir ;~).
Telastyn
Telastyn
Depending on the implimentation, the quicksave won't be any safer even in the multiuser environment.

Anyways, the thinking goes like this.

There are two major filesystem paradigms in the world today. The win32 way, and the unix way.

The win32 way places all the files, exe's, and everything in the app's install directory [with a few shortcuts and registry settings elsewhere, but...]. This is pretty good, because if you want something associated with an application, you know exactly where it is.

The unix way places all the exe's in one place [okay, okay, 4 places], all of the libraries in 1 place, all of the manuals in 1 place and so on, no matter the app. This is pretty good, because if you want something associated with an application, you go to the location of it's type, and there it is.

Win32 has been trying to make itself the unix way by promoting the use of homedirs in it's formal app writing docs and the such. The problem is, it's terribly arbitrary and half-assed. "user-data" goes into homedirs, but app data doesn't? What about per user-configs or things that edge the line? Suddenly the user needs to look in both areas, and cannot be guaranteed how their application interfaces with the filesystem.

Further, the main reason for the win32 homedir push [having mounted homedirs from an active directory server, so files, configurations and the such exist whereever the user logs in] does not apply at the home, which is the far and away market for PC games.
mutex
mutex
Quote:
*shrug* I don't see the point in requiring admin level to even install the game.
There's no problem with requiring admin privileges to install a game, but requiring them to run a game in unsafe. I do all my work as a regular user, and I do not want to logon or even have to runas Administrator to play a game. A game that only saves games under Program Files requires a privileged account to run, and that's unacceptable when there are perfectly good alternative save locations.

Quote:
Win32 has been trying to make itself the unix way by promoting the use of homedirs in it's formal app writing docs and the such. The problem is, it's terribly arbitrary and half-assed. "user-data" goes into homedirs, but app data doesn't? What about per user-configs or things that edge the line? Suddenly the user needs to look in both areas, and cannot be guaranteed how their application interfaces with the filesystem.
I think Microsoft's documentation makes it quite clear: data that's visible to the users (their saved documents, the default file save location) goes in the My Documents folder, while user-specific data that should be hidden from the user (perhaps saved preferences, etc.) goes in the user's Application Data folder. Data shared by the entire computer goes in the common Application Data folder. In all cases all of the user's data is always stored within their C:\Documents and Settings\username directory.

Quote:
Further, the main reason for the win32 homedir push [having mounted homedirs from an active directory server, so files, configurations and the such exist whereever the user logs in] does not apply at the home, which is the far and away market for PC games.
True, but only when users run with admin privileges. As soon as they password-protect their accounts and run under as a regular user they'll be unable to access Program Files, HKLM, and other protected areas of the computer. Even though this is not the default now, Longhorn will change that and consider access of such areas incorrect. Why rely on a compatibility layer when Longhorn comes out when you can simply do things correctly in the first place?

Anon Mike
Anon Mike
Actually the big issue surrounding this question is security. MS really, really wants to lock everything down to limit the effectiveness of viruses, spyware, adware, etc, etc. But since virtually every Windows app in existance assumes it has admin priviledges they have a tough time doing that because the whole world comes tumbling down.

So the takeaway is as a developer you should do your part to help things and follow the guidelines in the links mutex posted.
-Mike
Telastyn
Telastyn
*shrug* Then I'll be less likely to use windows in the future. Call it personal preference if you will then. As long as apps are free to use their own installers, I'll not care for them installing files outside of the directory I install the app into.

Personally, I've a seperate games drive, which is mounted on c:\games [imagine that]. I'd love for that drive to remain functional should the system drive/partition die, or something with the OS crap out. Spreading files across directories breaks that encapsulation.

And frankly, running as an unprivledged user isn't going to do jack as long as windows services [running as system] remain so hopelessly overflow-ridden.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.