mirror of https://github.com/PCSX2/pcsx2.git
common: Add common null plugin config code
This adds code that allows modifying the log options via the GUI (Windows, Linux) and also saving and loading the log options in a reusable form.
This commit is contained in:
parent
ac7cbdf6c3
commit
9d4f8a322c
|
@ -0,0 +1,130 @@
|
||||||
|
/* PCSX2 - PS2 Emulator for PCs
|
||||||
|
* Copyright (C) 2018 PCSX2 Dev Team
|
||||||
|
*
|
||||||
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
||||||
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
||||||
|
* ation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
||||||
|
* If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "PS2Eext.h"
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#include <windows.h>
|
||||||
|
#include "resource.h"
|
||||||
|
#elif defined(__unix__)
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
#endif
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
PluginLog g_plugin_log;
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
|
||||||
|
static HINSTANCE s_hinstance;
|
||||||
|
|
||||||
|
BOOL APIENTRY DllMain(HINSTANCE hinstance, DWORD reason, LPVOID /* reserved */)
|
||||||
|
{
|
||||||
|
if (reason == DLL_PROCESS_ATTACH)
|
||||||
|
s_hinstance = hinstance;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static INT_PTR CALLBACK ConfigureDialogProc(HWND dialog, UINT message, WPARAM wparam, LPARAM lparam)
|
||||||
|
{
|
||||||
|
switch (message) {
|
||||||
|
case WM_INITDIALOG:
|
||||||
|
CheckDlgButton(dialog, IDC_LOG_TO_CONSOLE, g_plugin_log.WriteToConsole);
|
||||||
|
CheckDlgButton(dialog, IDC_LOG_TO_FILE, g_plugin_log.WriteToFile);
|
||||||
|
return TRUE;
|
||||||
|
case WM_COMMAND:
|
||||||
|
switch (LOWORD(wparam)) {
|
||||||
|
case IDOK:
|
||||||
|
g_plugin_log.WriteToConsole = IsDlgButtonChecked(dialog, IDC_LOG_TO_CONSOLE) == BST_CHECKED;
|
||||||
|
g_plugin_log.WriteToFile = IsDlgButtonChecked(dialog, IDC_LOG_TO_FILE) == BST_CHECKED;
|
||||||
|
EndDialog(dialog, 0);
|
||||||
|
return TRUE;
|
||||||
|
case IDCANCEL:
|
||||||
|
EndDialog(dialog, 0);
|
||||||
|
return TRUE;
|
||||||
|
default:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigureLogging()
|
||||||
|
{
|
||||||
|
DialogBox(s_hinstance, MAKEINTRESOURCE(IDD_DIALOG), GetActiveWindow(), ConfigureDialogProc);
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(__unix__)
|
||||||
|
|
||||||
|
void ConfigureLogging()
|
||||||
|
{
|
||||||
|
GtkDialogFlags flags = static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT);
|
||||||
|
GtkWidget *dialog = gtk_dialog_new_with_buttons("Config", nullptr, flags,
|
||||||
|
"Cancel", GTK_RESPONSE_REJECT,
|
||||||
|
"Ok", GTK_RESPONSE_ACCEPT,
|
||||||
|
nullptr);
|
||||||
|
|
||||||
|
GtkWidget *console_checkbox = gtk_check_button_new_with_label("Log to console");
|
||||||
|
GtkWidget *file_checkbox = gtk_check_button_new_with_label("Log to file");
|
||||||
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(console_checkbox), g_plugin_log.WriteToConsole);
|
||||||
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(file_checkbox), g_plugin_log.WriteToFile);
|
||||||
|
|
||||||
|
GtkWidget *content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
|
||||||
|
gtk_container_add(GTK_CONTAINER(content_area), console_checkbox);
|
||||||
|
gtk_container_add(GTK_CONTAINER(content_area), file_checkbox);
|
||||||
|
|
||||||
|
gtk_widget_show_all(dialog);
|
||||||
|
|
||||||
|
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
|
||||||
|
g_plugin_log.WriteToConsole = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(console_checkbox)) == TRUE;
|
||||||
|
g_plugin_log.WriteToFile = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(file_checkbox)) == TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_widget_destroy(dialog);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
void ConfigureLogging()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void SaveConfig(const std::string &pathname)
|
||||||
|
{
|
||||||
|
PluginConf ini;
|
||||||
|
if (!ini.Open(pathname, WRITE_FILE)) {
|
||||||
|
g_plugin_log.WriteLn("Failed to open %s", pathname.c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ini.WriteInt("write_to_console", g_plugin_log.WriteToConsole);
|
||||||
|
ini.WriteInt("write_to_file", g_plugin_log.WriteToFile);
|
||||||
|
ini.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoadConfig(const std::string &pathname)
|
||||||
|
{
|
||||||
|
PluginConf ini;
|
||||||
|
if (!ini.Open(pathname, READ_FILE)) {
|
||||||
|
g_plugin_log.WriteLn("Failed to open %s", pathname.c_str());
|
||||||
|
SaveConfig(pathname);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_plugin_log.WriteToConsole = ini.ReadInt("write_to_console", 0) != 0;
|
||||||
|
g_plugin_log.WriteToFile = ini.ReadInt("write_to_file", 0) != 0;
|
||||||
|
ini.Close();
|
||||||
|
}
|
|
@ -0,0 +1,106 @@
|
||||||
|
// Microsoft Visual C++ generated resource script.
|
||||||
|
//
|
||||||
|
#include "resource.h"
|
||||||
|
|
||||||
|
#define APSTUDIO_READONLY_SYMBOLS
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Generated from the TEXTINCLUDE 2 resource.
|
||||||
|
//
|
||||||
|
#include "winres.h"
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
#undef APSTUDIO_READONLY_SYMBOLS
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// English (United Kingdom) resources
|
||||||
|
|
||||||
|
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG)
|
||||||
|
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
|
||||||
|
|
||||||
|
#ifdef APSTUDIO_INVOKED
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// TEXTINCLUDE
|
||||||
|
//
|
||||||
|
|
||||||
|
1 TEXTINCLUDE
|
||||||
|
BEGIN
|
||||||
|
"resource.h\0"
|
||||||
|
END
|
||||||
|
|
||||||
|
2 TEXTINCLUDE
|
||||||
|
BEGIN
|
||||||
|
"#include ""winres.h""\r\n"
|
||||||
|
"\0"
|
||||||
|
END
|
||||||
|
|
||||||
|
3 TEXTINCLUDE
|
||||||
|
BEGIN
|
||||||
|
"\r\n"
|
||||||
|
"\0"
|
||||||
|
END
|
||||||
|
|
||||||
|
#endif // APSTUDIO_INVOKED
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Dialog
|
||||||
|
//
|
||||||
|
|
||||||
|
IDD_DIALOG DIALOGEX 0, 0, 123, 53
|
||||||
|
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||||
|
CAPTION "Config"
|
||||||
|
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||||
|
BEGIN
|
||||||
|
DEFPUSHBUTTON "OK",IDOK,7,32,50,14
|
||||||
|
PUSHBUTTON "Cancel",IDCANCEL,66,32,50,14
|
||||||
|
CONTROL "Log to console",IDC_LOG_TO_CONSOLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,7,62,10
|
||||||
|
CONTROL "Log to file",IDC_LOG_TO_FILE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,19,47,10
|
||||||
|
END
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// DESIGNINFO
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifdef APSTUDIO_INVOKED
|
||||||
|
GUIDELINES DESIGNINFO
|
||||||
|
BEGIN
|
||||||
|
IDD_DIALOG, DIALOG
|
||||||
|
BEGIN
|
||||||
|
LEFTMARGIN, 7
|
||||||
|
RIGHTMARGIN, 116
|
||||||
|
TOPMARGIN, 7
|
||||||
|
BOTTOMMARGIN, 46
|
||||||
|
END
|
||||||
|
END
|
||||||
|
#endif // APSTUDIO_INVOKED
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// AFX_DIALOG_LAYOUT
|
||||||
|
//
|
||||||
|
|
||||||
|
IDD_DIALOG AFX_DIALOG_LAYOUT
|
||||||
|
BEGIN
|
||||||
|
0
|
||||||
|
END
|
||||||
|
|
||||||
|
#endif // English (United Kingdom) resources
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef APSTUDIO_INVOKED
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Generated from the TEXTINCLUDE 3 resource.
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
#endif // not APSTUDIO_INVOKED
|
|
@ -0,0 +1,18 @@
|
||||||
|
//{{NO_DEPENDENCIES}}
|
||||||
|
// Microsoft Visual C++ generated include file.
|
||||||
|
// Used by null.rc
|
||||||
|
//
|
||||||
|
#define IDD_DIALOG 101
|
||||||
|
#define IDC_LOG_TO_CONSOLE 1001
|
||||||
|
#define IDC_LOG_TO_FILE 1002
|
||||||
|
|
||||||
|
// Next default values for new objects
|
||||||
|
//
|
||||||
|
#ifdef APSTUDIO_INVOKED
|
||||||
|
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||||
|
#define _APS_NEXT_RESOURCE_VALUE 103
|
||||||
|
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||||
|
#define _APS_NEXT_CONTROL_VALUE 1002
|
||||||
|
#define _APS_NEXT_SYMED_VALUE 101
|
||||||
|
#endif
|
||||||
|
#endif
|
Loading…
Reference in New Issue