SPU2: fix config path

This commit is contained in:
Gauvain 'GovanifY' Roussel-Tarbouriech 2020-09-27 01:42:33 +02:00 committed by refractionpcsx2
parent c36c26800b
commit 444f5ed515
2 changed files with 31 additions and 3 deletions

View File

@ -13,15 +13,21 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "AppConfig.h"
#include "Dialogs.h"
#include <wx/fileconf.h>
wxFileConfig* spuConfig = nullptr;
wxString path(L"~/.config/PCSX2/inis/SPU2.ini");
wxString path(L"SPU2.ini");
bool pathSet = false;
void initIni()
{
if(!pathSet)
{
path = GetSettingsFolder().Combine( path ).GetFullPath();
pathSet = true;
}
if (spuConfig == nullptr)
spuConfig = new wxFileConfig(L"", L"", path, L"", wxCONFIG_USE_LOCAL_FILE);
}
@ -35,7 +41,7 @@ void setIni(const wchar_t* Section)
void CfgSetSettingsDir(const char* dir)
{
FileLog("CfgSetSettingsDir(%s)\n", dir);
path = wxString::FromUTF8(dir) + L"/SPU2.ini";
path = Path::Combine((dir == nullptr) ? wxString(L"inis") : wxString::FromUTF8(dir), L"SPU2.ini");
pathSet = true;
}

View File

@ -14,6 +14,7 @@
*/
#include "PrecompiledHeader.h"
#include "AppConfig.h"
#include "../Global.h"
#include "Dialogs.h"
@ -50,10 +51,21 @@ void SysMessage(const wchar_t* fmt, ...)
#include "Utilities/Path.h"
static wxString CfgFile(L"inis/SPU2.ini");
wxString CfgFile(L"SPU2.ini");
bool pathSet = false;
void initIni()
{
if (!pathSet)
{
CfgFile = GetSettingsFolder().Combine(CfgFile).GetFullPath();
pathSet = true;
}
}
void CfgSetSettingsDir(const char* dir)
{
initIni();
CfgFile = Path::Combine((dir == nullptr) ? wxString(L"inis") : wxString::FromUTF8(dir), L"SPU2.ini");
}
@ -75,12 +87,14 @@ void CfgSetSettingsDir(const char* dir)
void CfgWriteBool(const TCHAR* Section, const TCHAR* Name, bool Value)
{
initIni();
const TCHAR* Data = Value ? L"TRUE" : L"FALSE";
WritePrivateProfileString(Section, Name, Data, CfgFile);
}
void CfgWriteInt(const TCHAR* Section, const TCHAR* Name, int Value)
{
initIni();
TCHAR Data[32];
_itow(Value, Data, 10);
WritePrivateProfileString(Section, Name, Data, CfgFile);
@ -88,6 +102,7 @@ void CfgWriteInt(const TCHAR* Section, const TCHAR* Name, int Value)
void CfgWriteFloat(const TCHAR* Section, const TCHAR* Name, float Value)
{
initIni();
TCHAR Data[32];
_swprintf(Data, L"%f", Value);
WritePrivateProfileString(Section, Name, Data, CfgFile);
@ -100,6 +115,7 @@ WritePrivateProfileString( Section, Name, Data, CfgFile );
void CfgWriteStr(const TCHAR* Section, const TCHAR* Name, const wxString& Data)
{
initIni();
WritePrivateProfileString(Section, Name, Data, CfgFile);
}
@ -107,6 +123,7 @@ void CfgWriteStr(const TCHAR* Section, const TCHAR* Name, const wxString& Data)
bool CfgReadBool(const TCHAR* Section, const TCHAR* Name, bool Default)
{
initIni();
TCHAR Data[255] = {0};
GetPrivateProfileString(Section, Name, L"", Data, 255, CfgFile);
@ -133,6 +150,7 @@ bool CfgReadBool(const TCHAR* Section, const TCHAR* Name, bool Default)
int CfgReadInt(const TCHAR* Section, const TCHAR* Name, int Default)
{
initIni();
TCHAR Data[255] = {0};
GetPrivateProfileString(Section, Name, L"", Data, 255, CfgFile);
Data[254] = 0;
@ -148,6 +166,7 @@ int CfgReadInt(const TCHAR* Section, const TCHAR* Name, int Default)
float CfgReadFloat(const TCHAR* Section, const TCHAR* Name, float Default)
{
initIni();
TCHAR Data[255] = {0};
GetPrivateProfileString(Section, Name, L"", Data, 255, CfgFile);
Data[254] = 0;
@ -163,6 +182,7 @@ float CfgReadFloat(const TCHAR* Section, const TCHAR* Name, float Default)
void CfgReadStr(const TCHAR* Section, const TCHAR* Name, TCHAR* Data, int DataSize, const TCHAR* Default)
{
initIni();
GetPrivateProfileString(Section, Name, L"", Data, DataSize, CfgFile);
if (wcslen(Data) == 0)
@ -174,6 +194,7 @@ void CfgReadStr(const TCHAR* Section, const TCHAR* Name, TCHAR* Data, int DataSi
void CfgReadStr(const TCHAR* Section, const TCHAR* Name, wxString& Data, const TCHAR* Default)
{
initIni();
wchar_t workspace[512];
GetPrivateProfileString(Section, Name, L"", workspace, ArraySize(workspace), CfgFile);
@ -190,6 +211,7 @@ void CfgReadStr(const TCHAR* Section, const TCHAR* Name, wxString& Data, const T
// Returns FALSE if the value isn't found.
bool CfgFindName(const TCHAR* Section, const TCHAR* Name)
{
initIni();
// Only load 24 characters. No need to load more.
TCHAR Data[24] = {0};
GetPrivateProfileString(Section, Name, L"", Data, 24, CfgFile);