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.
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-04-27 02:04:31 +00:00
|
|
|
#pragma once
|
|
|
|
|
2010-06-07 08:56:28 +00:00
|
|
|
#include "Path.h"
|
2010-06-25 11:12:24 +00:00
|
|
|
#include "FixedPointTypes.h"
|
2009-04-27 02:04:31 +00:00
|
|
|
#include <wx/config.h>
|
2011-01-04 22:49:58 +00:00
|
|
|
#include <wx/gdicmn.h>
|
2009-04-27 02:04:31 +00:00
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// IniInterface (abstract base class)
|
|
|
|
// --------------------------------------------------------------------------------------
|
2009-04-27 02:04:31 +00:00
|
|
|
// This is used as an interchangable interface for both loading and saving options from an
|
|
|
|
// ini/configuration file. The LoadSave code takes an IniInterface, and the interface
|
|
|
|
// implementation defines whether the options are read or written.
|
|
|
|
//
|
|
|
|
// See also: IniLoader, IniSaver
|
|
|
|
//
|
|
|
|
class IniInterface
|
|
|
|
{
|
|
|
|
protected:
|
2010-06-06 23:26:07 +00:00
|
|
|
wxConfigBase* m_Config;
|
2009-04-27 02:04:31 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~IniInterface();
|
|
|
|
explicit IniInterface();
|
|
|
|
explicit IniInterface( wxConfigBase& config );
|
2010-06-06 23:26:07 +00:00
|
|
|
explicit IniInterface( wxConfigBase* config );
|
2009-04-27 02:04:31 +00:00
|
|
|
|
|
|
|
void SetPath( const wxString& path );
|
|
|
|
void Flush();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2011-07-24 13:02:50 +00:00
|
|
|
wxConfigBase& GetConfig() { pxAssert( m_Config ); return *m_Config; }
|
2010-06-06 23:26:07 +00:00
|
|
|
bool IsOk() const { return m_Config != NULL; }
|
2009-07-04 20:53:05 +00:00
|
|
|
|
|
|
|
virtual bool IsLoading() const=0;
|
|
|
|
bool IsSaving() const { return !IsLoading(); }
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2011-01-04 22:49:58 +00:00
|
|
|
virtual void Entry( const wxString& var, wxString& value, const wxString defvalue=wxString() )=0;
|
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
|
|
|
virtual void Entry( const wxString& var, wxDirName& value, const wxDirName defvalue=wxDirName(), bool isAllowRelative=false )=0;
|
2011-03-26 07:02:46 +00:00
|
|
|
virtual void Entry( const wxString& var, wxFileName& value, const wxFileName defvalue=wxFileName(), bool isAllowRelative=false )=0;
|
2009-04-27 02:04:31 +00:00
|
|
|
virtual void Entry( const wxString& var, int& value, const int defvalue=0 )=0;
|
|
|
|
virtual void Entry( const wxString& var, uint& value, const uint defvalue=0 )=0;
|
2009-07-20 00:39:38 +00:00
|
|
|
virtual void Entry( const wxString& var, bool& value, const bool defvalue=false )=0;
|
|
|
|
|
|
|
|
// This special form of Entry is provided for bitfields, which cannot be passed by reference.
|
2009-07-23 02:11:45 +00:00
|
|
|
virtual bool EntryBitBool( const wxString& var, bool value, const bool defvalue=false )=0;
|
|
|
|
virtual int EntryBitfield( const wxString& var, int value, const int defvalue=0 )=0;
|
2009-04-27 02:04:31 +00:00
|
|
|
|
2011-01-04 22:49:58 +00:00
|
|
|
virtual void Entry( const wxString& var, Fixed100& value, const Fixed100 defvalue=Fixed100() )=0;
|
2009-12-03 15:51:39 +00:00
|
|
|
|
2011-01-04 22:49:58 +00:00
|
|
|
virtual void Entry( const wxString& var, wxPoint& value, const wxPoint defvalue=wxDefaultPosition )=0;
|
|
|
|
virtual void Entry( const wxString& var, wxSize& value, const wxSize defvalue=wxDefaultSize )=0;
|
|
|
|
virtual void Entry( const wxString& var, wxRect& value, const wxRect defvalue=wxDefaultRect )=0;
|
2009-04-27 02:04:31 +00:00
|
|
|
|
2009-07-23 02:11:45 +00:00
|
|
|
template< typename T >
|
|
|
|
void EnumEntry( const wxString& var, T& value, const wxChar* const* enumArray=NULL, const T defvalue=(T)0 )
|
|
|
|
{
|
|
|
|
int tstore = (int)value;
|
|
|
|
if( enumArray == NULL )
|
|
|
|
Entry( var, tstore, defvalue );
|
|
|
|
else
|
|
|
|
_EnumEntry( var, tstore, enumArray, defvalue );
|
|
|
|
value = (T)tstore;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2009-11-04 09:30:22 +00:00
|
|
|
virtual void _EnumEntry( const wxString& var, int& value, const wxChar* const* enumArray, int defvalue )=0;
|
2009-04-27 02:04:31 +00:00
|
|
|
};
|
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
2010-08-04 19:10:41 +00:00
|
|
|
// ScopedIniGroup
|
2010-06-06 23:26:07 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
2010-08-04 19:10:41 +00:00
|
|
|
class ScopedIniGroup
|
2009-08-21 04:44:47 +00:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
IniInterface& m_mom;
|
|
|
|
|
|
|
|
public:
|
2010-08-04 19:10:41 +00:00
|
|
|
ScopedIniGroup( IniInterface& mommy, const wxString& group );
|
|
|
|
virtual ~ScopedIniGroup();
|
2009-08-21 04:44:47 +00:00
|
|
|
};
|
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// IniLoader
|
|
|
|
// --------------------------------------------------------------------------------------
|
2009-04-27 02:04:31 +00:00
|
|
|
// Implementation of the IniInterface base class, which maps ini actions to loading from
|
|
|
|
// an ini source file.
|
|
|
|
//
|
|
|
|
// See also: IniInterface
|
|
|
|
//
|
|
|
|
class IniLoader : public IniInterface
|
|
|
|
{
|
|
|
|
public:
|
2010-01-08 07:11:33 +00:00
|
|
|
virtual ~IniLoader() throw();
|
2009-04-27 02:04:31 +00:00
|
|
|
explicit IniLoader();
|
|
|
|
explicit IniLoader( wxConfigBase& config );
|
2010-06-06 23:26:07 +00:00
|
|
|
explicit IniLoader( wxConfigBase* config );
|
2009-04-27 02:04:31 +00:00
|
|
|
|
2009-07-04 20:53:05 +00:00
|
|
|
bool IsLoading() const { return true; }
|
|
|
|
|
2011-01-04 22:49:58 +00:00
|
|
|
void Entry( const wxString& var, wxString& value, const wxString defvalue=wxEmptyString );
|
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
|
|
|
void Entry( const wxString& var, wxDirName& value, const wxDirName defvalue=wxDirName(), bool isAllowRelative=false );
|
2011-03-26 07:02:46 +00:00
|
|
|
void Entry( const wxString& var, wxFileName& value, const wxFileName defvalue=wxFileName(), bool isAllowRelative=false );
|
2009-04-27 02:04:31 +00:00
|
|
|
void Entry( const wxString& var, int& value, const int defvalue=0 );
|
|
|
|
void Entry( const wxString& var, uint& value, const uint defvalue=0 );
|
|
|
|
void Entry( const wxString& var, bool& value, const bool defvalue=false );
|
|
|
|
|
2009-07-23 02:11:45 +00:00
|
|
|
bool EntryBitBool( const wxString& var, bool value, const bool defvalue=false );
|
|
|
|
int EntryBitfield( const wxString& var, int value, const int defvalue=0 );
|
2009-07-20 00:39:38 +00:00
|
|
|
|
2011-01-04 22:49:58 +00:00
|
|
|
void Entry( const wxString& var, Fixed100& value, const Fixed100 defvalue=Fixed100() );
|
2009-12-03 15:51:39 +00:00
|
|
|
|
2011-01-04 22:49:58 +00:00
|
|
|
void Entry( const wxString& var, wxPoint& value, const wxPoint defvalue=wxDefaultPosition );
|
|
|
|
void Entry( const wxString& var, wxSize& value, const wxSize defvalue=wxDefaultSize );
|
|
|
|
void Entry( const wxString& var, wxRect& value, const wxRect defvalue=wxDefaultRect );
|
2009-04-27 02:04:31 +00:00
|
|
|
|
2009-07-23 02:11:45 +00:00
|
|
|
protected:
|
2009-11-04 09:30:22 +00:00
|
|
|
void _EnumEntry( const wxString& var, int& value, const wxChar* const* enumArray, int defvalue );
|
2009-04-27 02:04:31 +00:00
|
|
|
};
|
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// IniSaver
|
|
|
|
// --------------------------------------------------------------------------------------
|
2009-04-27 02:04:31 +00:00
|
|
|
// Implementation of the IniInterface base class, which maps ini actions to saving to
|
|
|
|
// an ini dest file.
|
|
|
|
//
|
|
|
|
// See also: IniInterface
|
|
|
|
//
|
|
|
|
class IniSaver : public IniInterface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~IniSaver();
|
|
|
|
explicit IniSaver();
|
|
|
|
explicit IniSaver( wxConfigBase& config );
|
2010-06-06 23:26:07 +00:00
|
|
|
explicit IniSaver( wxConfigBase* config );
|
2009-04-27 02:04:31 +00:00
|
|
|
|
2009-07-04 20:53:05 +00:00
|
|
|
bool IsLoading() const { return false; }
|
|
|
|
|
2011-01-04 22:49:58 +00:00
|
|
|
void Entry( const wxString& var, wxString& value, const wxString defvalue=wxString() );
|
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
|
|
|
void Entry( const wxString& var, wxDirName& value, const wxDirName defvalue=wxDirName(), bool isAllowRelative=false );
|
2011-03-26 07:02:46 +00:00
|
|
|
void Entry( const wxString& var, wxFileName& value, const wxFileName defvalue=wxFileName(), bool isAllowRelative=false );
|
2009-04-27 02:04:31 +00:00
|
|
|
void Entry( const wxString& var, int& value, const int defvalue=0 );
|
|
|
|
void Entry( const wxString& var, uint& value, const uint defvalue=0 );
|
|
|
|
void Entry( const wxString& var, bool& value, const bool defvalue=false );
|
|
|
|
|
2009-07-23 02:11:45 +00:00
|
|
|
bool EntryBitBool( const wxString& var, bool value, const bool defvalue=false );
|
|
|
|
int EntryBitfield( const wxString& var, int value, const int defvalue=0 );
|
2009-07-20 00:39:38 +00:00
|
|
|
|
2011-01-04 22:49:58 +00:00
|
|
|
void Entry( const wxString& var, Fixed100& value, const Fixed100 defvalue=Fixed100() );
|
2009-12-03 15:51:39 +00:00
|
|
|
|
2011-01-04 22:49:58 +00:00
|
|
|
void Entry( const wxString& var, wxPoint& value, const wxPoint defvalue=wxDefaultPosition );
|
|
|
|
void Entry( const wxString& var, wxSize& value, const wxSize defvalue=wxDefaultSize );
|
|
|
|
void Entry( const wxString& var, wxRect& value, const wxRect defvalue=wxDefaultRect );
|
2009-04-27 02:04:31 +00:00
|
|
|
|
2009-07-23 02:11:45 +00:00
|
|
|
protected:
|
2009-11-04 09:30:22 +00:00
|
|
|
void _EnumEntry( const wxString& var, int& value, const wxChar* const* enumArray, int defvalue );
|
2009-04-27 02:04:31 +00:00
|
|
|
};
|
2009-07-07 20:53:32 +00:00
|
|
|
|
2009-08-04 08:21:10 +00:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
// GCC Note: wxT() macro is required when using string token pasting. For some reason L generates
|
|
|
|
// syntax errors. >_<
|
|
|
|
//
|
2011-01-04 22:49:58 +00:00
|
|
|
#define IniEntry( varname ) ini.Entry( wxT(#varname), varname, varname )
|
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
|
|
|
#define IniEntryDirFile( varname, isAllowRelative ) ini.Entry( wxT(#varname), varname, varname, isAllowRelative )
|
2011-01-04 22:49:58 +00:00
|
|
|
#define IniBitfield( varname ) varname = ini.EntryBitfield( wxT(#varname), varname, varname )
|
|
|
|
#define IniBitBool( varname ) varname = ini.EntryBitBool( wxT(#varname), !!varname, varname )
|
2009-11-02 07:00:59 +00:00
|
|
|
|
2011-01-04 22:49:58 +00:00
|
|
|
#define IniBitfieldEx( varname, textname ) varname = ini.EntryBitfield( wxT(textname), varname, varname )
|
|
|
|
#define IniBitBoolEx( varname, textname ) varname = ini.EntryBitBool( wxT(textname), !!varname, varname )
|
2011-03-26 07:02:46 +00:00
|
|
|
|
|
|
|
//used for filenames and folder names as ini values.
|
|
|
|
//Set to app root folder, so all files and folders which are inside appRoot will be written as relative.
|
|
|
|
void SetFullBaseDir( wxDirName appRoot );
|