bug: ofToDataPath broken again #1250

Closed
elliotwoods opened this Issue May 10, 2012 · 12 comments

Projects

None yet

6 participants

@elliotwoods

:(

It seems i'm getting double 'data/' in my paths
after a little tracking down, i found this is because ofSystemLoadDialog changes the current working directory

so we could try and either fix that by popping the folder after the dialog,
of for windows using something like GetModuleFileName to get the path of the current exe rather than using the current working directory

I can't seem to run GetModuleFileName from ofUtils.cpp even though windows.h is included in ofConstants.h (included in ofUtils.h)

@ofTheo ofTheo was assigned Aug 4, 2012
@ofTheo

I'm up for whatever works!! :)
this is a frustrating bug otherwise.

@bilderbuchi
openFrameworks member

I'm pushing this back to 0073.

@toniorush

Hi,

I had problems with this and wrote my own long time ago...
I used it to put the data path inside the application bundle for osx/ios and use GetModuleFileName for windows
Very messy but just in case...

std::string getDataFilePath(const string &file_name) {
#if defined TARGET_OSX || defined TARGET_OF_IPHONE

// absolute ?
if(file_name.length() != 0 && file_name[0] == '/') {
    return file_name;
}

CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
char path[PATH_MAX];
if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX))
{
    // error!
}
CFRelease(resourcesURL);

string full_path(path);
full_path += "/";
full_path += file_name;
return full_path;

#else
static string abs_path;

// absolute ?
if(file_name.length() > 1 && (file_name[1] == ':' || file_name[1] == '\\')) {
    return file_name;
}

if(abs_path.empty()) {
    char buffer[MAX_PATH];
    ::GetModuleFileNameA( NULL, buffer, MAX_PATH );
    string::size_type pos = string( buffer ).find_last_of( "\\/" );
    abs_path = string( buffer ).substr( 0, pos) + "\\data";
}

return abs_path + string("\\") + file_name;

#endif
}

@elliotwoods

wait a sec. i'm working on this to get it ready for 0072 (as agreed at dev meet)
it's a serious bug which breaks too many projects whenever it rears

@toniorush

sorry i'm new here and don't know about dev meets
just ignore my comment

@elliotwoods elliotwoods was assigned Aug 30, 2012
@bilderbuchi
openFrameworks member

Hey no problem. Put it back to 0072, and assigned you, @elliotwoods. :-)
@toniorush I think he meant my previous comment, not yours, in his reply.

@elliotwoods

ah sorry toniourish! i'm continuing the discussion from
#1251

@bilderbuchi
openFrameworks member

well, according to your comment in #1251, 1251 is not a PR for this bug report, that's why I pushed back - didn't know you would fix this bug, too, in one go.

@bilderbuchi
openFrameworks member

pushing back to 0073 as per #1523 (comment)

@roymacdonald

this seems to be quite old and already fixed. shouldn't it be closed?

@bilderbuchi
openFrameworks member

I don't think so, #1523 is not merged yet. @elliotwoods ?

@kylemcdonald

omg closed by #1523

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment