[Project64] Clean up some code related to Settings Type files

This commit is contained in:
zilmar 2016-01-18 22:27:25 +11:00
parent 821922f133
commit 0f57b5d42e
16 changed files with 116 additions and 47 deletions

View File

@ -60,6 +60,13 @@ CSettingTypeApplication::~CSettingTypeApplication()
void CSettingTypeApplication::Initialize( const char * /*AppName*/ ) void CSettingTypeApplication::Initialize( const char * /*AppName*/ )
{ {
CPath BaseDir(g_Settings->LoadStringVal(Cmd_BaseDirectory).c_str(),"");
if (!BaseDir.DirectoryExists())
{
printf("BaseDir does not exists, doing nothing");
return;
}
stdstr SettingsFile, OrigSettingsFile; stdstr SettingsFile, OrigSettingsFile;
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
@ -77,7 +84,11 @@ void CSettingTypeApplication::Initialize( const char * /*AppName*/ )
{ {
delete m_SettingsIniFile; delete m_SettingsIniFile;
} }
#ifdef _WIN32
CPath SettingsDir(CPath(SettingsFile).GetDriveDirectory(),""); CPath SettingsDir(CPath(SettingsFile).GetDriveDirectory(),"");
#else
CPath SettingsDir(CPath(SettingsFile).GetDirectory(), "");
#endif
if (!SettingsDir.DirectoryExists()) if (!SettingsDir.DirectoryExists())
{ {
SettingsDir.DirectoryCreate(); SettingsDir.DirectoryCreate();
@ -123,7 +134,9 @@ bool CSettingTypeApplication::Load ( int /*Index*/, bool & Value ) const
if (m_DefaultSetting == Default_Constant) if (m_DefaultSetting == Default_Constant)
{ {
Value = m_DefaultValue != 0; Value = m_DefaultValue != 0;
} else { }
else
{
g_Settings->LoadBool(m_DefaultSetting,Value); g_Settings->LoadBool(m_DefaultSetting,Value);
} }
} }
@ -138,7 +151,9 @@ bool CSettingTypeApplication::Load ( int /*Index*/, uint32_t & Value ) const
if (m_DefaultSetting == Default_Constant) if (m_DefaultSetting == Default_Constant)
{ {
Value = m_DefaultValue; Value = m_DefaultValue;
} else { }
else
{
g_Settings->LoadDword(m_DefaultSetting,Value); g_Settings->LoadDword(m_DefaultSetting,Value);
} }
} }
@ -168,7 +183,9 @@ void CSettingTypeApplication::LoadDefault ( int /*Index*/, bool & Value ) cons
if (m_DefaultSetting == Default_Constant) if (m_DefaultSetting == Default_Constant)
{ {
Value = m_DefaultValue != 0; Value = m_DefaultValue != 0;
} else { }
else
{
g_Settings->LoadBool(m_DefaultSetting,Value); g_Settings->LoadBool(m_DefaultSetting,Value);
} }
} }
@ -181,7 +198,9 @@ void CSettingTypeApplication::LoadDefault ( int /*Index*/, uint32_t & Value ) c
if (m_DefaultSetting == Default_Constant) if (m_DefaultSetting == Default_Constant)
{ {
Value = m_DefaultValue; Value = m_DefaultValue;
} else { }
else
{
g_Settings->LoadDword(m_DefaultSetting,Value); g_Settings->LoadDword(m_DefaultSetting,Value);
} }
} }
@ -194,7 +213,9 @@ void CSettingTypeApplication::LoadDefault ( int /*Index*/, stdstr & Value ) cons
if (m_DefaultSetting == Default_Constant) if (m_DefaultSetting == Default_Constant)
{ {
Value = m_DefaultStr; Value = m_DefaultStr;
} else { }
else
{
g_Settings->LoadStringVal(m_DefaultSetting,Value); g_Settings->LoadStringVal(m_DefaultSetting,Value);
} }
} }

View File

@ -11,7 +11,7 @@
#pragma once #pragma once
#include <Common/IniFileClass.h> #include <Common/IniFileClass.h>
#include "SettingsType-Base.h" #include <Project64-core/Settings/SettingType/SettingsType-Base.h>
class CSettingTypeApplication : class CSettingTypeApplication :
public CSettingType public CSettingType

View File

@ -26,6 +26,7 @@ CSettingTypeApplicationPath::~CSettingTypeApplicationPath()
bool CSettingTypeApplicationPath::Load ( int Index, stdstr & Value ) const bool CSettingTypeApplicationPath::Load ( int Index, stdstr & Value ) const
{ {
bool bRes = CSettingTypeApplication::Load(Index,Value); bool bRes = CSettingTypeApplication::Load(Index,Value);
#ifdef WIN32
if (bRes) if (bRes)
{ {
if (Value.substr(0,2) == ".\\" || Value.substr(0,2) == "./" || if (Value.substr(0,2) == ".\\" || Value.substr(0,2) == "./" ||
@ -38,5 +39,6 @@ bool CSettingTypeApplicationPath::Load ( int Index, stdstr & Value ) const
Value = (const std::string &)FullFilePath; Value = (const std::string &)FullFilePath;
} }
} }
#endif
return bRes; return bRes;
} }

View File

@ -10,9 +10,11 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include "../Settings.h" #include <Project64-core/Settings/Settings.h>
#include <Common/StdString.h>
enum SettingType { enum SettingType
{
SettingType_Unknown = -1, SettingType_Unknown = -1,
SettingType_ConstString = 0, SettingType_ConstString = 0,
SettingType_ConstValue = 1, SettingType_ConstValue = 1,

View File

@ -10,7 +10,7 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include "SettingsType-Base.h" #include <Project64-core/Settings/SettingType/SettingsType-Base.h>
#include <Common/IniFileClass.h> #include <Common/IniFileClass.h>
class CSettingTypeCheats : class CSettingTypeCheats :

View File

@ -11,7 +11,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "SettingsType-RomDatabase.h" #include "SettingsType-RomDatabase.h"
#include "SettingsType-RDBCpuType.h" #include "SettingsType-RDBCpuType.h"
#include "../../N64System/N64Types.h" #include <Project64-core/N64System/N64Types.h>
CSettingTypeRDBCpuType::CSettingTypeRDBCpuType(const char * Name, SettingID DefaultSetting ) : CSettingTypeRDBCpuType::CSettingTypeRDBCpuType(const char * Name, SettingID DefaultSetting ) :
CSettingTypeRomDatabase(Name,DefaultSetting) CSettingTypeRomDatabase(Name,DefaultSetting)

View File

@ -11,7 +11,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "SettingsType-RomDatabase.h" #include "SettingsType-RomDatabase.h"
#include "SettingsType-RDBSaveChip.h" #include "SettingsType-RDBSaveChip.h"
#include "../../N64System/N64Types.h" #include <Project64-core/N64System/N64Types.h>
CSettingTypeRDBSaveChip::CSettingTypeRDBSaveChip(const char * Name, SettingID DefaultSetting ) : CSettingTypeRDBSaveChip::CSettingTypeRDBSaveChip(const char * Name, SettingID DefaultSetting ) :
CSettingTypeRomDatabase(Name,DefaultSetting) CSettingTypeRomDatabase(Name,DefaultSetting)

View File

@ -11,19 +11,22 @@
#include "stdafx.h" #include "stdafx.h"
#include "SettingsType-RelativePath.h" #include "SettingsType-RelativePath.h"
CSettingTypeRelativePath::CSettingTypeRelativePath(const char * Path, const char * FileName) CSettingTypeRelativePath::CSettingTypeRelativePath(const char * Directory, const char * FileName) :
m_Directory(Directory),
m_FileName(FileName)
{ {
m_FileName = CPath(CPath::MODULE_DIRECTORY,FileName); BuildPath();
m_FileName.AppendDirectory(Path); g_Settings->RegisterChangeCB(Cmd_BaseDirectory, this, RefreshSettings);
} }
CSettingTypeRelativePath::~CSettingTypeRelativePath(void) CSettingTypeRelativePath::~CSettingTypeRelativePath(void)
{ {
g_Settings->UnregisterChangeCB(Cmd_BaseDirectory, this, RefreshSettings);
} }
bool CSettingTypeRelativePath::Load(int /*Index*/, stdstr & value) const bool CSettingTypeRelativePath::Load(int /*Index*/, stdstr & value) const
{ {
value = (const char *)m_FileName; value = m_FullPath;
return true; return true;
} }
@ -55,15 +58,32 @@ void CSettingTypeRelativePath::Save ( int /*Index*/, uint32_t /*Value*/ )
void CSettingTypeRelativePath::Save(int /*Index*/, const stdstr & Value) void CSettingTypeRelativePath::Save(int /*Index*/, const stdstr & Value)
{ {
m_FileName = CPath(CPath::MODULE_DIRECTORY,Value.c_str()); m_Directory = "";
m_FileName = Value;
BuildPath();
} }
void CSettingTypeRelativePath::Save(int /*Index*/, const char * Value) void CSettingTypeRelativePath::Save(int /*Index*/, const char * Value)
{ {
m_FileName = CPath(CPath::MODULE_DIRECTORY,Value); m_Directory = "";
m_FileName = Value;
BuildPath();
} }
void CSettingTypeRelativePath::Delete(int /*Index*/) void CSettingTypeRelativePath::Delete(int /*Index*/)
{ {
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
} }
void CSettingTypeRelativePath::BuildPath(void)
{
CPath FullPath(g_Settings->LoadStringVal(Cmd_BaseDirectory).c_str(),"");
FullPath.AppendDirectory(m_Directory.c_str());
FullPath.SetNameExtension(m_FileName.c_str());
m_FullPath = (const char *)FullPath;
}
void CSettingTypeRelativePath::RefreshSettings(void * _this)
{
((CSettingTypeRelativePath *)_this)->BuildPath();
}

View File

@ -10,15 +10,13 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include <Common/path.h> #include <Common/path.h>
#include "SettingsType-Base.h" #include <Project64-core/Settings/SettingType/SettingsType-Base.h>
class CSettingTypeRelativePath : class CSettingTypeRelativePath :
public CSettingType public CSettingType
{ {
CPath m_FileName;
public: public:
CSettingTypeRelativePath(const char * Path, const char * FileName); CSettingTypeRelativePath(const char * Directory, const char * FileName);
~CSettingTypeRelativePath(); ~CSettingTypeRelativePath();
bool IndexBasedSetting ( void ) const { return false; } bool IndexBasedSetting ( void ) const { return false; }
@ -47,4 +45,11 @@ private:
CSettingTypeRelativePath(void); // Disable default constructor CSettingTypeRelativePath(void); // Disable default constructor
CSettingTypeRelativePath(const CSettingTypeRelativePath&); // Disable copy constructor CSettingTypeRelativePath(const CSettingTypeRelativePath&); // Disable copy constructor
CSettingTypeRelativePath& operator=(const CSettingTypeRelativePath&); // Disable assignment CSettingTypeRelativePath& operator=(const CSettingTypeRelativePath&); // Disable assignment
static void RefreshSettings(void * _this);
void BuildPath ( void );
std::string m_FullPath;
std::string m_Directory;
std::string m_FileName;
}; };

View File

@ -65,12 +65,14 @@ void CSettingTypeRomDatabase::Initialize( void )
m_GlideIniFile = new CIniFile(g_Settings->LoadStringVal(SupportFile_Glide64RDB).c_str()); m_GlideIniFile = new CIniFile(g_Settings->LoadStringVal(SupportFile_Glide64RDB).c_str());
g_Settings->RegisterChangeCB(Game_IniKey,NULL,GameChanged); g_Settings->RegisterChangeCB(Game_IniKey,NULL,GameChanged);
g_Settings->RegisterChangeCB(Cmd_BaseDirectory,NULL,BaseDirChanged);
m_SectionIdent = new stdstr(g_Settings->LoadStringVal(Game_IniKey)); m_SectionIdent = new stdstr(g_Settings->LoadStringVal(Game_IniKey));
} }
void CSettingTypeRomDatabase::CleanUp( void ) void CSettingTypeRomDatabase::CleanUp( void )
{ {
g_Settings->UnregisterChangeCB(Cmd_BaseDirectory,NULL,BaseDirChanged);
g_Settings->UnregisterChangeCB(Game_IniKey,NULL,GameChanged); g_Settings->UnregisterChangeCB(Game_IniKey,NULL,GameChanged);
if (m_SettingsIniFile) if (m_SettingsIniFile)
{ {
@ -89,6 +91,22 @@ void CSettingTypeRomDatabase::CleanUp( void )
} }
} }
void CSettingTypeRomDatabase::BaseDirChanged ( void * /*Data */ )
{
if (m_SettingsIniFile)
{
delete m_SettingsIniFile;
m_SettingsIniFile = NULL;
}
if (m_GlideIniFile)
{
delete m_GlideIniFile;
m_GlideIniFile = NULL;
}
m_SettingsIniFile = new CIniFile(g_Settings->LoadStringVal(SupportFile_RomDatabase).c_str());
m_GlideIniFile = new CIniFile(g_Settings->LoadStringVal(SupportFile_Glide64RDB).c_str());
}
void CSettingTypeRomDatabase::GameChanged ( void * /*Data */ ) void CSettingTypeRomDatabase::GameChanged ( void * /*Data */ )
{ {
if (m_SectionIdent) if (m_SectionIdent)

View File

@ -11,7 +11,7 @@
#pragma once #pragma once
#include <Common/IniFileClass.h> #include <Common/IniFileClass.h>
#include "SettingsType-Base.h" #include <Project64-core/Settings/SettingType/SettingsType-Base.h>
class CSettingTypeRomDatabase : class CSettingTypeRomDatabase :
public CSettingType public CSettingType
@ -51,6 +51,7 @@ public:
protected: protected:
static void GameChanged ( void * /*Data */ ); static void GameChanged ( void * /*Data */ );
static void BaseDirChanged ( void * /*Data */ );
static bool IsGlideSetting (const char * Name); static bool IsGlideSetting (const char * Name);
static const char * StripNameSection (const char * Name); static const char * StripNameSection (const char * Name);

View File

@ -10,7 +10,7 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include "SettingsType-Base.h" #include <Project64-core/Settings/SettingType/SettingsType-Base.h>
class CSettingTypeSelectedDirectory : class CSettingTypeSelectedDirectory :
public CSettingType public CSettingType

View File

@ -10,7 +10,7 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include "SettingsType-Base.h" #include <Project64-core/Settings/SettingType/SettingsType-Base.h>
class CSettingTypeTempBool : class CSettingTypeTempBool :
public CSettingType public CSettingType

View File

@ -10,7 +10,7 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include "SettingsType-Base.h" #include <Project64-core/Settings/SettingType/SettingsType-Base.h>
class CSettingTypeTempNumber : class CSettingTypeTempNumber :
public CSettingType public CSettingType

View File

@ -10,7 +10,7 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include "SettingsType-Base.h" #include <Project64-core/Settings/SettingType/SettingsType-Base.h>
class CSettingTypeTempString : class CSettingTypeTempString :
public CSettingType public CSettingType