From 47d65c3f89ed6b07d0db817911f4e0a42d9d0fec Mon Sep 17 00:00:00 2001 From: Gauvain 'GovanifY' Roussel-Tarbouriech Date: Thu, 5 Nov 2020 11:53:58 +0100 Subject: [PATCH] USB: fix ini saves --- pcsx2/USB/USB.cpp | 7 ++----- pcsx2/USB/Win32/Config_usb.cpp | 3 ++- pcsx2/USB/configuration.cpp | 30 +++++++++++++++++++++--------- pcsx2/USB/configuration.h | 4 ++-- pcsx2/USB/linux/config-gtk.cpp | 1 + 5 files changed, 28 insertions(+), 17 deletions(-) diff --git a/pcsx2/USB/USB.cpp b/pcsx2/USB/USB.cpp index 10f1991ed4..26435143bf 100644 --- a/pcsx2/USB/USB.cpp +++ b/pcsx2/USB/USB.cpp @@ -27,6 +27,7 @@ #include "qemu-usb/desc.h" #include "shared/shared_usb.h" #include "deviceproxy.h" +#include "configuration.h" #define PSXCLK 36864000 /* 36.864 Mhz */ @@ -183,7 +184,7 @@ void CreateDevices() s32 USBinit() { - OSDebugOut(TEXT("USBinit\n")); + USBsetSettingsDir(); RegisterDevice::Register(); LoadConfig(); @@ -196,7 +197,6 @@ s32 USBinit() usbLog = wfopen(LogDir.c_str(), "wb"); // L"wb,ccs=UNICODE"); #endif //if(usbLog) setvbuf(usbLog, NULL, _IONBF, 0); - USB_LOG("USBinit\n"); } qemu_ohci = ohci_create(0x1f801600, 2); @@ -238,9 +238,6 @@ s32 USBopen(void* pDsp) //if(usbLog) setvbuf(usbLog, NULL, _IONBF, 0); } - USB_LOG("USBopen\n"); - OSDebugOut(TEXT("USBopen\n")); - #if _WIN32 HWND hWnd = (HWND)pDsp; diff --git a/pcsx2/USB/Win32/Config_usb.cpp b/pcsx2/USB/Win32/Config_usb.cpp index 37292ca66f..adf8bac15f 100644 --- a/pcsx2/USB/Win32/Config_usb.cpp +++ b/pcsx2/USB/Win32/Config_usb.cpp @@ -237,10 +237,11 @@ BOOL CALLBACK ConfigureDlgProcUSB(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lPar void USBconfigure() { ScopedCoreThreadPause paused_core; + USBsetSettingsDir(); RegisterDevice::Register(); DialogBox(hInstUSB, MAKEINTRESOURCE(IDD_CONFIG), GetActiveWindow(), (DLGPROC)ConfigureDlgProcUSB); paused_core.AllowResume(); -} \ No newline at end of file +} diff --git a/pcsx2/USB/configuration.cpp b/pcsx2/USB/configuration.cpp index cd159e9293..4f778d480b 100644 --- a/pcsx2/USB/configuration.cpp +++ b/pcsx2/USB/configuration.cpp @@ -19,24 +19,29 @@ #include "configuration.h" #include "shared/inifile_usb.h" #include "platcompat.h" +#include "AppConfig.h" #include #include std::map, std::string> changedAPIs; -const TCHAR* iniFile = TEXT("USBqemu-wheel.ini"); +wxString iniFile(L"USB.ini"); static TSTDSTRING usb_path; -TSTDSTRING IniPath = TSTDSTRING(TEXT("./inis/")) + iniFile; // default path, just in case +TSTDSTRING IniPath; // default path, just in case TSTDSTRING LogDir; CIniFile ciniFile; +bool USBpathSet = false; -void USBsetSettingsDir(const char* dir) +void USBsetSettingsDir() { + if(!USBpathSet) + { #ifdef _WIN32 - IniPath = str_to_wstr(dir); + IniPath = GetSettingsFolder().Combine( iniFile ).GetFullPath(); // default path, just in case #else - IniPath = dir; + IniPath = std::string(GetSettingsFolder().Combine( iniFile ).GetFullPath()); // default path, just in case #endif - IniPath.append(iniFile); + USBpathSet = true; + } } void USBsetLogDir(const char* dir) @@ -50,6 +55,7 @@ void USBsetLogDir(const char* dir) std::string GetSelectedAPI(const std::pair& pair) { + USBsetSettingsDir(); auto it = changedAPIs.find(pair); if (it != changedAPIs.end()) return it->second; @@ -58,6 +64,7 @@ std::string GetSelectedAPI(const std::pair& pair) bool LoadSettingValue(const TSTDSTRING& ini, const TSTDSTRING& section, const TCHAR* param, TSTDSTRING& value) { + USBsetSettingsDir(); CIniKey* key; #ifdef _WIN32 auto sect = ciniFile.GetSection(section); @@ -79,6 +86,7 @@ bool LoadSettingValue(const TSTDSTRING& ini, const TSTDSTRING& section, const TC bool LoadSettingValue(const TSTDSTRING& ini, const TSTDSTRING& section, const TCHAR* param, int32_t& value) { + USBsetSettingsDir(); CIniKey* key; #ifdef _WIN32 auto sect = ciniFile.GetSection(section); @@ -109,6 +117,7 @@ bool LoadSettingValue(const TSTDSTRING& ini, const TSTDSTRING& section, const TC bool SaveSettingValue(const TSTDSTRING& ini, const TSTDSTRING& section, const TCHAR* param, const TSTDSTRING& value) { + USBsetSettingsDir(); #ifdef _WIN32 ciniFile.SetKeyValue(section, param, value); #else @@ -119,6 +128,7 @@ bool SaveSettingValue(const TSTDSTRING& ini, const TSTDSTRING& section, const TC bool SaveSettingValue(const TSTDSTRING& ini, const TSTDSTRING& section, const TCHAR* param, int32_t value) { + USBsetSettingsDir(); #ifdef _WIN32 ciniFile.SetKeyValue(section, param, TSTDTOSTRING(value)); #else @@ -129,7 +139,7 @@ bool SaveSettingValue(const TSTDSTRING& ini, const TSTDSTRING& section, const TC void SaveConfig() { - + USBsetSettingsDir(); #ifdef _WIN32 SaveSetting(L"MAIN", L"log", conf.Log); #else @@ -167,8 +177,8 @@ void SaveConfig() void LoadConfig() { - std::cerr << "USB load config\n" - << std::endl; + + USBsetSettingsDir(); #ifdef _WIN32 ciniFile.Load(IniPath); @@ -224,6 +234,7 @@ void LoadConfig() void ClearSection(const TCHAR* section) { + USBsetSettingsDir(); #ifdef _WIN32 auto s = ciniFile.GetSection(section); #else @@ -237,6 +248,7 @@ void ClearSection(const TCHAR* section) void RemoveSection(const char* dev_type, int port, const std::string& key) { + USBsetSettingsDir(); TSTDSTRING tkey; tkey.assign(key.begin(), key.end()); diff --git a/pcsx2/USB/configuration.h b/pcsx2/USB/configuration.h index 91a65cd28a..6156f0d925 100644 --- a/pcsx2/USB/configuration.h +++ b/pcsx2/USB/configuration.h @@ -71,7 +71,7 @@ void RemoveSection(const char* dev_type, int port, const std::string& key); extern TSTDSTRING IniPath; extern TSTDSTRING LogDir; -extern const TCHAR* iniFile; +extern wxString iniFile; extern std::map, std::string> changedAPIs; std::string GetSelectedAPI(const std::pair& pair); @@ -86,7 +86,7 @@ bool LoadSettingValue(const TSTDSTRING& ini, const TSTDSTRING& section, const TC bool SaveSettingValue(const TSTDSTRING& ini, const TSTDSTRING& section, const TCHAR* param, const std::string& value); #endif -void USBsetSettingsDir(const char* dir); +void USBsetSettingsDir(); void USBsetLogDir(const char* dir); template diff --git a/pcsx2/USB/linux/config-gtk.cpp b/pcsx2/USB/linux/config-gtk.cpp index 43ea18bfe4..c8c38005cf 100644 --- a/pcsx2/USB/linux/config-gtk.cpp +++ b/pcsx2/USB/linux/config-gtk.cpp @@ -207,6 +207,7 @@ void USBconfigure() { ScopedCoreThreadPause paused_core; + USBsetSettingsDir(); RegisterDevice::Register(); LoadConfig(); void* that = NULL;