Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Simple file open command?

Simple file open command?
Thread Tools
Mac Elite
Join Date: May 2001
Location: Up north
Status: Offline
Reply With Quote
Dec 2, 2001, 04:18 PM
 
Do you guys remember in Codewarrior 5 using the console you could open files with a simple fp = fopen( "Whatever", "r" ), and you could then just read it into a buffer or whatever?

Well it would be great if I could use this same function in OS X, specifically so I don't have to bother with the file manager API. My program is using the file manager api right now, but I have to get it to ask to user to locate the file I want to open. The file is in the same directory as the compiled program, and in OS 9 using fopen, I did not have to search for the file name, and use all that file manager crap.

Very frustrating, all I want to do is open a simple ASCI file that is in the same directory as my app, and I would like to do it in a few lines of code.

------------------------------------------------------------
Is there a way to put a list of the contents of my apps directory into a strucutre so that I can display a list of maps that the user can open, without exiting the game specific user interface that I have created?
     
Grizzled Veteran
Join Date: Feb 2001
Location: Germany
Status: Offline
Reply With Quote
Dec 2, 2001, 04:30 PM
 
never done any codewarrior programming, but it's really easy in cocoa...

add whatever file you want as a resource to your application/bundle and get a path to it this way:

NSString *pathToMyFile = [[NSBundle bundleForClass:[self class]] pathForResource:@"<whatever>" ofType:@""];

it'll find that resource no matter where the user stores your app since the resource resides inside your bundle. it's that simple.

hth.
     
Mac Elite
Join Date: May 2001
Location: Up north
Status: Offline
Reply With Quote
Dec 2, 2001, 06:25 PM
 
How does that work when one needs to release a patch. The game when it is finished will be over 600 mb. So do I have to release a 600 mb patch? or is there a way to extract files from bundles.

If it is relatively easy, I would like to try and keep with the traditional way of storing information for games, so users can add their own mods and stuff. Like in unreal tournament, you got all your maps in a map folder, and all of your Music in another, and your save games in another.
     
Grizzled Veteran
Join Date: Feb 2001
Location: Germany
Status: Offline
Reply With Quote
Dec 2, 2001, 06:40 PM
 
well, in that case use

NSString *myPath = [[NSWorkspace sharedWorkspace] fullPathForApplication:@"<yourAppNameGoesHe re>"];

then you could go on by calling NSString's stringByDeletingLastPathComponent and to add the name of the file you're looking for. does that sound logical?
     
Senior User
Join Date: Aug 2001
Location: CA
Status: Offline
Reply With Quote
Dec 2, 2001, 06:53 PM
 
Originally posted by 11011001:
<STRONG>How does that work when one needs to release a patch. The game when it is finished will be over 600 mb. So do I have to release a 600 mb patch? or is there a way to extract files from bundles. .</STRONG>
Er, a bundle is just a folder. Apple's installer will easily install one file (for a patch) inside your bundle.

I suggest you read some of the basic OS X documentation, such as "Inside Mac OS X: System Overview" before attempting to continue.

-B
Dual 800 - GF3 - 1.5GB
     
Dedicated MacNNer
Join Date: Apr 2001
Location: Bethesda, MD
Status: Offline
Reply With Quote
Dec 3, 2001, 12:13 PM
 
I've certainly used fopen under OS X. A whole lot of Unix programs would die without it.

At one point I did notice some weirdness about trying to read files in the current working directory. I worked around it by using the full pathnames. Never did figure out what I was doing wrong.

dave
     
Mac Elite
Join Date: May 2001
Location: Up north
Status: Offline
Reply With Quote
Dec 4, 2001, 04:44 PM
 
Ya, I read the app docs on OS X, I just stopped programming in X since the summer till now, so I don't remember it all. No offense to anyone either, but it is pretty dry reading when compared to actually programming things, but then I am kinda an impatient person with the attention span of a gerbil.

I knew a bundle was a folder, but I have not worked with apples installer thing, so I did not know just how much one could get it to do. Makes sense that the installer can do that, since you can see the contents of a bundle using the terminal commands, just a curious question, but is it just a flag or something that tells the finder that a bundle is a bundle, and not a folder?

Great, files have never really been my strong point. In fact you might say I hate working with them, but this is good news, the NSString looks perfect, exactly what I was looking for, and I will figure out how to get fopen to work, I was just not sure whether it could be used, cus I could not find the libraries with it, I guess I was not looking hard enough.

But thanks for the help, I should be cruising again...
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 11:18 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2