From 4f013a2960488a229084d975dffcf190c1df0da9 Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Mon, 26 Jan 2015 23:45:15 +0100 Subject: [PATCH] lilypad: import common utility to manage config Based work on spu2x equivalent file. Only convert the file to a CfgHelper object --- plugins/LilyPad/CMakeLists.txt | 1 + plugins/LilyPad/Global.h | 4 + plugins/LilyPad/Linux/Config.cpp | 14 ++-- plugins/LilyPad/Linux/ConfigHelper.cpp | 112 +++++++++++++++++++++++++ plugins/LilyPad/Linux/ConfigHelper.h | 48 +++++++++++ 5 files changed, 171 insertions(+), 8 deletions(-) create mode 100644 plugins/LilyPad/Linux/ConfigHelper.cpp create mode 100644 plugins/LilyPad/Linux/ConfigHelper.h diff --git a/plugins/LilyPad/CMakeLists.txt b/plugins/LilyPad/CMakeLists.txt index 86bd2da6b4..f7073171f1 100644 --- a/plugins/LilyPad/CMakeLists.txt +++ b/plugins/LilyPad/CMakeLists.txt @@ -29,6 +29,7 @@ set(lilypadSources DeviceEnumerator.cpp InputManager.cpp Linux/Config.cpp + Linux/ConfigHelper.cpp Linux/KeyboardQueue.cpp Linux/LilyPad.cpp) diff --git a/plugins/LilyPad/Global.h b/plugins/LilyPad/Global.h index f09526ed28..799eb5f55a 100644 --- a/plugins/LilyPad/Global.h +++ b/plugins/LilyPad/Global.h @@ -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 diff --git a/plugins/LilyPad/Linux/Config.cpp b/plugins/LilyPad/Linux/Config.cpp index ec506baf44..55849f689c 100644 --- a/plugins/LilyPad/Linux/Config.cpp +++ b/plugins/LilyPad/Linux/Config.cpp @@ -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(); diff --git a/plugins/LilyPad/Linux/ConfigHelper.cpp b/plugins/LilyPad/Linux/ConfigHelper.cpp new file mode 100644 index 0000000000..e7f299f65d --- /dev/null +++ b/plugins/LilyPad/Linux/ConfigHelper.cpp @@ -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 . + */ + +#include "Linux/ConfigHelper.h" +#include + +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(); +} diff --git a/plugins/LilyPad/Linux/ConfigHelper.h b/plugins/LilyPad/Linux/ConfigHelper.h new file mode 100644 index 0000000000..6a74b9ae26 --- /dev/null +++ b/plugins/LilyPad/Linux/ConfigHelper.h @@ -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 . + */ + +#include "Global.h" +#include + +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); + +};