diff options
| author | nakeee <nakeee@gmail.com> | 2009-02-28 23:21:51 +0000 |
|---|---|---|
| committer | nakeee <nakeee@gmail.com> | 2009-02-28 23:21:51 +0000 |
| commit | 324abc9a7f00af884c062ec974c95cb88137cbb4 (patch) | |
| tree | e80cf23271bd35935ead245c43aa827cfb73a5eb /Source/Core/Common/Src/FileUtil.cpp | |
| parent | 7d4e374c21b088431ed9b75310d574b010f0b75a (diff) | |
fix compile on osx and linux
added GetPluginDirectory (please check on windows)
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2490 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core/Common/Src/FileUtil.cpp')
| -rw-r--r-- | Source/Core/Common/Src/FileUtil.cpp | 113 |
1 files changed, 89 insertions, 24 deletions
diff --git a/Source/Core/Common/Src/FileUtil.cpp b/Source/Core/Common/Src/FileUtil.cpp index 617fd35a75..889c715ac2 100644 --- a/Source/Core/Common/Src/FileUtil.cpp +++ b/Source/Core/Common/Src/FileUtil.cpp @@ -32,6 +32,13 @@ #include <stdlib.h> #endif +#if defined(__APPLE__) +#include <CoreFoundation/CFString.h> +#include <CoreFoundation/CFUrl.h> +#include <CoreFoundation/CFBundle.h> +#include <sys/param.h> +#endif + #include <fstream> #include <sys/stat.h> @@ -305,30 +312,6 @@ bool Copy(const char *srcFilename, const char *destFilename) #endif } -// Returns a pointer to a string with a Dolphin data dir in the user's home directory. -// To be used in "multi-user" mode (that is, installed). -const char *GetUserDirectory() -{ - // Make sure we only need to do it once - static char path[MAX_PATH] = {0}; - if (strlen(path) > 0) - return path; - -#ifdef WIN32 - char homedir[MAX_PATH]; - if (!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, path))) - return NULL; -#else - char *homedir = getenv("HOME"); - if (!homedir) - return NULL; -#endif - - snprintf(path, sizeof(path), "%s" DIR_SEP DOLPHIN_DATA_DIR, homedir); - INFO_LOG(COMMON, "GetUserDirectory: Setting to %s:", path); - return path; -} - // Returns the size of filename (64bit) u64 GetSize(const char *filename) { @@ -520,5 +503,87 @@ bool SetCurrentDirectory(const char *_rDirectory) return chdir(_rDirectory) == 0; } +#if defined(__APPLE__) +std::string GetBundleDirectory() +{ + // Plugin path will be Dolphin.app/Contents/PlugIns + CFURLRef BundleRef; + char AppBundlePath[MAXPATHLEN]; + // Get the main bundle for the app + BundleRef = CFBundleCopyBundleURL(CFBundleGetMainBundle()); + CFStringRef BundlePath = CFURLCopyFileSystemPath(BundleRef, kCFURLPOSIXPathStyle); + CFStringGetFileSystemRepresentation(BundlePath, AppBundlePath, sizeof(AppBundlePath)); + CFRelease(BundleRef); + CFRelease(BundlePath); + + return AppBundlePath; +} +#endif + +// Returns the path to where the plugins are +std::string GetPluginsDirectory() +{ + std::string pluginsDir; + +#if defined (__APPLE__) + PluginsDir = GetBundleDirectory(); + PluginsDir += DIR_SEP; + PluginsDir += PLUGINS_DIR; +#elsif __linux__ + pluginsDir = PLUGINS_DIR; + // FIXME global install +#else + pluginsDir = PLUGINS_DIR; +#endif + + INFO_LOG(COMMON, "GetPluginsDirectory: Setting to %s:", pluginsDir.c_str()); + return pluginsDir; + +} + +// Returns the path to where the sys file are +std::string GetSysDirectory() +{ + std::string sysDir; + +#if defined (__APPLE__) + sysDir = GetBundleDirectory(); + sysDir += DIR_SEP; + sysDir += SYSDATA_DIR; +#elsif __linux__ + sysDir = SYSDATA_DIR; + // FIXME global install +#else + sysDir = SYSDATA_DIR; +#endif + + INFO_LOG(COMMON, "GetSysDirectory: Setting to %s:", sysDir.c_str()); + return sysDir; + +} +// Returns a pointer to a string with a Dolphin data dir in the user's home +// directory. To be used in "multi-user" mode (that is, installed). +const char *GetUserDirectory() +{ + // Make sure we only need to do it once + static char path[MAX_PATH] = {0}; + if (strlen(path) > 0) + return path; + +#ifdef WIN32 + char homedir[MAX_PATH]; + if (!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, path))) + return NULL; +#else + char *homedir = getenv("HOME"); + if (!homedir) + return NULL; +#endif + + snprintf(path, sizeof(path), "%s" DIR_SEP DOLPHIN_DATA_DIR, homedir); + INFO_LOG(COMMON, "GetUserDirectory: Setting to %s:", path); + return path; +} + } // namespace |
