From 94ae54d6c028a6b0ba49bb49e487308d1f2d9a36 Mon Sep 17 00:00:00 2001 From: arcum42 Date: Tue, 25 May 2010 05:26:39 +0000 Subject: [PATCH] spu2-x: Some changes to how the ini file writing works in Linux. (still buggy) git-svn-id: http://pcsx2.googlecode.com/svn/trunk@3072 96395faa-99c1-11dd-bbfe-3dabce05a288 --- plugins/spu2-x/src/Linux/CfgHelpers.cpp | 71 ++++++++++--------------- plugins/spu2-x/src/Linux/Config.cpp | 15 ++++++ plugins/spu2-x/src/Linux/Config.h | 4 +- plugins/spu2-x/src/Linux/SPU2-X.cbp | 1 + 4 files changed, 48 insertions(+), 43 deletions(-) diff --git a/plugins/spu2-x/src/Linux/CfgHelpers.cpp b/plugins/spu2-x/src/Linux/CfgHelpers.cpp index b58cd48d46..89c73d43ff 100644 --- a/plugins/spu2-x/src/Linux/CfgHelpers.cpp +++ b/plugins/spu2-x/src/Linux/CfgHelpers.cpp @@ -19,63 +19,53 @@ #include wxConfigBase *oldConfig; - wxString path; + wxFileConfig *spuConfig; + wxString path(L"~/.pcsx2/inis/spu2-x.ini"); + bool pathSet = false; - wxFileConfig *setIni(const wchar_t* Section) +void initIni() +{ + spuConfig = new wxFileConfig(L"", L"", path, L"", wxCONFIG_USE_LOCAL_FILE); +} + +void setIni(const wchar_t* Section) { - wxConfig *tempConfig; - - oldConfig = wxConfigBase::Get(false); - - tempConfig = new wxFileConfig(L"", L"", path, L"", wxCONFIG_USE_LOCAL_FILE); - wxConfigBase::Set(tempConfig); - tempConfig->SetPath(L"/"); - tempConfig->SetPath(Section); - return tempConfig; - } - - void writeIni(wxFileConfig *tempConfig) - { - tempConfig->Flush(); - - if (oldConfig != NULL) wxConfigBase::Set(oldConfig); - delete tempConfig; + if (spuConfig == NULL) initIni(); + spuConfig->SetPath(wxsFormat(L"/%s", Section)); } void CfgSetSettingsDir(const char* dir) { - path = wxString::FromAscii(dir) + L"spu2-x.ini"; - + FileLog("CfgSetSettingsDir(%s)\n", dir); + path = wxString::FromAscii(dir) + L"/spu2-x.ini"; + pathSet = true; + initIni(); } void CfgWriteBool(const wchar_t* Section, const wchar_t* Name, bool Value) { - wxConfig *config = setIni(Section); - config->Write(Name, Value); - writeIni(config); + setIni(Section); + spuConfig->Write(Name, Value); } void CfgWriteInt(const wchar_t* Section, const wchar_t* Name, int Value) { - wxConfig *config = setIni(Section); - config->Write(Name, Value); - writeIni(config); + setIni(Section); + spuConfig->Write(Name, Value); } void CfgWriteStr(const wchar_t* Section, const wchar_t* Name, const wstring& Data) { - wxConfig *config = setIni(Section); - config->Write(Name, Data); - writeIni(config); + setIni(Section); + spuConfig->Write(Name, Data); } bool CfgReadBool(const wchar_t *Section,const wchar_t* Name, bool Default) { bool ret; - wxConfig *config = setIni(Section); - config->Read(Name, &ret, Default); - writeIni(config); + setIni(Section); + spuConfig->Read(Name, &ret, Default); return ret; } @@ -84,25 +74,22 @@ int CfgReadInt(const wchar_t* Section, const wchar_t* Name,int Default) { int ret; - wxConfig *config = setIni(Section); - config->Read(Name, &ret, Default); - writeIni(config); + setIni(Section); + spuConfig->Read(Name, &ret, Default); return ret; } void CfgReadStr(const wchar_t* Section, const wchar_t* Name, wchar_t* Data, int DataSize, const wchar_t* Default) { - wxConfig *config = setIni(Section); - wcscpy(Data, config->Read(Name, Default)); - writeIni(config); + setIni(Section); + wcscpy(Data, spuConfig->Read(Name, Default)); } void CfgReadStr(const wchar_t* Section, const wchar_t* Name, wxString& Data, int DataSize, const wchar_t* Default) { - wxConfig *config = setIni(Section); - Data = config->Read(Name, Default); - writeIni(config); + setIni(Section); + Data = spuConfig->Read(Name, Default); } void CfgReadStr(const wchar_t* Section, const wchar_t* Name, wstring& Data, int DataSize, const wchar_t* Default) diff --git a/plugins/spu2-x/src/Linux/Config.cpp b/plugins/spu2-x/src/Linux/Config.cpp index 0f20dac0ff..68e27c4dea 100644 --- a/plugins/spu2-x/src/Linux/Config.cpp +++ b/plugins/spu2-x/src/Linux/Config.cpp @@ -54,6 +54,14 @@ bool asyncMixingEnabled = false; void ReadSettings() { + // For some reason this can be called before we know what ini file we're writing to. + // Lets not try to read it if that happens. + if (!pathSet) + { + FileLog("Read called without the path set.\n"); + return; + } + Interpolation = CfgReadInt( L"MIXING",L"Interpolation", 1 ); EffectsDisabled = CfgReadBool( L"MIXING", L"Disable_Effects", false ); ReverbBoost = CfgReadInt( L"MIXING",L"Reverb_Boost", 0 ); @@ -76,12 +84,19 @@ void ReadSettings() Clampify( SndOutLatencyMS, LATENCY_MIN, LATENCY_MAX ); WriteSettings(); + spuConfig->Flush(); } /*****************************************************************************/ void WriteSettings() { + if (!pathSet) + { + FileLog("Write called without the path set.\n"); + return; + } + CfgWriteInt(L"MIXING",L"Interpolation",Interpolation); CfgWriteBool(L"MIXING",L"Disable_Effects",EffectsDisabled); CfgWriteInt(L"MIXING",L"Reverb_Boost",ReverbBoost); diff --git a/plugins/spu2-x/src/Linux/Config.h b/plugins/spu2-x/src/Linux/Config.h index 8b80108458..0e1a979142 100644 --- a/plugins/spu2-x/src/Linux/Config.h +++ b/plugins/spu2-x/src/Linux/Config.h @@ -20,6 +20,7 @@ #include #include +#include extern bool DebugEnabled; @@ -109,5 +110,6 @@ void ReadSettings(); void WriteSettings(); void configure(); void AboutBox(); - +extern wxFileConfig *spuConfig; +extern bool pathSet; #endif // CONFIG_H_INCLUDED diff --git a/plugins/spu2-x/src/Linux/SPU2-X.cbp b/plugins/spu2-x/src/Linux/SPU2-X.cbp index 66a0f0eb9a..d69b2a2fe3 100644 --- a/plugins/spu2-x/src/Linux/SPU2-X.cbp +++ b/plugins/spu2-x/src/Linux/SPU2-X.cbp @@ -13,6 +13,7 @@