File Code Problems - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: File Code Problems (/thread-7718.html)
Pages: 1 2
File Code Problems - Muffinking - Jun 6, 2002 05:12 PM
this time I actually have a message
I am going quite insane here.. nothing I try works.. and I have not been able to find any example code for what I need.
and what I need is this:
all I want is to be able to create an FSSpec to a file called "World Map" which is located in a folder called "Files" inside my programs directory..
how do I open it... I really need help on this one... I cannot progress with my engine until I get this working. I need to use to world map data to test out my code.
can someone post some code that opens a file within a folder inside the programs directory. or at least direct me to some place where I can learn how to do this..
this would be under carbon.
and I need to access the data fork of the file.
I just need to be able to create an FSSpec to the file..
then I can use FSRead etc..
I am starting to pull hair out over this... for the sake of my hair.. I need help.
thanks in advance.
File Code Problems - Tobi - Jun 9, 2002 10:20 PM
Try this code. It works perfectly for me. If it doesn't work for you, please tell me.
File Code Problems - wadesworld - Jun 10, 2002 11:56 PM
Quote: if (!CFStringGetCString(sr, routePath, 1024, kCFStringEncodingASCII) )
Note that in this code, the routePath is defined to be 1024 characters.
In the original example I posted, I simply used 1024 because I knew it to be sufficently long for my purposes.
However, you should make sure that it is sufficiently long for your purposes, and really you probably ought to define it as the maximum path length. I'm sure that's defined in a header somewhere, but I haven't taken the time to look and see what it is.
File Code Problems - WFleming - Jun 11, 2002 01:42 AM
I'm trying to do the same thing with Classic OS (I know, I know I should be doing carbon, but I won't be able to afford a computer i'd be happy running OS X for awhile (need to get the $$ for next year's tuition first)).
After spending the last few hours digging around Inside Macintosh i've come to the conclusion that Apple has purposefully made this very hard to do without using StandardGetFile(). But the thought of making a user have to select the data files the app uses using StandardGetFile() makes me cringe.
I also found Tech Note 2015 - Locating Application Support Files under Mac OS X, but that isn't much use to me. Couldn't find anything similiar for Classic (did I miss something?
I've thought up a couple of ways that might work, but have run into problems with both.
1) I could do this:
resRefNum = OpenResFile("\pMy Graphics File");
Definately easy, but OpenResFile isn't supported in Carbon (which I would like to at some point port my code to). So I need to use FSpOpenResFile(), but I need a FSSpec with it, but I don't know how to do that without StandardGetFile().
2) I could get a resRefNum for my app by
resRefNum = CurResFile();
at startup. Then find some way of getting a FSSpec using the resRefNum. Getting the FSSpec of the app file would give me the vRefNum (volume reference number) and the parID (parent directory ID) of the app and the data file (assuming they are in the same directory)?. So all I would need would be the name of the data file and I could create a FSSpec using FSMakeFSSpec().
However, I have been so far unable to find any functions that can get me a FSSpec from a resRefNum (I suspect that there is no way to actually do this).
Does anyone have any suggestions or code that might be useful?
File Code Problems - OneSadCookie - Jun 11, 2002 02:51 AM
If you're running OS 8.6 or later you can do Carbon development. That gives you access to all the tasty bundle goodness people are using here. 8.1 gives you access to some of Carbon, but I'm not quite sure how much; whether CoreFoundation is included. My recollection is yes, but I could be wrong.
ANSI C's fopen call will get you access to the data fork of a file with a relative path if that's all you want. You'll still have to do bundle stuff when you port, but it'd be a solution for the moment.
There was a "standard" way of doing this sort of thing which involved passing a relative path and 0 volume & other flags to FSMakeSpec or something -- but I never did it myself. Somebody else?
File Code Problems - WFleming - Jun 11, 2002 04:10 AM
Quote:Originally posted by OneSadCookie
I've thought about doing it carbon, but from what i've heard, often when a app in OS 8 or 9 works with CarbonLib, it doesn't mean it will work properly in OS X. Maybe someone can clarify this for me (the thought of making someone with OS X have to boot in OS 9 and then use CarbonLib to run the game seems rather unappealing)
Since I don't have access to a machine running X till at the earliest the end of summer i'm thinking i'll just stick with Classic for the time being. Plus once I get OS X (and finish this game, if it ever gets done) i'm going to try to delve into cocoa and see how that goes.
Regardless, I am going to buy a carbon book in the next few days at least, just need to figure which one I want. At least that will get me reasonably up to date with some things. But in the meantime if anyone does know a solution to my problem it would be much appreciated.
File Code Problems - geezusfreeek - Jun 11, 2002 08:14 AM
Quote:Originally posted by WFleming
All they meant was that certain requirements have to be met in both OSs. As long as you make sure to meet all the requirements of both OSs, then it should run in both OSs. This does not necesarrily mean that, in OS X, it would boot in OS 9. Sometimes, it means that it simply won't work. If it DOES make it boot into OS 9, it means that you have a resource set wrong (I forgot what it was called). You can find the requirements for Carbon programming in the preface of the Carbon programming book that is downloadable at mactech.com.
File Code Problems - WFleming - Jun 11, 2002 03:58 PM
Quote:Originally posted by geezusfreeek
Sorry, should have been clearer. My understanding is that just because a game runs under CarbonLib in OS 8/9 doesn't mean it will work properly in OS X.
So if it didn't work (this is becoming very hypothetical) in X but did in 9, my understanding is that the user would have to reboot the computer in OS 9 for it to work.
My original plan was to do a classic version of the game, then release a carbon version once I can afford OS X. But I'm beginning to think that I might just not release the classic version, and wait till I get X (sometime in the next 6-12 months)
File Code Problems - geezusfreeek - Jun 11, 2002 04:11 PM
Ok. If you're gonna wait to get OS X, you might as well wait until they release Jaguar. It'll be a lot better than the current version, mainly because it'll incorporate OpenGL into all graphics, using hardware acceleration whenever it's useable. I think it's out in July sometime. I may be mistaken. Not too far off from now. I made the mistake of buying it now instead of then. Now I'll either have to get an update or be stuck without it. Stinks.
File Code Problems - wadesworld - Jun 13, 2002 10:06 PM
Quote:My understanding is that just because a game runs under CarbonLib in OS 8/9 doesn't mean it will work properly in OS X.
That's only partially correct. Ninety-nine percent of the Carbon code for a game is completely usable in both environments. The one part that isn't is input devices. However, there's now an input-sprocket compatibility library for OS X, so you can even keep using ISp code on OS X.
However, I would recommend you learn the OS X way of doing things too, rather than use that.
So in short, write your game in Carbon, but just call the OS X input code if the game is currently running on OS X, or the OS 9 input code if the game is currently running on OS 9.
Quote:I think it's out in July sometime. I may be mistaken.
You're definitely mistaken. Jaguar is not likely to appear until September.
Quote:I made the mistake of buying it now instead of then. Now I'll either have to get an update or be stuck without it. Stinks.
Why does it stink? You're getting use out of it now, aren't you? If you waited until September, you wouldn't have to pay for an upgrade, but you also wouldn't have been able to use it.
File Code Problems - Josh - Jun 14, 2002 08:47 AM
WFleming, are you just trying to open a resource file in Classic? If that is all, I have some simple code that does that...
File Code Problems - geezusfreeek - Jun 14, 2002 11:18 AM
Quote:Originally posted by wadesworld
Well, yes, but I do not have a steady income, due to the fact that I'm just a high school student with no job. Money is much more valuable to me than to somebody with a real job. I dunno. I was more frustrated when I thought it came out next month. It is worth it since it comes out in September though.
File Code Problems - WFleming - Jun 14, 2002 04:14 PM
Quote:Originally posted by jabber
Don't worry about it. I've decided to just use OpenResFile() for the time being, and when I finally stop procrastinating and get around to doing this in carbon, i'll either use the code above or figure another way to do it.
File Code Problems - Josh - Jun 14, 2002 05:32 PM
I'll give it to you anway... :) Basic idea is this:
File Code Problems - WFleming - Jun 17, 2002 05:13 PM
Quote:Originally posted by jabber
In addition I found some code (Technical Q&A FL14) at developer.apple.com that shows how to use the Process Manager to get the vRefNum and dirID of the application. I assume it would be better to plug these into FSpOpenResFile than using 0 for them?