Preference Files

BlitzMax Forums/BlitzMax Beginners Area/Preference Files

John G(Posted 2009) [#1]
Working on a small game that needs a basic text Preference File for PC and Mac. Want to store in standard lPC or Mac ocations. No clue how to proceed.

Thanks, John G


grable(Posted 2009) [#2]
Im unsure of wat exactly you are after, but heres something to get you going.
It uses simple KEY=VALUE syntax. not tested!



TaskMaster(Posted 2009) [#3]
I think he wants to know how to find the "Normal" location to store files on each of the 3 major OS's.

I know Grey Alien spent some time figuring this out, and it may be in the public domain portion of his Framework that was posted here somewhere. I am sure you could find it if you search for "Grey Alien Public Domain" or something like that.


matibee(Posted 2009) [#4]
This'll save you a search..

http://www.blitzbasic.com/Community/posts.php?topic=73305#819232


Htbaa(Posted 2009) [#5]
Or you use bah.volumes.


Brucey(Posted 2009) [#6]
This'll save you a search..


Of course, you shouldn't be saving prefs in the "app folder". They should of course be saved in some kind of "user folder".

My BaH.Volumes module has support for a "user app" folder, where you'd normally create subfolders in there for your app. eg :
Linux : /home/username
Mac OS : /Users/username/Library/Application Support
Win32 : C:\Documents and Settings\username\Application Data


On Linux you would create your particular "app" subfolder beginning with a dot, so for example a folder called ".myapp". This makes it "hidden", which is standard.

Of course, if you really want to write data to the app/install folder, feel free to, but that's not where they are meant to go. (No wonder Windows is so prone security problems if developers are happy to override security in order to save files in app folders).


matibee(Posted 2009) [#7]
Of course, if you really want to write data to the app/install folder, feel free to, but that's not where they are meant to go. (No wonder Windows is so prone security problems if developers are happy to override security in order to save files in app folders).


I'm sure Vista doesn't. As far as I'm aware Vista will silently write the file somewhere 'safe'. This fallback had to be added because writing files to the app directory had become the norm. Developers aren't supposed to rely on this fallback and instead should 'do the right thing' (whatever that is :) ).

Writing to the app folder is nothing, you should see how much fun a coder can have writing to c:\windows :D

Grey's code covers another specific Windows situation where he needs read/write access to the same file across all user accounts.


John G(Posted 2009) [#8]
I think he wants to know how to find the "Normal" location to store files on each of the 3 major OS's.
Yes, that's it exactly. I want to put my game preferences in the 'right place' and be able to find them again reliably. Doesn't almost everyone face this task?

I try not to have an 'app folder', just 2 files -- game and prefs. Prefs includes data and registration. The Mac for example has several Preference folders -- User, Shared, etc.

Thanks for all the great responses. I'll study new info. Thanks again.


Volker(Posted 2009) [#9]
I'm not sure if I understand this correctly.
If I have a settings file in my app folder after installing, and read
AND write to it, Vista will make problems?
Or only if i create a new file?


matibee(Posted 2009) [#10]
Volker; Generally, you shouldn't write to any file installed in the app folder or it's subfolders. Make a new file in the user's data area for writing to.

When reading your settings file your app should look for the user version first.


John G(Posted 2009) [#11]
Thanks Brucey and others. Brain blockage opened slightly. I'll start out with the Mac OS: /Users/Shared/Preferences/ folder and wrestle with Windows/Linux later. I came to BlitzMax for cross-platform, but still use PowerPC Mac as does my chief beta tester (Hamilton, NZ). I've already written and retrieved "Hello World" to/from Prefs file!


John G(Posted 2012) [#12]
CAUTION: Old thread revived.

Only targeting Windows for now -- XP, Vista, 7, & 8?.
Don't understand any OOP.
Successfully used Users/Public to store Prefs (game data) File.
Prefer to switch to unique UserName File locations.

Does anyone have some simple code they can share?

Thanks in advance.


Midimaster(Posted 2012) [#13]
What you need is the module Bah.Volumes from Brucey. It knows the right path to the users directory on mac and pc:

SuperStrict   
Import BaH.Volumes 
Global EigeneDateien$ , FactoryPath$, AppPath$, DataPath$
Global MyCompany$ , MyGame$
Print AppFile

MyCompany="Midimaster"
MyGame= StripAll(AppFile) 

SetPathes


Print "EigeneDateien$ = " + EigeneDateien 
Print "FactoryPath$ = " + FactoryPath
Print "AppPath$ = " + AppPath
Print "DataPath$ = " + DataPath



Function SetPathes()
?Win32
	EigeneDateien = GetUserDocumentsDir() + "\"
	FactoryPath = GetUserAppDir() + "\" + MyCompany + "\" 
	AppPath = FactoryPath + MyGame+ "\"
	DataPath = AppPath + "Data\"

?MacOs
	EigeneDateien = GetUserDocumentsDir() + "/"
	FactoryPath = GetUserAppDir() + "/" + MyCompany + "/" 
	AppPath = FactoryPath + MyGame+ "/"
	DataPath = AppPath + "Data/"
?	
End Function



John G(Posted 2012) [#14]
@Midimaster: Thanks much. I'll give this a whirl. I've downloaded Bah.Volumes a few times but didn't know what to do with it.
Thanks again.


John G(Posted 2012) [#15]
Bah.Volumes worked fine for Win 7 and XP. Anyone tried it on Win 8 Pro Desktop (Legacy)? Love to claim Win 8 Pro compatibility. Thanks much.