Mac ini file being ignore yet data saved!?

BlitzMax Forums/BlitzMax Beginners Area/Mac ini file being ignore yet data saved!?

Grey Alien(Posted 2007) [#1]
This is weird, but I'm a Mac noob so maybe you know what's going on.

I'm compiling my ATOMG demo on the MAc and it has an ini file in the same folder as the exe.

When I change any settings in the ini file the game is ignoring them. However, if I change the settings in the game, they are being retained and loaded next time I load the game BUT not in the local ini file - somewhere else instead!

My game makes a default ini file if it can't load from the ini file so maybe it's doing that, but the question is where? I've done a finder for AOTMG.ini and the only one it finds is in the same folder as my game. Are apps on the Mac not allowed to write to folders on desktop or something (this is where my game is), like Vista's UAC - is it virtualising my ini file somewhere else?

Maybe I've just cocked up the paths, I've used forward slashes everywhere. The game data loads fine, just not the ini file!

Thanks for any advice.


Grey Alien(Posted 2007) [#2]
oops, think it was a problem with my code that checks the file name for "debug" to see if it's running in debug mode - I was looking for ".exe" and not ".app".

HOWEVER, why the hell is my filename (obtained via AppFile()) like this:

"/Users/jakebirkett/desktop/BMax Jake/AOTMG/AOTMG.debug.app/Contents/MacOS/AOTMG.debug"

Basically what the hell is Contents/MacOS/AOTMG.debug doing on the end. Sounds like some kind of virtualisation.

Is there a place where I should tell the BMax IDE it's safe to write to in the OS and where my game can safely write ini files etc? Thanks.


Grey Alien(Posted 2007) [#3]
wow found out some more. If I right click on the AOTMG.app I can select "Show Package Contents", this has a several sub folders and eventually I can find the actual end program and of course an ini file sitting in the same folder.

If I run the program in that folder, I get a Terminal window appearing and the the game runs but the mouse pointer I've made doesn't keep up with the Mac mouse pointer, weirdness.

All data is read properly and profiles are written to the correct place so I just need to fix how I test if the filename is a debug version or not seeing as that's how I auto-determine the name of the ini file...


Grey Alien(Posted 2007) [#4]
OK fixed it.


JazzieB(Posted 2007) [#5]
Glad you've sorted it, but I have been advised in the past that although it's OK to store all your application's resources in the application bundle, it's NOT a good idea to allow the app to write stuff there, i.e. your INI file.

What I've done in my Rockfall game is to store the INI file and player profiles in the /Users/Shared/ folder, but obviously created a sub-directory of SOS Software/Rockfall - The Return DX/.

Also, you may want to check AppArgs[], as the first argument passed to the app is the name of the app. Not sure if this is in a different format to that obtained by AppFile(). I'd check, but I'm not on my Mac at the moment.


Grey Alien(Posted 2007) [#6]
JazzieB: Thanks for advice. Any idea why writing in the app bundle is a bad idea (Actually I'm not writing in the app bundle, I'm writing in the same folder that the app bundle is in, so at the top level of the app bundle).

Anyway I may have to change where it writes for Vista, so I'll just use that special folder you mentioned on Mac.


Brucey(Posted 2007) [#7]
A good place to put preference type files is either in

/Users/<user>/Application Support/<app>/...

or

/Users/<user>/Library/Preferences/...

But rather than hard-coding the paths, use the API to get to the folder.

If you really want to put it in Shared, it should probably go in /Users/Shared/Library/Application Support/<app>/...

(for <app> you might also do your company name instead, of course).

:o)


Grey Alien(Posted 2007) [#8]
Thanks Brucey, good advice on the paths front.

Hmm, however if it's an ini file it should really go in shared in case the user changes as another use may still want to play it. Also any game profiles should go in shared so that you can see an list when you play the game...also high scores. In fact there's not much I'd want to store that would be user specific...


JazzieB(Posted 2007) [#9]
Sorry Grey, I misunderstood your post and took it to be that you were writing to within the app bundle itself. To answer your question though, from what I understand, it all comes down to the file permissions of the running app. Not sure of the implications, other than it not working as expected, but was advised not to do this in a thread around here somewhere.

Also, in the same thread I believe, it was also suggested to use the /Users/<user>/Library/Preferences/ folder, but this only seems to be user specific. In other words, there is no such folder for Shared, which is why I do it the way that I do, which I'm guessing is how you would like to do it also.

EDIT - Just discovered that there is a /Library/Preferences/ folder, which is not in the /Users/ folder. Not sure if this works as an alternative to just using the /Shared/ folder, but I would still be inclined to use the latter nonetheless.


Grey Alien(Posted 2007) [#10]
yep, shared folder sounds the way to go for me. Thanks for the heads up. Have you any code to retrieve that folder via a system call?


JazzieB(Posted 2007) [#11]
No special API call. The folder should be present on all Mac's and is always called /Users/Shared/, even when the Mac is set-up for another language.

If it's not there, then I use Brucey's Special Folder mod to retrieve the user's own folder and store the files there instead.


Grey Alien(Posted 2007) [#12]
OK thanks.