Fix IniFile to use string& instead of char*

Also removes .c_str() usages where found.
This commit is contained in:
Matthew Parlane
2014-02-08 18:50:37 +13:00
parent 079b1ba93d
commit 3fe05e0a9f
17 changed files with 205 additions and 218 deletions

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

@ -4,12 +4,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) :
@ -29,13 +29,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);
@ -52,13 +52,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);
}
@ -70,7 +70,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;
}
@ -78,11 +78,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()