Preference Files
BlitzMax Forums/BlitzMax Beginners Area/Preference Files
| ||
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 |
| ||
Im unsure of wat exactly you are after, but heres something to get you going. It uses simple KEY=VALUE syntax. not tested! |
| ||
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. |
| ||
This'll save you a search.. http://www.blitzbasic.com/Community/posts.php?topic=73305#819232 |
| ||
Or you use bah.volumes. |
| ||
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). |
| ||
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. |
| ||
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. |
| ||
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? |
| ||
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. |
| ||
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! |
| ||
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. |
| ||
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 |
| ||
@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. |
| ||
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. |