From c7c86b71522a1e668b6da629184790b1bd7a6a30 Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Wed, 4 Feb 2015 15:23:21 +0600 Subject: [PATCH] Add API function FindPluginPath() since plugin's path is different for Mupen64Plus and Zilmar specs emus. --- PluginAPI.h | 4 +++- RSP.cpp | 29 ++------------------------- mupenplus/CommonAPIImpl_mupenplus.cpp | 28 ++++++++++++++++++++++++++ windows/CommonAPIImpl_windows.cpp | 22 ++++++++++++++++++++ 4 files changed, 55 insertions(+), 28 deletions(-) diff --git a/PluginAPI.h b/PluginAPI.h index 5c803614..f54675e1 100644 --- a/PluginAPI.h +++ b/PluginAPI.h @@ -44,6 +44,8 @@ public: int InitiateGFX(const GFX_INFO & _gfxInfo); void ChangeWindow(); + void FindPluginPath(wchar_t * _strPath); + #ifndef MUPENPLUSAPI // Zilmar void DllTest(HWND /*_hParent*/) {} @@ -86,7 +88,7 @@ private: PluginAPI() #ifdef RSPTHREAD : m_pRspThread(NULL), m_command(acNone) - #endif +#endif {} PluginAPI(const PluginAPI &); diff --git a/RSP.cpp b/RSP.cpp index 021f4536..c4d06b53 100644 --- a/RSP.cpp +++ b/RSP.cpp @@ -10,6 +10,7 @@ #include "FrameBuffer.h" #include "DepthBuffer.h" #include "GBI.h" +#include "PluginAPI.h" #include "Config.h" using namespace std; @@ -265,32 +266,6 @@ void RSP_SetDefaultState() gDPPipelineMode(G_PM_NPRIMITIVE); } -static -void _findPluginPath() -{ -#ifdef OS_WINDOWS - GetModuleFileNameW(NULL, RSP.pluginpath, PLUGIN_PATH_SIZE); -#elif OS_LINUX - char path[512]; - int res = readlink("/proc/self/exe", path, 510); - if (res != -1) { - path[res] = 0; - ::mbstowcs(RSP.pluginpath, path, PLUGIN_PATH_SIZE); - } -#elif OS_MAC_OS_X - char path[MAXPATHLEN]; - uint32_t pathLen = MAXPATHLEN*2; - if (_NSGetExecutablePath(path, pathLen) == 0) { - ::mbstowcs(RSP.pluginpath, path, PLUGIN_PATH_SIZE); - } -#else - RSP.pluginpath = L"\0"; -#endif - wstring pluginPath(RSP.pluginpath); - wstring::size_type pos = pluginPath.find_last_of(L"\\/"); - wcscpy(RSP.pluginpath, pluginPath.substr(0, pos).c_str()); -} - void RSP_Init() { #ifdef OS_WINDOWS @@ -333,7 +308,7 @@ void RSP_Init() if (strstr(RSP.romname, (const char *)"OgreBattle64")) config.generalEmulation.hacks |= hack_Ogre64; - _findPluginPath(); + api().FindPluginPath(RSP.pluginpath); RSP_SetDefaultState(); } diff --git a/mupenplus/CommonAPIImpl_mupenplus.cpp b/mupenplus/CommonAPIImpl_mupenplus.cpp index 8bd71e1a..eb605a5b 100644 --- a/mupenplus/CommonAPIImpl_mupenplus.cpp +++ b/mupenplus/CommonAPIImpl_mupenplus.cpp @@ -1,6 +1,7 @@ #include "../PluginAPI.h" #include "../OpenGL.h" #include "../Config.h" +#include "../RSP.h" int PluginAPI::InitiateGFX(const GFX_INFO & _gfxInfo) { @@ -10,3 +11,30 @@ int PluginAPI::InitiateGFX(const GFX_INFO & _gfxInfo) return TRUE; } + +void PluginAPI::FindPluginPath(wchar_t * _strPath) +{ + if (_strPath == NULL) + return; +#ifdef OS_WINDOWS + GetModuleFileNameW(NULL, _strPath, PLUGIN_PATH_SIZE); +#elif OS_LINUX + char path[512]; + int res = readlink("/proc/self/exe", path, 510); + if (res != -1) { + path[res] = 0; + ::mbstowcs(_strPath, path, PLUGIN_PATH_SIZE); + } +#elif OS_MAC_OS_X + char path[MAXPATHLEN]; + uint32_t pathLen = MAXPATHLEN * 2; + if (_NSGetExecutablePath(path, pathLen) == 0) { + ::mbstowcs(_strPath, path, PLUGIN_PATH_SIZE); + } +#else + _strPath = L"\0"; +#endif + std::wstring pluginPath(_strPath); + std::wstring::size_type pos = pluginPath.find_last_of(L"\\/"); + wcscpy(_strPath, pluginPath.substr(0, pos).c_str()); +} diff --git a/windows/CommonAPIImpl_windows.cpp b/windows/CommonAPIImpl_windows.cpp index 2872d294..47e1caaf 100644 --- a/windows/CommonAPIImpl_windows.cpp +++ b/windows/CommonAPIImpl_windows.cpp @@ -2,6 +2,11 @@ #include #include "../PluginAPI.h" #include "../OpenGL.h" +#include "../RSP.h" + +#ifdef OS_WINDOWS +EXTERN_C IMAGE_DOS_HEADER __ImageBase; +#endif BOOL CALLBACK FindToolBarProc( HWND hWnd, LPARAM lParam ) { @@ -23,3 +28,20 @@ int PluginAPI::InitiateGFX(const GFX_INFO & _gfxInfo) EnumChildWindows( hWnd, FindToolBarProc, 0 ); return TRUE; } + +void PluginAPI::FindPluginPath(wchar_t * _strPath) +{ + if (_strPath == NULL) + return; +#ifdef OS_WINDOWS + TCHAR strDLLPath[PLUGIN_PATH_SIZE]; + ::GetModuleFileName((HINSTANCE)&__ImageBase, strDLLPath, PLUGIN_PATH_SIZE); + ::mbstowcs(_strPath, strDLLPath, PLUGIN_PATH_SIZE); +#else + // TODO: for other OS + return; +#endif + std::wstring pluginPath(_strPath); + std::wstring::size_type pos = pluginPath.find_last_of(L"\\/"); + wcscpy(_strPath, pluginPath.substr(0, pos).c_str()); +}