Switch to JSON.
Custom Path's and Colors needs to be redo for this.
This commit is contained in:
parent
18733e7a9b
commit
08b962b560
8 changed files with 111 additions and 458 deletions
|
|
@ -30,14 +30,25 @@
|
|||
#include <string>
|
||||
|
||||
namespace Config {
|
||||
|
||||
// [UI]
|
||||
extern int lang; // The current Language.
|
||||
extern int Color1, Color2, Color3, TxtColor, SelectedColor, UnselectedColor; // Colors!
|
||||
extern std::string ScriptPath;
|
||||
|
||||
void loadConfig();
|
||||
void saveConfig();
|
||||
void load();
|
||||
void save();
|
||||
void initializeNewConfig();
|
||||
|
||||
bool getBool(const std::string &key);
|
||||
void setBool(const std::string &key, bool v);
|
||||
|
||||
int getInt(const std::string &key);
|
||||
void setInt(const std::string &key, int v);
|
||||
|
||||
std::string getString(const std::string &key);
|
||||
void setString(const std::string &key, const std::string &v);
|
||||
|
||||
int getLang(const std::string &key);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
#ifndef _INIFILE_H_
|
||||
#define _INIFILE_H_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class CIniFile
|
||||
{
|
||||
public:
|
||||
CIniFile();
|
||||
CIniFile(const std::string& filename);
|
||||
virtual ~CIniFile();
|
||||
|
||||
public:
|
||||
bool LoadIniFile(const std::string& FileName);
|
||||
bool SaveIniFile(const std::string& FileName);
|
||||
bool SaveIniFileModified(const std::string& FileName);
|
||||
|
||||
std::string GetString(const std::string& Section,const std::string& Item,const std::string& DefaultValue);
|
||||
void SetString(const std::string& Section,const std::string& Item,const std::string& Value);
|
||||
int GetInt(const std::string& Section,const std::string& Item,int DefaultValue);
|
||||
void SetInt(const std::string& Section,const std::string& Item,int Value);
|
||||
void GetStringVector(const std::string& Section,const std::string& Item,std::vector<std::string>& strings,char delimiter=',');
|
||||
void SetStringVector(const std::string& Section,const std::string& Item,std::vector<std::string>& strings,char delimiter=',');
|
||||
protected:
|
||||
std::string m_sFileName;
|
||||
typedef std::vector<std::string> cStringArray;
|
||||
cStringArray m_FileContainer;
|
||||
bool m_bLastResult;
|
||||
bool m_bModified;
|
||||
bool m_bReadOnly;
|
||||
typedef std::map<std::string,size_t> cSectionCache;
|
||||
cSectionCache m_Cache;
|
||||
|
||||
bool InsertLine(size_t line,const std::string& str);
|
||||
bool ReplaceLine(size_t line,const std::string& str);
|
||||
|
||||
void SetFileString(const std::string& Section,const std::string& Item,const std::string& Value);
|
||||
std::string GetFileString(const std::string& Section,const std::string& Item);
|
||||
|
||||
std::string GetString(const std::string& Section,const std::string& Item);
|
||||
int GetInt(const std::string& Section,const std::string& Item);
|
||||
};
|
||||
|
||||
#endif // _INIFILE_H_
|
||||
|
|
@ -35,7 +35,6 @@
|
|||
#include "utils/config.hpp"
|
||||
#include "utils/extract.hpp"
|
||||
#include "utils/fileBrowse.h"
|
||||
#include "utils/inifile.h"
|
||||
#include "utils/thread.hpp"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
|
|
|||
|
|
@ -63,11 +63,11 @@ int main()
|
|||
mkdir("sdmc:/3ds/Universal-Updater", 0777);
|
||||
mkdir("sdmc:/3ds/Universal-Updater/scripts", 0777);
|
||||
|
||||
Config::loadConfig();
|
||||
// We need to make sure, the file exist.
|
||||
if(access("sdmc:/3ds/Universal-Updater/Settings.ini", F_OK) == -1 ) {
|
||||
Config::saveConfig();
|
||||
if(access("sdmc:/3ds/Universal-Updater/Settings.json", F_OK) == -1 ) {
|
||||
Config::initializeNewConfig();
|
||||
}
|
||||
Config::load();
|
||||
Lang::load(Config::lang);
|
||||
Gui::setScreen(std::make_unique<MainMenu>());
|
||||
osSetSpeedupEnable(true); // Enable speed-up for New 3DS users
|
||||
|
|
|
|||
|
|
@ -309,7 +309,7 @@ void ScriptList::DrawList(void) const {
|
|||
Gui::DrawStringCentered(0, 80, 0.7f, Config::TxtColor, Lang::get("TITLE") + std::string(fileInfo[selection].title), 400);
|
||||
Gui::DrawStringCentered(0, 100, 0.7f, Config::TxtColor, Lang::get("AUTHOR") + std::string(fileInfo[selection].author), 400);
|
||||
Gui::DrawStringCentered(0, 120, 0.6f, Config::TxtColor, std::string(fileInfo[selection].shortDesc), 400);
|
||||
|
||||
|
||||
Gui::DrawBottom();
|
||||
if (listMode == 0) {
|
||||
for(int i=0;i<ENTRIES_PER_SCREEN && i<(int)fileInfo.size();i++) {
|
||||
|
|
@ -508,7 +508,7 @@ void ScriptList::SelectFunction(u32 hDown, u32 hHeld) {
|
|||
Config::TxtColor = TextColor;
|
||||
Config::SelectedColor = selected;
|
||||
Config::UnselectedColor = unselected;
|
||||
Config::saveConfig();
|
||||
Config::save();
|
||||
}
|
||||
|
||||
if (hDown & KEY_B) {
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ void Settings::LanguageSelection(u32 hDown, touchPosition touch) {
|
|||
if (touching(touch, langBlocks[language])) {
|
||||
Config::lang = language;
|
||||
Lang::load(Config::lang);
|
||||
Config::saveConfig();
|
||||
Config::save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -161,7 +161,7 @@ void Settings::colorChanging(u32 hDown, touchPosition touch) {
|
|||
int blue;
|
||||
|
||||
if (hDown & KEY_B) {
|
||||
Config::saveConfig();
|
||||
Config::save();
|
||||
Gui::screenBack();
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,17 +27,12 @@
|
|||
#include "gui.hpp"
|
||||
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/inifile.h"
|
||||
#include "utils/config.hpp"
|
||||
#include "utils/json.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
|
||||
using std::string;
|
||||
using std::wstring;
|
||||
|
||||
static CIniFile settingsini( "sdmc:/3ds/Universal-Updater/Settings.ini" );
|
||||
|
||||
int Config::lang; // Current Language.
|
||||
int Config::Color1;
|
||||
int Config::Color2;
|
||||
|
|
@ -46,28 +41,96 @@ int Config::TxtColor;
|
|||
int Config::SelectedColor;
|
||||
int Config::UnselectedColor;
|
||||
std::string Config::ScriptPath;
|
||||
nlohmann::json configJson;
|
||||
|
||||
void Config::loadConfig() {
|
||||
// [UI]
|
||||
Config::lang = settingsini.GetInt("UI", "LANGUAGE", 2);
|
||||
Config::Color1 = settingsini.GetInt("UI", "BARCOLOR", BarColor);
|
||||
Config::Color2 = settingsini.GetInt("UI", "TOPBGCOLOR", TopBGColor);
|
||||
Config::Color3 = settingsini.GetInt("UI", "BOTTOMBGCOLOR", BottomBGColor);
|
||||
Config::TxtColor = settingsini.GetInt("UI", "TEXTCOLOR", WHITE);
|
||||
Config::SelectedColor = settingsini.GetInt("UI", "SELECTEDCOLOR", SelectedColordefault);
|
||||
Config::UnselectedColor = settingsini.GetInt("UI", "UNSELECTEDCOLOR", UnselectedColordefault);
|
||||
Config::ScriptPath = settingsini.GetString("UI", "SCRIPTPATH", SCRIPTS_PATH);
|
||||
void Config::load() {
|
||||
FILE* file = fopen("sdmc:/3ds/Universal-Updater/Settings.json", "r");
|
||||
if(file) {
|
||||
configJson = nlohmann::json::parse(file, nullptr, false);
|
||||
Config::Color1 = getInt("BARCOLOR");
|
||||
Config::Color2 = getInt("TOPBGCOLOR");
|
||||
Config::Color3 = getInt("BOTTOMBGCOLOR");
|
||||
Config::TxtColor = getInt("TEXTCOLOR");
|
||||
Config::SelectedColor = getInt("SELECTEDCOLOR");
|
||||
Config::UnselectedColor = getInt("UNSELECTEDCOLOR");
|
||||
Config::ScriptPath = getString("SCRIPTPATH");
|
||||
Config::lang = getInt("LANGUAGE");
|
||||
fclose(file);
|
||||
} else {
|
||||
Config::Color1 = BarColor;
|
||||
Config::Color2 = TopBGColor;
|
||||
Config::Color3 = BottomBGColor;
|
||||
Config::TxtColor = WHITE;
|
||||
Config::SelectedColor = SelectedColordefault;
|
||||
Config::UnselectedColor = UnselectedColordefault;
|
||||
Config::ScriptPath = SCRIPTS_PATH;
|
||||
Config::lang = 2;
|
||||
}
|
||||
}
|
||||
|
||||
void Config::saveConfig() {
|
||||
// [UI]
|
||||
settingsini.SetInt("UI", "LANGUAGE", Config::lang);
|
||||
settingsini.SetInt("UI", "BARCOLOR", Config::Color1);
|
||||
settingsini.SetInt("UI", "TOPBGCOLOR", Config::Color2);
|
||||
settingsini.SetInt("UI", "BOTTOMBGCOLOR", Config::Color3);
|
||||
settingsini.SetInt("UI", "TEXTCOLOR", Config::TxtColor);
|
||||
settingsini.SetInt("UI", "SELECTEDCOLOR", Config::SelectedColor);
|
||||
settingsini.SetInt("UI", "UNSELECTEDCOLOR", Config::UnselectedColor);
|
||||
settingsini.SetString("UI", "SCRIPTPATH", Config::ScriptPath);
|
||||
settingsini.SaveIniFile("sdmc:/3ds/Universal-Updater/Settings.ini");
|
||||
void Config::save() {
|
||||
Config::setInt("BARCOLOR", Config::Color1);
|
||||
Config::setInt("TOPBGCOLOR", Config::Color2);
|
||||
Config::setInt("BOTTOMBGCOLOR", Config::Color3);
|
||||
Config::setInt("TEXTCOLOR", Config::TxtColor);
|
||||
Config::setInt("SELECTEDCOLOR", Config::SelectedColor);
|
||||
Config::setInt("UNSELECTEDCOLOR", Config::UnselectedColor);
|
||||
Config::setString("SCRIPTPATH", SCRIPTS_PATH);
|
||||
Config::setInt("LANGUAGE", 2);
|
||||
FILE* file = fopen("sdmc:/3ds/Universal-Updater/Settings.json", "w");
|
||||
if(file) fwrite(configJson.dump(1, '\t').c_str(), 1, configJson.dump(1, '\t').size(), file);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
void Config::initializeNewConfig() {
|
||||
FILE* file = fopen("sdmc:/3ds/Universal-Updater/Settings.json", "r");
|
||||
if(file) configJson = nlohmann::json::parse(file, nullptr, false);
|
||||
Config::setInt("BARCOLOR", BarColor);
|
||||
Config::setInt("TOPBGCOLOR", TopBGColor);
|
||||
Config::setInt("BOTTOMBGCOLOR", BottomBGColor);
|
||||
Config::setInt("TEXTCOLOR", WHITE);
|
||||
Config::setInt("SELECTEDCOLOR", SelectedColordefault);
|
||||
Config::setInt("UNSELECTEDCOLOR", UnselectedColordefault);
|
||||
Config::setString("SCRIPTPATH", SCRIPTS_PATH);
|
||||
Config::setInt("LANGUAGE", 2);
|
||||
if(file) fwrite(configJson.dump(1, '\t').c_str(), 1, configJson.dump(1, '\t').size(), file);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
|
||||
bool Config::getBool(const std::string &key) {
|
||||
if(!configJson.contains(key)) {
|
||||
return false;
|
||||
}
|
||||
return configJson.at(key).get_ref<const bool&>();
|
||||
}
|
||||
void Config::setBool(const std::string &key, bool v) {
|
||||
configJson[key] = v;
|
||||
}
|
||||
|
||||
int Config::getInt(const std::string &key) {
|
||||
if(!configJson.contains(key)) {
|
||||
return 0;
|
||||
}
|
||||
return configJson.at(key).get_ref<const int64_t&>();
|
||||
}
|
||||
void Config::setInt(const std::string &key, int v) {
|
||||
configJson[key] = v;
|
||||
}
|
||||
|
||||
std::string Config::getString(const std::string &key) {
|
||||
if(!configJson.contains(key)) {
|
||||
return "";
|
||||
}
|
||||
return configJson.at(key).get_ref<const std::string&>();
|
||||
}
|
||||
void Config::setString(const std::string &key, const std::string &v) {
|
||||
configJson[key] = v;
|
||||
}
|
||||
|
||||
int Config::getLang(const std::string &key) {
|
||||
if(!configJson.contains(key)) {
|
||||
return 1;
|
||||
}
|
||||
return configJson.at(key).get_ref<const int64_t&>();
|
||||
}
|
||||
|
|
@ -1,374 +0,0 @@
|
|||
#include "utils/inifile.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
static bool freadLine(FILE* f,std::string& str)
|
||||
{
|
||||
str.clear();
|
||||
__read:
|
||||
char p=0;
|
||||
|
||||
size_t readed=fread(&p,1,1,f);
|
||||
if(0==readed)
|
||||
{
|
||||
str="";
|
||||
return false;
|
||||
}
|
||||
if('\n'==p||'\r'==p)
|
||||
{
|
||||
str="";
|
||||
return true;
|
||||
}
|
||||
|
||||
while(p!='\n'&&p!='\r'&&readed)
|
||||
{
|
||||
str+=p;
|
||||
readed=fread(&p,1,1,f);
|
||||
}
|
||||
|
||||
if(str.empty()||""==str)
|
||||
{
|
||||
goto __read;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void trimString(std::string& str)
|
||||
{
|
||||
size_t first=str.find_first_not_of(" \t"),last;
|
||||
if(first==str.npos)
|
||||
{
|
||||
str="";
|
||||
}
|
||||
else
|
||||
{
|
||||
last=str.find_last_not_of(" \t");
|
||||
if(first>0||(last+1)<str.length()) str=str.substr(first,last-first+1);
|
||||
}
|
||||
}
|
||||
|
||||
CIniFile::CIniFile()
|
||||
{
|
||||
m_bLastResult=false;
|
||||
m_bModified=false;
|
||||
m_bReadOnly=false;
|
||||
}
|
||||
|
||||
CIniFile::CIniFile(const std::string& filename)
|
||||
{
|
||||
m_sFileName=filename;
|
||||
m_bLastResult=false;
|
||||
m_bModified=false;
|
||||
m_bReadOnly=false;
|
||||
LoadIniFile(m_sFileName);
|
||||
}
|
||||
|
||||
CIniFile::~CIniFile()
|
||||
{
|
||||
if(m_FileContainer.size()>0)
|
||||
{
|
||||
m_FileContainer.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void CIniFile::SetString(const std::string& Section,const std::string& Item,const std::string& Value)
|
||||
{
|
||||
if(GetFileString(Section,Item)!=Value)
|
||||
{
|
||||
SetFileString(Section,Item,Value);
|
||||
m_bModified=true;
|
||||
}
|
||||
}
|
||||
|
||||
void CIniFile::SetInt(const std::string& Section,const std::string& Item,int Value)
|
||||
{
|
||||
char buf[16];
|
||||
snprintf(buf, sizeof(buf), "%d", Value);
|
||||
std::string strtemp(buf);
|
||||
|
||||
if(GetFileString(Section,Item)!=strtemp)
|
||||
{
|
||||
SetFileString(Section,Item,strtemp);
|
||||
m_bModified=true;
|
||||
}
|
||||
}
|
||||
|
||||
std::string CIniFile::GetString(const std::string& Section,const std::string& Item)
|
||||
{
|
||||
return GetFileString(Section,Item);
|
||||
}
|
||||
|
||||
std::string CIniFile::GetString(const std::string& Section,const std::string& Item,const std::string& DefaultValue)
|
||||
{
|
||||
std::string temp=GetString(Section,Item);
|
||||
if(!m_bLastResult)
|
||||
{
|
||||
SetString(Section,Item,DefaultValue);
|
||||
temp=DefaultValue;
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
void CIniFile::GetStringVector(const std::string& Section,const std::string& Item,std::vector< std::string >& strings,char delimiter)
|
||||
{
|
||||
std::string strValue=GetFileString(Section,Item);
|
||||
strings.clear();
|
||||
size_t pos;
|
||||
while((pos=strValue.find(delimiter),strValue.npos!=pos))
|
||||
{
|
||||
const std::string string=strValue.substr(0,pos);
|
||||
if(string.length())
|
||||
{
|
||||
strings.push_back(string);
|
||||
}
|
||||
strValue=strValue.substr(pos+1,strValue.npos);
|
||||
}
|
||||
if(strValue.length())
|
||||
{
|
||||
strings.push_back(strValue);
|
||||
}
|
||||
}
|
||||
|
||||
void CIniFile::SetStringVector(const std::string& Section,const std::string& Item,std::vector<std::string>& strings,char delimiter)
|
||||
{
|
||||
std::string strValue;
|
||||
for(size_t ii=0;ii<strings.size();++ii)
|
||||
{
|
||||
if(ii) strValue+=delimiter;
|
||||
strValue+=strings[ii];
|
||||
}
|
||||
SetString(Section,Item,strValue);
|
||||
}
|
||||
|
||||
int CIniFile::GetInt(const std::string& Section,const std::string& Item)
|
||||
{
|
||||
std::string value=GetFileString(Section,Item);
|
||||
if(value.size()>2&&'0'==value[0]&&('x'==value[1]||'X'==value[1]))
|
||||
return strtol(value.c_str(),NULL,16);
|
||||
else
|
||||
return strtol(value.c_str(),NULL,10);
|
||||
}
|
||||
|
||||
int CIniFile::GetInt(const std::string& Section,const std::string& Item,int DefaultValue)
|
||||
{
|
||||
int temp;
|
||||
temp=GetInt(Section,Item);
|
||||
if(!m_bLastResult)
|
||||
{
|
||||
SetInt(Section,Item,DefaultValue);
|
||||
temp=DefaultValue;
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
bool CIniFile::LoadIniFile(const std::string& FileName)
|
||||
{
|
||||
//dbg_printf("load %s\n",FileName.c_str());
|
||||
if(FileName!="") m_sFileName=FileName;
|
||||
|
||||
FILE* f=fopen(FileName.c_str(),"rb");
|
||||
|
||||
if(NULL==f) return false;
|
||||
|
||||
//check for utf8 bom.
|
||||
char bom[3];
|
||||
if(fread(bom,3,1,f)==1&&bom[0]==0xef&&bom[1]==0xbb&&bom[2]==0xbf) ;
|
||||
else fseek(f,0,SEEK_SET);
|
||||
|
||||
std::string strline("");
|
||||
m_FileContainer.clear();
|
||||
|
||||
while(freadLine(f,strline))
|
||||
{
|
||||
trimString(strline);
|
||||
if(strline!=""&&';'!=strline[0]&&'/'!=strline[0]&&'!'!=strline[0]) m_FileContainer.push_back(strline);
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
m_bLastResult=false;
|
||||
m_bModified=false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CIniFile::SaveIniFileModified(const std::string& FileName)
|
||||
{
|
||||
if(m_bModified==true)
|
||||
{
|
||||
return SaveIniFile(FileName);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CIniFile::SaveIniFile(const std::string& FileName)
|
||||
{
|
||||
if(FileName!="")
|
||||
m_sFileName=FileName;
|
||||
|
||||
FILE* f=fopen(m_sFileName.c_str(),"wb");
|
||||
if(NULL==f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for(size_t ii=0;ii<m_FileContainer.size();ii++)
|
||||
{
|
||||
std::string& strline=m_FileContainer[ii];
|
||||
size_t notSpace=strline.find_first_not_of(' ');
|
||||
strline=strline.substr(notSpace);
|
||||
if(strline.find('[')==0&&ii>0)
|
||||
{
|
||||
if(!m_FileContainer[ii-1].empty()&&m_FileContainer[ii-1]!="")
|
||||
fwrite("\r\n",1,2,f);
|
||||
}
|
||||
if(!strline.empty()&&strline!="")
|
||||
{
|
||||
fwrite(strline.c_str(),1,strline.length(),f);
|
||||
fwrite("\r\n",1,2,f);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
m_bModified=false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string CIniFile::GetFileString(const std::string& Section,const std::string& Item)
|
||||
{
|
||||
std::string strline;
|
||||
std::string strSection;
|
||||
std::string strItem;
|
||||
std::string strValue;
|
||||
|
||||
size_t ii=0;
|
||||
size_t iFileLines=m_FileContainer.size();
|
||||
|
||||
if(m_bReadOnly)
|
||||
{
|
||||
cSectionCache::iterator it=m_Cache.find(Section);
|
||||
if((it!=m_Cache.end())) ii=it->second;
|
||||
}
|
||||
|
||||
m_bLastResult=false;
|
||||
|
||||
if(iFileLines>=0)
|
||||
{
|
||||
while(ii<iFileLines)
|
||||
{
|
||||
strline=m_FileContainer[ii++];
|
||||
|
||||
size_t rBracketPos=0;
|
||||
if('['==strline[0]) rBracketPos=strline.find(']');
|
||||
if(rBracketPos>0&&rBracketPos!=std::string::npos)
|
||||
{
|
||||
strSection=strline.substr(1,rBracketPos-1);
|
||||
if(m_bReadOnly) m_Cache.insert(std::make_pair(strSection,ii-1));
|
||||
if(strSection==Section)
|
||||
{
|
||||
while(ii<iFileLines)
|
||||
{
|
||||
strline=m_FileContainer[ii++];
|
||||
size_t equalsignPos=strline.find('=');
|
||||
if(equalsignPos!=strline.npos)
|
||||
{
|
||||
size_t last=equalsignPos?strline.find_last_not_of(" \t",equalsignPos-1):strline.npos;
|
||||
if(last==strline.npos) strItem="";
|
||||
else strItem=strline.substr(0,last+1);
|
||||
|
||||
if(strItem==Item)
|
||||
{
|
||||
size_t first=strline.find_first_not_of(" \t",equalsignPos+1);
|
||||
if(first==strline.npos) strValue="";
|
||||
else strValue=strline.substr(first);
|
||||
m_bLastResult=true;
|
||||
return strValue;
|
||||
}
|
||||
}
|
||||
else if('['==strline[0])
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return std::string("");
|
||||
}
|
||||
|
||||
void CIniFile::SetFileString(const std::string& Section,const std::string& Item,const std::string& Value)
|
||||
{
|
||||
std::string strline;
|
||||
std::string strSection;
|
||||
std::string strItem;
|
||||
|
||||
if(m_bReadOnly) return;
|
||||
|
||||
size_t ii=0;
|
||||
size_t iFileLines=m_FileContainer.size();
|
||||
|
||||
while(ii<iFileLines)
|
||||
{
|
||||
strline=m_FileContainer[ii++];
|
||||
|
||||
size_t rBracketPos=0;
|
||||
if('['==strline[0]) rBracketPos=strline.find(']');
|
||||
if(rBracketPos>0&&rBracketPos!=std::string::npos)
|
||||
{
|
||||
strSection=strline.substr(1,rBracketPos-1);
|
||||
if(strSection==Section)
|
||||
{
|
||||
while(ii<iFileLines)
|
||||
{
|
||||
strline=m_FileContainer[ii++];
|
||||
size_t equalsignPos=strline.find('=');
|
||||
if(equalsignPos!=strline.npos)
|
||||
{
|
||||
size_t last=equalsignPos?strline.find_last_not_of(" \t",equalsignPos-1):strline.npos;
|
||||
if(last==strline.npos) strItem="";
|
||||
else strItem=strline.substr(0,last+1);
|
||||
|
||||
if(Item==strItem)
|
||||
{
|
||||
ReplaceLine(ii-1,Item+" = "+Value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if('['==strline[0])
|
||||
{
|
||||
InsertLine(ii-1,Item+" = "+Value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
InsertLine(ii,Item+" = "+Value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
InsertLine(ii,"["+Section+"]");
|
||||
InsertLine(ii+1,Item+" = "+Value);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool CIniFile::InsertLine(size_t line,const std::string& str)
|
||||
{
|
||||
m_FileContainer.insert(m_FileContainer.begin()+line,str);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CIniFile::ReplaceLine(size_t line,const std::string& str)
|
||||
{
|
||||
m_FileContainer[line]=str;
|
||||
return true;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue