2009-09-08 12:08:10 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
2010-05-03 14:08:02 +00:00
|
|
|
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* 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.
|
2009-04-27 02:04:31 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* 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.
|
2009-04-27 02:04:31 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
2009-04-27 02:04:31 +00:00
|
|
|
*/
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-06-25 02:35:27 +00:00
|
|
|
#include <wx/gdicmn.h>
|
|
|
|
|
2021-09-01 20:31:46 +00:00
|
|
|
#include "common/IniInterface.h"
|
|
|
|
#include "common/Console.h"
|
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
const wxRect wxDefaultRect(wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, wxDefaultCoord);
|
2010-06-25 02:35:27 +00:00
|
|
|
|
2011-03-26 07:02:46 +00:00
|
|
|
wxDirName g_fullBaseDirName = wxDirName(L"");
|
2016-11-12 15:28:37 +00:00
|
|
|
void SetFullBaseDir(wxDirName appRoot)
|
2011-03-26 07:02:46 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
g_fullBaseDirName = appRoot;
|
2011-03-26 07:02:46 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
static int _calcEnumLength(const wxChar* const* enumArray)
|
2009-09-05 23:07:23 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
int cnt = 0;
|
|
|
|
while (*enumArray != NULL)
|
|
|
|
{
|
|
|
|
enumArray++;
|
|
|
|
cnt++;
|
|
|
|
}
|
2009-09-05 23:07:23 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
return cnt;
|
2009-09-05 23:07:23 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
ScopedIniGroup::ScopedIniGroup(IniInterface& mommy, const wxString& group)
|
|
|
|
: m_mom(mommy)
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
pxAssertDev(wxStringTokenize(group, L"/").Count() <= 1, L"Cannot nest more than one group deep per instance of ScopedIniGroup.");
|
|
|
|
m_mom.SetPath(group);
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2010-08-04 19:10:41 +00:00
|
|
|
ScopedIniGroup::~ScopedIniGroup()
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
m_mom.SetPath(L"..");
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// IniInterface (implementations)
|
|
|
|
// --------------------------------------------------------------------------------------
|
2021-09-06 18:28:26 +00:00
|
|
|
IniInterface::IniInterface(wxConfigBase& config)
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
m_Config = &config;
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
IniInterface::IniInterface(wxConfigBase* config)
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
m_Config = config;
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
IniInterface::IniInterface()
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
m_Config = wxConfigBase::Get(false);
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
IniInterface::~IniInterface()
|
2009-08-21 04:44:47 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
Flush();
|
2009-08-21 04:44:47 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void IniInterface::SetPath(const wxString& path)
|
2009-08-21 04:44:47 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (m_Config)
|
|
|
|
m_Config->SetPath(path);
|
2009-08-21 04:44:47 +00:00
|
|
|
}
|
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
void IniInterface::Flush()
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (m_Config)
|
|
|
|
m_Config->Flush();
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// IniLoader (implementations)
|
|
|
|
// --------------------------------------------------------------------------------------
|
2021-09-06 18:28:26 +00:00
|
|
|
IniLoader::IniLoader(wxConfigBase& config)
|
|
|
|
: IniInterface(config)
|
2016-11-12 15:28:37 +00:00
|
|
|
{
|
|
|
|
}
|
2017-05-06 11:00:55 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
IniLoader::IniLoader(wxConfigBase* config)
|
|
|
|
: IniInterface(config)
|
2016-11-12 15:28:37 +00:00
|
|
|
{
|
|
|
|
}
|
2010-06-06 23:26:07 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
IniLoader::IniLoader()
|
2021-09-06 18:28:26 +00:00
|
|
|
: IniInterface()
|
2016-11-12 15:28:37 +00:00
|
|
|
{
|
|
|
|
}
|
2009-04-27 02:04:31 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void IniLoader::Entry(const wxString& var, wxString& value, const wxString defvalue)
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (m_Config)
|
|
|
|
m_Config->Read(var, &value, defvalue);
|
|
|
|
else
|
|
|
|
value = defvalue;
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void IniLoader::Entry(const wxString& var, wxDirName& value, const wxDirName defvalue, bool isAllowRelative)
|
2009-07-04 20:53:05 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
wxString dest;
|
|
|
|
if (m_Config)
|
|
|
|
m_Config->Read(var, &dest, wxEmptyString);
|
2009-07-04 20:53:05 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
if (dest.IsEmpty())
|
|
|
|
value = defvalue;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value = dest;
|
|
|
|
if (isAllowRelative)
|
|
|
|
value = g_fullBaseDirName + value;
|
Portable mode: now allows fully custom folders, but still allows relocation of pcsx2 folder without breaking (install mode unmodified).
Details:
The major differences between install and portable modes should now be:
1. Portable mode doesn't use the registry at all.
2. Portable mode uses the folders inside pcsx2 folder as default (install mode has some default at "my documents").
3. Portable mode tries to save relative paths at the ini file where possible*.
Specifically, portable mode now allows to select custom folders for plugins, bios, etc via the standard UI, which allows using several portable pcsx2 folder sharing the same resources (bios, iso, memcards, etc).
* Relative paths where possible = the following sequence (thanks to pseudonym for the brilliant idea):
1. If the file/folder is inside pcsx2 folder, it's saved as completely relative (to pcsx2.exe)
2. Else, if the file/folder is at the same drive as pcsx2.exe, it's saved as absolute path without the drive letter (e.g. /ISO/...)
3. Else, saved as absolute path, including the drive letter (for linux, without drive letter naturally).
This allows to create a removable drive with (one or more) pcsx2 folder on it, configure all the files/folders to point to the same drive (ISOs, save states, etc), and then take this drive, plug it into another computer (where it will be assigned with a different drive letter), and everything will continue working.
Please test it if you can. Bugs here can be inconvenient...
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@4507 96395faa-99c1-11dd-bbfe-3dabce05a288
2011-03-29 17:41:11 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
if (value.IsAbsolute())
|
|
|
|
value.Normalize();
|
|
|
|
}
|
2009-07-04 20:53:05 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void IniLoader::Entry(const wxString& var, wxFileName& value, const wxFileName defvalue, bool isAllowRelative)
|
2009-07-04 20:53:05 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
wxString dest(defvalue.GetFullPath());
|
|
|
|
if (m_Config)
|
|
|
|
m_Config->Read(var, &dest, defvalue.GetFullPath());
|
|
|
|
value = dest;
|
|
|
|
if (isAllowRelative)
|
|
|
|
value = g_fullBaseDirName + value;
|
2011-03-26 07:02:46 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
if (value.IsAbsolute())
|
|
|
|
value.Normalize();
|
2011-03-26 07:02:46 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
if (value.HasVolume())
|
|
|
|
value.SetVolume(value.GetVolume().Upper());
|
2009-07-04 20:53:05 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void IniLoader::Entry(const wxString& var, int& value, const int defvalue)
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (m_Config)
|
|
|
|
m_Config->Read(var, &value, defvalue);
|
|
|
|
else
|
|
|
|
value = defvalue;
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void IniLoader::Entry(const wxString& var, uint& value, const uint defvalue)
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (m_Config)
|
|
|
|
m_Config->Read(var, (int*)&value, (int)defvalue);
|
|
|
|
else
|
|
|
|
value = defvalue;
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void IniLoader::Entry(const wxString& var, bool& value, const bool defvalue)
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
// TODO : Stricter value checking on enabled/disabled?
|
|
|
|
wxString dest;
|
|
|
|
if (defvalue)
|
|
|
|
dest = wxString("enabled");
|
|
|
|
else
|
|
|
|
dest = wxString("disabled");
|
2020-08-23 03:59:15 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
if (m_Config)
|
|
|
|
m_Config->Read(var, &dest, dest);
|
|
|
|
value = (dest == L"enabled") || (dest == L"1");
|
2009-07-20 00:39:38 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
bool IniLoader::EntryBitBool(const wxString& var, bool value, const bool defvalue)
|
2009-07-20 00:39:38 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
// Note: 'value' param is used by inisaver only.
|
|
|
|
bool result;
|
|
|
|
Entry(var, result, defvalue);
|
|
|
|
return result;
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
int IniLoader::EntryBitfield(const wxString& var, int value, const int defvalue)
|
2009-07-23 02:11:45 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
int result;
|
|
|
|
Entry(var, result, defvalue);
|
|
|
|
return result;
|
2009-07-23 02:11:45 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void IniLoader::Entry(const wxString& var, double& value, const double defvalue)
|
2009-12-03 15:51:39 +00:00
|
|
|
{
|
2021-09-06 19:18:27 +00:00
|
|
|
auto readval = wxString::FromCDouble(value);
|
2009-12-03 15:51:39 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
if (m_Config)
|
|
|
|
m_Config->Read(var, &readval);
|
2021-08-30 07:10:48 +00:00
|
|
|
|
2021-09-06 19:18:27 +00:00
|
|
|
if (!readval.ToCDouble(&value))
|
2021-09-06 18:28:26 +00:00
|
|
|
value = 0.0;
|
2009-12-03 15:51:39 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void IniLoader::Entry(const wxString& var, wxPoint& value, const wxPoint defvalue)
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (!m_Config)
|
|
|
|
{
|
|
|
|
value = defvalue;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TryParse(value, m_Config->Read(var, ToString(defvalue)), defvalue);
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void IniLoader::Entry(const wxString& var, wxSize& value, const wxSize defvalue)
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (!m_Config)
|
|
|
|
{
|
|
|
|
value = defvalue;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TryParse(value, m_Config->Read(var, ToString(defvalue)), defvalue);
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void IniLoader::Entry(const wxString& var, wxRect& value, const wxRect defvalue)
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (!m_Config)
|
|
|
|
{
|
|
|
|
value = defvalue;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TryParse(value, m_Config->Read(var, ToString(defvalue)), defvalue);
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void IniLoader::_EnumEntry(const wxString& var, int& value, const wxChar* const* enumArray, int defvalue)
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
// Confirm default value sanity...
|
2009-09-05 23:07:23 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
const int cnt = _calcEnumLength(enumArray);
|
|
|
|
if (!IndexBoundsCheck(L"IniLoader EnumDefaultValue", defvalue, cnt))
|
|
|
|
{
|
|
|
|
Console.Error("(LoadSettings) Default enumeration index is out of bounds. Truncating.");
|
|
|
|
defvalue = cnt - 1;
|
|
|
|
}
|
2009-09-05 23:07:23 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
// Sanity confirmed, proceed with craziness!
|
2009-09-05 23:07:23 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
if (!m_Config)
|
|
|
|
{
|
|
|
|
value = defvalue;
|
|
|
|
return;
|
|
|
|
}
|
2010-06-06 23:26:07 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
wxString retval;
|
|
|
|
m_Config->Read(var, &retval, enumArray[defvalue]);
|
2009-04-27 02:04:31 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
int i = 0;
|
|
|
|
while (enumArray[i] != NULL && (retval != enumArray[i]))
|
|
|
|
i++;
|
2009-04-27 02:04:31 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
if (enumArray[i] == NULL)
|
|
|
|
{
|
|
|
|
Console.Warning(L"(LoadSettings) Warning: Unrecognized value '%s' on key '%s'\n\tUsing the default setting of '%s'.",
|
|
|
|
WX_STR(retval), WX_STR(var), enumArray[defvalue]);
|
|
|
|
value = defvalue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
value = i;
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2021-09-21 10:05:11 +00:00
|
|
|
void IniLoader::Entry(const wxString& var, std::string& value, const std::string& default_value)
|
|
|
|
{
|
|
|
|
if (m_Config)
|
|
|
|
{
|
|
|
|
wxString temp;
|
2021-01-14 07:13:33 +00:00
|
|
|
m_Config->Read(var, &temp, fromUTF8(default_value));
|
2021-09-21 10:05:11 +00:00
|
|
|
value = temp.ToStdString();
|
|
|
|
}
|
|
|
|
else if (&value != &default_value)
|
|
|
|
{
|
|
|
|
value.assign(default_value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// IniSaver (implementations)
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
IniSaver::IniSaver(wxConfigBase& config)
|
|
|
|
: IniInterface(config)
|
2016-11-12 15:28:37 +00:00
|
|
|
{
|
|
|
|
}
|
2017-05-06 11:00:55 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
IniSaver::IniSaver(wxConfigBase* config)
|
|
|
|
: IniInterface(config)
|
2016-11-12 15:28:37 +00:00
|
|
|
{
|
|
|
|
}
|
2009-04-27 02:04:31 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
IniSaver::IniSaver()
|
2021-09-06 18:28:26 +00:00
|
|
|
: IniInterface()
|
2016-11-12 15:28:37 +00:00
|
|
|
{
|
|
|
|
}
|
2009-04-27 02:04:31 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void IniSaver::Entry(const wxString& var, wxString& value, const wxString defvalue)
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (!m_Config)
|
|
|
|
return;
|
|
|
|
m_Config->Write(var, value);
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void IniSaver::Entry(const wxString& var, wxDirName& value, const wxDirName defvalue, bool isAllowRelative)
|
2009-07-04 20:53:05 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (!m_Config)
|
|
|
|
return;
|
|
|
|
wxDirName res(value);
|
Portable mode: now allows fully custom folders, but still allows relocation of pcsx2 folder without breaking (install mode unmodified).
Details:
The major differences between install and portable modes should now be:
1. Portable mode doesn't use the registry at all.
2. Portable mode uses the folders inside pcsx2 folder as default (install mode has some default at "my documents").
3. Portable mode tries to save relative paths at the ini file where possible*.
Specifically, portable mode now allows to select custom folders for plugins, bios, etc via the standard UI, which allows using several portable pcsx2 folder sharing the same resources (bios, iso, memcards, etc).
* Relative paths where possible = the following sequence (thanks to pseudonym for the brilliant idea):
1. If the file/folder is inside pcsx2 folder, it's saved as completely relative (to pcsx2.exe)
2. Else, if the file/folder is at the same drive as pcsx2.exe, it's saved as absolute path without the drive letter (e.g. /ISO/...)
3. Else, saved as absolute path, including the drive letter (for linux, without drive letter naturally).
This allows to create a removable drive with (one or more) pcsx2 folder on it, configure all the files/folders to point to the same drive (ISOs, save states, etc), and then take this drive, plug it into another computer (where it will be assigned with a different drive letter), and everything will continue working.
Please test it if you can. Bugs here can be inconvenient...
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@4507 96395faa-99c1-11dd-bbfe-3dabce05a288
2011-03-29 17:41:11 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
if (res.IsAbsolute())
|
|
|
|
res.Normalize();
|
Portable mode: now allows fully custom folders, but still allows relocation of pcsx2 folder without breaking (install mode unmodified).
Details:
The major differences between install and portable modes should now be:
1. Portable mode doesn't use the registry at all.
2. Portable mode uses the folders inside pcsx2 folder as default (install mode has some default at "my documents").
3. Portable mode tries to save relative paths at the ini file where possible*.
Specifically, portable mode now allows to select custom folders for plugins, bios, etc via the standard UI, which allows using several portable pcsx2 folder sharing the same resources (bios, iso, memcards, etc).
* Relative paths where possible = the following sequence (thanks to pseudonym for the brilliant idea):
1. If the file/folder is inside pcsx2 folder, it's saved as completely relative (to pcsx2.exe)
2. Else, if the file/folder is at the same drive as pcsx2.exe, it's saved as absolute path without the drive letter (e.g. /ISO/...)
3. Else, saved as absolute path, including the drive letter (for linux, without drive letter naturally).
This allows to create a removable drive with (one or more) pcsx2 folder on it, configure all the files/folders to point to the same drive (ISOs, save states, etc), and then take this drive, plug it into another computer (where it will be assigned with a different drive letter), and everything will continue working.
Please test it if you can. Bugs here can be inconvenient...
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@4507 96395faa-99c1-11dd-bbfe-3dabce05a288
2011-03-29 17:41:11 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
if (isAllowRelative)
|
|
|
|
res = wxDirName::MakeAutoRelativeTo(res, g_fullBaseDirName.ToString());
|
2010-06-06 23:26:07 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
/*if( value == defvalue )
|
2010-06-06 23:26:07 +00:00
|
|
|
m_Config->Write( var, wxString() );
|
2009-10-26 08:57:30 +00:00
|
|
|
else*/
|
2021-09-06 18:28:26 +00:00
|
|
|
m_Config->Write(var, res.ToString());
|
2009-07-04 20:53:05 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void IniSaver::Entry(const wxString& var, wxFileName& value, const wxFileName defvalue, bool isAllowRelative)
|
2009-07-04 20:53:05 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (!m_Config)
|
|
|
|
return;
|
|
|
|
wxFileName res(value);
|
2016-11-12 15:28:37 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
if (res.IsAbsolute())
|
|
|
|
res.Normalize();
|
2011-03-26 07:02:46 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
if (isAllowRelative)
|
|
|
|
res = wxDirName::MakeAutoRelativeTo(res, g_fullBaseDirName.ToString());
|
2016-11-12 15:28:37 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
m_Config->Write(var, res.GetFullPath());
|
2009-07-04 20:53:05 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void IniSaver::Entry(const wxString& var, int& value, const int defvalue)
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (!m_Config)
|
|
|
|
return;
|
|
|
|
m_Config->Write(var, value);
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void IniSaver::Entry(const wxString& var, uint& value, const uint defvalue)
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (!m_Config)
|
|
|
|
return;
|
|
|
|
m_Config->Write(var, (int)value);
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void IniSaver::Entry(const wxString& var, bool& value, const bool defvalue)
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (!m_Config)
|
|
|
|
return;
|
|
|
|
m_Config->Write(var, value ? L"enabled" : L"disabled");
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
bool IniSaver::EntryBitBool(const wxString& var, bool value, const bool defvalue)
|
2009-07-20 00:39:38 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (m_Config)
|
|
|
|
m_Config->Write(var, value ? L"enabled" : L"disabled");
|
|
|
|
return value;
|
2009-07-20 00:39:38 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
int IniSaver::EntryBitfield(const wxString& var, int value, const int defvalue)
|
2009-07-23 02:11:45 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (m_Config)
|
|
|
|
m_Config->Write(var, value);
|
|
|
|
return value;
|
2009-07-23 02:11:45 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void IniSaver::Entry(const wxString& var, double& value, const double defvalue)
|
2009-12-03 15:51:39 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (!m_Config)
|
|
|
|
return;
|
2010-06-06 23:26:07 +00:00
|
|
|
|
2021-09-06 19:18:27 +00:00
|
|
|
m_Config->Write(var, wxString::FromCDouble(value));
|
2009-12-03 15:51:39 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void IniSaver::Entry(const wxString& var, wxPoint& value, const wxPoint defvalue)
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (!m_Config)
|
|
|
|
return;
|
|
|
|
m_Config->Write(var, ToString(value));
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void IniSaver::Entry(const wxString& var, wxSize& value, const wxSize defvalue)
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (!m_Config)
|
|
|
|
return;
|
|
|
|
m_Config->Write(var, ToString(value));
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void IniSaver::Entry(const wxString& var, wxRect& value, const wxRect defvalue)
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (!m_Config)
|
|
|
|
return;
|
|
|
|
m_Config->Write(var, ToString(value));
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void IniSaver::_EnumEntry(const wxString& var, int& value, const wxChar* const* enumArray, int defvalue)
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
const int cnt = _calcEnumLength(enumArray);
|
2009-11-04 09:30:22 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
// Confirm default value sanity...
|
2009-11-04 09:30:22 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
if (!IndexBoundsCheck(L"IniSaver EnumDefaultValue", defvalue, cnt))
|
|
|
|
{
|
|
|
|
Console.Error("(SaveSettings) Default enumeration index is out of bounds. Truncating.");
|
|
|
|
defvalue = cnt - 1;
|
|
|
|
}
|
2009-11-04 09:30:22 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
if (!m_Config)
|
|
|
|
return;
|
2010-06-06 23:26:07 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
if (value >= cnt)
|
|
|
|
{
|
|
|
|
Console.Warning(L"(SaveSettings) An illegal enumerated index was detected when saving '%s'", WX_STR(var));
|
|
|
|
Console.Indent().Warning(
|
|
|
|
L"Illegal Value: %d\n"
|
|
|
|
L"Using Default: %d (%s)\n",
|
|
|
|
value, defvalue, enumArray[defvalue]);
|
2009-09-05 23:07:23 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
// Cause a debug assertion, since this is a fully recoverable error.
|
|
|
|
pxAssert(value < cnt);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
value = defvalue;
|
|
|
|
}
|
2009-09-05 23:07:23 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
m_Config->Write(var, enumArray[value]);
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
2021-09-21 10:05:11 +00:00
|
|
|
|
|
|
|
void IniSaver::Entry(const wxString& var, std::string& value, const std::string& default_value)
|
|
|
|
{
|
|
|
|
if (!m_Config)
|
|
|
|
return;
|
2021-01-14 07:13:33 +00:00
|
|
|
m_Config->Write(var, fromUTF8(value));
|
2021-09-21 10:05:11 +00:00
|
|
|
}
|