Load IniFile from Path

Buildfixing
This commit is contained in:
Henrik Rydgård 2021-05-09 12:41:59 +02:00
parent 025bcb1673
commit b7fe72bfc9
3 changed files with 18 additions and 25 deletions

View file

@ -516,23 +516,19 @@ void IniFile::SortSections()
std::sort(sections.begin(), sections.end());
}
bool IniFile::Load(const char* filename)
bool IniFile::Load(const Path &path)
{
sections.clear();
sections.push_back(Section(""));
// first section consists of the comments before the first real section
// Open file
std::ifstream in;
#if defined(_WIN32) && !defined(__MINGW32__)
in.open(ConvertUTF8ToWString(filename), std::ios::in);
#else
in.open(filename, std::ios::in);
#endif
if (in.fail()) return false;
bool success = Load(in);
in.close();
std::string data;
if (!File::ReadFileToString(true, path.ToString().c_str(), data)) {
return false;
}
std::stringstream sstream(data);
bool success = Load(sstream);
return success;
}
@ -559,13 +555,13 @@ bool IniFile::Load(std::istream &in) {
std::string line = templine;
// Remove UTF-8 byte order marks.
if (line.substr(0, 3) == "\xEF\xBB\xBF")
if (line.substr(0, 3) == "\xEF\xBB\xBF") {
line = line.substr(3);
}
#ifndef _WIN32
// Check for CRLF eol and convert it to LF
if (!line.empty() && line.at(line.size()-1) == '\r')
{
if (!line.empty() && line.at(line.size()-1) == '\r') {
line.erase(line.size()-1);
}
#endif
@ -596,7 +592,7 @@ bool IniFile::Load(std::istream &in) {
return true;
}
bool IniFile::Save(const char* filename)
bool IniFile::Save(const Path &filename)
{
FILE *file = File::OpenCFile(Path(filename), "w");
if (!file) {

View file

@ -77,18 +77,15 @@ protected:
std::string comment;
};
class IniFile
{
bool Load(const char *filename);
bool Save(const char *filename);
class IniFile {
public:
bool Load(const Path &path) { return Load(path.c_str()); } // TODO(scoped)
bool Load(const std::string &filename) { return Load(filename.c_str()); }
bool Load(const Path &path);
bool Load(const std::string &filename) { return Load(Path(filename)); }
bool Load(std::istream &istream);
bool LoadFromVFS(const std::string &filename);
bool Save(const Path &path) { return Save(path.c_str()); } // TODO(scoped)
bool Save(const std::string &filename) { return Save(filename.c_str()); }
bool Save(const Path &path);
bool Save(const std::string &filename) { return Save(Path(filename)); }
// Returns true if key exists in section
bool Exists(const char* sectionName, const char* key) const;

View file

@ -537,8 +537,8 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
#if !PPSSPP_PLATFORM(WINDOWS)
g_Config.AddSearchPath(Path(user_data_path));
g_Config.AddSearchPath(Path(GetSysDirectory(DIRECTORY_SYSTEM)));
g_Config.SetDefaultPath(Path(GetSysDirectory(DIRECTORY_SYSTEM)));
g_Config.AddSearchPath(GetSysDirectory(DIRECTORY_SYSTEM));
g_Config.SetDefaultPath(GetSysDirectory(DIRECTORY_SYSTEM));
// Note that if we don't have storage permission here, loading the config will
// fail and it will be set to the default. Later, we load again when we get permission.