哪里是存储我的应用程序特定数据的正确位置? [英] Where is the correct place to store my application specific data?

查看:136
本文介绍了哪里是存储我的应用程序特定数据的正确位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个小型的C#Winforms游戏,我想要做的事情之一是保存特定于应用程序的数据。不过,我正在努力了解这个应该存储的正确位置。



据我所见,应用程序可能会存储多种类型的数据,因此可能存在不同的地方:

1。应用程序属性
- 应用程序存储数据的位置,最后一次登录用户的位置,默认窗口大小,位置等设置。此信息是否可以进入app.settings,或者进入注册表?



2。全局应用程序数据
- 这可能包括在此机器上运行应用程序的每个用户使用的精灵和其他游戏资产。这个普通数据在哪里存储?值得注意的是,在我的特殊情况下,这些数据将不会提供默认安装,用户将被允许添加自己的游戏资源,这些资源应该可以在同一台计算机上的任何其他用户使用。



3。用户特定的应用程序数据
- 这将包括用户保存的游戏文件,其特定的应用程序首选项和他们的个人资料信息。我应该在哪里存储这个?



理想情况下,我希望我的应用程序与Windows XP,Vista,7以及即将推出的Windows 8兼容 - 我不知道如果这改变了方法,但希望它会协助提供意见。

这是我第一次进入这种发展,我将不胜感激一些最佳做法的建议。

解决方案

问题2:我建议在 Environment.SpecialFolder.CommonAppData (默认情况下,在Windows7上映射到 C:\ ProgramData )。这是一个隐藏的文件夹。

问题3:

将这些文件放入 Environment.SpecialFolder.AppData (默认情况下隐藏文件夹映射到 C:\ Users \ [USERNAME] \AppData\Roaming ),如果您希望用户不打算备份/修改这些。一些游戏也把他们的游戏保存到 Environment.SpecialFolder.MyDocuments 中,这可能是因为用户在那里找到它们比较容易。

示例代码:

  var directory = Environment.GetFolderPath(Environment .SpecialFolder.AppData); 


使用(FileStream fs = File.Create(Path.Combine(directory,myAppDirectory,myFile.txt))
{
// write数据
}

对于在Windows上的特殊文件夹的完整列表按照链接



SIDENOTES


  • 允许用户移动这些目录,因此请确保您使用上面提供的代码

  • 在Windows 7 x64中有一个关于 CommonAppData 目录的bug,并且在Windows 8 x64 CP中bug越来越严重。在Windows 7 x64和Windows 8 x64上移动CommonAppData目录后出现的问题


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.

解决方案

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

这篇关于哪里是存储我的应用程序特定数据的正确位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆