Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

printf

macrumors regular
Original poster
Aug 27, 2008
105
0
the title says it all. i'm trying to launch html-based help files in the same directory as my app.

i've tried both LSOpenCFURLRef, as well as LSOpenFSRef, but can only get them to work with www urls but NOT local files like "file:///Developer/help.html". all i get is an OSStatus of -43, which doesn't seem to be in the range of the documented Launch Services result codes.

anyone ever get this to work?
 

printf

macrumors regular
Original poster
Aug 27, 2008
105
0
hhas, thanks for your response and that link.

i'd love to adopt that system, and probably will somehow in the future, but for the sake of time, and because this is the same system used in my win32 app, i need to just pop open the html files using the aforementioned technique.

any idea how?
 

Sayer

macrumors 6502a
Jan 4, 2002
981
0
Austin, TX
You need to get a CFURL reference to the html file to open, most likely in the app bundle. So first you get a reference to the main app's bundle, which you can then use to get the embedded HTML file.

so do:

Code:
CFBundle bundle = CFGetMainBundle();
CFURL  = CFBundleCopyResourceURL( bundle, "Help", "html", "HelpContentFolder" );

So "Help" is the file name minus extension, "html" is the file type extension (hurray for Unix/Windows!) and "HelpContentFolder" is the name of the folder in the Resources folder inside the app bundle that contains the Help files.

App Bundle > Contents > Resources > HelpContentFolder

Then its just a matter of: Pass that CFURL to LSOpenCFURLRef.
 

printf

macrumors regular
Original poster
Aug 27, 2008
105
0
-43 = file not found. Probably your URL is wrong. Post the relevant code if you want specifics.

here's both my attempts at this. i hard-coded the path in place of CFBundleCopyBundleURL(CFBundleGetMainBundle()), where my help files are stored just to eliminate any further points of failure. and i can assure you, that html file is in fact at that location.

Code:
//attempt 1
CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR("file:///Developer/Projects/help.html"), kCFURLPOSIXPathStyle, false);
OSStatus result = LSOpenCFURLRef(url,NULL);

//attempt 2
FSRef ref = {0};
Boolean isDir = false;			
OSStatus result = FSPathMakeRef((UInt8 *)"file:///Developer/Projects/help.html", &ref, &isDir);			
LSOpenFSRef(&ref,NULL);

and sayer, if i'm understanding you correctly that would require the help files to be 'inside' the app. i'd like the help to be external from the app so updates don't require a full download of the main app, and so the user can get to help without the app being loaded.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
In your examples you are passing the absolute string of a file URL instead of the absolute path.
 

printf

macrumors regular
Original poster
Aug 27, 2008
105
0
In your examples you are passing the absolute string of a file URL instead of the absolute path.

haha kainjow, i had JUST figured that out and came back to post my result!!! haha, thanks! (and i think you meant relative in the second part)

note to self: read EVERY line of the api documentation!
 

printf

macrumors regular
Original poster
Aug 27, 2008
105
0
for posterity:

Code:
CFURLRef fURL = CFURLCreateWithFileSystemPath(NULL, CFSTR("Help/help.html"), kCFURLPOSIXPathStyle, false); //Help resides in folder relative to app
LSOpenCFURLRef(fURL, NULL);
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Hm I could be wrong, but I don't think that code will work all the time. Did you test it by running your app outside of Xcode (e.g. via the Finder)? Xcode sets the current working directory usually to the Debug/Release directory, but the Finder doesn't.
 

printf

macrumors regular
Original poster
Aug 27, 2008
105
0
Hm I could be wrong, but I don't think that code will work all the time. Did you test it by running your app outside of Xcode (e.g. via the Finder)? Xcode sets the current working directory usually to the Debug/Release directory, but the Finder doesn't.

awww crap, you're right - it doesn't work when launched from finder! how do i get around that then?
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Well if the Help folder is in the same folder as your .app you can use CFBundleCopyBundleURL() and manipulate it from there (as a URL, or convert to C-string, etc). But since we're dealing with a Mac app, the Help folder *should* be located inside the .app's Resources folder, and if that's the case you can use Sayer's recommendation of CFBundleCopyResourceURL.
 

printf

macrumors regular
Original poster
Aug 27, 2008
105
0
kainjow, does this theory apply to dylib files as well? i just noticed dlopen is failing if i pass in a relative path and run my app from finder - but it works when i run it in xcode..

if so, that would seem contradictory to the point of a 'dynamically' linked lib, methinks
 

printf

macrumors regular
Original poster
Aug 27, 2008
105
0
i was able to fix the dlopen issue using CFBundleCopyBundleURL(CFBundleGetMainBundle()), however my question still stands.

is the mac standard to package dylib's with the .app's bundle? if this is the case, i would greatly appreciate a link to documentation on this, so i can follow these best practices!
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Yes, you can link to a dylib inside your application bundle. You have to copy it to a certain folder (probably Contents/Frameworks), and then write a run script to use install_name_tool to set the path to relative based on the directory. I used to do this with a project but I don't have the script anymore.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.