char *add_exe_path(const char *name) { static char path[PATH_BUF_SIZE]; char *mypath=exe_dir(); /* No snprintf in Turbo C 2.0 library, so just check by hand and exit if something goes wrong */ if (strchr(name,'%')) { /* there is substitution */ if (strlen(name)-1+strlen(mypath)>=PATH_BUF_SIZE) { fprintf(stderr,"Invalid config file. file name \"%s\" too long " "after substitution\n",name); exit(1); } sprintf(path,name,exe_dir()); return path; } else { return name; } }
String Get(Key key, const String& relative_path, const String& alternate_base) { if (key != RESOURCE) { SILOG(core,fatal,"Get with alternate base paths is only supported for RESOURCE"); assert(key == RESOURCE); return ""; } // We can always find the resource directory as an offset from the // binary's directory. boost::filesystem::path exe_dir(Get(DIR_EXE_BUNDLE)); // From there, we have a couple of possibilities. In the installed // version we'll have, e.g., /usr/bin or /usr/lib/sirikata and // /usr/share/sirikata { // Try for /usr/bin boost::filesystem::path share_dir_resource = exe_dir.parent_path() / "share" / "sirikata" / relative_path; if (boost::filesystem::exists(share_dir_resource)) return share_dir_resource.string(); } { // Try for /usr/lib/sirikata boost::filesystem::path share_dir_resource = exe_dir.parent_path().parent_path() / "share" / "sirikata" / relative_path; if (boost::filesystem::exists(share_dir_resource)) return share_dir_resource.string(); } // Otherwise we need to try the alternate base path within the // tree. { #if SIRIKATA_PLATFORM == SIRIKATA_PLATFORM_WINDOWS // On windows we need to deal with the fact that we have Debug/ // and RelWithDebInfo/ directories under build/cmake/. boost::filesystem::path source_base = exe_dir.parent_path().parent_path().parent_path(); #else // On other platforms, we just have the normal offset in build/cmake/. boost::filesystem::path source_base = exe_dir.parent_path().parent_path(); #endif boost::filesystem::path intree_resource = source_base / alternate_base / relative_path; if (boost::filesystem::exists(intree_resource)) return intree_resource.string(); } return ""; }