From dc5e4e61c535500f84f96c4c04e9db970156a87b Mon Sep 17 00:00:00 2001 From: Gauvain 'GovanifY' Roussel-Tarbouriech Date: Sat, 12 Dec 2020 21:01:31 +0100 Subject: [PATCH] PAD: fix ini on windows --- pcsx2/PAD/Windows/PAD.cpp | 19 +------------------ pcsx2/PAD/Windows/PAD.h | 1 - pcsx2/PAD/Windows/PADConfig.cpp | 27 +++++++++++++++------------ pcsx2/USB/configuration.cpp | 6 +++--- pcsx2/USB/configuration.h | 1 - 5 files changed, 19 insertions(+), 35 deletions(-) diff --git a/pcsx2/PAD/Windows/PAD.cpp b/pcsx2/PAD/Windows/PAD.cpp index 4451accc8e..8d0e161b20 100644 --- a/pcsx2/PAD/Windows/PAD.cpp +++ b/pcsx2/PAD/Windows/PAD.cpp @@ -36,6 +36,7 @@ #include "KeyboardQueue.h" #include "svnrev.h" #include "DualShock3.h" +#include "AppConfig.h" #include #include "Utilities/pxStreams.h" @@ -477,24 +478,6 @@ char padReadKeyUpdated[4] = {0, 0, 0, 0}; #define LOCK_BUTTONS 4 #define LOCK_BOTH 1 -#ifdef _MSC_VER -struct EnterScopedSection -{ - CRITICAL_SECTION& m_cs; - - EnterScopedSection(CRITICAL_SECTION& cs) - : m_cs(cs) - { - EnterCriticalSection(&m_cs); - } - - ~EnterScopedSection() - { - LeaveCriticalSection(&m_cs); - } -}; -#endif - void Update(unsigned int port, unsigned int slot) { char* stateUpdated; diff --git a/pcsx2/PAD/Windows/PAD.h b/pcsx2/PAD/Windows/PAD.h index c1db5939ee..9b4cbe6461 100644 --- a/pcsx2/PAD/Windows/PAD.h +++ b/pcsx2/PAD/Windows/PAD.h @@ -44,7 +44,6 @@ typedef struct unsigned char reserved[91]; } PadDataS; - void PADupdate(int pad); void PADshutdown(); s32 PADinit(); diff --git a/pcsx2/PAD/Windows/PADConfig.cpp b/pcsx2/PAD/Windows/PADConfig.cpp index 28b1a46401..ba5214486c 100644 --- a/pcsx2/PAD/Windows/PADConfig.cpp +++ b/pcsx2/PAD/Windows/PADConfig.cpp @@ -26,6 +26,7 @@ #include "KeyboardQueue.h" #include "WndProcEater.h" #include "DualShock3.h" +#include "PAD.h" #include @@ -33,6 +34,7 @@ #include "PADRawInput.h" #include #include +#include "AppConfig.h" //max len 24 wchar_t const wchar_t* padTypes[] = { @@ -331,20 +333,21 @@ wchar_t* GetCommandStringW(u8 command, int port, int slot) return L""; } -static wchar_t iniFile[MAX_PATH * 2] = L"inis/PAD.ini"; +static wchar_t iniFileUSB[MAX_PATH * 2] = L"inis/PAD.ini"; +// we disregard dir and use global settings instead, we should probably clean that up someday... void PADsetSettingsDir(const char* dir) { - //swprintf_s( iniFile, L"%S", (dir==NULL) ? "inis" : dir ); + //swprintf_s( iniFileUSB, L"%S", (dir==NULL) ? "inis" : dir ); //uint targlen = MultiByteToWideChar(CP_ACP, 0, dir, -1, NULL, 0); - MultiByteToWideChar(CP_UTF8, 0, dir, -1, iniFile, MAX_PATH * 2); - wcscat_s(iniFile, L"/PAD.ini"); + wxString iniName = "PAD.ini"; + MultiByteToWideChar(CP_UTF8, 0, std::string(GetSettingsFolder().Combine(iniName).GetFullPath()).c_str(), -1, iniFileUSB, MAX_PATH * 2); createIniDir = false; FILE* temp = nullptr; - _wfopen_s(&temp, iniFile, L"r"); + _wfopen_s(&temp, iniFileUSB, L"r"); if (!temp) { // File not found, possibly. HRSRC res = FindResource(hInst, MAKEINTRESOURCE(IDR_INI1), RT_RCDATA); @@ -355,7 +358,7 @@ void PADsetSettingsDir(const char* dir) return; size_t size = SizeofResource(hInst, res); u8* fdata = (u8*)LockResource(data); - _wfopen_s(&temp, iniFile, L"w"); + _wfopen_s(&temp, iniFileUSB, L"w"); if (!temp) return; fwrite(fdata, 1, size, temp); @@ -933,7 +936,7 @@ int SaveSettings(wchar_t* file = 0) // Need this either way for saving path. if (!file) { - file = iniFile; + file = iniFileUSB; } else { @@ -948,8 +951,8 @@ int SaveSettings(wchar_t* file = 0) } DeleteFileW(file); - WritePrivateProfileStringW(L"General Settings", L"Last Config Path", config.lastSaveConfigPath, iniFile); - WritePrivateProfileStringW(L"General Settings", L"Last Config Name", config.lastSaveConfigFileName, iniFile); + WritePrivateProfileStringW(L"General Settings", L"Last Config Path", config.lastSaveConfigPath, iniFileUSB); + WritePrivateProfileStringW(L"General Settings", L"Last Config Name", config.lastSaveConfigFileName, iniFileUSB); // Just check first, last, and all pad bindings. Should be more than enough. No real need to check // config path. @@ -1063,7 +1066,7 @@ int LoadSettings(int force, wchar_t* file) if (!file) { - file = iniFile; + file = iniFileUSB; GetPrivateProfileStringW(L"General Settings", L"Last Config Path", L"inis", config.lastSaveConfigPath, sizeof(config.lastSaveConfigPath), file); GetPrivateProfileStringW(L"General Settings", L"Last Config Name", L"PAD.pad", config.lastSaveConfigFileName, sizeof(config.lastSaveConfigFileName), file); } @@ -1076,8 +1079,8 @@ int LoadSettings(int force, wchar_t* file) wcscpy(config.lastSaveConfigPath, file); wcscpy(config.lastSaveConfigFileName, c + 1); *c = '\\'; - WritePrivateProfileStringW(L"General Settings", L"Last Config Path", config.lastSaveConfigPath, iniFile); - WritePrivateProfileStringW(L"General Settings", L"Last Config Name", config.lastSaveConfigFileName, iniFile); + WritePrivateProfileStringW(L"General Settings", L"Last Config Path", config.lastSaveConfigPath, iniFileUSB); + WritePrivateProfileStringW(L"General Settings", L"Last Config Name", config.lastSaveConfigFileName, iniFileUSB); } } diff --git a/pcsx2/USB/configuration.cpp b/pcsx2/USB/configuration.cpp index 22816832cf..6ecfc56b9f 100644 --- a/pcsx2/USB/configuration.cpp +++ b/pcsx2/USB/configuration.cpp @@ -23,7 +23,7 @@ #include std::map, std::string> changedAPIs; -wxString iniFile(L"USB.ini"); +wxString iniFileUSB(L"USB.ini"); static TSTDSTRING usb_path; TSTDSTRING IniPath; // default path, just in case TSTDSTRING LogDir; @@ -35,9 +35,9 @@ void USBsetSettingsDir() if(!USBpathSet) { #ifdef _WIN32 - IniPath = GetSettingsFolder().Combine( iniFile ).GetFullPath(); // default path, just in case + IniPath = GetSettingsFolder().Combine( iniFileUSB ).GetFullPath(); // default path, just in case #else - IniPath = std::string(GetSettingsFolder().Combine( iniFile ).GetFullPath()); // default path, just in case + IniPath = std::string(GetSettingsFolder().Combine( iniFileUSB ).GetFullPath()); // default path, just in case #endif USBpathSet = true; } diff --git a/pcsx2/USB/configuration.h b/pcsx2/USB/configuration.h index b54f822e85..a3698c9441 100644 --- a/pcsx2/USB/configuration.h +++ b/pcsx2/USB/configuration.h @@ -71,7 +71,6 @@ void RemoveSection(const char* dev_type, int port, const std::string& key); extern TSTDSTRING IniPath; extern TSTDSTRING LogDir; -extern wxString iniFile; extern std::map, std::string> changedAPIs; std::string GetSelectedAPI(const std::pair& pair);