Routing to a certain file in C++

Member
Posts: 116
Joined: 2005.02
Post: #1
If I bundled a file in a package, (in C++) how would I get it to route to that file every time with different user names? For instance to get to a file on my desktop "/users/matthew/desktop/myapp/data/titlehead.jpg" except at a point that I can use the "matthew" part as any user name...I need this information to finish a project of mine...

Last login: Sat Aug 6 09:15:05 on console
Welcome to Darwin!
Matt-Chelens-Computer:~ matthew$
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #2
You'd just do "(name_of_app).app/Contents/data/titlehead.jpg". That'll load it from within the bundle. This will only work assuming that's the correct location of the file and if you actually built in into the app. After building, right click the app and select Show Package Contents. This will let you explore the insides of the app and see where files are located.
Quote this message in a reply
Member
Posts: 198
Joined: 2005.01
Post: #3
I've read somewhere (can't remember where now...) that you're not really guaranteed any working directory from within a running .app. Here's a super safe way, if you have an Obj-C component to your app (probably at least main, yeah?) --

Code:
NSString * resPath = [[NSBundle mainBundle] pathForResource:@"data" ofType:nil];
chdir([resPath cString]);

Then put a directory called "data" in your Resources dir inside the app bundle (e.g. with a copy build step) that has all your data files in it. You can then use relative paths to access it.

Cryptic Allusion Games / Cryptic Allusion, LLC
http://www.cagames.com/
Quote this message in a reply
Moderator
Posts: 522
Joined: 2002.04
Post: #4
You want to change the cwd (current working directory) and keep things relative to the Resources folder in your app

PHP Code:
CFURLRef resourceURL CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
char resourcePath[PATH_MAX];
if (
CFURLGetFileSystemRepresentation(resourceURLtrue, (UInt8 *)resourcePathPATH_MAX))
    
chdir(resourcePath);
else
    
fprintf(stderr"Cannot change path to resources directory!\n"); 
-Jon
Quote this message in a reply
Member
Posts: 116
Joined: 2005.02
Post: #5
ok, with that answered, how do I get something to route to a certain webpage if a button is hit? ie: the 'Buy Now' button

Last login: Sat Aug 6 09:15:05 on console
Welcome to Darwin!
Matt-Chelens-Computer:~ matthew$
Quote this message in a reply
Moderator
Posts: 704
Joined: 2002.04
Post: #6
Code:
CFURLRef url;

if(( url = CFURLCreateWithString( kCFAllocatorDefault,
  CFSTR( "http://www.sealfin.com/" ),
  NULL )) != NULL )
{
  LSOpenCFURLRef( url,
    NULL );
  CFRelease( url );
}

That works, but error handling code would probably be nice...

Mark Bishop
--
Student and freelance OS X & iOS developer
Quote this message in a reply
Member
Posts: 198
Joined: 2005.01
Post: #7
And Obj-C in case you have a use for it:

Code:
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString: @"http://foo"]];

Cryptic Allusion Games / Cryptic Allusion, LLC
http://www.cagames.com/
Quote this message in a reply
Member
Posts: 116
Joined: 2005.02
Post: #8
Understood, last question, through OGL, how would you import a model that you made? Not just make quads and tris

I'm adding this but, last one for sure, in Cocoa or C++, how would you get to a certain item in the .nib file when using the Cocoa and C++ frameworks? ie: a slider, WebView, Text bar, button.

Last login: Sat Aug 6 09:15:05 on console
Welcome to Darwin!
Matt-Chelens-Computer:~ matthew$
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #9
Keep in mind that for unrelated questions, separate topics are usually best. For the nibs, when you load the nib itself the runtime will take care of connecting all of your outlets/actions for you, so if you do that in IB it will keep them.

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Member
Posts: 116
Joined: 2005.02
Post: #10
I asked that because I'm trying to do a drop down menu that will go to different places for each item...

Last login: Sat Aug 6 09:15:05 on console
Welcome to Darwin!
Matt-Chelens-Computer:~ matthew$
Quote this message in a reply
Member
Posts: 168
Joined: 2004.10
Post: #11
Blorx2 Wrote:I'm adding this but, last one for sure, in Cocoa or C++, how would you get to a certain item in the .nib file when using the Cocoa and C++ frameworks? ie: a slider, WebView, Text bar, button.
This is where you have to use objc in a c++ file. Presuming you're using xcode, then what it does is use GCC to compile the code and build it with the nib files. It compiles both languages in the same program. Therefore, every piece of code you write-just because it only has c++ code in it doesn't mean it is limited to that.
I however, recommend you go the nice and easy route with full screen SDL Wink You can get on to nibs later when necessary, as you are only making games.
Quote this message in a reply
Member
Posts: 116
Joined: 2005.02
Post: #12
Actually, I'm using this stuff for a weird game and a 'forum browser' that people have talked about and i decided to give it a go, so SDL won't help much in this case.

Last login: Sat Aug 6 09:15:05 on console
Welcome to Darwin!
Matt-Chelens-Computer:~ matthew$
Quote this message in a reply
Member
Posts: 168
Joined: 2004.10
Post: #13
If you're making an app and not a game, then you really should be in idevapps.com .

For a first proper like game thingy, I also recommend you don't chose a weird idea for one. Wink
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #14
Blorx2 Wrote:Understood, last question, through OGL, how would you import a model that you made? Not just make quads and tris
That is the only way to import models. That's all that Maya, Wings3D, or any modeler does. It just keeps track of quads and tris and draws them all (though from what I've read, OpenGL makes all quads into tris anyway). There's no real set-up way in OGL to do this. You have to write your own code.
Quote this message in a reply
Member
Posts: 168
Joined: 2004.10
Post: #15
Presumably the easy route to do it would be to parse the text based obj files and taking tris and quads from them...
Perhaps quake 2 models may be easier to implement - mark (the one who made rotrix) used them so he must have found an easy way to do them rather than another fileformat.
Quote this message in a reply
Post Reply