From 7e503dc1923b58586855beac88302017e6ad8dd4 Mon Sep 17 00:00:00 2001 From: zilmar Date: Mon, 12 Oct 2020 16:51:23 +1030 Subject: [PATCH] Project64: In ini handling change SectionList from vector to set --- Source/Common/IniFileClass.cpp | 10 +++--- Source/Common/IniFileClass.h | 7 ++-- Source/JoinSettings/main.cpp | 32 ++++++++--------- .../SettingType/SettingsType-Application.cpp | 36 +++++++++---------- Source/Project64/Project64.vcxproj | 3 -- Source/Project64/Project64.vcxproj.filters | 9 ----- 6 files changed, 43 insertions(+), 54 deletions(-) diff --git a/Source/Common/IniFileClass.cpp b/Source/Common/IniFileClass.cpp index 724341ed6..2430aa88b 100644 --- a/Source/Common/IniFileClass.cpp +++ b/Source/Common/IniFileClass.cpp @@ -497,7 +497,7 @@ bool CIniFileBase::DeleteSection(const char * lpSectionName) CGuard Guard(m_CS); if (!m_File.IsOpen()) { return false; } - + SaveCurrentSection(); if (!MoveToSectionNameData(lpSectionName, true)) { @@ -517,10 +517,10 @@ bool CIniFileBase::DeleteSection(const char * lpSectionName) if (result <= 1) { continue; } if (strlen(CleanLine(Input)) <= 1) { continue; } - if (Input[0] != '[') - { + if (Input[0] != '[') + { NextLine = (m_File.GetPosition() - DataSize) + ReadPos; - continue; + continue; } NextSectionStart = NextLine != 0 ? NextLine : (m_File.GetPosition() - DataSize) + ReadPos; break; @@ -869,7 +869,7 @@ void CIniFileBase::GetVectorOfSections(SectionList & sections) for (FILELOC::const_iterator iter = m_SectionsPos.begin(); iter != m_SectionsPos.end(); iter++) { - sections.push_back(iter->first); + sections.insert(iter->first); } } diff --git a/Source/Common/IniFileClass.h b/Source/Common/IniFileClass.h index d8c1adc90..5f8e5fd39 100644 --- a/Source/Common/IniFileClass.h +++ b/Source/Common/IniFileClass.h @@ -10,14 +10,15 @@ #include #include #include +#include #include class CIniFileBase { public: typedef std::map KeyValueData; - typedef std::vector SectionList; - typedef std::list strlist; + typedef std::set SectionList; + typedef std::list strlist; typedef std::pair KeyValueItem; typedef std::vector KeyValueVector; typedef void(*SortData)(KeyValueVector &); @@ -68,7 +69,7 @@ private: typedef std::map FILELOC; typedef FILELOC::iterator FILELOC_ITR; typedef std::map KeyValueList; - + std::string m_CurrentSection; bool m_CurrentSectionDirty; int m_CurrentSectionFilePos; // Where in the file is the current Section diff --git a/Source/JoinSettings/main.cpp b/Source/JoinSettings/main.cpp index 1ae778419..9eb1fa7d3 100644 --- a/Source/JoinSettings/main.cpp +++ b/Source/JoinSettings/main.cpp @@ -70,9 +70,9 @@ void SplitFile(const char * FileName, const char * Target) CIniFile CheatIniFile(FileName); CheatIniFile.GetVectorOfSections(Sections); - for (size_t i = 0, n = Sections.size(); i < n; i++) + for (CIniFile::SectionList::const_iterator SectionItr = Sections.begin(); SectionItr != Sections.end(); SectionItr++) { - const char * Section = Sections[i].c_str(); + const char * Section = SectionItr->c_str(); CIniFile::KeyValueData data; CheatIniFile.GetKeyValueData(Section, data); @@ -136,9 +136,9 @@ void RegionSection(CFile &TargetIniFile, Files &files, const char * Region, cons bool found = false; stdstr_f searchStr(":%s", RegionCode); - for (size_t i = 0, n = Sections.size(); i < n; i++) + for (CIniFile::SectionList::const_iterator SectionItr = Sections.begin(); SectionItr != Sections.end(); SectionItr++) { - const char * Section = Sections[i].c_str(); + const char * Section = SectionItr->c_str(); const char * pos = strstr(Section, searchStr.c_str()); if (pos == NULL) { @@ -147,15 +147,15 @@ void RegionSection(CFile &TargetIniFile, Files &files, const char * Region, cons found = true; break; } - + if (!found) { continue; } - for (size_t i = 0, n = Sections.size(); i < n; i++) + for (CIniFile::SectionList::const_iterator SectionItr = Sections.begin(); SectionItr != Sections.end(); SectionItr++) { - const char * Section = Sections[i].c_str(); + const char * Section = SectionItr->c_str(); CIniFile::KeyValueData data; GameIniFile.GetKeyValueData(Section, data); @@ -200,9 +200,9 @@ void JoinFile(const char * Directory, const char * Target) CIniFile::SectionList Sections; GameIniFile.GetVectorOfSections(Sections); - for (size_t i = 0, n = Sections.size(); i < n; i++) + for (CIniFile::SectionList::const_iterator SectionItr = Sections.begin(); SectionItr != Sections.end(); SectionItr++) { - const char * Section = Sections[i].c_str(); + const char * Section = SectionItr->c_str(); stdstr Name = GameIniFile.GetString(Section, "Name", Section); Name.Trim("\t ="); if (Name.size() > 0) @@ -239,7 +239,7 @@ void JoinFile(const char * Directory, const char * Target) { CIniFile::KeyValueData data; MetaIniFile.GetKeyValueData("Meta", data); - + LineData = stdstr_f("[Meta]\r\n"); TargetIniFile.Write(LineData.c_str(), (int)LineData.length()); for (CIniFile::KeyValueData::const_iterator itr = data.begin(); itr != data.end(); itr++) @@ -282,9 +282,9 @@ void UpdateNames(const char* Directory, const char* RdbFile) CIniFile::SectionList Sections; CheatFile.GetVectorOfSections(Sections); CheatFile.SetCustomSort(CustomSortData); - for (size_t i = 0, n = Sections.size(); i < n; i++) + for (CIniFile::SectionList::const_iterator SectionItr = Sections.begin(); SectionItr != Sections.end(); SectionItr++) { - const char * Section = Sections[i].c_str(); + const char * Section = SectionItr->c_str(); std::string Name = RdbIni.GetString(Section, "Good Name", ""); if (Name.empty()) { @@ -616,9 +616,9 @@ void convertGS(const char* Directory) CIniFile::SectionList Sections; CheatFile.GetVectorOfSections(Sections); CheatFile.SetCustomSort(CustomSortData); - for (size_t i = 0, n = Sections.size(); i < n; i++) + for (CIniFile::SectionList::const_iterator SectionItr = Sections.begin(); SectionItr != Sections.end(); SectionItr++) { - const char * Section = Sections[i].c_str(); + const char * Section = SectionItr->c_str(); for (uint32_t cheat = 0; cheat < MaxCheats; cheat++) { std::string CheatEntry = CheatFile.GetString(Section, stdstr_f("Cheat%d", cheat).c_str(), ""); @@ -846,9 +846,9 @@ void ConvertNew(const char * Src, const char * Dest) MaxCheats = 50000, }; - for (size_t i = 0, n = Sections.size(); i < n; i++) + for (CIniFile::SectionList::const_iterator SectionItr = Sections.begin(); SectionItr != Sections.end(); SectionItr++) { - const char * Section = Sections[i].c_str(); + const char * Section = SectionItr->c_str(); std::string GameName = SrcIniFile.GetString(Section, "Name", ""); DstCheatFile.SetName(Section, GameName.c_str()); for (uint32_t cheat = 0; cheat < MaxCheats; cheat++) diff --git a/Source/Project64-core/Settings/SettingType/SettingsType-Application.cpp b/Source/Project64-core/Settings/SettingType/SettingsType-Application.cpp index 0206ffe68..227aa7f06 100644 --- a/Source/Project64-core/Settings/SettingType/SettingsType-Application.cpp +++ b/Source/Project64-core/Settings/SettingType/SettingsType-Application.cpp @@ -121,9 +121,9 @@ void CSettingTypeApplication::ResetAll() } CIniFile::SectionList sections; m_SettingsIniFile->GetVectorOfSections(sections); - for (size_t i = 0; i < sections.size(); i++) + for (CIniFile::SectionList::const_iterator itr = sections.begin(); itr != sections.end(); itr++) { - m_SettingsIniFile->DeleteSection(sections[i].c_str()); + m_SettingsIniFile->DeleteSection(itr->c_str()); } } @@ -156,14 +156,14 @@ bool CSettingTypeApplication::Load(uint32_t Index, bool & Value) const } else { - if (g_Settings->IndexBasedSetting(m_DefaultSetting)) - { - g_Settings->LoadBoolIndex(m_DefaultSetting, Index, Value); - } - else - { - g_Settings->LoadBool(m_DefaultSetting, Value); - } + if (g_Settings->IndexBasedSetting(m_DefaultSetting)) + { + g_Settings->LoadBoolIndex(m_DefaultSetting, Index, Value); + } + else + { + g_Settings->LoadBool(m_DefaultSetting, Value); + } } } return bRes; @@ -203,13 +203,13 @@ void CSettingTypeApplication::LoadDefault(uint32_t Index, bool & Value) const { Value = m_DefaultValue != 0; } - else if (g_Settings->IndexBasedSetting(m_DefaultSetting)) - { - g_Settings->LoadBoolIndex(m_DefaultSetting, Index, Value); - } - else - { - g_Settings->LoadBool(m_DefaultSetting, Value); + else if (g_Settings->IndexBasedSetting(m_DefaultSetting)) + { + g_Settings->LoadBoolIndex(m_DefaultSetting, Index, Value); + } + else + { + g_Settings->LoadBool(m_DefaultSetting, Value); } } } @@ -233,7 +233,7 @@ void CSettingTypeApplication::LoadDefault(uint32_t /*Index*/, std::string & Valu //Update the settings void CSettingTypeApplication::Save(uint32_t Index, bool Value) { - bool indexed = g_Settings->IndexBasedSetting(m_DefaultSetting); + bool indexed = g_Settings->IndexBasedSetting(m_DefaultSetting); if (m_DefaultSetting != Default_None && ((m_DefaultSetting == Default_Constant && m_DefaultValue == (uint32_t)Value) || diff --git a/Source/Project64/Project64.vcxproj b/Source/Project64/Project64.vcxproj index cfaf32fad..1e9afd451 100644 --- a/Source/Project64/Project64.vcxproj +++ b/Source/Project64/Project64.vcxproj @@ -118,10 +118,8 @@ - - @@ -157,7 +155,6 @@ - diff --git a/Source/Project64/Project64.vcxproj.filters b/Source/Project64/Project64.vcxproj.filters index d436f28fe..687fd4bcf 100644 --- a/Source/Project64/Project64.vcxproj.filters +++ b/Source/Project64/Project64.vcxproj.filters @@ -353,9 +353,6 @@ Header Files - - Header Files - Header Files\User Interface Headers\WTL Controls Headers @@ -428,9 +425,6 @@ Header Files\User Interface Headers\Debugger Headers - - Header Files\User Interface Headers\Debugger Headers - Header Files\User Interface Headers\Debugger Headers @@ -461,9 +455,6 @@ Header Files\User Interface Headers\Settings Header - - Header Files - Header Files\User Interface Headers\WTL Controls Headers