应用程序设置方法? c++

发布于 2024-09-03 01:39:32 字数 236 浏览 6 评论 0原文

我正在考虑向应用程序添加可配置设置,我认为最简单的方法是外部文件或 win 注册表(它是仅限 win 的应用程序)。

哪种方式更好?

我想知道,没有足够权限的用户可能无法创建/写入配置文件。就注册表而言,今天的防病毒软件允许我添加/编辑/删除注册表项吗?或者他们只监控某些按键?

另外,如果有人知道在 vc++ 中管理配置设置(在纯 win32 中)的类/lib,请发布它。

I am thinking about adding configurable settings to an application, and I think the easiest ways are an external file or win registry (its a win only app).

Which way would be better?

I was wondering, an user with not enough permissions may not be able to create/write the config file. And in the case of the registry, would todays antivirus allow me to add/edit/remove keys? Or they only monitor certain keys?

Also, if someone knows a class/lib to manage config settings (in pure win32) in vc++ please post it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

春花秋月 2024-09-10 01:39:33

“仅限 Windows”是限制还是限制解除?如果您不介意跨平台,那么我建议您给出 boost::program_options 尝试一下。该库通过命令行、环境变量和 INI 文件支持程序选项。 Boost 的 program_options 还通过 variables_map 很好地集成和粘合了各种解析器,您可以将其视为选项及其值之间的映射。

Is "Windows-only" a restriction or a restriction-relief? If you don't mind being cross-platform then I suggest you give boost::program_options a go. The library supports program options through commandline, through evironment-variables and through INI files. Boost's program_options also integrates and glues the various parsers very nicely with variables_map, which you can view as a map between options and their value.

日久见人心 2024-09-10 01:39:33

对于简单的事情,您不妨使用注册表。但是,配置文件有很多好处......您可以为应用程序的不同用途保存/加载多个不同的配置,更容易在用户或计算机之间共享或迁移设置等。

如果您最终选择文件路径,我会推荐Boost的Property Tree库:

http://www .boost.org/doc/libs/1_41_0/doc/html/property_tree.html

它有一个非常好的语法:

boost::property_tree::ptree properties;

std::string name = properties.get<std::string>("blah.name");
int score = properties.get<int>("blah.score");

properties.put("blah.name", "Inverse");
properties.put("blah.score", 1000);

它还支持读取和写入各种格式,例如 xml 等。

For simple stuff, you might as well just use the registry. However, there are many benefits to a config file... you can save/load several different configs for different uses of your app, it's easier to share or migrate settings between users or machines, etc.

If you end up going the file route, I would recommend Boost's Property Tree library:

http://www.boost.org/doc/libs/1_41_0/doc/html/property_tree.html

It has a pretty nice syntax:

boost::property_tree::ptree properties;

std::string name = properties.get<std::string>("blah.name");
int score = properties.get<int>("blah.score");

properties.put("blah.name", "Inverse");
properties.put("blah.score", 1000);

It also supports reading and writing to various formats, like xml and others.

烙印 2024-09-10 01:39:33

我认为新的默认设置是在用户文件夹下的用户“AppData”文件夹中写入一个配置文件,该文件应该可以安全地写入/读取。

我们使用一个简单的 XML 格式的文件来存储设置;但您可以使用 INI 文件类型格式。

I think the new default thing is to write a configuration file in the user's "AppData" folder under the user's folder which should be safe to write/read from.

We're using a simple XML formatted file to store settings; but you could use a INI file type formatting.

冬天旳寂寞 2024-09-10 01:39:33

如果您使用 CSIDL_COMMON_APPDATA 将配置文件保存在应用程序数据目录 SHGetFolderPath() 中,所有用户都将能够看到该配置。如果您使用CSIDL_LOCAL_APPDATA,则只有一个用户能够看到该配置。注册表不一定是保存所有配置数据的地方。

If you save your configuration file in the Application Data directory SHGetFolderPath() with CSIDL_COMMON_APPDATA all users will be able to see the configuration. If you use CSIDL_LOCAL_APPDATA then only the one user will be able to see the configuration. The registry is not necessarily the place to save all configuration data.

放飞的风筝 2024-09-10 01:39:32

据我所知:

没有足够权限的用户可能无法创建/写入配置文件

您应该能够在用户的“主目录”或“应用程序数据”目录中创建文件,无论权限如何。通常这些目录应该是可写的。

今天的防病毒软件允许我添加/编辑/删除密钥吗?

从未见过我的防病毒软件干扰注册表操作。只要您不在注册表中做任何可疑的事情,您可能就没事。

哪种方式会更好?

这是品味问题。我认为文本文件更好 - 允许更轻松地迁移设置。只是卸载后不要留下垃圾。

此外,如果有人知道在 vc++ 中管理配置设置的类/库

另外,如果有人知道在 vc++ QSettings Qt 4。但是仅仅使用整个 Qt 来保存设置绝对是一种矫枉过正。您还可以检查 JSON 等配置语言,使用 lua 进行设置(比使用 Qt 4 更省力)或获取任何 XML 库。此外,直接使用注册表或使用 iostreams 或 stdio 编写配置文件应该不难。如果您愿意,您随时可以编写自己的配置库。

As far as I know:

an user with not enough permissions may not be able to create/write the config file

You should be able to make files inside user's "home directory" or "application data" directory, regardless of permissions. Normally those directories should be writeable.

would todays antivirus allow me to add/edit/remove keys?

Haven't ever seen my antivirus interfere with registry manipulation. You probably will be fine as long as you aren't doing anything suspicious in registry.

Which way would be better?

It is matter of taste. I think that text file is better - allows easier migration of settings. Just don't leave junk behind after uninstall.

Also, if someone knows a class/lib to manage config settings in vc++

QSettings in Qt 4. But using entire Qt for just saving settings is definitely an overkill. You could also check configuration languages like JSON, use lua for settings (less overkill than using Qt 4) or get any XML library. Also, working with registry directly or writing configuration files using iostreams or stdio shouldn't be hard. And you can always write your own configuration library - if you feel like it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文