Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where should my win32 program keep its files?

Tags:

c++

winapi

Our win32 applications (written in C++) have been around for over 10 years, and haven't been updated to follow "good practices" in terms of where they keep files. The application defaults to installing in the "C:\AppName" folder, and keeps application-generated files, configuration files, downloaded files, and saved user documents in subfolders of that folder.

Presumably, it's "best practices" to default to installing under "c:\Program Files\AppName" nowadays. But if we do that, where should we keep the rest of our files? Starting from Vista, writing to the program files folder is problematic, and there seem to be a million other places that you can put different files, and I'm confused.

Is there a reference somewhere for what goes where?


Edit: To expand on questions people have asked so far:


I'm familiar with the SHGetFolderPath function, but there are lots and lots of options that you can get from it, and I can't find a resource that says "Here is exactly what each of these options is used for, and when you might want to use it".

Up until now, we've done the "All files, including saved user files, under one folder" thing, and it's worked fine - but not when people want to install the app under the Program Files folder. For some reason, the virtualization monkeying around that Vista does isn't working for our application; if we're going to be making changes anyway, we might as well make an effort to do things the "right" way, since we don't want to have to change it again in 12 months time.


Further question:


We include some "sample" documents with our app, which we update every now and again. Is it appropriate to install them into My Documents, if we'll be overwriting them every few months? Or is My Documents assumed to be totally safe for users to mess around in?

If we can't install them to My Documents, where should we put them so that users can see them easily?

like image 725
Colen Avatar asked Feb 23 '09 22:02

Colen


2 Answers

Presumably, it's "best practices" to default to installing under "c:\Program Files\AppName"

Close, but not quite. Users can configure the name of the Program Files folder and may not even have a C: drive. Instead, install to the %ProgramFiles%\AppName environment variable folder.

Note you should assume you only have read access to this folder after the installation has finished. For program data files where you might need write access, use %AppData%\AppName.

Finally, are you sure yours is the only app with that name? If you're not 100% certain of that, you might want to include your company name in there as well.

The mechanisms you use to retrieve those variables will vary depending on your programming platform. It normally comes down to the SHGetFolderPath() Win32 method in the end, but different platforms like Java or .Net may provide simpler abstractions as well.

like image 142
Joel Coehoorn Avatar answered Oct 06 '22 02:10

Joel Coehoorn


Some guidelines are in this Knowledge Base article: How to write a Windows XP Application that stores user and application data in the correct location by using Visual C++. Also, if you search MSDN for Windows Logo Program you will find documentation regarding what an app needs to do to be truly compliant.

SHGetKnownFolderPath can get you the directories you need. If backwards compatibility with XP and earlier is required, use the deprecated SHGetFolderPath

Having said that, if you app came with documentation that said "everything used by this app is in this directory" I would love it ;)

like image 24
Paul Dixon Avatar answered Oct 06 '22 03:10

Paul Dixon