From 9d4f8a322c03bb9062e8e6bd87ccd66a1c2a6486 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Wed, 23 May 2018 19:19:52 +0100 Subject: [PATCH] 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. --- common/include/null/config.inl | 130 +++++++++++++++++++++++++++++++++ common/include/null/null.rc | 106 +++++++++++++++++++++++++++ common/include/null/resource.h | 18 +++++ 3 files changed, 254 insertions(+) create mode 100644 common/include/null/config.inl create mode 100644 common/include/null/null.rc create mode 100644 common/include/null/resource.h diff --git a/common/include/null/config.inl b/common/include/null/config.inl new file mode 100644 index 0000000000..c9a19a4f0b --- /dev/null +++ b/common/include/null/config.inl @@ -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 . + */ + +#include "PS2Eext.h" +#if defined(_WIN32) +#include +#include "resource.h" +#elif defined(__unix__) +#include +#endif +#include + +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(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(); +} diff --git a/common/include/null/null.rc b/common/include/null/null.rc new file mode 100644 index 0000000000..ff9d07770d --- /dev/null +++ b/common/include/null/null.rc @@ -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 diff --git a/common/include/null/resource.h b/common/include/null/resource.h new file mode 100644 index 0000000000..346664358e --- /dev/null +++ b/common/include/null/resource.h @@ -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