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

GLideNUI: introduce Config{Init,Cleanup}

This commit is contained in:
Rosalie Wanders 2021-08-07 12:43:37 +02:00 committed by Sergey Lipskiy
parent 60c07f5b60
commit 0ebc545c93
7 changed files with 49 additions and 41 deletions

View File

@ -438,13 +438,16 @@ public:
GlideN64WtlModule * WtlModule = NULL; GlideN64WtlModule * WtlModule = NULL;
void ConfigInit(void * hinst) { extern "C"
{
EXPORT void CALL ConfigInit(void * hinst) {
WtlModule = new GlideN64WtlModule((HINSTANCE)hinst); WtlModule = new GlideN64WtlModule((HINSTANCE)hinst);
} }
void ConfigCleanup(void) { EXPORT void CALL ConfigCleanup(void) {
if (WtlModule) { if (WtlModule) {
delete WtlModule; delete WtlModule;
WtlModule = NULL; WtlModule = NULL;
} }
} }
}

View File

@ -76,8 +76,3 @@ protected:
uint32_t m_TabLeft, m_ProfileLeft; uint32_t m_TabLeft, m_ProfileLeft;
bool m_Saved; bool m_Saved;
}; };
#ifdef _WIN32
void ConfigInit(void * hinst);
void ConfigCleanup(void);
#endif

View File

@ -13,6 +13,8 @@ extern "C" {
#define CALL #define CALL
#endif #endif
EXPORT void CALL ConfigInit(void * hinst);
EXPORT void CALL ConfigCleanup(void);
EXPORT bool CALL RunConfig(const wchar_t * _strFileName, const char * _romName, unsigned int _maxMSAALevel, unsigned int _maxAnisotropy); EXPORT bool CALL RunConfig(const wchar_t * _strFileName, const char * _romName, unsigned int _maxMSAALevel, unsigned int _maxAnisotropy);
EXPORT int CALL RunAbout(const wchar_t * _strFileName); EXPORT int CALL RunAbout(const wchar_t * _strFileName);
EXPORT void CALL LoadConfig(const wchar_t * _strFileName); EXPORT void CALL LoadConfig(const wchar_t * _strFileName);

View File

@ -20,29 +20,21 @@ Q_IMPORT_PLUGIN(QWindowsVistaStylePlugin)
inline void initMyResource() { Q_INIT_RESOURCE(icon); } inline void initMyResource() { Q_INIT_RESOURCE(icon); }
inline void cleanMyResource() { Q_CLEANUP_RESOURCE(icon); } inline void cleanMyResource() { Q_CLEANUP_RESOURCE(icon); }
static std::unique_ptr<QApplication> s_pQApp;
static QCoreApplication* s_pAppInstance;
static static
int openConfigDialog(const wchar_t * _strFileName, const char * _romName, unsigned int _maxMSAALevel, float _maxAnisotropy, bool & _accepted) int openConfigDialog(const wchar_t * _strFileName, const char * _romName, unsigned int _maxMSAALevel, float _maxAnisotropy, bool & _accepted)
{ {
cleanMyResource();
initMyResource();
QString strIniFileName = QString::fromWCharArray(_strFileName); QString strIniFileName = QString::fromWCharArray(_strFileName);
loadSettings(strIniFileName); loadSettings(strIniFileName);
if (config.generalEmulation.enableCustomSettings != 0 && _romName != nullptr && strlen(_romName) != 0) if (config.generalEmulation.enableCustomSettings != 0 && _romName != nullptr && strlen(_romName) != 0)
loadCustomRomSettings(strIniFileName, _romName); loadCustomRomSettings(strIniFileName, _romName);
std::unique_ptr<QApplication> pQApp;
QCoreApplication* pApp = QCoreApplication::instance();
if (pApp == nullptr) {
int argc = 0;
char * argv = 0;
pQApp.reset(new QApplication(argc, &argv));
pApp = pQApp.get();
}
QTranslator translator; QTranslator translator;
if (translator.load(getTranslationFile(), strIniFileName)) if (translator.load(getTranslationFile(), strIniFileName)) {
pApp->installTranslator(&translator); s_pAppInstance->installTranslator(&translator);
}
ConfigDialog w(Q_NULLPTR, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint, _maxMSAALevel, _maxAnisotropy); ConfigDialog w(Q_NULLPTR, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint, _maxMSAALevel, _maxAnisotropy);
@ -51,7 +43,7 @@ int openConfigDialog(const wchar_t * _strFileName, const char * _romName, unsign
w.setTitle(); w.setTitle();
w.show(); w.show();
int res = pQApp ? pQApp->exec() : w.exec(); int res = s_pQApp ? s_pQApp->exec() : w.exec();
_accepted = w.isAccepted(); _accepted = w.isAccepted();
return res; return res;
} }
@ -59,20 +51,13 @@ int openConfigDialog(const wchar_t * _strFileName, const char * _romName, unsign
static static
int openAboutDialog(const wchar_t * _strFileName) int openAboutDialog(const wchar_t * _strFileName)
{ {
cleanMyResource();
initMyResource();
int argc = 0;
char * argv = 0;
QApplication a(argc, &argv);
QTranslator translator; QTranslator translator;
if (translator.load(getTranslationFile(), QString::fromWCharArray(_strFileName))) if (translator.load(getTranslationFile(), QString::fromWCharArray(_strFileName)))
a.installTranslator(&translator); s_pAppInstance->installTranslator(&translator);
AboutDialog w(Q_NULLPTR, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint); AboutDialog w(Q_NULLPTR, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint);
w.show(); w.show();
return a.exec(); return s_pQApp ? s_pQApp->exec() : w.exec();
} }
bool runConfigThread(const wchar_t * _strFileName, const char * _romName, unsigned int _maxMSAALevel, unsigned int _maxAnisotropy) { bool runConfigThread(const wchar_t * _strFileName, const char * _romName, unsigned int _maxMSAALevel, unsigned int _maxAnisotropy) {
@ -97,6 +82,26 @@ int runAboutThread(const wchar_t * _strFileName) {
return 0; return 0;
} }
EXPORT void CALL ConfigInit(void * hinst)
{
initMyResource();
s_pAppInstance = QCoreApplication::instance();
if (s_pAppInstance == nullptr) {
int argc = 0;
char * argv = 0;
s_pQApp.reset(new QApplication(argc, &argv));
s_pAppInstance = s_pQApp.get();
}
}
EXPORT void CALL ConfigCleanup(void)
{
cleanMyResource();
s_pQApp.release();
}
EXPORT bool CALL RunConfig(const wchar_t * _strFileName, const char * _romName, unsigned int _maxMSAALevel, unsigned int _maxAnisotropy) EXPORT bool CALL RunConfig(const wchar_t * _strFileName, const char * _romName, unsigned int _maxMSAALevel, unsigned int _maxAnisotropy)
{ {
return runConfigThread(_strFileName, _romName, _maxMSAALevel, _maxAnisotropy); return runConfigThread(_strFileName, _romName, _maxMSAALevel, _maxAnisotropy);

View File

@ -7,12 +7,14 @@ extern "C" {
#ifdef OS_WINDOWS #ifdef OS_WINDOWS
#define EXPORT __declspec(dllexport) #define EXPORT __declspec(dllexport)
#define CALL __cdecl #define CALL __cdecl
#else #else
#define EXPORT __attribute__((visibility("default"))) #define EXPORT __attribute__((visibility("default")))
#define CALL #define CALL
#endif #endif
EXPORT void CALL ConfigInit(void * hinst);
EXPORT void CALL ConfigCleanup(void);
EXPORT bool CALL RunConfig(const wchar_t * _strFileName, const char * _romName, unsigned int _maxMSAALevel, unsigned int _maxAnisotropy); EXPORT bool CALL RunConfig(const wchar_t * _strFileName, const char * _romName, unsigned int _maxMSAALevel, unsigned int _maxAnisotropy);
EXPORT int CALL RunAbout(const wchar_t * _strFileName); EXPORT int CALL RunAbout(const wchar_t * _strFileName);
EXPORT void CALL LoadConfig(const wchar_t * _strFileName); EXPORT void CALL LoadConfig(const wchar_t * _strFileName);

View File

@ -11,6 +11,10 @@
#define DLSYM(a, b) dlsym(a, b) #define DLSYM(a, b) dlsym(a, b)
#endif // OS_WINDOWS #endif // OS_WINDOWS
#ifdef M64P_GLIDENUI
#include "GLideNUI/GLideNUI.h"
#endif
ptr_ConfigGetSharedDataFilepath ConfigGetSharedDataFilepath = nullptr; ptr_ConfigGetSharedDataFilepath ConfigGetSharedDataFilepath = nullptr;
ptr_ConfigGetUserConfigPath ConfigGetUserConfigPath = nullptr; ptr_ConfigGetUserConfigPath ConfigGetUserConfigPath = nullptr;
ptr_ConfigGetUserDataPath ConfigGetUserDataPath = nullptr; ptr_ConfigGetUserDataPath ConfigGetUserDataPath = nullptr;
@ -103,6 +107,8 @@ m64p_error PluginAPI::PluginStartup(m64p_dynlib_handle _CoreLibHandle)
Config_SetDefault(); Config_SetDefault();
} }
} }
#else
ConfigInit(nullptr);
#endif // M64P_GLIDENUI #endif // M64P_GLIDENUI
return M64ERR_SUCCESS; return M64ERR_SUCCESS;
@ -122,6 +128,9 @@ m64p_error PluginAPI::PluginShutdown()
_callAPICommand(acRomClosed); _callAPICommand(acRomClosed);
delete m_pRspThread; delete m_pRspThread;
m_pRspThread = nullptr; m_pRspThread = nullptr;
#endif
#ifdef M64P_GLIDENUI
ConfigCleanup();
#endif #endif
return M64ERR_SUCCESS; return M64ERR_SUCCESS;
} }

View File

@ -1,18 +1,13 @@
#include "GLideN64_Windows.h" #include "GLideN64_Windows.h"
#include "GLideNUI/GLideNUI.h"
HWND hWnd; HWND hWnd;
HWND hStatusBar; HWND hStatusBar;
HWND hToolBar; HWND hToolBar;
HINSTANCE hInstance; HINSTANCE hInstance;
#ifdef WTL_UI
void ConfigInit(void * hinst);
void ConfigCleanup(void);
#endif
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID /*lpvReserved*/) BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID /*lpvReserved*/)
{ {
#ifdef WTL_UI
if (dwReason == DLL_PROCESS_ATTACH) if (dwReason == DLL_PROCESS_ATTACH)
{ {
hInstance = hinstDLL; hInstance = hinstDLL;
@ -22,8 +17,5 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID /*lpvReserved*/)
{ {
ConfigCleanup(); ConfigCleanup();
} }
#else
hInstance = hinstDLL;
#endif
return TRUE; return TRUE;
} }