Jump to content
  • Advertisement
Sign in to follow this  
Aphyxia

XCode fileIO

This topic is 3492 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to figure out how to open a fstream with a relative filepath for an iphone game i'm making, I know there is a phones section but i'm pretty sure this problem is compiler specific not iphone specific. for example in visual studio it goes from the project file so if i wanted to open a file "openme.txt" in the path that follows c:/(...)/solution folder/the Project Folder/subfolder1/subfolder2/openme.txt i would do ifstream fin("subfolder1/subfolder2/openme.txt"); The only way i can figure out in xcode is give it the absolute path(eww). or NSString* path = [[NSBundle mainBundle] pathForResource: @"openme" ofType: @"txt"]; ifstream fin([path cStringUsingEncoding:1]); I have 3 major problems with that method. 1. that fills path out with a fullpath name still, not a relative one (not a big deal yet but seems ugly) 2. for that function to work it requires the file to be included in the project, so i can't just make a new image and script file with that file name in it to create a new level, I have to actually rebuild the project with a new image... makes 'expansion packs' difficult. 3. I realize its not what apple "prefers" but i'm trying to keep the 'objective-C' out of the actual game code and just in the wrappers so that the game itself is as portable as can be. Anyway, i suppose this could have been shorter but i wanted to explain why I'd prefer not to use that approch. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Since no one's answered, I'll go ahead and post a reply. I don't know how things work on the iPhone, but on a Mac running OS X, the method I'm familiar with for changing the current working directory involves using Objective C (like in your example).

My own Mac apps are built around SDL, so this just involves making some changes to SDL_main (which isn't too difficult).

If you get really stuck on this (and don't get any additional replies here), you might try posting over on idevgames.com.

Share this post


Link to post
Share on other sites
There should be a setting in the IDE to set the working directory for the active executable. It's probably in a slightly different place depending on the version of XCode you've got. But I'd start by right-clicking the executable in the tree of stuff on the left.

EDIT: http://developer.apple.com/documentation/developertools/conceptual/XcodeProjectManagement/080-Defining_Executable_Environments/chapter_9_section_5.html

Share this post


Link to post
Share on other sites
Thanks guys, i'll look into those... I'm also going to write an archiver so i can hide the indivdual files from the end user. then i only need to open the one file and the files in the archive I can change/link to however i want.

Share this post


Link to post
Share on other sites
Either method should work for testing on your Mac, but remember that you can't read/write arbitrary files on the iPhone - the security features only let you read files stored inside your application bundle anyway.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!