Library/Preferences folder

someone
Unregistered
 
Post: #1
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.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #2
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.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #3
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.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #4
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.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #5
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!
Quote this message in a reply
millercdusa
Unregistered
 
Post: #6
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 );
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  C++ with SDL2 Framework: Loading .bmp files in same folder in XCode 5 on Mavericks exitcode 1 1,169 Feb 23, 2014 11:15 PM
Last Post: SethWillits
  Xcode4: Resource not in Documents folder? SparkyNZ 3 6,671 Apr 9, 2011 03:29 PM
Last Post: SparkyNZ
  moving all folder project = error imaumac 2 3,018 Oct 13, 2008 08:46 AM
Last Post: imaumac
  how do I a set a ICNS to a file or folder Najdorf 8 5,455 Dec 21, 2005 12:25 PM
Last Post: Najdorf
  XCode tip: Generating folders in the Resource folder Malarkey 2 4,113 Nov 11, 2005 06:25 PM
Last Post: Malarkey