From 804accc0b73169ad618f25308285d1081a734240 Mon Sep 17 00:00:00 2001 From: zilmar Date: Thu, 27 Sep 2012 09:13:09 +1000 Subject: [PATCH] Add Application Path setting and change config files to able to change where they are located --- Source/Project64/Project64.vcproj | 8 +++++ Source/Project64/Settings.h | 7 +++++ .../SettingType/SettingsType-Application.cpp | 13 ++++++-- .../SettingType/SettingsType-Application.h | 2 +- .../SettingsType-ApplicationPath.cpp | 31 +++++++++++++++++++ .../SettingsType-ApplicationPath.h | 19 ++++++++++++ Source/Project64/Settings/Settings Class.cpp | 28 +++++++++++------ 7 files changed, 95 insertions(+), 13 deletions(-) create mode 100644 Source/Project64/Settings/SettingType/SettingsType-ApplicationPath.cpp create mode 100644 Source/Project64/Settings/SettingType/SettingsType-ApplicationPath.h diff --git a/Source/Project64/Project64.vcproj b/Source/Project64/Project64.vcproj index 763345a80..203b543e1 100644 --- a/Source/Project64/Project64.vcproj +++ b/Source/Project64/Project64.vcproj @@ -270,6 +270,10 @@ RelativePath="Settings\SettingType\SettingsType-ApplicationIndex.cpp" > + + @@ -983,6 +987,10 @@ RelativePath="Settings\SettingType\SettingsType-ApplicationIndex.h" > + + diff --git a/Source/Project64/Settings.h b/Source/Project64/Settings.h index a2d8012db..6e14fd875 100644 --- a/Source/Project64/Settings.h +++ b/Source/Project64/Settings.h @@ -15,12 +15,19 @@ enum SettingID { SupportFile_Settings, SupportFile_SettingsDefault, SupportFile_RomDatabase, + SupportFile_RomDatabaseDefault, SupportFile_Cheats, + SupportFile_CheatsDefault, SupportFile_Notes, + SupportFile_NotesDefault, SupportFile_ExtInfo, + SupportFile_ExtInfoDefault, SupportFile_ShortCuts, + SupportFile_ShortCutsDefault, SupportFile_RomListCache, + SupportFile_RomListCacheDefault, SupportFile_7zipCache, + SupportFile_7zipCacheDefault, //Settings Setting_ApplicationName, diff --git a/Source/Project64/Settings/SettingType/SettingsType-Application.cpp b/Source/Project64/Settings/SettingType/SettingsType-Application.cpp index 824b6d65a..99f0dd033 100644 --- a/Source/Project64/Settings/SettingType/SettingsType-Application.cpp +++ b/Source/Project64/Settings/SettingType/SettingsType-Application.cpp @@ -56,7 +56,10 @@ void CSettingTypeApplication::Initilize( const char * AppName ) for (int i = 0; i < 100; i++) { OrigSettingsFile = SettingsFile; - SettingsFile = _Settings->LoadString(SupportFile_Settings); + if (!_Settings->LoadString(SupportFile_Settings,SettingsFile) && i > 0) + { + break; + } if (SettingsFile == OrigSettingsFile) { break; @@ -65,8 +68,14 @@ void CSettingTypeApplication::Initilize( const char * AppName ) { delete m_SettingsIniFile; } + CPath SettingsDir(CPath(SettingsFile).GetDriveDirectory(),""); + if (!SettingsDir.DirectoryExists()) + { + SettingsDir.CreateDirectory(); + } + m_SettingsIniFile = new CIniFile(SettingsFile.c_str()); - } while (SettingsFile != OrigSettingsFile); + } m_SettingsIniFile->SetAutoFlush(false); m_UseRegistry = _Settings->LoadBool(Setting_UseFromRegistry); diff --git a/Source/Project64/Settings/SettingType/SettingsType-Application.h b/Source/Project64/Settings/SettingType/SettingsType-Application.h index 14d49cf88..b4003fe76 100644 --- a/Source/Project64/Settings/SettingType/SettingsType-Application.h +++ b/Source/Project64/Settings/SettingType/SettingsType-Application.h @@ -24,7 +24,7 @@ public: CSettingTypeApplication(LPCSTR Section, LPCSTR Name, bool DefaultValue ); CSettingTypeApplication(LPCSTR Section, LPCSTR Name, DWORD DefaultValue ); CSettingTypeApplication(LPCSTR Section, LPCSTR Name, SettingID DefaultSetting ); - ~CSettingTypeApplication(); + virtual ~CSettingTypeApplication(); virtual bool IndexBasedSetting ( void ) const { return false; } virtual SettingType GetSettingType ( void ) const { return m_UseRegistry ? SettingType_Registry : SettingType_CfgFile; } diff --git a/Source/Project64/Settings/SettingType/SettingsType-ApplicationPath.cpp b/Source/Project64/Settings/SettingType/SettingsType-ApplicationPath.cpp new file mode 100644 index 000000000..b92e0466d --- /dev/null +++ b/Source/Project64/Settings/SettingType/SettingsType-ApplicationPath.cpp @@ -0,0 +1,31 @@ +#include "stdafx.h" +#include "SettingsType-Application.h" +#include "SettingsType-ApplicationPath.h" + +CSettingTypeApplicationPath::CSettingTypeApplicationPath(LPCSTR Section, LPCSTR Name, SettingID DefaultSetting ) : + CSettingTypeApplication(Section,Name,DefaultSetting) +{ + +} + +CSettingTypeApplicationPath::~CSettingTypeApplicationPath() +{ +} + +bool CSettingTypeApplicationPath::Load ( int Index, stdstr & Value ) const +{ + bool bRes = CSettingTypeApplication::Load(Index,Value); + if (bRes) + { + if (Value.substr(0,2) == ".\\" || Value.substr(0,2) == "./" || + Value.substr(0,3) == "..\\" || Value.substr(0,3) == "../") + { + CPath FullFilePath(CPath::MODULE_DIRECTORY), RelativePath(Value); + FullFilePath.SetNameExtension(RelativePath.GetNameExtension().c_str()); + FullFilePath.AppendDirectory(RelativePath.GetDirectory().c_str()); + + Value = FullFilePath; + } + } + return bRes; +} diff --git a/Source/Project64/Settings/SettingType/SettingsType-ApplicationPath.h b/Source/Project64/Settings/SettingType/SettingsType-ApplicationPath.h new file mode 100644 index 000000000..257cf26f2 --- /dev/null +++ b/Source/Project64/Settings/SettingType/SettingsType-ApplicationPath.h @@ -0,0 +1,19 @@ +#pragma once + +class CSettingTypeApplicationPath : + public CSettingTypeApplication +{ +private: + CSettingTypeApplicationPath(LPCSTR Section, LPCSTR Name, LPCSTR DefaultValue ); + CSettingTypeApplicationPath(LPCSTR Section, LPCSTR Name, bool DefaultValue ); + CSettingTypeApplicationPath(LPCSTR Section, LPCSTR Name, DWORD DefaultValue ); + +public: + virtual ~CSettingTypeApplicationPath(); + + CSettingTypeApplicationPath(LPCSTR Section, LPCSTR Name, SettingID DefaultSetting ); + + //return the values + virtual bool Load ( int Index, stdstr & Value ) const; +}; + diff --git a/Source/Project64/Settings/Settings Class.cpp b/Source/Project64/Settings/Settings Class.cpp index 6cd8dccff..458f42c3b 100644 --- a/Source/Project64/Settings/Settings Class.cpp +++ b/Source/Project64/Settings/Settings Class.cpp @@ -1,6 +1,7 @@ #include "stdafx.h" #include "SettingType/SettingsType-Application.h" +#include "SettingType/SettingsType-ApplicationPath.h" #include "SettingType/SettingsType-ApplicationIndex.h" #include "SettingType/SettingsType-Cheats.h" #include "SettingType/SettingsType-GameSetting.h" @@ -65,16 +66,23 @@ void CSettings::AddHowToHandleSetting () //Support Files - AddHandler(SupportFile_SettingsDefault, new CSettingTypeRelativePath("Config","Project64.cfg")); - AddHandler(SupportFile_Settings, new CSettingTypeApplication("","ConfigFile",SupportFile_SettingsDefault)); - AddHandler(SupportFile_SettingsDefault, new CSettingTypeRelativePath("Config","Project64.cfg")); - AddHandler(SupportFile_RomDatabase, new CSettingTypeRelativePath("Config","Project64.rdb")); - AddHandler(SupportFile_Cheats, new CSettingTypeRelativePath("Config","Project64.cht")); - AddHandler(SupportFile_Notes, new CSettingTypeRelativePath("Config","Project64.rdn")); - AddHandler(SupportFile_ExtInfo, new CSettingTypeRelativePath("Config","Project64.rdx")); - AddHandler(SupportFile_ShortCuts, new CSettingTypeRelativePath("Config","Project64.sc3")); - AddHandler(SupportFile_RomListCache,new CSettingTypeRelativePath("Config","Project64.cache3")); - AddHandler(SupportFile_7zipCache, new CSettingTypeRelativePath("Config","Project64.zcache")); + AddHandler(SupportFile_SettingsDefault, new CSettingTypeRelativePath("Config","Project64.cfg")); + AddHandler(SupportFile_Settings, new CSettingTypeApplicationPath("","ConfigFile",SupportFile_SettingsDefault)); + AddHandler(SupportFile_SettingsDefault, new CSettingTypeRelativePath("Config","Project64.cfg")); + AddHandler(SupportFile_RomDatabase, new CSettingTypeApplicationPath("","RomDatabase",SupportFile_RomDatabaseDefault)); + AddHandler(SupportFile_RomDatabaseDefault, new CSettingTypeRelativePath("Config","Project64.rdb")); + AddHandler(SupportFile_Cheats, new CSettingTypeApplicationPath("","Cheats",SupportFile_CheatsDefault)); + AddHandler(SupportFile_CheatsDefault, new CSettingTypeRelativePath("Config","Project64.cht")); + AddHandler(SupportFile_Notes, new CSettingTypeApplicationPath("","Notes",SupportFile_NotesDefault)); + AddHandler(SupportFile_NotesDefault, new CSettingTypeRelativePath("Config","Project64.rdn")); + AddHandler(SupportFile_ExtInfo, new CSettingTypeApplicationPath("","ExtInfo",SupportFile_ExtInfoDefault)); + AddHandler(SupportFile_ExtInfoDefault, new CSettingTypeRelativePath("Config","Project64.rdx")); + AddHandler(SupportFile_ShortCuts, new CSettingTypeApplicationPath("","ShortCuts",SupportFile_ShortCutsDefault)); + AddHandler(SupportFile_ShortCutsDefault, new CSettingTypeRelativePath("Config","Project64.sc3")); + AddHandler(SupportFile_RomListCache, new CSettingTypeApplicationPath("","RomListCache",SupportFile_ShortCutsDefault)); + AddHandler(SupportFile_RomListCacheDefault,new CSettingTypeRelativePath("Config","Project64.cache3")); + AddHandler(SupportFile_7zipCache, new CSettingTypeApplicationPath("","7zipCache",SupportFile_7zipCacheDefault)); + AddHandler(SupportFile_7zipCacheDefault, new CSettingTypeRelativePath("Config","Project64.zcache")); //AddHandler(SyncPluginDir, new CSettingTypeRelativePath("SyncPlugin",""));