summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2015-01-24 09:45:07 +0100
committerMattes D <github@xoft.cz>2015-01-27 14:53:25 +0100
commit7990d223eaef21e095c8b25389ffa20ff3137316 (patch)
tree722f021b936df69c60d25b2189b8880b66680604 /src
parentStringUtils: Added string vector manipulation. (diff)
downloadcuberite-7990d223eaef21e095c8b25389ffa20ff3137316.tar
cuberite-7990d223eaef21e095c8b25389ffa20ff3137316.tar.gz
cuberite-7990d223eaef21e095c8b25389ffa20ff3137316.tar.bz2
cuberite-7990d223eaef21e095c8b25389ffa20ff3137316.tar.lz
cuberite-7990d223eaef21e095c8b25389ffa20ff3137316.tar.xz
cuberite-7990d223eaef21e095c8b25389ffa20ff3137316.tar.zst
cuberite-7990d223eaef21e095c8b25389ffa20ff3137316.zip
Diffstat (limited to 'src')
-rw-r--r--src/IniFile.cpp36
-rw-r--r--src/IniFile.h24
2 files changed, 56 insertions, 4 deletions
diff --git a/src/IniFile.cpp b/src/IniFile.cpp
index ded7e4199..3a213a90e 100644
--- a/src/IniFile.cpp
+++ b/src/IniFile.cpp
@@ -888,3 +888,39 @@ void cIniFile::RemoveBom(AString & a_line) const
+
+AStringVector ReadUpgradeIniPorts(
+ cIniFile & a_IniFile,
+ const AString & a_KeyName,
+ const AString & a_PortsValueName,
+ const AString & a_OldIPv4ValueName,
+ const AString & a_OldIPv6ValueName,
+ const AString & a_DefaultValue
+)
+{
+ // 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), ";,");
+
+ 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);
+ Ports = MergeStringVectors(StringSplitAndTrim(Ports4, ";,"), StringSplitAndTrim(Ports6, ";,"));
+ a_IniFile.DeleteValue(a_KeyName, a_OldIPv4ValueName);
+ a_IniFile.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, ','));
+ }
+
+ return Ports;
+}
+
+
+
+
diff --git a/src/IniFile.h b/src/IniFile.h
index e5879f46c..3e717723f 100644
--- a/src/IniFile.h
+++ b/src/IniFile.h
@@ -15,9 +15,7 @@
!! MODIFIED BY FAKETRUTH and madmaxoft!!
*/
-#ifndef CIniFile_H
-#define CIniFile_H
-
+#pragma once
@@ -215,4 +213,22 @@ public:
// tolua_end
-#endif
+
+
+
+
+/** Reads the list of ports from the INI file, possibly upgrading from IPv4/IPv6-specific values into new version-agnostic value.
+Reads the list of ports from a_PortsValueName. If that value doesn't exist or is empty, the list is combined from values
+in a_OldIPv4ValueName and a_OldIPv6ValueName; in this case the old values are removed from the INI file.
+If there is none of the three values or they are all empty, the default is used and stored in the Ports value. */
+AStringVector ReadUpgradeIniPorts(
+ cIniFile & a_IniFile,
+ const AString & a_KeyName,
+ const AString & a_PortsValueName,
+ const AString & a_OldIPv4ValueName,
+ const AString & a_OldIPv6ValueName,
+ const AString & a_DefaultValue
+);
+
+
+