Link to home
Start Free TrialLog in
Avatar of steven_bryant
steven_bryant

asked on

How Do I Access user data folder on mac using carbon

I am trying to get path to user data in C++ with carbon.

The path is /Users/{username}/Library/Application Support

I have seen code like
      FSRef fsRef;
      char szPath[1024];
      OSErr tError = noErr;
      tError = FSFindFolder(kOnAppropriateDisk,kPreferenceFolderType,kDontCreateFolder,&fsRef);
      tError = FSRefMakePath(&fsRef,(UInt8*)path,1024);

However since I am writing cross-application plug-in for adobe application, I will not have a mac to test on for another couple of days. Can someone verify code that would work for me.
Avatar of pgnatyuk
pgnatyuk
Flag of Israel image

kPreferenceFolderType - what is this?
Usually it looks like:
myOSStatus = FSFindFolder(kUserDomain,kChewableFolderType,kCreateFolder,&myTempFolderFSRef);

In the next line:
 tError = FSRefMakePath(&fsRef,(UInt8*)path,1024);

'path' - what is this? Probably you wanted to declare
unsigned char path[260]?

Do you need to get to your bundle?

Here you will find many examples and the last one is similar to yours.
http://www.cocoadev.com/index.pl?ApplicationSupportFolder
Avatar of steven_bryant
steven_bryant

ASKER

Thanks pgnatyuk for your comment.
I just copied and pasted code without really inspecting too much.

However is FSFindFolde carbon?

Also would it be possible to test the code and rewrite it, since I can't test at this time
I re-read your question again and see: "The path is /Users/{username}/Library/Application Support". So I do understand more or less what you need.
Yes, it is Carbon. I'll check it.
 
Here is another piece of code I received on Adobe forum http://forums.adobe.com/message/2729174#2729174

FSRef yourUserFolderRef;
OSErr err = FSFindFolder(kUserDomain, kCurrentUserFolderType, kDontCreateFolder, &yourUserFolderRef);
 
CFURLRef fURL = CFURLCreateFromFSRef(kCFAllocatorDefault, &yourUserFolderRef);
CFURLRef fHomeURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, fURL, CFSTR("Library/Application Support"), true);
CFRelease(fURL);
 
CFStringRef fHFSPath = CFURLCopyFileSystemPath(fHomeURL, kCFURLHFSPathStyle);

What do you think about it?
ASKER CERTIFIED SOLUTION
Avatar of pgnatyuk
pgnatyuk
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You last comment is about the same - simply another folder. I've posted a link where all this stuff is explained.
http://www.cocoadev.com/index.pl?ApplicationSupportFolder
However, I have not tested it yet at this time, but it looks goof
what is the #include for core foundation framework
In Xcode you simple add a framework. Through popup menu. Or -framework CoreServices to the compile and lnk flags.
 
Thanks. Please excuse my total mac ineptness. I imagine that the plugin project will already include that, but if i'm stuck i'll holler back. Thanks for your help.
One more question. Will this work with Unicode string. Lets say username is non-english. Am I getting back a unicode or at least UTF8 string?
I work more with Cocoa than with Carbon. I do not understand why you need Carbon. The latest Xcode even does not have these project templates. Everything works fine in Cocoa. NSString covers all these Unicode problems.
I'm kind of confused myself. But I think the indesign sdk which uses c++ needs carbon code.

Could you give me cocoa sample that I can test to see if it works
If your carbon code works, leave it as it is.  Inside a cocoa project (objective-c) you can use c, c++, etc