Project64: In ini handling change SectionList from vector to set

This commit is contained in:
zilmar 2020-10-12 16:51:23 +10:30
parent f5c2c33149
commit 7e503dc192
6 changed files with 43 additions and 54 deletions

View File

@ -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);
}
}

View File

@ -10,14 +10,15 @@
#include <map>
#include <vector>
#include <list>
#include <set>
#include <memory>
class CIniFileBase
{
public:
typedef std::map<std::string, std::string> KeyValueData;
typedef std::vector<std::string> SectionList;
typedef std::list<std::string> strlist;
typedef std::set<std::string> SectionList;
typedef std::list<std::string> strlist;
typedef std::pair<const std::string *, const std::string *> KeyValueItem;
typedef std::vector<KeyValueItem> KeyValueVector;
typedef void(*SortData)(KeyValueVector &);
@ -68,7 +69,7 @@ private:
typedef std::map<std::string, long> FILELOC;
typedef FILELOC::iterator FILELOC_ITR;
typedef std::map<std::string, std::string, insensitive_compare> KeyValueList;
std::string m_CurrentSection;
bool m_CurrentSectionDirty;
int m_CurrentSectionFilePos; // Where in the file is the current Section

View File

@ -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++)

View File

@ -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) ||

View File

@ -118,10 +118,8 @@
<ClCompile Include="UserInterface\WTLControls\wtl-BitmapPicture.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="DiscordRPC.h" />
<ClInclude Include="UserInterface\Debugger\CPULog.h" />
<ClInclude Include="UserInterface\Debugger\Debugger-CPULogView.h" />
<ClInclude Include="N64System\Debugger\OpInfo.h" />
<ClInclude Include="N64System.h" />
<ClInclude Include="Settings\GuiSettings.h" />
<ClInclude Include="Settings\NotificationSettings.h" />
@ -157,7 +155,6 @@
<ClInclude Include="UserInterface\Debugger\ScriptHook.h" />
<ClInclude Include="UserInterface\Debugger\ScriptInstance.h" />
<ClInclude Include="UserInterface\Debugger\ScriptSystem.h" />
<ClInclude Include="UserInterface\Debugger\stdafx.h" />
<ClInclude Include="UserInterface\Debugger\Symbols.h" />
<ClInclude Include="UserInterface\EnhancementConfig.h" />
<ClInclude Include="UserInterface\MainWindow.h" />

View File

@ -353,9 +353,6 @@
<ClInclude Include="UserInterface\SupportWindow.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="N64System\Debugger\OpInfo.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="UserInterface\WTLControls\TooltipDialog.h">
<Filter>Header Files\User Interface Headers\WTL Controls Headers</Filter>
</ClInclude>
@ -428,9 +425,6 @@
<ClInclude Include="UserInterface\Debugger\ScriptSystem.h">
<Filter>Header Files\User Interface Headers\Debugger Headers</Filter>
</ClInclude>
<ClInclude Include="UserInterface\Debugger\stdafx.h">
<Filter>Header Files\User Interface Headers\Debugger Headers</Filter>
</ClInclude>
<ClInclude Include="UserInterface\Debugger\Symbols.h">
<Filter>Header Files\User Interface Headers\Debugger Headers</Filter>
</ClInclude>
@ -461,9 +455,6 @@
<ClInclude Include="UserInterface\Settings\SettingsPage-DiskDrive.h">
<Filter>Header Files\User Interface Headers\Settings Header</Filter>
</ClInclude>
<ClInclude Include="DiscordRPC.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="UserInterface\WTLControls\HexEditCtrl.h">
<Filter>Header Files\User Interface Headers\WTL Controls Headers</Filter>
</ClInclude>