USB: fix ini saves

This commit is contained in:
Gauvain 'GovanifY' Roussel-Tarbouriech 2020-11-05 11:53:58 +01:00 committed by refractionpcsx2
parent b5dbd794de
commit 47d65c3f89
5 changed files with 28 additions and 17 deletions

View File

@ -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;

View File

@ -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();
}
}

View File

@ -19,24 +19,29 @@
#include "configuration.h"
#include "shared/inifile_usb.h"
#include "platcompat.h"
#include "AppConfig.h"
#include <map>
#include <vector>
std::map<std::pair<int, std::string>, 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<int, std::string>& pair)
{
USBsetSettingsDir();
auto it = changedAPIs.find(pair);
if (it != changedAPIs.end())
return it->second;
@ -58,6 +64,7 @@ std::string GetSelectedAPI(const std::pair<int, std::string>& 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());

View File

@ -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::pair<int /*port*/, std::string /*devname*/>, std::string> changedAPIs;
std::string GetSelectedAPI(const std::pair<int /*port*/, std::string /*devname*/>& 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 <typename Type>

View File

@ -207,6 +207,7 @@ void USBconfigure()
{
ScopedCoreThreadPause paused_core;
USBsetSettingsDir();
RegisterDevice::Register();
LoadConfig();
void* that = NULL;