Best place for user data files (vista and before)

Just starting out? Need help? Post your questions and find answers here.
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Best place for user data files (vista and before)

Post 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! :)
Dare2 cut down to size
maw

Post 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 :)
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post 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. :)
Dare2 cut down to size
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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"
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post 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?
Dare2 cut down to size
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post 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 :wink:
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)
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

That returns exactly the same as GetHOmeDirectory()+"Application Data" here! :)

Strange.
I may look like a mule, but I'm not a complete ass.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post 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"
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Read it and weep. (at least I did)

http://www.microsoft.com/downloads/deta ... layLang=en

cheers
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post 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?
Dare2 cut down to size
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post 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?
--Kale

Image
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post 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!
Dare2 cut down to size
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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?
I may look like a mule, but I'm not a complete ass.
Post Reply