Merge pull request #5127 from lioncash/gcode

GeckoCodeConfig: Minor changes
This commit is contained in:
Matthew Parlane
2017-03-23 07:13:45 +13:00
committed by GitHub

View File

@ -79,14 +79,15 @@ std::vector<GeckoCode> LoadCodes(const IniFile& globalIni, const IniFile& localI
for (const std::string& line : lines) for (const std::string& line : lines)
{ {
if (line.size() == 0 || line[0] != '$') if (line.empty() || line[0] != '$')
{ {
continue; continue;
} }
std::string name = line.substr(1);
for (GeckoCode& ogcode : gcodes) for (GeckoCode& ogcode : gcodes)
{ {
if (ogcode.name == name) // Exclude the initial '$' from the comparison.
if (line.compare(1, std::string::npos, ogcode.name) == 0)
{ {
ogcode.enabled = true; ogcode.enabled = true;
} }
@ -97,44 +98,39 @@ std::vector<GeckoCode> LoadCodes(const IniFile& globalIni, const IniFile& localI
return gcodes; return gcodes;
} }
static std::string MakeGeckoCodeTitle(const GeckoCode& code)
{
std::string title = '$' + code.name;
if (!code.creator.empty())
{
title += " [" + code.creator + ']';
}
return title;
}
// used by the SaveGeckoCodes function // used by the SaveGeckoCodes function
static void SaveGeckoCode(std::vector<std::string>& lines, std::vector<std::string>& enabledLines, static void SaveGeckoCode(std::vector<std::string>& lines, std::vector<std::string>& enabledLines,
const GeckoCode& gcode) const GeckoCode& gcode)
{ {
if (gcode.enabled) if (gcode.enabled)
enabledLines.push_back("$" + gcode.name); enabledLines.push_back('$' + gcode.name);
if (!gcode.user_defined) if (!gcode.user_defined)
return; return;
std::string name; lines.push_back(MakeGeckoCodeTitle(gcode));
// save the name
name += '$';
name += gcode.name;
// save the creator name
if (gcode.creator.size())
{
name += " [";
name += gcode.creator;
name += ']';
}
lines.push_back(name);
// save all the code lines // save all the code lines
for (const GeckoCode::Code& code : gcode.codes) for (const GeckoCode::Code& code : gcode.codes)
{ {
// ss << std::hex << codes_iter->address << ' ' << codes_iter->data;
// lines.push_back(StringFromFormat("%08X %08X", codes_iter->address, codes_iter->data));
lines.push_back(code.original_line); lines.push_back(code.original_line);
// ss.clear();
} }
// save the notes // save the notes
for (const std::string& note : gcode.notes) for (const std::string& note : gcode.notes)
lines.push_back(std::string("*") + note); lines.push_back('*' + note);
} }
void SaveCodes(IniFile& inifile, const std::vector<GeckoCode>& gcodes) void SaveCodes(IniFile& inifile, const std::vector<GeckoCode>& gcodes)