From 324abc9a7f00af884c062ec974c95cb88137cbb4 Mon Sep 17 00:00:00 2001 From: nakeee Date: Sat, 28 Feb 2009 23:21:51 +0000 Subject: [PATCH] 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 --- Source/Core/Common/Src/CommonFuncs.h | 3 +- Source/Core/Common/Src/FileUtil.cpp | 113 ++++++++++++++---- Source/Core/Common/Src/FileUtil.h | 14 ++- Source/Core/Common/Src/Misc.cpp | 14 ++- Source/Core/Core/Src/ConfigManager.cpp | 17 +-- Source/Plugins/Plugin_VideoOGL/Src/SConscript | 1 - 6 files changed, 119 insertions(+), 43 deletions(-) diff --git a/Source/Core/Common/Src/CommonFuncs.h b/Source/Core/Common/Src/CommonFuncs.h index ff6efe993e..fe369cd292 100644 --- a/Source/Core/Common/Src/CommonFuncs.h +++ b/Source/Core/Common/Src/CommonFuncs.h @@ -27,7 +27,8 @@ #ifndef _WIN32 #if defined __APPLE__ -char* strndup (char const *s, size_t n); +char* strndup (char const *s, size_t n); +size_t strnlen(const char *s, size_t n); #else #include #endif // APPLE 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 #endif +#if defined(__APPLE__) +#include +#include +#include +#include +#endif + #include #include @@ -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 diff --git a/Source/Core/Common/Src/FileUtil.h b/Source/Core/Common/Src/FileUtil.h index cf47cce442..4fc3020504 100644 --- a/Source/Core/Common/Src/FileUtil.h +++ b/Source/Core/Common/Src/FileUtil.h @@ -84,9 +84,21 @@ const char *GetCurrentDirectory(); // Set the current directory to given directory bool SetCurrentDirectory(const char *directory); -// Returns a pointer to a string with the dolphin data dir + +// 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(); +// Returns the path to where the plugins are +std::string GetPluginsDirectory(); + +// Returns the path to where the sys file are +std::string GetSysDirectory(); + +#ifdef __APPLE__ +std::string GetBundleDirectory(); +#endif + } // namespace #endif diff --git a/Source/Core/Common/Src/Misc.cpp b/Source/Core/Common/Src/Misc.cpp index b0e6373f10..40b7623ba5 100644 --- a/Source/Core/Common/Src/Misc.cpp +++ b/Source/Core/Common/Src/Misc.cpp @@ -37,14 +37,24 @@ const char *GetLastErrorMsg() return errStr; } -char *strndup (char const *s, size_t n) +#ifdef __APPLE__ +// strlen with cropping after size n +size_t strnlen(const char *s, size_t n) +{ + const char *p = (const char *)memchr(s, 0, n); + return(p ? p-s : n); +} +#endif + +// strdup with cropping after size n +char* strndup(char const *s, size_t n) { size_t len = strnlen(s, n); char *dup = (char *)malloc(len + 1); if (dup == NULL) return NULL; - + dup[len] = '\0'; return (char *)memcpy(dup, s, len); } diff --git a/Source/Core/Core/Src/ConfigManager.cpp b/Source/Core/Core/Src/ConfigManager.cpp index 8f63c08f26..80f6b507d3 100644 --- a/Source/Core/Core/Src/ConfigManager.cpp +++ b/Source/Core/Core/Src/ConfigManager.cpp @@ -20,10 +20,8 @@ #include "Common.h" #include "IniFile.h" #include "ConfigManager.h" - -#if defined(__APPLE__) #include "FileUtil.h" -#endif + SConfig SConfig::m_Instance; @@ -119,23 +117,14 @@ void SConfig::LoadSettings() { IniFile ini; ini.Load(CONFIG_FILE); -#if defined(__APPLE__) std::string PluginsDir = File::GetPluginsDirectory(); + // Hard coded default m_DefaultGFXPlugin = PluginsDir + DEFAULT_GFX_PLUGIN; m_DefaultDSPPlugin = PluginsDir + DEFAULT_DSP_PLUGIN; m_DefaultPADPlugin = PluginsDir + DEFAULT_PAD_PLUGIN; m_DefaultWiiMotePlugin = PluginsDir + DEFAULT_WIIMOTE_PLUGIN; - -#else - // Hard coded default plugin - { - m_DefaultGFXPlugin = PLUGINS_DIR DIR_SEP DEFAULT_GFX_PLUGIN; - m_DefaultDSPPlugin = PLUGINS_DIR DIR_SEP DEFAULT_DSP_PLUGIN; - m_DefaultPADPlugin = PLUGINS_DIR DIR_SEP DEFAULT_PAD_PLUGIN; - m_DefaultWiiMotePlugin = PLUGINS_DIR DIR_SEP DEFAULT_WIIMOTE_PLUGIN; - } -#endif + // General { ini.Get("General", "LastFilename", &m_LastFilename); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/SConscript b/Source/Plugins/Plugin_VideoOGL/Src/SConscript index 9a7fbb164c..8846e613cb 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/SConscript +++ b/Source/Plugins/Plugin_VideoOGL/Src/SConscript @@ -23,7 +23,6 @@ files = [ 'VertexManager.cpp', 'VertexLoaderManager.cpp', 'XFB.cpp', - 'XFStructs.cpp', 'TextureConversionShader.cpp', 'OnScreenDisplay.cpp', ]