Merge pull request #50 from Parlane/inifile_tidy

Fix IniFile to use string& instead of char*
This commit is contained in:
Matthew Parlane 2014-02-13 19:04:27 +13:00
commit 88526be3b5
17 changed files with 205 additions and 218 deletions

View File

@ -37,7 +37,9 @@ void ParseLine(const std::string& line, std::string* keyOut, std::string* valueO
}
void IniFile::Section::Set(const char* key, const char* newValue)
const std::string& IniFile::NULL_STRING = "";
void IniFile::Section::Set(const std::string& key, const std::string& newValue)
{
auto it = values.find(key);
if (it != values.end())
@ -49,7 +51,7 @@ void IniFile::Section::Set(const char* key, const char* newValue)
}
}
void IniFile::Section::Set(const char* key, const std::string& newValue, const std::string& defaultValue)
void IniFile::Section::Set(const std::string& key, const std::string& newValue, const std::string& defaultValue)
{
if (newValue != defaultValue)
Set(key, newValue);
@ -57,7 +59,7 @@ void IniFile::Section::Set(const char* key, const std::string& newValue, const s
Delete(key);
}
void IniFile::Section::Set(const char* key, const float newValue, const float defaultValue)
void IniFile::Section::Set(const std::string& key, const float newValue, const float defaultValue)
{
if (newValue != defaultValue)
Set(key, newValue);
@ -65,7 +67,7 @@ void IniFile::Section::Set(const char* key, const float newValue, const float de
Delete(key);
}
void IniFile::Section::Set(const char* key, int newValue, int defaultValue)
void IniFile::Section::Set(const std::string& key, int newValue, int defaultValue)
{
if (newValue != defaultValue)
Set(key, newValue);
@ -73,7 +75,7 @@ void IniFile::Section::Set(const char* key, int newValue, int defaultValue)
Delete(key);
}
void IniFile::Section::Set(const char* key, bool newValue, bool defaultValue)
void IniFile::Section::Set(const std::string& key, bool newValue, bool defaultValue)
{
if (newValue != defaultValue)
Set(key, newValue);
@ -81,7 +83,7 @@ void IniFile::Section::Set(const char* key, bool newValue, bool defaultValue)
Delete(key);
}
void IniFile::Section::Set(const char* key, const std::vector<std::string>& newValues)
void IniFile::Section::Set(const std::string& key, const std::vector<std::string>& newValues)
{
std::string temp;
// Join the strings with ,
@ -92,10 +94,10 @@ void IniFile::Section::Set(const char* key, const std::vector<std::string>& newV
}
// remove last ,
temp.resize(temp.length() - 1);
Set(key, temp.c_str());
Set(key, temp);
}
bool IniFile::Section::Get(const char* key, std::string* value, const char* defaultValue)
bool IniFile::Section::Get(const std::string& key, std::string* value, const std::string& defaultValue)
{
auto it = values.find(key);
if (it != values.end())
@ -103,7 +105,7 @@ bool IniFile::Section::Get(const char* key, std::string* value, const char* defa
*value = it->second;
return true;
}
else if (defaultValue)
else if (&defaultValue != &NULL_STRING)
{
*value = defaultValue;
return true;
@ -112,10 +114,10 @@ bool IniFile::Section::Get(const char* key, std::string* value, const char* defa
return false;
}
bool IniFile::Section::Get(const char* key, std::vector<std::string>& out)
bool IniFile::Section::Get(const std::string& key, std::vector<std::string>& out)
{
std::string temp;
bool retval = Get(key, &temp, 0);
bool retval = Get(key, &temp);
if (!retval || temp.empty())
{
return false;
@ -138,62 +140,62 @@ bool IniFile::Section::Get(const char* key, std::vector<std::string>& out)
return true;
}
bool IniFile::Section::Get(const char* key, int* value, int defaultValue)
bool IniFile::Section::Get(const std::string& key, int* value, int defaultValue)
{
std::string temp;
bool retval = Get(key, &temp, 0);
if (retval && TryParse(temp.c_str(), value))
return true;
*value = defaultValue;
return false;
}
bool IniFile::Section::Get(const char* key, u32* value, u32 defaultValue)
{
std::string temp;
bool retval = Get(key, &temp, 0);
bool retval = Get(key, &temp);
if (retval && TryParse(temp, value))
return true;
*value = defaultValue;
return false;
}
bool IniFile::Section::Get(const char* key, bool* value, bool defaultValue)
bool IniFile::Section::Get(const std::string& key, u32* value, u32 defaultValue)
{
std::string temp;
bool retval = Get(key, &temp, 0);
if (retval && TryParse(temp.c_str(), value))
bool retval = Get(key, &temp);
if (retval && TryParse(temp, value))
return true;
*value = defaultValue;
return false;
}
bool IniFile::Section::Get(const char* key, float* value, float defaultValue)
bool IniFile::Section::Get(const std::string& key, bool* value, bool defaultValue)
{
std::string temp;
bool retval = Get(key, &temp, 0);
if (retval && TryParse(temp.c_str(), value))
bool retval = Get(key, &temp);
if (retval && TryParse(temp, value))
return true;
*value = defaultValue;
return false;
}
bool IniFile::Section::Get(const char* key, double* value, double defaultValue)
bool IniFile::Section::Get(const std::string& key, float* value, float defaultValue)
{
std::string temp;
bool retval = Get(key, &temp, 0);
if (retval && TryParse(temp.c_str(), value))
bool retval = Get(key, &temp);
if (retval && TryParse(temp, value))
return true;
*value = defaultValue;
return false;
}
bool IniFile::Section::Exists(const char *key) const
bool IniFile::Section::Get(const std::string& key, double* value, double defaultValue)
{
std::string temp;
bool retval = Get(key, &temp);
if (retval && TryParse(temp, value))
return true;
*value = defaultValue;
return false;
}
bool IniFile::Section::Exists(const std::string& key) const
{
return values.find(key) != values.end();
}
bool IniFile::Section::Delete(const char *key)
bool IniFile::Section::Delete(const std::string& key)
{
auto it = values.find(key);
if (it == values.end())
@ -206,23 +208,23 @@ bool IniFile::Section::Delete(const char *key)
// IniFile
const IniFile::Section* IniFile::GetSection(const char* sectionName) const
const IniFile::Section* IniFile::GetSection(const std::string& sectionName) const
{
for (const auto& sect : sections)
if (!strcasecmp(sect.name.c_str(), sectionName))
if (!strcasecmp(sect.name.c_str(), sectionName.c_str()))
return (&(sect));
return 0;
}
IniFile::Section* IniFile::GetSection(const char* sectionName)
IniFile::Section* IniFile::GetSection(const std::string& sectionName)
{
for (auto& sect : sections)
if (!strcasecmp(sect.name.c_str(), sectionName))
if (!strcasecmp(sect.name.c_str(), sectionName.c_str()))
return (&(sect));
return 0;
}
IniFile::Section* IniFile::GetOrCreateSection(const char* sectionName)
IniFile::Section* IniFile::GetOrCreateSection(const std::string& sectionName)
{
Section* section = GetSection(sectionName);
if (!section)
@ -233,7 +235,7 @@ IniFile::Section* IniFile::GetOrCreateSection(const char* sectionName)
return section;
}
bool IniFile::DeleteSection(const char* sectionName)
bool IniFile::DeleteSection(const std::string& sectionName)
{
Section* s = GetSection(sectionName);
if (!s)
@ -249,7 +251,7 @@ bool IniFile::DeleteSection(const char* sectionName)
return false;
}
bool IniFile::Exists(const char* sectionName, const char* key) const
bool IniFile::Exists(const std::string& sectionName, const std::string& key) const
{
const Section* section = GetSection(sectionName);
if (!section)
@ -257,13 +259,13 @@ bool IniFile::Exists(const char* sectionName, const char* key) const
return section->Exists(key);
}
void IniFile::SetLines(const char* sectionName, const std::vector<std::string> &lines)
void IniFile::SetLines(const std::string& sectionName, const std::vector<std::string> &lines)
{
Section* section = GetOrCreateSection(sectionName);
section->lines = lines;
}
bool IniFile::DeleteKey(const char* sectionName, const char* key)
bool IniFile::DeleteKey(const std::string& sectionName, const std::string& key)
{
Section* section = GetSection(sectionName);
if (!section)
@ -272,7 +274,7 @@ bool IniFile::DeleteKey(const char* sectionName, const char* key)
}
// Return a list of all keys in a section
bool IniFile::GetKeys(const char* sectionName, std::vector<std::string>& keys) const
bool IniFile::GetKeys(const std::string& sectionName, std::vector<std::string>& keys) const
{
const Section* section = GetSection(sectionName);
if (!section)
@ -282,7 +284,7 @@ bool IniFile::GetKeys(const char* sectionName, std::vector<std::string>& keys) c
}
// Return a list of all lines in a section
bool IniFile::GetLines(const char* sectionName, std::vector<std::string>& lines, const bool remove_comments) const
bool IniFile::GetLines(const std::string& sectionName, std::vector<std::string>& lines, const bool remove_comments) const
{
const Section* section = GetSection(sectionName);
if (!section)
@ -319,7 +321,7 @@ void IniFile::SortSections()
std::sort(sections.begin(), sections.end());
}
bool IniFile::Load(const char* filename, bool keep_current_data)
bool IniFile::Load(const std::string& filename, bool keep_current_data)
{
// Maximum number of letters in a line
static const int MAX_BYTES = 1024*32;
@ -359,7 +361,7 @@ bool IniFile::Load(const char* filename, bool keep_current_data)
{
// New section!
std::string sub = line.substr(1, endpos - 1);
current_section = GetOrCreateSection(sub.c_str());
current_section = GetOrCreateSection(sub);
}
}
else
@ -374,9 +376,9 @@ bool IniFile::Load(const char* filename, bool keep_current_data)
// INI is a hack anyway.
if ((key == "" && value == "")
|| (line.size() >= 1 && (line[0] == '$' || line[0] == '+' || line[0] == '*')))
current_section->lines.push_back(line.c_str());
current_section->lines.push_back(line);
else
current_section->Set(key, value.c_str());
current_section->Set(key, value);
}
}
}
@ -386,7 +388,7 @@ bool IniFile::Load(const char* filename, bool keep_current_data)
return true;
}
bool IniFile::Save(const char* filename)
bool IniFile::Save(const std::string& filename)
{
std::ofstream out;
std::string temp = File::GetTempFilenameForAtomicWrite(filename);
@ -422,20 +424,7 @@ bool IniFile::Save(const char* filename)
return File::RenameSync(temp, filename);
}
bool IniFile::Get(const char* sectionName, const char* key, std::string* value, const char* defaultValue)
{
Section* section = GetSection(sectionName);
if (!section) {
if (defaultValue) {
*value = defaultValue;
}
return false;
}
return section->Get(key, value, defaultValue);
}
bool IniFile::Get(const char *sectionName, const char* key, std::vector<std::string>& values)
bool IniFile::Get(const std::string& sectionName, const std::string& key, std::vector<std::string>& values)
{
Section *section = GetSection(sectionName);
if (!section)
@ -443,7 +432,7 @@ bool IniFile::Get(const char *sectionName, const char* key, std::vector<std::str
return section->Get(key, values);
}
bool IniFile::Get(const char* sectionName, const char* key, int* value, int defaultValue)
bool IniFile::Get(const std::string& sectionName, const std::string& key, int* value, int defaultValue)
{
Section *section = GetSection(sectionName);
if (!section) {
@ -454,7 +443,7 @@ bool IniFile::Get(const char* sectionName, const char* key, int* value, int defa
}
}
bool IniFile::Get(const char* sectionName, const char* key, u32* value, u32 defaultValue)
bool IniFile::Get(const std::string& sectionName, const std::string& key, u32* value, u32 defaultValue)
{
Section *section = GetSection(sectionName);
if (!section) {
@ -465,7 +454,7 @@ bool IniFile::Get(const char* sectionName, const char* key, u32* value, u32 defa
}
}
bool IniFile::Get(const char* sectionName, const char* key, bool* value, bool defaultValue)
bool IniFile::Get(const std::string& sectionName, const std::string& key, bool* value, bool defaultValue)
{
Section *section = GetSection(sectionName);
if (!section) {
@ -476,6 +465,19 @@ bool IniFile::Get(const char* sectionName, const char* key, bool* value, bool de
}
}
bool IniFile::Get(const std::string& sectionName, const std::string& key, std::string* value, const std::string& defaultValue)
{
Section* section = GetSection(sectionName);
if (!section) {
if (&defaultValue != &NULL_STRING) {
*value = defaultValue;
}
return false;
}
return section->Get(key, value, defaultValue);
}
// Unit test. TODO: Move to the real unit test framework.
/*

View File

@ -30,45 +30,42 @@ public:
Section() {}
Section(const std::string& _name) : name(_name) {}
bool Exists(const char *key) const;
bool Delete(const char *key);
bool Exists(const std::string& key) const;
bool Delete(const std::string& key);
void Set(const char* key, const char* newValue);
void Set(const char* key, const std::string& newValue, const std::string& defaultValue);
void Set(const std::string& key, const std::string& newValue);
void Set(const std::string& key, const std::string& newValue, const std::string& defaultValue);
void Set(const std::string &key, const std::string &value) {
Set(key.c_str(), value.c_str());
}
bool Get(const char* key, std::string* value, const char* defaultValue);
bool Get(const std::string& key, std::string* value, const std::string& defaultValue = NULL_STRING);
void Set(const char* key, u32 newValue) {
Set(key, StringFromFormat("0x%08x", newValue).c_str());
void Set(const std::string& key, u32 newValue) {
Set(key, StringFromFormat("0x%08x", newValue));
}
void Set(const char* key, float newValue) {
Set(key, StringFromFormat("%f", newValue).c_str());
void Set(const std::string& key, float newValue) {
Set(key, StringFromFormat("%f", newValue));
}
void Set(const char* key, const float newValue, const float defaultValue);
void Set(const char* key, double newValue) {
Set(key, StringFromFormat("%f", newValue).c_str());
void Set(const std::string& key, const float newValue, const float defaultValue);
void Set(const std::string& key, double newValue) {
Set(key, StringFromFormat("%f", newValue));
}
void Set(const char* key, int newValue, int defaultValue);
void Set(const char* key, int newValue) {
Set(key, StringFromInt(newValue).c_str());
void Set(const std::string& key, int newValue, int defaultValue);
void Set(const std::string& key, int newValue) {
Set(key, StringFromInt(newValue));
}
void Set(const char* key, bool newValue, bool defaultValue);
void Set(const char* key, bool newValue) {
Set(key, StringFromBool(newValue).c_str());
void Set(const std::string& key, bool newValue, bool defaultValue);
void Set(const std::string& key, bool newValue) {
Set(key, StringFromBool(newValue));
}
void Set(const char* key, const std::vector<std::string>& newValues);
void Set(const std::string& key, const std::vector<std::string>& newValues);
bool Get(const char* key, int* value, int defaultValue = 0);
bool Get(const char* key, u32* value, u32 defaultValue = 0);
bool Get(const char* key, bool* value, bool defaultValue = false);
bool Get(const char* key, float* value, float defaultValue = false);
bool Get(const char* key, double* value, double defaultValue = false);
bool Get(const char* key, std::vector<std::string>& values);
bool Get(const std::string& key, int* value, int defaultValue = 0);
bool Get(const std::string& key, u32* value, u32 defaultValue = 0);
bool Get(const std::string& key, bool* value, bool defaultValue = false);
bool Get(const std::string& key, float* value, float defaultValue = false);
bool Get(const std::string& key, double* value, double defaultValue = false);
bool Get(const std::string& key, std::vector<std::string>& values);
bool operator < (const Section& other) const {
return name < other.name;
@ -90,70 +87,63 @@ public:
* @warning Using any other operations than "Get*" and "Exists" is untested and will behave unexpectedly
* @todo This really is just a hack to support having two levels of gameinis (defaults and user-specified) and should eventually be replaced with a less stupid system.
*/
bool Load(const char* filename, bool keep_current_data = false);
bool Load(const std::string &filename, bool keep_current_data = false) { return Load(filename.c_str(), keep_current_data); }
bool Load(const std::string& filename, bool keep_current_data = false);
bool Save(const char* filename);
bool Save(const std::string &filename) { return Save(filename.c_str()); }
bool Save(const std::string& filename);
// Returns true if key exists in section
bool Exists(const char* sectionName, const char* key) const;
bool Exists(const std::string& sectionName, const std::string& key) const;
// TODO: Get rid of these, in favor of the Section ones.
void Set(const char* sectionName, const char* key, const char* newValue) {
void Set(const std::string& sectionName, const std::string& key, const std::string& newValue) {
GetOrCreateSection(sectionName)->Set(key, newValue);
}
void Set(const char* sectionName, const char* key, const std::string& newValue) {
GetOrCreateSection(sectionName)->Set(key, newValue.c_str());
}
void Set(const char* sectionName, const char* key, int newValue) {
void Set(const std::string& sectionName, const std::string& key, int newValue) {
GetOrCreateSection(sectionName)->Set(key, newValue);
}
void Set(const char* sectionName, const char* key, u32 newValue) {
void Set(const std::string& sectionName, const std::string& key, u32 newValue) {
GetOrCreateSection(sectionName)->Set(key, newValue);
}
void Set(const char* sectionName, const char* key, bool newValue) {
void Set(const std::string& sectionName, const std::string& key, bool newValue) {
GetOrCreateSection(sectionName)->Set(key, newValue);
}
void Set(const char* sectionName, const char* key, const std::vector<std::string>& newValues) {
void Set(const std::string& sectionName, const std::string& key, const std::vector<std::string>& newValues) {
GetOrCreateSection(sectionName)->Set(key, newValues);
}
// TODO: Get rid of these, in favor of the Section ones.
bool Get(const char* sectionName, const char* key, std::string* value, const char* defaultValue = "");
bool Get(const char* sectionName, const char* key, int* value, int defaultValue = 0);
bool Get(const char* sectionName, const char* key, u32* value, u32 defaultValue = 0);
bool Get(const char* sectionName, const char* key, bool* value, bool defaultValue = false);
bool Get(const char* sectionName, const char* key, std::vector<std::string>& values);
bool Get(const std::string& sectionName, const std::string& key, int* value, int defaultValue = 0);
bool Get(const std::string& sectionName, const std::string& key, u32* value, u32 defaultValue = 0);
bool Get(const std::string& sectionName, const std::string& key, bool* value, bool defaultValue = false);
bool Get(const std::string& sectionName, const std::string& key, std::vector<std::string>& values);
bool Get(const std::string& sectionName, const std::string& key, std::string* value, const std::string& defaultValue = NULL_STRING);
template<typename T> bool GetIfExists(const char* sectionName, const char* key, T value)
template<typename T> bool GetIfExists(const std::string& sectionName, const std::string& key, T value)
{
if (Exists(sectionName, key))
return Get(sectionName, key, value);
return false;
}
bool GetKeys(const char* sectionName, std::vector<std::string>& keys) const;
bool GetKeys(const std::string& sectionName, std::vector<std::string>& keys) const;
void SetLines(const char* sectionName, const std::vector<std::string> &lines);
bool GetLines(const char* sectionName, std::vector<std::string>& lines, const bool remove_comments = true) const;
void SetLines(const std::string& sectionName, const std::vector<std::string> &lines);
bool GetLines(const std::string& sectionName, std::vector<std::string>& lines, const bool remove_comments = true) const;
inline bool DeleteKey(const char* sectionName, const std::string& key)
{
return DeleteKey(sectionName, key.c_str());
}
bool DeleteKey(const char* sectionName, const char* key);
bool DeleteSection(const char* sectionName);
bool DeleteKey(const std::string& sectionName, const std::string& key);
bool DeleteSection(const std::string& sectionName);
void SortSections();
Section* GetOrCreateSection(const char* section);
Section* GetOrCreateSection(const std::string& section);
private:
std::vector<Section> sections;
const Section* GetSection(const char* section) const;
Section* GetSection(const char* section);
std::string* GetLine(const char* section, const char* key);
void CreateSection(const char* section);
const Section* GetSection(const std::string& section) const;
Section* GetSection(const std::string& section);
std::string* GetLine(const std::string& section, const std::string& key);
void CreateSection(const std::string& section);
static const std::string& NULL_STRING;
};

View File

@ -28,7 +28,7 @@ const u8* SettingsHandler::GetData() const
return m_buffer;
}
const std::string SettingsHandler::GetValue(const std::string key)
const std::string SettingsHandler::GetValue(const std::string& key)
{
std::string delim = std::string("\r\n");
std::string toFind = delim + key + "=";
@ -79,20 +79,16 @@ void SettingsHandler::Reset()
memset(m_buffer, 0, SETTINGS_SIZE);
}
void SettingsHandler::AddSetting(const char *key, const char *value)
void SettingsHandler::AddSetting(const std::string& key, const std::string& value)
{
while (*key != 0)
{
WriteByte(*key);
key++;
for(const char& c : key) {
WriteByte(c);
}
WriteByte('=');
while (*value != 0)
{
WriteByte(*value);
value++;
for(const char& c : value) {
WriteByte(c);
}
WriteByte(13);

View File

@ -21,15 +21,11 @@ public:
// Key used to encrypt/decrypt setting.txt contents
INITIAL_SEED = 0x73B5DBFA
};
inline void AddSetting(const char *key, const std::string& value)
{
AddSetting(key, value.c_str());
}
void AddSetting(const char *key, const char *value);
void AddSetting(const std::string& key, const std::string& value);
const u8 *GetData() const;
const std::string GetValue(const std::string key);
const std::string GetValue(const std::string& key);
void Decrypt();
void Reset();

View File

@ -246,7 +246,7 @@ void LogInfo(const char *format, ...)
{
std::string text = temp;
text += '\n';
arLog.push_back(text.c_str());
arLog.push_back(text);
}
}
}

View File

@ -144,7 +144,7 @@ bool BootCore(const std::string& _rFilename)
game_ini.Get("Core", "BlockMerging", &StartUp.bMergeBlocks, StartUp.bMergeBlocks);
game_ini.Get("Core", "DSPHLE", &StartUp.bDSPHLE, StartUp.bDSPHLE);
game_ini.Get("Core", "DSPThread", &StartUp.bDSPThread, StartUp.bDSPThread);
game_ini.Get("Core", "GFXBackend", &StartUp.m_strVideoBackend, StartUp.m_strVideoBackend.c_str());
game_ini.Get("Core", "GFXBackend", &StartUp.m_strVideoBackend, StartUp.m_strVideoBackend);
game_ini.Get("Core", "CPUCore", &StartUp.iCPUCore, StartUp.iCPUCore);
game_ini.Get("Core", "HLE_BS2", &StartUp.bHLE_BS2, StartUp.bHLE_BS2);
if (game_ini.Get("Core", "FrameLimit", &SConfig::GetInstance().m_Framelimit, SConfig::GetInstance().m_Framelimit))
@ -152,13 +152,13 @@ bool BootCore(const std::string& _rFilename)
if (game_ini.Get("DSP", "Volume", &SConfig::GetInstance().m_Volume, SConfig::GetInstance().m_Volume))
config_cache.bSetVolume = true;
game_ini.Get("DSP", "EnableJIT", &SConfig::GetInstance().m_EnableJIT, SConfig::GetInstance().m_EnableJIT);
game_ini.Get("DSP", "Backend", &SConfig::GetInstance().sBackend, SConfig::GetInstance().sBackend.c_str());
game_ini.Get("DSP", "Backend", &SConfig::GetInstance().sBackend, SConfig::GetInstance().sBackend);
VideoBackend::ActivateBackend(StartUp.m_strVideoBackend);
for (unsigned int i = 0; i < MAX_SI_CHANNELS; ++i)
{
int source;
game_ini.Get("Controls", StringFromFormat("PadType%u", i).c_str(), &source, -1);
game_ini.Get("Controls", StringFromFormat("PadType%u", i), &source, -1);
if (source >= (int) SIDEVICE_NONE && source <= (int) SIDEVICE_AM_BASEBOARD)
{
SConfig::GetInstance().m_SIDevice[i] = (SIDevices) source;
@ -175,7 +175,7 @@ bool BootCore(const std::string& _rFilename)
int source;
for (unsigned int i = 0; i < MAX_WIIMOTES; ++i)
{
game_ini.Get("Controls", StringFromFormat("WiimoteSource%u", i).c_str(), &source, -1);
game_ini.Get("Controls", StringFromFormat("WiimoteSource%u", i), &source, -1);
if (source != -1 && g_wiimote_sources[i] != (unsigned) source && source >= WIIMOTE_SRC_NONE && source <= WIIMOTE_SRC_HYBRID)
{
config_cache.bSetWiimoteSource[i] = true;

View File

@ -8,6 +8,7 @@
#include "IniFile.h"
#include "FileUtil.h"
#include "NANDContentLoader.h"
#include "HW/SI.h"
SConfig* SConfig::m_Instance;
@ -158,7 +159,7 @@ void SConfig::SaveSettings()
for (int i = 0; i < numPaths; i++)
{
ini.Set("General", StringFromFormat("GCMPath%i", i).c_str(), m_ISOFolder[i]);
ini.Set("General", StringFromFormat("GCMPath%i", i), m_ISOFolder[i]);
}
ini.Set("General", "RecursiveGCMPaths", m_RecursiveISOFolder);
@ -190,7 +191,7 @@ void SConfig::SaveSettings()
for (int i = 0; i < NUM_HOTKEYS; i++)
{
ini.Set("Hotkeys", g_HKData[i].IniText, m_LocalCoreStartupParameter.iHotkey[i]);
ini.Set("Hotkeys", (std::string(g_HKData[i].IniText) + "Modifier").c_str(),
ini.Set("Hotkeys", std::string(g_HKData[i].IniText) + "Modifier",
m_LocalCoreStartupParameter.iHotkeyModifier[i]);
}
@ -245,9 +246,9 @@ void SConfig::SaveSettings()
ini.Set("Core", "SlotB", m_EXIDevice[1]);
ini.Set("Core", "SerialPort1", m_EXIDevice[2]);
ini.Set("Core", "BBA_MAC", m_bba_mac);
for (int i = 0; i < 4; ++i)
for (int i = 0; i < MAX_SI_CHANNELS; ++i)
{
ini.Set("Core", StringFromFormat("SIDevice%i", i).c_str(), m_SIDevice[i]);
ini.Set("Core", StringFromFormat("SIDevice%i", i), m_SIDevice[i]);
}
ini.Set("Core", "WiiSDCard", m_WiiSDCard);
ini.Set("Core", "WiiKeyboard", m_WiiKeyboard);
@ -300,7 +301,7 @@ void SConfig::LoadSettings()
for (int i = 0; i < numGCMPaths; i++)
{
std::string tmpPath;
ini.Get("General", StringFromFormat("GCMPath%i", i).c_str(), &tmpPath, "");
ini.Get("General", StringFromFormat("GCMPath%i", i), &tmpPath, "");
m_ISOFolder.push_back(std::move(tmpPath));
}
}
@ -338,7 +339,7 @@ void SConfig::LoadSettings()
{
ini.Get("Hotkeys", g_HKData[i].IniText,
&m_LocalCoreStartupParameter.iHotkey[i], g_HKData[i].DefaultKey);
ini.Get("Hotkeys", (std::string(g_HKData[i].IniText) + "Modifier").c_str(),
ini.Get("Hotkeys", std::string(g_HKData[i].IniText) + "Modifier",
&m_LocalCoreStartupParameter.iHotkeyModifier[i], g_HKData[i].DefaultModifier);
}
@ -400,9 +401,9 @@ void SConfig::LoadSettings()
ini.Get("Core", "BBA_MAC", &m_bba_mac);
ini.Get("Core", "TimeProfiling",&m_LocalCoreStartupParameter.bJITILTimeProfiling, false);
ini.Get("Core", "OutputIR", &m_LocalCoreStartupParameter.bJITILOutputIR, false);
for (int i = 0; i < 4; ++i)
for (int i = 0; i < MAX_SI_CHANNELS; ++i)
{
ini.Get("Core", StringFromFormat("SIDevice%i", i).c_str(), (u32*)&m_SIDevice[i], (i == 0) ? SIDEVICE_GC_CONTROLLER : SIDEVICE_NONE);
ini.Get("Core", StringFromFormat("SIDevice%i", i), (u32*)&m_SIDevice[i], (i == 0) ? SIDEVICE_GC_CONTROLLER : SIDEVICE_NONE);
}
ini.Get("Core", "WiiSDCard", &m_WiiSDCard, false);
ini.Get("Core", "WiiKeyboard", &m_WiiKeyboard, false);
@ -413,7 +414,7 @@ void SConfig::LoadSettings()
ini.Get("Core", "MMU", &m_LocalCoreStartupParameter.bMMU, false);
ini.Get("Core", "TLBHack", &m_LocalCoreStartupParameter.bTLBHack, false);
ini.Get("Core", "BBDumpPort", &m_LocalCoreStartupParameter.iBBDumpPort, -1);
ini.Get("Core", "VBeam", &m_LocalCoreStartupParameter.bVBeamSpeedHack, false);
ini.Get("Core", "VBeam", &m_LocalCoreStartupParameter.bVBeamSpeedHack, false);
ini.Get("Core", "SyncGPU", &m_LocalCoreStartupParameter.bSyncGPU, false);
ini.Get("Core", "FastDiscSpeed", &m_LocalCoreStartupParameter.bFastDiscSpeed, false);
ini.Get("Core", "DCBZ", &m_LocalCoreStartupParameter.bDCBZOFF, false);

View File

@ -134,7 +134,7 @@ bool SCoreStartupParameter::AutoSetup(EBootBS2 _BootBS2)
bootDrive)
{
m_BootType = BOOT_ISO;
DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(m_strFilename.c_str());
DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(m_strFilename);
if (pVolume == NULL)
{
if (bootDrive)
@ -210,7 +210,7 @@ bool SCoreStartupParameter::AutoSetup(EBootBS2 _BootBS2)
bNTSC = true;
m_BootType = BOOT_DFF;
FifoDataFile *ddfFile = FifoDataFile::Load(m_strFilename.c_str(), true);
FifoDataFile *ddfFile = FifoDataFile::Load(m_strFilename, true);
if (ddfFile)
{
@ -220,7 +220,7 @@ bool SCoreStartupParameter::AutoSetup(EBootBS2 _BootBS2)
}
else if (DiscIO::CNANDContentManager::Access().GetNANDLoader(m_strFilename).IsValid())
{
const DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(m_strFilename.c_str());
const DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(m_strFilename);
const DiscIO::INANDContentLoader& ContentLoader = DiscIO::CNANDContentManager::Access().GetNANDLoader(m_strFilename);
if (ContentLoader.GetContentByIndex(ContentLoader.GetBootIndex()) == NULL)

View File

@ -565,13 +565,13 @@ void LoadSettings()
{
std::string secname("Wiimote");
secname += (char)('1' + i);
IniFile::Section& sec = *inifile.GetOrCreateSection(secname.c_str());
IniFile::Section& sec = *inifile.GetOrCreateSection(secname);
sec.Get("Source", &g_wiimote_sources[i], i ? WIIMOTE_SRC_NONE : WIIMOTE_SRC_EMU);
}
std::string secname("BalanceBoard");
IniFile::Section& sec = *inifile.GetOrCreateSection(secname.c_str());
IniFile::Section& sec = *inifile.GetOrCreateSection(secname);
sec.Get("Source", &g_wiimote_sources[WIIMOTE_BALANCE_BOARD], WIIMOTE_SRC_NONE);
}

View File

@ -53,7 +53,7 @@ void LoadPatchSection(const char *section, std::vector<Patch> &patches,
std::string enabledSectionName = std::string(section) + "_Enabled";
std::vector<std::string> enabledLines;
std::set<std::string> enabledNames;
localIni.GetLines(enabledSectionName.c_str(), enabledLines);
localIni.GetLines(enabledSectionName, enabledLines);
for (auto& line : enabledLines)
{
if (line.size() != 0 && line[0] == '$')
@ -140,7 +140,7 @@ static void LoadSpeedhacks(const char *section, std::map<u32, int> &hacks, IniFi
{
std::string key = *iter;
std::string value;
ini.Get(section, key.c_str(), &value, "BOGUS");
ini.Get(section, key, &value, "BOGUS");
if (value != "BOGUS")
{
u32 address;

View File

@ -101,7 +101,7 @@ namespace ButtonManager
bool hasbind = false;
char modifier = 0;
std::string value;
ini.Get("Android", config.str().c_str(), &value, "None");
ini.Get("Android", config.str(), &value, "None");
if (value == "None")
continue;
if (std::string::npos != value.find("Axis"))

View File

@ -82,7 +82,7 @@ void CCodeWindow::Load()
? Parent->Perspectives[Parent->ActivePerspective].Name : "Perspective 1");
for (int i = 0; i <= IDM_CODEWINDOW - IDM_LOGWINDOW; i++)
ini.Get(_Section.c_str(), SettingName[i], &iNbAffiliation[i], 0);
ini.Get(_Section, SettingName[i], &iNbAffiliation[i], 0);
// Get floating setting
for (int i = 0; i <= IDM_CODEWINDOW - IDM_LOGWINDOW; i++)
@ -121,7 +121,7 @@ void CCodeWindow::Save()
// Save notebook affiliations
std::string _Section = "P - " + Parent->Perspectives[Parent->ActivePerspective].Name;
for (int i = 0; i <= IDM_CODEWINDOW - IDM_LOGWINDOW; i++)
ini.Set(_Section.c_str(), SettingName[i], iNbAffiliation[i]);
ini.Set(_Section, SettingName[i], iNbAffiliation[i]);
// Save floating setting
for (int i = IDM_LOGWINDOW_PARENT; i <= IDM_CODEWINDOW_PARENT; i++)

View File

@ -917,13 +917,13 @@ void CFrame::LoadIniPerspectives()
continue;
_Section = StringFromFormat("P - %s", Tmp.Name.c_str());
ini.Get(_Section.c_str(), "Perspective", &_Perspective,
ini.Get(_Section, "Perspective", &_Perspective,
"layout2|"
"name=Pane 0;caption=Pane 0;state=768;dir=5;prop=100000;|"
"name=Pane 1;caption=Pane 1;state=31458108;dir=4;prop=100000;|"
"dock_size(5,0,0)=22|dock_size(4,0,0)=333|");
ini.Get(_Section.c_str(), "Width", &_Widths, "70,25");
ini.Get(_Section.c_str(), "Height", &_Heights, "80,80");
ini.Get(_Section, "Width", &_Widths, "70,25");
ini.Get(_Section, "Height", &_Heights, "80,80");
Tmp.Perspective = StrToWxStr(_Perspective);
@ -988,14 +988,14 @@ void CFrame::SaveIniPerspectives()
STmp += Perspective.Name + ",";
}
STmp = STmp.substr(0, STmp.length()-1);
ini.Set("Perspectives", "Perspectives", STmp.c_str());
ini.Set("Perspectives", "Perspectives", STmp);
ini.Set("Perspectives", "Active", ActivePerspective);
// Save the perspectives
for (auto& Perspective : Perspectives)
{
std::string _Section = "P - " + Perspective.Name;
ini.Set(_Section.c_str(), "Perspective", WxStrToStr(Perspective.Perspective));
ini.Set(_Section, "Perspective", WxStrToStr(Perspective.Perspective));
std::string SWidth = "", SHeight = "";
for (u32 j = 0; j < Perspective.Width.size(); j++)
@ -1007,8 +1007,8 @@ void CFrame::SaveIniPerspectives()
SWidth = SWidth.substr(0, SWidth.length()-1);
SHeight = SHeight.substr(0, SHeight.length()-1);
ini.Set(_Section.c_str(), "Width", SWidth.c_str());
ini.Set(_Section.c_str(), "Height", SHeight.c_str());
ini.Set(_Section, "Width", SWidth);
ini.Set(_Section, "Height", SHeight);
}
ini.Save(File::GetUserPath(F_DEBUGGERCONFIG_IDX));

View File

@ -252,13 +252,13 @@ void WiimoteConfigDiag::Save(wxCommandEvent& event)
{
std::string secname("Wiimote");
secname += (char)('1' + i);
IniFile::Section& sec = *inifile.GetOrCreateSection(secname.c_str());
IniFile::Section& sec = *inifile.GetOrCreateSection(secname);
sec.Set("Source", (int)g_wiimote_sources[i]);
}
std::string secname("BalanceBoard");
IniFile::Section& sec = *inifile.GetOrCreateSection(secname.c_str());
IniFile::Section& sec = *inifile.GetOrCreateSection(secname);
sec.Set("Source", (int)g_wiimote_sources[WIIMOTE_BALANCE_BOARD]);
inifile.Save(ini_filename);

View File

@ -47,17 +47,17 @@ void ControllerEmu::ControlGroup::LoadConfig(IniFile::Section *sec, const std::s
// settings
for (auto& s : settings)
{
sec->Get((group + s->name).c_str(), &s->value, s->default_value * 100);
sec->Get(group + s->name, &s->value, s->default_value * 100);
s->value /= 100;
}
for (auto& c : controls)
{
// control expression
sec->Get((group + c->name).c_str(), &c->control_ref->expression, "");
sec->Get(group + c->name, &c->control_ref->expression, "");
// range
sec->Get((group + c->name + "/Range").c_str(), &c->control_ref->range, 100.0f);
sec->Get(group + c->name + "/Range", &c->control_ref->range, 100.0f);
c->control_ref->range /= 100;
}
@ -65,12 +65,12 @@ void ControllerEmu::ControlGroup::LoadConfig(IniFile::Section *sec, const std::s
// extensions
if (type == GROUP_TYPE_EXTENSION)
{
Extension* const ext = ((Extension*)this);
Extension* const ext = (Extension*)this;
ext->switch_extension = 0;
unsigned int n = 0;
std::string extname;
sec->Get((base + name).c_str(), &extname, "");
sec->Get(base + name, &extname, "");
for (auto& ai : ext->attachments)
{
@ -90,7 +90,7 @@ void ControllerEmu::LoadConfig(IniFile::Section *sec, const std::string& base)
std::string defdev = default_device.ToString();
if (base.empty())
{
sec->Get((base + "Device").c_str(), &defdev, "");
sec->Get(base + "Device", &defdev, "");
default_device.FromString(defdev);
}
@ -103,22 +103,22 @@ void ControllerEmu::ControlGroup::SaveConfig(IniFile::Section *sec, const std::s
std::string group(base + name); group += "/";
for (auto& s : settings)
sec->Set((group + s->name).c_str(), s->value*100.0f, s->default_value*100.0f);
sec->Set(group + s->name, s->value*100.0f, s->default_value*100.0f);
for (auto& c : controls)
{
// control expression
sec->Set((group + c->name).c_str(), c->control_ref->expression, "");
sec->Set(group + c->name, c->control_ref->expression, "");
// range
sec->Set((group + c->name + "/Range").c_str(), c->control_ref->range*100.0f, 100.0f);
sec->Set(group + c->name + "/Range", c->control_ref->range*100.0f, 100.0f);
}
// extensions
if (type == GROUP_TYPE_EXTENSION)
{
Extension* const ext = ((Extension*)this);
sec->Set((base + name).c_str(), ext->attachments[ext->switch_extension]->GetName(), "None");
Extension* const ext = (Extension*)this;
sec->Set(base + name, ext->attachments[ext->switch_extension]->GetName(), "None");
for (auto& ai : ext->attachments)
ai->SaveConfig(sec, base + ai->GetName() + "/");
@ -129,7 +129,7 @@ void ControllerEmu::SaveConfig(IniFile::Section *sec, const std::string& base)
{
const std::string defdev = default_device.ToString();
if (base.empty())
sec->Set((/*std::string(" ") +*/ base + "Device").c_str(), defdev, "");
sec->Set(/*std::string(" ") +*/ base + "Device", defdev, "");
for (auto& ctrlGroup : groups)
ctrlGroup->SaveConfig(sec, defdev, base);

View File

@ -40,15 +40,17 @@ bool InputPlugin::LoadConfig(bool isGC)
game_ini.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + SConfig::GetInstance().m_LocalCoreStartupParameter.GetUniqueID() + ".ini", true);
for (int i = 0; i < 4; i++)
{
if (game_ini.Exists("Controls", (type + "Profile" + num[i]).c_str()))
if (game_ini.Exists("Controls", type + "Profile" + num[i]))
{
game_ini.Get("Controls", (type + "Profile" + num[i]).c_str(), &profile[i]);
if (File::Exists(File::GetUserPath(D_CONFIG_IDX) + path + profile[i] + ".ini"))
useProfile[i] = true;
else
if (game_ini.Get("Controls", type + "Profile" + num[i], &profile[i]))
{
// TODO: Having a PanicAlert for this is dumb.
PanicAlertT("Selected controller profile does not exist");
if (File::Exists(File::GetUserPath(D_CONFIG_IDX) + path + profile[i] + ".ini"))
useProfile[i] = true;
else
{
// TODO: Having a PanicAlert for this is dumb.
PanicAlertT("Selected controller profile does not exist");
}
}
}
}
@ -68,7 +70,7 @@ bool InputPlugin::LoadConfig(bool isGC)
}
else
{
pad->LoadConfig(inifile.GetOrCreateSection(pad->GetName().c_str()));
pad->LoadConfig(inifile.GetOrCreateSection(pad->GetName()));
}
// Update refs
@ -95,7 +97,7 @@ void InputPlugin::SaveConfig()
inifile.Load(ini_filename);
for (ControllerEmu* pad : controllers)
pad->SaveConfig(inifile.GetOrCreateSection(pad->GetName().c_str()));
pad->SaveConfig(inifile.GetOrCreateSection(pad->GetName()));
inifile.Save(ini_filename);
}

View File

@ -8,12 +8,12 @@
#include <stdlib.h>
#include <string.h>
const char* DefaultPort(const int index)
const std::string DefaultPort(const int index)
{
static std::string s;
s = "443";
s += (char)('2' + index);
return s.c_str();
return s;
}
UDPWrapper::UDPWrapper(int indx, const char* const _name) :
@ -33,13 +33,13 @@ void UDPWrapper::LoadConfig(IniFile::Section *sec, const std::string& defdev, co
std::string group( base + name ); group += "/";
int _updAccel,_updIR,_updButt,_udpEn,_updNun,_updNunAccel;
sec->Get((group + "Enable").c_str(),&_udpEn, 0);
sec->Get((group + "Port").c_str(), &port, DefaultPort(index));
sec->Get((group + "Update_Accel").c_str(), &_updAccel, 1);
sec->Get((group + "Update_IR").c_str(), &_updIR, 1);
sec->Get((group + "Update_Butt").c_str(), &_updButt, 1);
sec->Get((group + "Update_Nunchuk").c_str(), &_updNun, 1);
sec->Get((group + "Update_NunchukAccel").c_str(), &_updNunAccel, 0);
sec->Get(group + "Enable",&_udpEn, 0);
sec->Get(group + "Port", &port, DefaultPort(index));
sec->Get(group + "Update_Accel", &_updAccel, 1);
sec->Get(group + "Update_IR", &_updIR, 1);
sec->Get(group + "Update_Butt", &_updButt, 1);
sec->Get(group + "Update_Nunchuk", &_updNun, 1);
sec->Get(group + "Update_NunchukAccel", &_updNunAccel, 0);
udpEn=(_udpEn>0);
updAccel=(_updAccel>0);
@ -56,13 +56,13 @@ void UDPWrapper::SaveConfig(IniFile::Section *sec, const std::string& defdev, co
{
ControlGroup::SaveConfig(sec,defdev,base);
std::string group( base + name ); group += "/";
sec->Set((group + "Enable").c_str(), (int)udpEn, 0);
sec->Set((group + "Port").c_str(), port, DefaultPort(index));
sec->Set((group + "Update_Accel").c_str(), (int)updAccel, 1);
sec->Set((group + "Update_IR").c_str(), (int)updIR, 1);
sec->Set((group + "Update_Butt").c_str(), (int)updButt, 1);
sec->Set((group + "Update_Nunchuk").c_str(), (int)updNun, 1);
sec->Set((group + "Update_NunchukAccel").c_str(), (int)updNunAccel, 0);
sec->Set(group + "Enable", (int)udpEn, 0);
sec->Set(group + "Port", port, DefaultPort(index));
sec->Set(group + "Update_Accel", (int)updAccel, 1);
sec->Set(group + "Update_IR", (int)updIR, 1);
sec->Set(group + "Update_Butt", (int)updButt, 1);
sec->Set(group + "Update_Nunchuk", (int)updNun, 1);
sec->Set(group + "Update_NunchukAccel", (int)updNunAccel, 0);
}
@ -74,7 +74,7 @@ void UDPWrapper::Refresh()
if (strcmp(inst->getPort(),port.c_str()))
{
delete inst;
inst= new UDPWiimote(port.c_str(),"Dolphin-Emu",index); //TODO: Changeable display name
inst = new UDPWiimote(port.c_str(),"Dolphin-Emu",index); //TODO: Changeable display name
}
return;
}
@ -82,11 +82,11 @@ void UDPWrapper::Refresh()
{
if (inst)
delete inst;
inst=NULL;
inst = NULL;
return;
}
//else
inst= new UDPWiimote(port.c_str(),"Dolphin-Emu",index);
inst = new UDPWiimote(port.c_str(),"Dolphin-Emu",index);
}
UDPWrapper::~UDPWrapper()