X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fsupport%2FPath.cpp;h=36837f6f9a06e2f530c0316f3f93db18d38813cc;hb=0a9735c5f7bbbaa24ac2e3e4fa745c6dfbc95a18;hp=4af4542f517fa0cac70990f916d0395501a7a960;hpb=f212b483355d68e93132fb469814e13335d0886b;p=lyx.git diff --git a/src/support/Path.cpp b/src/support/Path.cpp index 4af4542f51..36837f6f9a 100644 --- a/src/support/Path.cpp +++ b/src/support/Path.cpp @@ -3,33 +3,29 @@ * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * - * \author Lars Gullik Bjønnes + * \author Lars Gullik Bjønnes * * Full author contact details are available in file CREDITS. */ #include -// Needed to prevent the definition of the unnamed_Path macro in the header file. -#define PATH_C - #include "support/Path.h" -#include "support/lyxlib.h" - -using std::string; +// undef PathChanger macro when building PathChanger +#undef PathChanger namespace lyx { namespace support { -Path::Path(FileName const & path) +PathChanger::PathChanger(FileName const & path) : popped_(false) { if (!path.empty()) { - pushedDir_ = getcwd(); + pushedDir_ = FileName::getcwd(); - if (pushedDir_.empty() || chdir(path)) { + if (pushedDir_.empty() || !path.chdir()) { /* FIXME: throw */ } } else { @@ -38,13 +34,14 @@ Path::Path(FileName const & path) } -Path::~Path() +PathChanger::~PathChanger() { - if (!popped_) pop(); + if (!popped_) + pop(); } -int Path::pop() +int PathChanger::pop() { if (popped_) { // should throw an exception @@ -52,7 +49,7 @@ int Path::pop() return 0; } - if (chdir(pushedDir_)) { + if (!pushedDir_.chdir()) { // should throw an exception // throw DirChangeError(); } @@ -63,3 +60,33 @@ int Path::pop() } // namespace support } // namespace lyx + + +#define PathChanger(x) unnamed_PathChanger; + +#ifdef __APPLE__ + +#include + +int getPrivateFrameworkPathName(char * buf, unsigned len, char const * framework) +{ + // Get our application's main bundle from Core Foundation + CFBundleRef myAppsBundle = CFBundleGetMainBundle(); + int result = 0 ; + if (NULL != myAppsBundle) { + CFURLRef baseURL = CFBundleCopyPrivateFrameworksURL( myAppsBundle ); + if (NULL != baseURL) { + CFURLRef bundleURL = CFURLCreateCopyAppendingPathComponent( kCFAllocatorSystemDefault, baseURL, + CFStringCreateWithCString( kCFAllocatorSystemDefault, framework, CFStringGetSystemEncoding() ), + false ); + if (NULL != bundleURL) { + result = CFURLGetFileSystemRepresentation( bundleURL, TRUE, (UInt8*)buf, len ); + } + } + } + return result; +} + +#endif + +// in merged builds this is not the last line.