Page 1 of 2
Best place for user data files (vista and before)
Posted: Sun Jul 29, 2007 5:50 am
by Dare
Hi,
I want to settle on a place (path) to hold files that the app updates (user prefs, app data, etc) that will work for all users on all windows platforms (or at least 2000,NT,XP and Vista).
So where is the best folder to keep these files so that there is no security issue (or any other issues)? I am assuming somewhere inside "Documents and Settings".
Also, what is the best way to have PureBasic advise on this (in-built constants or commands, only API if absolutely necessary)?
How do you guys handle this?
Thanks!

Posted: Sun Jul 29, 2007 7:54 am
by maw
Personally I don't like the idea of separating settings and userdata from the program folder. Unfortunately in Vista, for the general user, you have to since they don't have write permit in the program folder.
I have Windows on C: and all my programs on D:, this way, when I reinstall Windows all my programs are there, ready to be used without reinstalling them all over again and configuring everything from scratch. I avoid programs that use the registry to save settings and programs that only save settings to the official settings folder (%appdata% or whatever it is).
Most programs I use simply use the program folder for saving settings if it finds the .ini file there. Others you have to start with a command line parameter to store settings where you want them. And then we have those programs which do not behave like you want, but you simply can't live without. Like Purebasic... (Yes, I know, you can use command line parameters to redirect the settings, but then you have to change the file association also or else you can't doubleclick a .pb file, really annoying) And of all the shareware programs I have paid for, currently only Purebasic is in the last category.
So in essence, I want to be in control of where stuff on my computer is saved, and I make my wish known by using and paying only for that kind of software. And telling the authors of software I reject why I don't use it!
I am not the only one who likes it this way, btw

Posted: Sun Jul 29, 2007 9:55 am
by Dare
Hi maw,
I have the same preferences as you, I think. But with Vista I now think this has to change for apps I release - so the end user doesn't have to do anything other than install.
(Most users don't want to faff around, it seems. I learned this lesson releasing a few apps without installer. "Just download and then double click to run" seemed good and unobtrusive to me. My word, the calls for help came thick and fast! So now I use inno installer and let them choose to have entries in the start menu, desk top icons, default installation folder, etc etc etc).
Now I fear that with Vista unless I conform I will spend ages answering questions about denied access (or whatever it does).
I have no Vista installed and also no clue about where the data is best stored.
And no clue about how to have my progs know the info (eg, some PB constant or command that says "this is the place for this user").
So any help appreciated.

Posted: Sun Jul 29, 2007 10:04 am
by Trond
How about this? It will store the preferences file in appdata if %appdata% is defined. Else, it will use the program directory (I hope, I didn't test it).
Code: Select all
#APPNAME = "My Program"
SetCurrentDirectory(GetPathPart(ProgramFilename()))
Appdata.s = GetEnvironmentVariable("%appdata%")
If Appdata
If Right(Appdata, 1) <> "\"
Appdata + "\"
EndIf
Appdata + #APPNAME + "\"
EndIf
; Store preferences here in Appdata + "Preferences.prefs"
Posted: Mon Jul 30, 2007 2:35 am
by Dare
Hi Trond
Thanks mate, I'll give it a whirl tonight.
If appdata is not set is there a default safe place for vista?
Posted: Mon Jul 30, 2007 10:13 am
by srod
Sorry Dare, would something like GetHomeDirectory()+"Application Data"+"\" not do the job? This is where PB (on my system at least) places it's pref files etc.
Posted: Mon Jul 30, 2007 10:30 am
by gnozal
srod wrote:Sorry Dare, would something like GetHomeDirectory()+"Application Data"+"" not do the job? This is where PB (on my system at least) places it's pref files etc.
This would fail on a french PC, as 'Application Data' is 'Données d'applications' here
So better use
Code: Select all
Procedure.s SpecialFolder(SpecialFolder)
Protected ListPtr.l, SpecialFolderPath.s
SpecialFolderPath = Space(#MAX_PATH)
If SHGetSpecialFolderLocation_(0, SpecialFolder, @ListPtr) = #NOERROR
SHGetPathFromIDList_(ListPtr, @SpecialFolderPath)
EndIf
ProcedureReturn Trim(SpecialFolderPath)
EndProcedure
Debug SpecialFolder(#CSIDL_APPDATA)
Posted: Mon Jul 30, 2007 10:40 am
by srod
That returns exactly the same as GetHOmeDirectory()+"Application Data" here!
Strange.
Posted: Mon Jul 30, 2007 10:55 am
by gnozal
srod wrote:That returns exactly the same as GetHOmeDirectory()+"Application Data" here!
Strange.
I get "C:\WINNT\Profiles\gnozal\Données d'applications" for CSIDL_APPDATA.
The purebasic preference files are in "C:\WINNT\Profiles\gnozal\Données d'applications\PureBasic"
Posted: Tue Jul 31, 2007 2:46 am
by rsts
Posted: Tue Jul 31, 2007 5:01 pm
by Dare
Read it and wept.
Thanks for the help guys.
I assume the procedure "SpecialFolder(SpecialFolder)" will provide a safe place in XP and Vista (and other versions of windows?) and that #CSIDL_COMMON_APPDATA would be be the flag to use?
(Giving, for eg, "C:\Documents and Settings\All Users\Application Data")
Also, what strategies do you guys have for dealing with possible name clashes?
Eg if you had an app called "myApp" and there was already a folder called "C:\Documents and Settings\All Users\Application Data\myApp" created by another application, do you have a strategy for dealing with this sort of thing?
Posted: Tue Jul 31, 2007 5:12 pm
by Kale
Dare wrote:Eg if you had an app called "myApp" and there was already a folder called "C:\Documents and Settings\All Users\Application Data\myApp" created by another application, do you have a strategy for dealing with this sort of thing?
This is where the .NET framework is nice and gives you a cool class called Isolated Storage. Basically it allows you to store up to (by default) 10mb of settings, etc. per user AND per assembly. In other words per exe. To emulate this using PB i guess you could save your stuff inside a folder called the md5 hash of the exe that created the file?
Posted: Tue Jul 31, 2007 5:14 pm
by Dare
Kale wrote:To emulate this using PB i guess you could save your stuff inside a folder called the md5 hash of the exe that created the file?
Now that is a concept worth exploring further.
Thanks!
Posted: Tue Jul 31, 2007 6:02 pm
by Trond
Dare wrote:
Also, what strategies do you guys have for dealing with possible name clashes?
Eg if you had an app called "myApp" and there was already a folder called "C:\Documents and Settings\All Users\Application Data\myApp" created by another application, do you have a strategy for dealing with this sort of thing?
Code: Select all
#APPNAME = "My Program"
#COMPANYNAME = "NOPQRSoftware"
SetCurrentDirectory(GetPathPart(ProgramFilename()))
Appdata.s = GetEnvironmentVariable("%appdata%")
If Appdata
If Right(Appdata, 1) <> ""
Appdata + ""
EndIf
Appdata + #COMPANYNAME + "" + #APPNAME + ""
EndIf
; Store preferences here in Appdata + "Preferences.prefs"
The chance of another program having the same name and company is less than one having the same checksum, I think. Also it's looks nicer than using an md5-named folder.
Posted: Tue Jul 31, 2007 6:31 pm
by srod
I'm probably being a little dense here!
But why does Appdata.s = GetEnvironmentVariable("%appdata%") just produce an empty string on my system?