Library/Preferences folder
I'm new to Mac, and i'm trying to port one of my games to that platform. Most of it goes rather smooth, but now I need to write a file to the Library/Preferences dir of the user. I tried google etc, but can't seem to find how to retrieve the correct path to this folder in C++
So i tought i'd post here, anyone here who knows how to do this?
Thanks.
So i tought i'd post here, anyone here who knows how to do this?
Thanks.
Code:
getenv("HOME")I'll assume you can figure it out from there.
Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Naughty, bad, mustn't. There's no guarantee that HOME will be set.
The unix way to find the home folder is to call getpwuid() (read the man page).
The Carbon way to find the Preferences folder is to use the FindFolder function.
The unix way to find the home folder is to call getpwuid() (read the man page).
The Carbon way to find the Preferences folder is to use the FindFolder function.
Really? I've used that all the time. Didn't know that.
Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
You should really use CFPreferences (well NSUserDefaults but no doubt there will be a "reason" why you cant), http://developer.apple.com/documentation...ences.html
Sir, e^iπ + 1 = 0, hence God exists; reply!
Here's the code I ended up using for a Carbon application:
// ask the MacOS to find the users preferences folder (/Users/{username}/Library/Preferences/ on US-english MacOS X)
// see http://developer.apple.com/samplecode/Mo...ting2.html
// and http://developer.apple.com/documentation...FindFolder
// and http://developer.apple.com/samplecode/Fi...ting1.html
const int kMaxPath = 1024;
FSRef fsRef;
char path[kMaxPath];
OSErr tError = noErr;
tError = FSFindFolder( kOnAppropriateDisk, kPreferencesFolderType, kDontCreateFolder, &fsRef );
tError = FSRefMakePath( &fsRef, (UInt8 *)path, kMaxPath );
// ask the MacOS to find the users preferences folder (/Users/{username}/Library/Preferences/ on US-english MacOS X)
// see http://developer.apple.com/samplecode/Mo...ting2.html
// and http://developer.apple.com/documentation...FindFolder
// and http://developer.apple.com/samplecode/Fi...ting1.html
const int kMaxPath = 1024;
FSRef fsRef;
char path[kMaxPath];
OSErr tError = noErr;
tError = FSFindFolder( kOnAppropriateDisk, kPreferencesFolderType, kDontCreateFolder, &fsRef );
tError = FSRefMakePath( &fsRef, (UInt8 *)path, kMaxPath );
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Xcode4: Resource not in Documents folder? | SparkyNZ | 3 | 5,572 |
Apr 9, 2011 03:29 PM Last Post: SparkyNZ |
|
| moving all folder project = error | imaumac | 2 | 2,639 |
Oct 13, 2008 08:46 AM Last Post: imaumac |
|
| how do I a set a ICNS to a file or folder | Najdorf | 8 | 4,612 |
Dec 21, 2005 12:25 PM Last Post: Najdorf |
|
| XCode tip: Generating folders in the Resource folder | Malarkey | 2 | 3,636 |
Nov 11, 2005 06:25 PM Last Post: Malarkey |
|
| Xcode 1.5 and SharedCaches folder | RedWolf | 0 | 1,866 |
Oct 2, 2005 12:49 AM Last Post: RedWolf |
|

