summaryrefslogtreecommitdiffstats
path: root/src/IniFile.cpp
diff options
context:
space:
mode:
authortycho <tycho@localhost>2015-05-14 16:47:51 +0200
committertycho <work.tycho@gmail.com>2015-05-16 11:46:51 +0200
commitb9efa02c80b54e044326771bbffdddf206daef2e (patch)
treeab615f16b3c46b107f1df0e180c835300dbd19b7 /src/IniFile.cpp
parentAdded TCLAP (diff)
downloadcuberite-b9efa02c80b54e044326771bbffdddf206daef2e.tar
cuberite-b9efa02c80b54e044326771bbffdddf206daef2e.tar.gz
cuberite-b9efa02c80b54e044326771bbffdddf206daef2e.tar.bz2
cuberite-b9efa02c80b54e044326771bbffdddf206daef2e.tar.lz
cuberite-b9efa02c80b54e044326771bbffdddf206daef2e.tar.xz
cuberite-b9efa02c80b54e044326771bbffdddf206daef2e.tar.zst
cuberite-b9efa02c80b54e044326771bbffdddf206daef2e.zip
Diffstat (limited to 'src/IniFile.cpp')
-rw-r--r--src/IniFile.cpp51
1 files changed, 41 insertions, 10 deletions
diff --git a/src/IniFile.cpp b/src/IniFile.cpp
index 99c0a5f0f..8dab87d15 100644
--- a/src/IniFile.cpp
+++ b/src/IniFile.cpp
@@ -49,6 +49,9 @@ cIniFile::cIniFile(void) :
bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect)
{
+
+ m_Filename = a_FileName;
+
// Normally you would use ifstream, but the SGI CC compiler has
// a few bugs with ifstream. So ... fstream used.
fstream f;
@@ -56,7 +59,8 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect)
AString keyname, valuename, value;
AString::size_type pLeft, pRight;
bool IsFromExampleRedirect = false;
-
+
+
f.open((FILE_IO_PREFIX + a_FileName).c_str(), ios::in);
if (f.fail())
{
@@ -650,7 +654,7 @@ void cIniFile::Clear(void)
-bool cIniFile::HasValue(const AString & a_KeyName, const AString & a_ValueName)
+bool cIniFile::HasValue(const AString & a_KeyName, const AString & a_ValueName) const
{
// Find the key:
int keyID = FindKey(a_KeyName);
@@ -889,8 +893,36 @@ void cIniFile::RemoveBom(AString & a_line) const
+bool cIniFile::KeyExists(AString a_keyname) const
+{
+ return FindKey(a_keyname) != noID;
+}
+
+
+
+
+
+std::vector<std::pair<AString, AString>> cIniFile::GetValues(AString a_keyName)
+{
+ std::vector<std::pair<AString, AString>> ret;
+ int keyID = FindKey(a_keyName);
+ if (keyID == noID)
+ {
+ return ret;
+ }
+ for (size_t valueID = 0; valueID < keys[keyID].names.size(); ++valueID)
+ {
+ ret.emplace_back(keys[keyID].names[valueID], keys[keyID].values[valueID]);
+ }
+ return ret;
+}
+
+
+
+
+
AStringVector ReadUpgradeIniPorts(
- cIniFile & a_IniFile,
+ cSettingsRepositoryInterface & a_Settings,
const AString & a_KeyName,
const AString & a_PortsValueName,
const AString & a_OldIPv4ValueName,
@@ -899,23 +931,23 @@ AStringVector ReadUpgradeIniPorts(
)
{
// Read the regular value, but don't use the default (in order to detect missing value for upgrade):
- AStringVector Ports = StringSplitAndTrim(a_IniFile.GetValue(a_KeyName, a_PortsValueName), ";,");
+ AStringVector Ports = StringSplitAndTrim(a_Settings.GetValue(a_KeyName, a_PortsValueName), ";,");
if (Ports.empty())
{
// Historically there were two separate entries for IPv4 and IPv6, merge them and migrate:
- AString Ports4 = a_IniFile.GetValue(a_KeyName, a_OldIPv4ValueName, a_DefaultValue);
- AString Ports6 = a_IniFile.GetValue(a_KeyName, a_OldIPv6ValueName);
+ AString Ports4 = a_Settings.GetValue(a_KeyName, a_OldIPv4ValueName, a_DefaultValue);
+ AString Ports6 = a_Settings.GetValue(a_KeyName, a_OldIPv6ValueName);
Ports = MergeStringVectors(StringSplitAndTrim(Ports4, ";,"), StringSplitAndTrim(Ports6, ";,"));
- a_IniFile.DeleteValue(a_KeyName, a_OldIPv4ValueName);
- a_IniFile.DeleteValue(a_KeyName, a_OldIPv6ValueName);
+ a_Settings.DeleteValue(a_KeyName, a_OldIPv4ValueName);
+ a_Settings.DeleteValue(a_KeyName, a_OldIPv6ValueName);
// If those weren't present or were empty, use the default:"
if (Ports.empty())
{
Ports = StringSplitAndTrim(a_DefaultValue, ";,");
}
- a_IniFile.SetValue(a_KeyName, a_PortsValueName, StringsConcat(Ports, ','));
+ a_Settings.SetValue(a_KeyName, a_PortsValueName, StringsConcat(Ports, ','));
}
return Ports;
@@ -923,4 +955,3 @@ AStringVector ReadUpgradeIniPorts(
-