1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-02 09:03:37 +00:00

Add PluginAPI functions: GetUserDataPath() and GetUserCachePath().

New functions are used for texture library initialization.
GetUserDataPath() returns default folder to search for hi-res texture packs.
GetUserCachePath() returns folder to store texture cache.

Mupen64Plus implementation: use system ConfigGetUserDataPath() and ConfigGetUserCachePath().
Windows implementation: just return FindPluginPath() for both functions.

Note: behaviour of Mupen64Plus changed.
Previously the emulator's folder was default path for hires textures and texture cache.
Now default path is system dependent.
For Windows it will be %HOME%\AppData\Roaming\Mupen64Plus
This commit is contained in:
Sergey Lipskiy 2015-05-23 17:53:08 +06:00
parent 0c416070c7
commit 2c7184cab6
7 changed files with 64 additions and 19 deletions

View File

@ -52,11 +52,11 @@ void Config::resetToDefaults()
textureFilter.txForce16bpp = 0;
textureFilter.txSaveCache = 1;
api().FindPluginPath(textureFilter.txPath);
api().GetUserDataPath(textureFilter.txPath);
wcscat(textureFilter.txPath, L"/hires_texture");
#ifdef OS_WINDOWS
font.name = "arial.ttf";
font.name.assign("arial.ttf");
#else
font.name = "FreeSans.ttf";
#endif

View File

@ -27,6 +27,7 @@
#include "Config.h"
#include "Log.h"
#include "TextDrawer.h"
#include "PluginAPI.h"
#include "PostProcessor.h"
using namespace std;
@ -1350,17 +1351,19 @@ void TextureFilterHandler::init()
wchar_t txPath[PLUGIN_PATH_SIZE+16];
wchar_t * pTexPackPath = config.textureFilter.txPath;
if (::wcslen(config.textureFilter.txPath) == 0) {
wcscpy(txPath, RSP.pluginpath);
api().GetUserDataPath(txPath);
wcscat(txPath, L"/hires_texture");
pTexPackPath = txPath;
}
wchar_t txCachePath[PLUGIN_PATH_SIZE];
api().GetUserCachePath(txCachePath);
m_inited = txfilter_init(maxTextureSize, // max texture width supported by hardware
maxTextureSize, // max texture height supported by hardware
32, // max texture bpp supported by hardware
options,
config.textureFilter.txCacheSize, // cache texture to system memory
RSP.pluginpath, // plugin path
txCachePath, // path to store cache files
pTexPackPath, // path to texture packs folder
wRomName, // name of ROM. must be no longer than 256 characters
displayLoadProgress);

View File

@ -45,6 +45,8 @@ public:
void ChangeWindow();
void FindPluginPath(wchar_t * _strPath);
void GetUserDataPath(wchar_t * _strPath);
void GetUserCachePath(wchar_t * _strPath);
#ifndef MUPENPLUSAPI
// Zilmar

View File

@ -1,3 +1,4 @@
#include "GLideN64_mupenplus.h"
#include "../PluginAPI.h"
#include "../OpenGL.h"
#include "../RSP.h"
@ -9,30 +10,52 @@ int PluginAPI::InitiateGFX(const GFX_INFO & _gfxInfo)
return TRUE;
}
static
void _cutLastPathSeparator(wchar_t * _strPath)
{
std::wstring pluginPath(_strPath);
std::wstring::size_type pos = pluginPath.find_last_of(L"\\/");
wcscpy(_strPath, pluginPath.substr(0, pos).c_str());
}
static
void _getWSPath(const char * _path, wchar_t * _strPath)
{
::mbstowcs(_strPath, _path, PLUGIN_PATH_SIZE);
_cutLastPathSeparator(_strPath);
}
void PluginAPI::GetUserDataPath(wchar_t * _strPath)
{
_getWSPath(ConfigGetUserDataPath(), _strPath);
}
void PluginAPI::GetUserCachePath(wchar_t * _strPath)
{
_getWSPath(ConfigGetUserCachePath(), _strPath);
}
void PluginAPI::FindPluginPath(wchar_t * _strPath)
{
if (_strPath == NULL)
return;
#ifdef OS_WINDOWS
GetModuleFileNameW(NULL, _strPath, PLUGIN_PATH_SIZE);
#elif OS_LINUX
_cutLastPathSeparator(_strPath);
#elif defined(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);
_getWSPath(path, _strPath);
}
#elif OS_MAC_OS_X
#elif defined(OS_MAC_OS_X)
char path[MAXPATHLEN];
uint32_t pathLen = MAXPATHLEN * 2;
if (_NSGetExecutablePath(path, pathLen) == 0) {
::mbstowcs(_strPath, path, PLUGIN_PATH_SIZE);
_getWSPath(path, _strPath);
}
#else
// TODO: Android implementation
::mbstowcs(_strPath, "Plugin", PLUGIN_PATH_SIZE);
#elif defined(ANDROID)
GetUserCachePath(_strPath);
#endif
std::wstring pluginPath(_strPath);
std::wstring::size_type pos = pluginPath.find_last_of(L"\\/");
wcscpy(_strPath, pluginPath.substr(0, pos).c_str());
}

View File

@ -103,6 +103,11 @@ bool Config_SetDefault()
assert(res == M64ERR_SUCCESS);
res = ConfigSetDefaultBool(g_configVideoGliden64, "txSaveCache", config.textureFilter.txSaveCache, "Save texture cache to hard disk.");
assert(res == M64ERR_SUCCESS);
// Convert to multibyte
char txPath[PLUGIN_PATH_SIZE * 2];
wcstombs(txPath, config.textureFilter.txPath, PLUGIN_PATH_SIZE * 2);
res = ConfigSetDefaultString(g_configVideoGliden64, "txPath", txPath, "Path to folder with hi-res texture packs.");
assert(res == M64ERR_SUCCESS);
res = ConfigSetDefaultString(g_configVideoGliden64, "fontName", config.font.name.c_str(), "File name of True Type Font for text messages.");
assert(res == M64ERR_SUCCESS);
@ -183,6 +188,8 @@ void Config_LoadConfig()
config.textureFilter.txForce16bpp = ConfigGetParamBool(g_configVideoGliden64, "txForce16bpp");
config.textureFilter.txCacheCompression = ConfigGetParamBool(g_configVideoGliden64, "txCacheCompression");
config.textureFilter.txSaveCache = ConfigGetParamBool(g_configVideoGliden64, "txSaveCache");
::mbstowcs(config.textureFilter.txPath, ConfigGetParamString(g_configVideoGliden64, "txPath"), PLUGIN_PATH_SIZE);
//#Font settings
config.font.name = ConfigGetParamString(g_configVideoGliden64, "fontName");
if (config.font.name.empty())

View File

@ -11,6 +11,8 @@
ptr_ConfigGetSharedDataFilepath ConfigGetSharedDataFilepath = NULL;
ptr_ConfigGetUserConfigPath ConfigGetUserConfigPath = NULL;
ptr_ConfigGetUserDataPath ConfigGetUserDataPath = NULL;
ptr_ConfigGetUserCachePath ConfigGetUserCachePath = NULL;
ptr_ConfigOpenSection ConfigOpenSection = NULL;
ptr_ConfigDeleteSection ConfigDeleteSection = NULL;
ptr_ConfigSaveSection ConfigSaveSection = NULL;
@ -41,6 +43,9 @@ m64p_error PluginAPI::PluginStartup(m64p_dynlib_handle _CoreLibHandle)
{
ConfigGetSharedDataFilepath = (ptr_ConfigGetSharedDataFilepath) DLSYM(_CoreLibHandle, "ConfigGetSharedDataFilepath");
ConfigGetUserConfigPath = (ptr_ConfigGetUserConfigPath) DLSYM(_CoreLibHandle, "ConfigGetUserConfigPath");
ConfigGetUserCachePath = (ptr_ConfigGetUserCachePath)DLSYM(_CoreLibHandle, "ConfigGetUserCachePath");
ConfigGetUserDataPath = (ptr_ConfigGetUserDataPath)DLSYM(_CoreLibHandle, "ConfigGetUserDataPath");
ConfigOpenSection = (ptr_ConfigOpenSection)DLSYM(_CoreLibHandle, "ConfigOpenSection");
ConfigDeleteSection = (ptr_ConfigDeleteSection)DLSYM(_CoreLibHandle, "ConfigDeleteSection");
ConfigSaveSection = (ptr_ConfigSaveSection)DLSYM(_CoreLibHandle, "ConfigSaveSection");

View File

@ -34,14 +34,19 @@ void PluginAPI::FindPluginPath(wchar_t * _strPath)
{
if (_strPath == NULL)
return;
#ifdef OS_WINDOWS
::GetModuleFileName((HINSTANCE)&__ImageBase, _strPath, PLUGIN_PATH_SIZE);
#else
// TODO: for other OS
return;
#endif
std::wstring pluginPath(_strPath);
std::replace(pluginPath.begin(), pluginPath.end(), L'\\', L'/');
std::wstring::size_type pos = pluginPath.find_last_of(L"/");
wcscpy(_strPath, pluginPath.substr(0, pos).c_str());
}
void PluginAPI::GetUserDataPath(wchar_t * _strPath)
{
FindPluginPath(_strPath);
}
void PluginAPI::GetUserCachePath(wchar_t * _strPath)
{
FindPluginPath(_strPath);
}