Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code/Modules/LocalFS/LocalFileSystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ LocalFileSystem::init(const StringAtom& scheme_) {
StringBuilder strBuilder;

// setup the root assign
strBuilder.Format(4096, "%s:///%s", this->scheme.AsCStr(), fsWrapper::getExecutableDir().AsCStr());
strBuilder.Format(4096, "%s:///%s", this->scheme.AsCStr(), fsWrapper::getRootDir().AsCStr());
IO::SetAssign("root:", strBuilder.GetString());

// setup the cwd assign
Expand Down
26 changes: 25 additions & 1 deletion code/Modules/LocalFS/posix/posixFSWrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#else
#include <unistd.h>
#endif
#if ORYOL_MACOS || ORYOL_IOS
#include <CoreFoundation/CoreFoundation.h>
#endif

namespace Oryol {
namespace _priv {
Expand Down Expand Up @@ -75,7 +78,27 @@ posixFSWrapper::close(handle h) {

//------------------------------------------------------------------------------
String
posixFSWrapper::getExecutableDir() {
posixFSWrapper::getRootDir() {
#if ORYOL_MACOS || ORYOL_IOS
// Get the main bundle for the app
char bundlePath[4096];
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef mainBundleURL = CFBundleCopyBundleURL( mainBundle);
CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle);
CFStringGetCString( cfStringRef, bundlePath, 4096, kCFStringEncodingASCII);

// Append the resources directory
StringBuilder strBuilder(bundlePath, 0, (int)CFStringGetLength(cfStringRef));
#if ORYOL_MACOS
// On iOS, bundled files live at the toplevel app bundle. On MacOS, they live
// in the resources directory beneath that.
strBuilder.Append( "/Contents/Resources");
#endif
strBuilder.Append( "/");
return strBuilder.GetString();

#else
// Anything else (such as windows) use the executable path
char buf[4096];
int length = wai_getExecutablePath(buf, sizeof(buf), nullptr);
if (length > 0) {
Expand All @@ -89,6 +112,7 @@ posixFSWrapper::getExecutableDir() {
else {
return String();
}
#endif
}

//------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions code/Modules/LocalFS/posix/posixFSWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class posixFSWrapper {
/// close file
static void close(handle f);

/// get path to own executable
static String getExecutableDir();
/// get path to where application resources are typically stored
static String getRootDir();
/// get current directory
static String getCwd();
};
Expand Down