Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the correct place to store my application specific data?

Tags:

c#

filesystems

I'm developing a small C# Winforms game and one of the things I'm wanting to do is save application specific data. However, I'm struggling a bit to understand the correct place this should be stored.

As far as I can see there are several types of data an application might store and accordingly different places for it to be held:

1. Application properties - Settings such as where the application stores it's data, who the last logged in user was, the default window size, position etc. Is this information suppose to go into app.settings, or perhaps into the registry?

2. Global application data - This might include sprites and other game assets that are used by every user that runs the application on this machine. Where would this common data be stored? It's worth noting that in my particular case this data will not be provided with a default install and users will be allowed to add their own game assets which should be then available to any other user on the same computer.

3. User specific application data - This would include a users saved game files, their specific application preferences and their profile information. Where should I be storing this?

Ideally I wish my application to be compatible with Windows XP, Vista, 7 and of course the upcoming Windows 8 - I don't know if this changes the methods but hopefully it will assist with providing advice.

This is my first foray into this kind of development and I would appreciate some 'best practice' advice.

like image 812
Martin Avatar asked May 12 '12 11:05

Martin


People also ask

Where can I store my application data?

When you install an app (either from the Google Play Store or through a downloaded apk file), Android places that into the device's app folder. That's /data/app/your_package_name for most apps. Some encrypted apps use /data/app-private/your_package_name.

Where do I put application data in Linux?

If an app is running as an ACTUAL user, the data should be stored under that users $HOME. If it is a system user, the install (as root or similar) should give that user ownership of its files and directories under /var, and add the user to any groups needed for access to additional devices/directories/files.

How do I find the application data folder in Google Drive?

Application data folder scope Before you can access the application data folder, you must request access to the https://www.googleapis.com/auth/drive.appdata scope. For more information about scopes and how to request access to them, refer to Authenticate your users.

What is the AppData folder in Windows?

What Is the AppData Folder? The AppData folder contains all the data specific to your Windows user profile. This means that your data can be transferred from one device to another as long as you sign in with the same profile. Several apps use the AppData folder so it's easy to keep data synced between devices.


1 Answers

Question 2:
I suggest using a subfolder in Environment.SpecialFolder.CommonAppData (maps to C:\ProgramData on Windows7 by default). This is a hidden folder.

Question 3:
Put those files into Environment.SpecialFolder.AppData(maps to C:\Users\[USERNAME]\AppData\Roaming by default, hidden folder), if you expect that the user does not intend to backup / modify those. Some games also put their save games into Environment.SpecialFolder.MyDocuments, probably because it is easier for users to find them there.

Example code:

var directory = Environment.GetFolderPath(Environment.SpecialFolder.AppData);   using (FileStream fs = File.Create(Path.Combine(directory, "myAppDirectory", "myFile.txt"))) {     // write data                } 

For a complete list of special folders on Windows follow the link

SIDENOTES

  • Users are allowed to move around those directories, so make sure you use the code provided above
  • There is a bug in Windows 7 x64 regarding CommonAppData directory and the bug gets more severe in Windows 8 x64 CP. I've blogged about this: problems after moving CommonAppData directory on Windows 7 x64 and Windows 8 x64
like image 83
yas4891 Avatar answered Sep 21 '22 07:09

yas4891