diff options
author | madmaxoft <github@xoft.cz> | 2013-10-25 11:15:44 +0200 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2013-10-25 11:15:44 +0200 |
commit | 9e9198e0907d3d6fd353c683478007f418d86dd8 (patch) | |
tree | 9dd53b8f34532b135ae199e47a0e9e59d77a76f4 /iniFile | |
parent | APIDump: Documented cMonster. (diff) | |
download | cuberite-9e9198e0907d3d6fd353c683478007f418d86dd8.tar cuberite-9e9198e0907d3d6fd353c683478007f418d86dd8.tar.gz cuberite-9e9198e0907d3d6fd353c683478007f418d86dd8.tar.bz2 cuberite-9e9198e0907d3d6fd353c683478007f418d86dd8.tar.lz cuberite-9e9198e0907d3d6fd353c683478007f418d86dd8.tar.xz cuberite-9e9198e0907d3d6fd353c683478007f418d86dd8.tar.zst cuberite-9e9198e0907d3d6fd353c683478007f418d86dd8.zip |
Diffstat (limited to 'iniFile')
-rw-r--r-- | iniFile/iniFile.cpp | 15 | ||||
-rw-r--r-- | iniFile/iniFile.h | 18 |
2 files changed, 13 insertions, 20 deletions
diff --git a/iniFile/iniFile.cpp b/iniFile/iniFile.cpp index 5ecbc5e06..06f5e5592 100644 --- a/iniFile/iniFile.cpp +++ b/iniFile/iniFile.cpp @@ -42,17 +42,16 @@ using namespace std; -cIniFile::cIniFile(const string & a_Path) : +cIniFile::cIniFile(void) : m_IsCaseInsensitive(true) { - Path(a_Path); } -bool cIniFile::ReadFile(bool a_AllowExampleRedirect) +bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect) { // Normally you would use ifstream, but the SGI CC compiler has // a few bugs with ifstream. So ... fstream used. @@ -62,14 +61,14 @@ bool cIniFile::ReadFile(bool a_AllowExampleRedirect) string::size_type pLeft, pRight; bool IsFromExampleRedirect = false; - f.open((FILE_IO_PREFIX + m_Path).c_str(), ios::in); + f.open((FILE_IO_PREFIX + a_FileName).c_str(), ios::in); if (f.fail()) { f.clear(); if (a_AllowExampleRedirect) { // Retry with the .example.ini file instead of .ini: - string ExPath(m_Path.substr(0, m_Path.length() - 4)); + string ExPath(a_FileName.substr(0, a_FileName.length() - 4)); ExPath.append(".example.ini"); f.open((FILE_IO_PREFIX + ExPath).c_str(), ios::in); if (f.fail()) @@ -166,7 +165,7 @@ bool cIniFile::ReadFile(bool a_AllowExampleRedirect) if (IsFromExampleRedirect) { - WriteFile(); + WriteFile(FILE_IO_PREFIX + a_FileName); } return true; } @@ -175,14 +174,14 @@ bool cIniFile::ReadFile(bool a_AllowExampleRedirect) -bool cIniFile::WriteFile(void) const +bool cIniFile::WriteFile(const AString & a_FileName) const { unsigned commentID, keyID, valueID; // Normally you would use ofstream, but the SGI CC compiler has // a few bugs with ofstream. So ... fstream used. fstream f; - f.open((FILE_IO_PREFIX + m_Path).c_str(), ios::out); + f.open((FILE_IO_PREFIX + a_FileName).c_str(), ios::out); if (f.fail()) { return false; diff --git a/iniFile/iniFile.h b/iniFile/iniFile.h index aef45c094..70342604f 100644 --- a/iniFile/iniFile.h +++ b/iniFile/iniFile.h @@ -36,7 +36,6 @@ class cIniFile { private: bool m_IsCaseInsensitive; - std::string m_Path; struct key { @@ -58,28 +57,23 @@ public: noID = -1, }; - /// Creates a new instance; sets m_Path to a_Path, but doesn't read the file - cIniFile(const std::string & a_Path = ""); + /// Creates a new instance with no data + cIniFile(void); // Sets whether or not keynames and valuenames should be case sensitive. // The default is case insensitive. void CaseSensitive (void) { m_IsCaseInsensitive = false; } void CaseInsensitive(void) { m_IsCaseInsensitive = true; } - // Sets path of ini file to read and write from. - void Path(const std::string & newPath) {m_Path = newPath;} - const std::string & Path(void) const {return m_Path;} - void SetPath(const std::string & newPath) {Path(newPath);} - - /** Reads the ini file specified in m_Path + /** Reads the contents of the specified ini file If the file doesn't exist and a_AllowExampleRedirect is true, tries to read <basename>.example.ini, and writes its contents as <basename>.ini, if successful. Returns true if successful, false otherwise. */ - bool ReadFile(bool a_AllowExampleRedirect = true); + bool ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect = true); - /// Writes data stored in class to ini file specified in m_Path - bool WriteFile(void) const; + /// Writes data stored in class to the specified ini file + bool WriteFile(const AString & a_FileName) const; /// Deletes all stored ini data (but doesn't touch the file) void Clear(void); |