lilypad: import common utility to manage config

Based work on spu2x equivalent file. Only convert the file to a CfgHelper object
This commit is contained in:
Gregory Hainaut 2015-01-26 23:45:15 +01:00
parent 156f66ef62
commit 4f013a2960
5 changed files with 171 additions and 8 deletions

View File

@ -29,6 +29,7 @@ set(lilypadSources
DeviceEnumerator.cpp
InputManager.cpp
Linux/Config.cpp
Linux/ConfigHelper.cpp
Linux/KeyboardQueue.cpp
Linux/LilyPad.cpp)

View File

@ -78,6 +78,10 @@ static inline unsigned int timeGetTime() {
return (ms & 0xFFFFFFFF); // MS code is u32 ...
}
#include "Utilities/Dependencies.h"
#include "Utilities/StringHelpers.h"
#include "Utilities/Path.h"
#endif

View File

@ -20,21 +20,19 @@
#include "InputManager.h"
#include "Config.h"
#include "DeviceEnumerator.h"
#include "Linux/ConfigHelper.h"
GeneralConfig config;
u8 ps2e = 0;
void CALLBACK PADsetSettingsDir( const char *dir )
{
CfgSetSettingsDir(dir);
}
int LoadSettings(int force, wchar_t *file) {
if (dm && !force) return 0;
#if 0
if( createIniDir )
{
CreateDirectory(L"inis", 0);
createIniDir = false;
}
#endif
// Could just do ClearDevices() instead, but if I ever add any extra stuff,
// this will still work.
UnloadConfigs();

View File

@ -0,0 +1,112 @@
/* LilyPad - Pad plugin for PS2 Emulator
* Copyright (C) 2002-2014 PCSX2 Dev Team/ChickenLiver
*
* File imported from SPU2-X (and tranformed to object)
*
* PCSX2 is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Found- ation, either version 3 of the License, or (at your option)
* any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along
* with PCSX2. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Linux/ConfigHelper.h"
#include <wx/fileconf.h>
wxString CfgHelper::m_path = L"inis/LilyPad.ini";
void CfgHelper::SetSettingsDir(const char* dir)
{
m_path = wxString::FromAscii(dir) + L"/LilyPad.ini";
}
CfgHelper::CfgHelper()
{
m_config = new wxFileConfig(L"", L"", m_path, L"", wxCONFIG_USE_LOCAL_FILE);
}
CfgHelper::~CfgHelper()
{
delete m_config;
}
void CfgHelper::setIni(const wchar_t* Section)
{
m_config->SetPath(wxsFormat(L"/%s", Section));
}
void CfgHelper::WriteBool(const wchar_t* Section, const wchar_t* Name, bool Value)
{
setIni(Section);
m_config->Write(Name, Value);
}
void CfgHelper::WriteInt(const wchar_t* Section, const wchar_t* Name, int Value)
{
setIni(Section);
m_config->Write(Name, Value);
}
void CfgHelper::WriteFloat(const wchar_t* Section, const wchar_t* Name, float Value)
{
setIni(Section);
m_config->Write(Name, (double)Value);
}
void CfgHelper::WriteStr(const wchar_t* Section, const wchar_t* Name, const wxString& Data)
{
setIni(Section);
m_config->Write(Name, Data);
}
bool CfgHelper::ReadBool(const wchar_t *Section,const wchar_t* Name, bool Default)
{
bool ret;
setIni(Section);
m_config->Read(Name, &ret, Default);
return ret;
}
int CfgHelper::ReadInt(const wchar_t* Section, const wchar_t* Name,int Default)
{
int ret;
setIni(Section);
m_config->Read(Name, &ret, Default);
return ret;
}
float CfgHelper::ReadFloat(const wchar_t* Section, const wchar_t* Name, float Default)
{
double ret;
setIni(Section);
m_config->Read(Name, &ret, (double)Default);
return (float)ret;
}
int CfgHelper::ReadStr(const wchar_t* Section, const wchar_t* Name, wchar_t* Data, const wchar_t* Default)
{
setIni(Section);
wcscpy(Data, m_config->Read(Name, Default).wc_str());
return wcslen(Data);
}
int CfgHelper::ReadStr(const wchar_t* Section, const wchar_t* Name, wxString& Data, const wchar_t* Default)
{
setIni(Section);
Data = m_config->Read(Name, Default);
return Data.size();
}

View File

@ -0,0 +1,48 @@
/* LilyPad - Pad plugin for PS2 Emulator
* Copyright (C) 2002-2014 PCSX2 Dev Team/ChickenLiver
*
* File imported from SPU2-X (and tranformed to object)
*
* PCSX2 is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Found- ation, either version 3 of the License, or (at your option)
* any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along
* with PCSX2. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Global.h"
#include <wx/fileconf.h>
extern void CfgSetSettingsDir(const char* dir);
class CfgHelper {
wxFileConfig* m_config;
static wxString m_path;
void setIni(const wchar_t* Section);
public:
CfgHelper();
~CfgHelper();
void WriteBool(const wchar_t* Section, const wchar_t* Name, bool Value);
void WriteInt(const wchar_t* Section, const wchar_t* Name, int Value);
void WriteFloat(const wchar_t* Section, const wchar_t* Name, float Value);
void WriteStr(const wchar_t* Section, const wchar_t* Name, const wxString& Data);
bool ReadBool(const wchar_t *Section,const wchar_t* Name, bool Default = false);
int ReadStr(const wchar_t* Section, const wchar_t* Name, wxString& Data, const wchar_t* Default = 0);
int ReadStr(const wchar_t* Section, const wchar_t* Name, wchar_t* Data, const wchar_t* Default = 0);
int ReadInt(const wchar_t* Section, const wchar_t* Name,int Default = 0);
float ReadFloat(const wchar_t* Section, const wchar_t* Name, float Default = 0.0f);
static void SetSettingsDir(const char* dir);
};