1
0

Merge branch 'IniFileCleanup'

This commit is contained in:
madmaxoft 2013-10-26 19:43:34 +02:00
commit 52f88b9595
17 changed files with 572 additions and 927 deletions

View File

@ -1015,101 +1015,155 @@ cFile:Delete("/usr/bin/virus.exe");
cIniFile = cIniFile =
{ {
Desc = [[The cIniFile is a class that makes it simple to read from and write to INI files. MCServer uses mostly INI files for settings and options. Desc = [[
]], This class implements a simple name-value storage represented on disk by an INI file. These files
are suitable for low-volume high-latency human-readable information storage, such as for
configuration. MCServer itself uses INI files for settings and options.</p>
<p>
The INI files follow this basic structure:
<pre class="prettyprint lang-ini">
; Header comment line
[KeyName0]
; Key comment line 0
ValueName0=Value0
ValueName1=Value1
[KeyName1]
; Key comment line 0
; Key comment line 1
ValueName0=SomeOtherValue
</pre>
The cIniFile object stores all the objects in numbered arrays and provides access to the information
either based on names (KeyName, ValueName) or zero-based indices.</p>
<p>
The objects of this class are created empty. You need to either load a file using ReadFile(), or
insert values by hand. Then you can store the object's contents to a disk file using WriteFile(), or
just forget everything by destroying the object. Note that the file operations are quite slow.</p>
<p>
For storing high-volume low-latency data, use the {{sqlite}} class. For storing
hierarchically-structured data, use the XML format, using the LuaExpat parser in the {{lxp}} class.
]],
Functions = Functions =
{ {
constructor = { Return = "{{cIniFile|cIniFile}}" }, constructor = { Params = "", Return = "cIniFile", Notes = "Creates a new empty cIniFile object." },
CaseSensitive = { Return = "" }, AddHeaderComment = { Params = "Comment", Return = "", Notes = "Adds a comment to be stored in the file header." },
CaseInsensitive = { Return = "" }, AddKeyComment =
Path = { Return = "" }, {
Path = { Return = "string" }, { Params = "KeyID, Comment", Return = "", Notes = "Adds a comment to be stored in the file under the specified key" },
SetPath = { Return = "" }, { Params = "KeyName, Comment", Return = "", Notes = "Adds a comment to be stored in the file under the specified key" },
ReadFile = { Return = "bool" }, },
WriteFile = { Return = "bool" }, AddKeyName = { Params = "KeyName", Returns = "number", Notes = "Adds a new key of the specified name. Returns the KeyID of the new key." },
Erase = { Return = "" }, CaseInsensitive = { Params = "", Return = "", Notes = "Sets key names' and value names' comparisons to case insensitive (default)." },
Clear = { Return = "" }, CaseSensitive = { Params = "", Return = "", Notes = "Sets key names and value names comparisons to case sensitive." },
Reset = { Return = "" }, Clear = { Params = "", Return = "", Notes = "Removes all the in-memory data. Note that , like all the other operations, this doesn't affect any file data." },
FindKey = { Notes = "long i" }, DeleteHeaderComment = { Params = "CommentID", Return = "bool" , Notes = "Deletes the specified header comment. Returns true if successful."},
FindValue = { Notes = "long i" }, DeleteHeaderComments = { Params = "", Return = "", Notes = "Deletes all headers comments." },
NumKeys = { Notes = "unsigned i" }, DeleteKey = { Params = "KeyName", Return = "bool", Notes = "Deletes the specified key, and all values in that key. Returns true if successful." },
GetNumKeys = { Notes = "unsigned i" }, DeleteKeyComment =
AddKeyName = { Notes = "unsigned int" }, {
KeyName = { Notes = "Stri" }, { Params = "KeyID, CommentID", Return = "bool", Notes = "Deletes the specified key comment. Returns true if successful." },
GetKeyName = { Notes = "Stri" }, { Params = "KeyName, CommentID", Return = "bool", Notes = "Deletes the specified key comment. Returns true if successful." },
NumValues = { Notes = "unsigned int" }, },
GetNumValues = { Notes = "unsigned int" }, DeleteKeyComments =
NumValues = { Notes = "unsigned int" }, {
GetNumValues = { Notes = "unsigned int" }, { Params = "KeyID", Return = "bool", Notes = "Deletes all comments for the specified key. Returns true if successful." },
ValueName = { Notes = "Stri" }, { Params = "KeyName", Return = "bool", Notes = "Deletes all comments for the specified key. Returns true if successful." },
GetValueName = { Notes = "Stri" }, },
ValueName = { Notes = "Stri" }, DeleteValue = { Params = "KeyName, ValueName", Return = "bool", Notes = "Deletes the specified value. Returns true if successful." },
GetValueName = { Notes = "Stri" }, DeleteValueByID = { Params = "KeyID, ValueID", Return = "bool", Notes = "Deletes the specified value. Returns true if successful." },
GetValue = { Notes = "Stri" }, FindKey = { Params = "KeyName", Return = "number", Notes = "Returns the KeyID for the specified key name, or the noID constant if the key doesn't exist." },
GetValue = { Notes = "Stri" }, FindValue = { Params = "KeyID, ValueName", Return = "numebr", Notes = "Returns the ValueID for the specified value name, or the noID constant if the specified key doesn't contain a value of that name." },
GetValueI = { Notes = "i" }, GetHeaderComment = { Params = "CommentID", Return = "string", Notes = "Returns the specified header comment, or an empty string if such comment doesn't exist" },
GetValueB = { Notes = "bo" }, GetKeyComment =
GetValueF = { Notes = "doub" }, {
GetValueSet = { Notes = "Stri" }, { Params = "KeyID, CommentID", Return = "string", Notes = "Returns the specified key comment, or an empty string if such a comment doesn't exist" },
GetValueSetI = { Notes = "i" }, { Params = "KeyName, CommentID", Return = "string", Notes = "Returns the specified key comment, or an empty string if such a comment doesn't exist" },
GetValueSetB = { Notes = "bo" }, },
GetValueSetF = { Notes = "doub" }, GetKeyName = { Params = "KeyID", Return = "string", Notes = "Returns the key name for the specified key ID. Inverse for FindKey()." },
SetValue = { Return = "bool" }, GetNumHeaderComments = { Params = "", Return = "number", Notes = "Retuns the number of header comments." },
SetValue = { Return = "bool" }, GetNumKeyComments =
SetValueI = { Return = "bool" }, {
SetValueB = { Return = "bool" }, { Params = "KeyID", Return = "number", Notes = "Returns the number of comments under the specified key" },
SetValueF = { Return = "bool" }, { Params = "KeyName", Return = "number", Notes = "Returns the number of comments under the specified key" },
DeleteValueByID = { Return = "bool" }, },
DeleteValue = { Return = "bool" }, GetNumKeys = { Params = "", Return = "number", Notes = "Returns the total number of keys. This is the range for the KeyID (0 .. GetNumKeys() - 1)" },
DeleteKey = { Return = "bool" }, GetNumValues =
NumHeaderComments = { Notes = "unsigned int" }, {
HeaderComment = { Return = "" }, { Params = "KeyID", Return = "number", Notes = "Returns the number of values stored under the specified key." },
HeaderComment = { Notes = "Stri" }, { Params = "KeyName", Return = "number", Notes = "Returns the number of values stored under the specified key." },
DeleteHeaderComment = { Return = "bool" }, },
DeleteHeaderComments = { Return = "" }, GetValue =
NumKeyComments = { Notes = "unsigned i" }, {
NumKeyComments = { Notes = "unsigned i" }, { Params = "KeyName, ValueName", Return = "string", Notes = "Returns the value of the specified name under the specified key. Returns an empty string if the value doesn't exist." },
KeyComment = { Return = "bool" }, { Params = "KeyID, ValueID", Return = "string", Notes = "Returns the value of the specified name under the specified key. Returns an empty string if the value doesn't exist." },
KeyComment = { Return = "bool" }, },
KeyComment = { Notes = "Stri" }, GetValueB = { Params = "KeyName, ValueName", Return = "bool", Notes = "Returns the value of the specified name under the specified key, as a bool. Returns false if the value doesn't exist." },
KeyComment = { Notes = "Stri" }, GetValueF = { Params = "KeyName, ValueName", Return = "number", Notes = "Returns the value of the specified name under the specified key, as a floating-point number. Returns zero if the value doesn't exist." },
DeleteKeyComment = { Return = "bool" }, GetValueI = { Params = "KeyName, ValueName", Return = "number", Notes = "Returns the value of the specified name under the specified key, as an integer. Returns zero if the value doesn't exist." },
DeleteKeyComment = { Return = "bool" }, GetValueName =
DeleteKeyComments = { Return = "bool" }, {
DeleteKeyComments = { Return = "bool" }, { Params = "KeyID, ValueID", Return = "string", Notes = "Returns the name of the specified value Inverse for FindValue()." },
{ Params = "KeyName, ValueID", Return = "string", Notes = "Returns the name of the specified value Inverse for FindValue()." },
},
GetValueSet = { Params = "KeyName, ValueName, Default", Return = "string", Notes = "Returns the value of the specified name under the specified key. If the value doesn't exist, creates it with the specified default." },
GetValueSetB = { Params = "KeyName, ValueName, Default", Return = "bool", Notes = "Returns the value of the specified name under the specified key, as a bool. If the value doesn't exist, creates it with the specified default." },
GetValueSetF = { Params = "KeyName, ValueName, Default", Return = "number", Notes = "Returns the value of the specified name under the specified key, as a floating-point number. If the value doesn't exist, creates it with the specified default." },
GetValueSetI = { Params = "KeyName, ValueName, Default", Return = "number", Notes = "Returns the value of the specified name under the specified key, as an integer. If the value doesn't exist, creates it with the specified default." },
ReadFile = { Params = "FileName, [AllowExampleFallback]", Return = "bool", Notes = "Reads the values from the specified file. Previous in-memory contents are lost. If the file cannot be opened, and AllowExample is true, another file, \"filename.example.ini\", is loaded and then saved as \"filename.ini\". Returns true if successful, false if not." },
SetValue =
{
{ Params = "KeyID, ValueID, NewValue", Return = "bool", Notes = "Overwrites the specified value with a new value. If the specified value doesn't exist, returns false (doesn't add)." },
{ Params = "KeyName, ValueName, NewValue, [CreateIfNotExists]", Return = "bool", Notes = "Overwrites the specified value with a new value. If CreateIfNotExists is true (default) and the value doesn't exist, it is first created. Returns true if the value was successfully set, false if not (didn't exists, CreateIfNotExists false)." },
},
SetValueB = { Params = "KeyName, ValueName, NewValueBool, [CreateIfNotExists]", Return = "bool", Notes = "Overwrites the specified value with a new bool value. If CreateIfNotExists is true (default) and the value doesn't exist, it is first created. Returns true if the value was successfully set, false if not (didn't exists, CreateIfNotExists false)." },
SetValueF = { Params = "KeyName, ValueName, NewValueFloat, [CreateIfNotExists]", Return = "bool", Notes = "Overwrites the specified value with a new floating-point number value. If CreateIfNotExists is true (default) and the value doesn't exist, it is first created. Returns true if the value was successfully set, false if not (didn't exists, CreateIfNotExists false)." },
SetValueI = { Params = "KeyName, ValueName, NewValueInt, [CreateIfNotExists]", Return = "bool", Notes = "Overwrites the specified value with a new integer value. If CreateIfNotExists is true (default) and the value doesn't exist, it is first created. Returns true if the value was successfully set, false if not (didn't exists, CreateIfNotExists false)." },
WriteFile = { Params = "FileName", Return = "bool", Notes = "Writes the current in-memory data into the specified file. Returns true if successful, false if not." },
}, },
Constants = Constants =
{ {
noID = { Notes = "" },
}, },
AdditionalInfo = AdditionalInfo =
{ {
{ {
Header = "Practical usage", Header = "Code example: Reading a simple value",
Contents = [[ Contents = [[
If you want to use cIniFile you need to know a couple of things; what is the key name and what
is the value name. Below is a demonstration of what is what.</p>
<pre class="prettyprint lang-ini">
; Comment line
[KeyName1]
ValueName1=Value1
ValueName2=Value2
[KeyName2]
ValueName1=Value3
</pre></p>
<p>
cIniFile is very easy to use. For example, you can find out what port the server is supposed to cIniFile is very easy to use. For example, you can find out what port the server is supposed to
use according to settings.ini by using this little snippet: use according to settings.ini by using this little snippet:
<pre class="prettyprint lang-lua"> <pre class="prettyprint lang-lua">
local IniFile = cIniFile("settings.ini"); local IniFile = cIniFile();
if (IniFile:ReadFile()) then if (IniFile:ReadFile("settings.ini")) then
ServerPort = IniFile:GetValueI("Server", "Port"); ServerPort = IniFile:GetValueI("Server", "Port");
end end
</pre> </pre>
]], ]],
}, },
}, {
}, Header = "Code example: Enumerating all objects in a file",
Contents = [[
To enumerate all keys in a file, you need to query the total number of keys, using GetNumKeys(),
and then query each key's name using GetKeyName(). Similarly, to enumerate all values under a
key, you need to query the total number of values using GetNumValues() and then query each
value's name using GetValueName().</p>
<p>
The following code logs all keynames and their valuenames into the server log:
<pre class="prettyprint lang-lua">
local IniFile = cIniFile();
IniFile:ReadFile("somefile.ini")
local NumKeys = IniFile:GetNumKeys();
for k = 0, NumKeys do
local NumValues = IniFile:GetNumValues(k);
LOG("key \"" .. IniFile:GetKeyName(k) .. "\" has " .. NumValues .. " values:");
for v = 0, NumValues do
LOG(" value \"" .. IniFile:GetValueName(k, v) .. "\".");
end
end
</pre>
]],
},
}, -- AdditionalInfo
}, -- cIniFile
cInventory = cInventory =
{ {
@ -1167,7 +1221,7 @@ These ItemGrids are available in the API and can be manipulated by the plugins,
invHotbarOffset = { Notes = "Starting slot number of the Hotbar part" }, invHotbarOffset = { Notes = "Starting slot number of the Hotbar part" },
invNumSlots = { Notes = "Total number of slots in a cInventory" }, invNumSlots = { Notes = "Total number of slots in a cInventory" },
}, },
}, }, -- cInventory
cItem = cItem =
{ {
@ -1254,7 +1308,7 @@ local Item5 = cItem(E_ITEM_DIAMOND_CHESTPLATE, 1, 0, "thorns=1;unbreaking=3");
]], ]],
}, },
}, },
}, }, -- cItem
cItemGrid = cItemGrid =
{ {
@ -1364,7 +1418,7 @@ end
]], ]],
}, },
}, -- AdditionalInfo }, -- AdditionalInfo
}, }, -- cItemGrid
cItems = cItems =
{ {
@ -1394,7 +1448,7 @@ end
Constants = Constants =
{ {
}, },
}, }, -- cItems
cLineBlockTracer = cLineBlockTracer =
{ {

View File

@ -6,20 +6,27 @@ CX = 0
CZ = 0 CZ = 0
CURRENT = 0 CURRENT = 0
TOTAL = 0 TOTAL = 0
-- AREA Variables -- AREA Variables
AreaStartX = -10 AreaStartX = -10
AreaStartZ = -10 AreaStartZ = -10
AreaEndX = 10 AreaEndX = 10
AreaEndZ = 10 AreaEndZ = 10
-- RADIAL Variables -- RADIAL Variables
RadialX = 0 RadialX = 0
RadialZ = 0 RadialZ = 0
Radius = 1 Radius = 10
-- WORLD -- WORLD
WORK_WORLD = cRoot:Get():GetDefaultWorld():GetName() WORK_WORLD = cRoot:Get():GetDefaultWorld():GetName()
WW_instance = cRoot:Get():GetDefaultWorld() WW_instance = cRoot:Get():GetDefaultWorld()
WORLDS = {} WORLDS = {}
function Initialize(Plugin) function Initialize(Plugin)
PLUGIN = Plugin PLUGIN = Plugin
@ -36,39 +43,25 @@ function Initialize(Plugin)
LOG("" .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. ": NO WORLD found :(") LOG("" .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. ": NO WORLD found :(")
end end
PLUGIN.IniFile = cIniFile("ChunkWorx.ini") -- Read the stored values:
if (PLUGIN.IniFile:ReadFile() == false) then local SettingsIni = cIniFile();
PLUGIN.IniFile:HeaderComment("ChunkWorx Save") SettingsIni:ReadFile("ChunkWorx.ini"); -- ignore any read errors
PLUGIN.IniFile:AddKeyName("Area data") AreaStartX = SettingsIni:GetValueSetI("Area data", "StartX", AreaStartX)
PLUGIN.IniFile:SetValueI("Area data", "StartX", AreaStartX) AreaStartZ = SettingsIni:GetValueSetI("Area data", "StartZ", AreaStartZ)
PLUGIN.IniFile:SetValueI("Area data", "StartZ", AreaStartZ) AreaEndX = SettingsIni:GetValueSetI("Area data", "EndX", AreaEndX)
PLUGIN.IniFile:SetValueI("Area data", "EndX", AreaEndX) AreaEndZ = SettingsIni:GetValueSetI("Area data", "EndZ", AreaEndZ)
PLUGIN.IniFile:SetValueI("Area data", "EndZ", AreaEndZ) RadialX = SettingsIni:GetValueSetI("Radial data", "RadialX", RadialX)
PLUGIN.IniFile:AddKeyName("Radial data") RadialZ = SettingsIni:GetValueSetI("Radial data", "RadialZ", RadialZ)
PLUGIN.IniFile:SetValueI("Radial data", "RadialX", RadialX) Radius = SettingsIni:GetValueSetI("Radial data", "Radius", Radius)
PLUGIN.IniFile:SetValueI("Radial data", "RadialZ", RadialZ) SettingsIni:WriteFile("ChunkWorx.ini");
PLUGIN.IniFile:SetValueI("Radial data", "Radius", Radius)
PLUGIN.IniFile:WriteFile()
end
AreaStartX = PLUGIN.IniFile:GetValueI("Area data", "StartX")
AreaStartZ = PLUGIN.IniFile:GetValueI("Area data", "StartZ")
AreaEndX = PLUGIN.IniFile:GetValueI("Area data", "EndX")
AreaEndZ = PLUGIN.IniFile:GetValueI("Area data", "EndZ")
RadialX = PLUGIN.IniFile:GetValueI("Radial data", "RadialX")
RadialZ = PLUGIN.IniFile:GetValueI("Radial data", "RadialZ")
Radius = PLUGIN.IniFile:GetValueI("Radial data", "Radius")
LOG("Initialized " .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion()) LOG("Initialized " .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion())
--LOG("Test1: " .. math.fmod(1.5, 1)) - return fractional part!
return true return true
end end
function OnDisable()
PLUGIN.IniFile:WriteFile()
LOG(PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. " is shutting down...")
end
function OnTick( DeltaTime ) function OnTick( DeltaTime )
if (GENERATION_STATE == 1 or GENERATION_STATE == 3) then if (GENERATION_STATE == 1 or GENERATION_STATE == 3) then
@ -128,7 +121,7 @@ function OnTick( DeltaTime )
end end
end end
end end
WW_instance:SaveAllChunks() WW_instance:QueueSaveAllChunks()
WW_instance:UnloadUnusedChunks() WW_instance:UnloadUnusedChunks()
end end
end end

View File

@ -1,11 +1,44 @@
-- chunkworx_web.lua
-- WebAdmin-related functions
local function Buttons_Player( Name ) local function Buttons_Player( Name )
return "<form method='POST'><input type='hidden' name='PlayerName' value='"..Name.."'><input type='submit' name='PlayerExact' value='Exact'><input type='submit' name='Player3x3' value='3x3'></form>" return "<form method='POST'><input type='hidden' name='PlayerName' value='"..Name.."'><input type='submit' name='PlayerExact' value='Exact'><input type='submit' name='Player3x3' value='3x3'></form>"
end end
local function Button_World( Name ) local function Button_World( Name )
return "<form method='POST'><input type='hidden' name='WorldName' value='"..Name.."'><input type='submit' name='SelectWorld' value='Select'></form>" return "<form method='POST'><input type='hidden' name='WorldName' value='"..Name.."'><input type='submit' name='SelectWorld' value='Select'></form>"
end end
local function SaveSettings()
local SettingsIni = cIniFile()
SettingsIni:SetValueI("Area data", "StartX", AreaStartX)
SettingsIni:SetValueI("Area data", "StartZ", AreaStartZ)
SettingsIni:SetValueI("Area data", "EndX", AreaEndX)
SettingsIni:SetValueI("Area data", "EndZ", AreaEndZ)
SettingsIni:SetValueI("Radial data", "RadialX", RadialX)
SettingsIni:SetValueI("Radial data", "RadialZ", RadialZ)
SettingsIni:SetValueI("Radial data", "Radius", Radius)
SettingsIni:WriteFile("ChunkWorx.ini")
end
function HandleRequest_Generation( Request ) function HandleRequest_Generation( Request )
local Content = "" local Content = ""
if (Request.PostParams["AGHRRRR"] ~= nil) then if (Request.PostParams["AGHRRRR"] ~= nil) then
@ -69,21 +102,12 @@ function HandleRequest_Generation( Request )
AreaStartZ = tonumber(Request.PostParams["FormAreaStartZ"]) AreaStartZ = tonumber(Request.PostParams["FormAreaStartZ"])
AreaEndX = tonumber(Request.PostParams["FormAreaEndX"]) AreaEndX = tonumber(Request.PostParams["FormAreaEndX"])
AreaEndZ = tonumber(Request.PostParams["FormAreaEndZ"]) AreaEndZ = tonumber(Request.PostParams["FormAreaEndZ"])
SaveSettings();
PLUGIN.IniFile:DeleteValue("Area data", "StartX")
PLUGIN.IniFile:DeleteValue("Area data", "StartZ")
PLUGIN.IniFile:DeleteValue("Area data", "EndX")
PLUGIN.IniFile:DeleteValue("Area data", "EndZ")
PLUGIN.IniFile:SetValueI("Area data", "StartX", AreaStartX)
PLUGIN.IniFile:SetValueI("Area data", "StartZ", AreaStartZ)
PLUGIN.IniFile:SetValueI("Area data", "EndX", AreaEndX)
PLUGIN.IniFile:SetValueI("Area data", "EndZ", AreaEndZ)
if (OPERATION_CODE == 0) then if (OPERATION_CODE == 0) then
GENERATION_STATE = 1 GENERATION_STATE = 1
elseif (OPERATION_CODE == 1) then elseif (OPERATION_CODE == 1) then
GENERATION_STATE = 3 GENERATION_STATE = 3
end end
PLUGIN.IniFile:WriteFile()
Content = ProcessingContent() Content = ProcessingContent()
return Content return Content
end end
@ -93,26 +117,19 @@ function HandleRequest_Generation( Request )
and Request.PostParams["FormRadius"] ~= nil ) then --(Re)Generation valid! and Request.PostParams["FormRadius"] ~= nil ) then --(Re)Generation valid!
-- COMMON (Re)gen -- COMMON (Re)gen
if( Request.PostParams["StartRadial"]) then if( Request.PostParams["StartRadial"]) then
RadialX = tonumber(Request.PostParams["FormRadialX"]) RadialX = tonumber(Request.PostParams["FormRadialX"]) or 0
RadialZ = tonumber(Request.PostParams["FormRadialZ"]) RadialZ = tonumber(Request.PostParams["FormRadialZ"]) or 0
Radius = tonumber(Request.PostParams["FormRadius"]) Radius = tonumber(Request.PostParams["FormRadius"]) or 10
AreaStartX = RadialX - Radius AreaStartX = RadialX - Radius
AreaStartZ = RadialZ - Radius AreaStartZ = RadialZ - Radius
AreaEndX = RadialX + Radius AreaEndX = RadialX + Radius
AreaEndZ = RadialZ + Radius AreaEndZ = RadialZ + Radius
SaveSettings()
PLUGIN.IniFile:DeleteValue("Radial data", "RadialX")
PLUGIN.IniFile:DeleteValue("Radial data", "RadialZ")
PLUGIN.IniFile:DeleteValue("Radial data", "Radius")
PLUGIN.IniFile:SetValueI("Radial data", "RadialX", RadialX)
PLUGIN.IniFile:SetValueI("Radial data", "RadialZ", RadialZ)
PLUGIN.IniFile:SetValueI("Radial data", "Radius", Radius)
if (OPERATION_CODE == 0) then if (OPERATION_CODE == 0) then
GENERATION_STATE = 1 GENERATION_STATE = 1
elseif (OPERATION_CODE == 1) then elseif (OPERATION_CODE == 1) then
GENERATION_STATE = 3 GENERATION_STATE = 3
end end
PLUGIN.IniFile:WriteFile()
Content = ProcessingContent() Content = ProcessingContent()
return Content return Content
end end
@ -214,7 +231,7 @@ function HandleRequest_Generation( Request )
Content = Content .. "</form>" Content = Content .. "</form>"
-- SELECTING RADIAL -- SELECTING RADIAL
Content = Content .. "<h4>Radial: </h4>Center X, Center Z, Raduis (0 to any)" Content = Content .. "<h4>Radial: </h4>Center X, Center Z, Radius"
Content = Content .. "<form method='POST'>" Content = Content .. "<form method='POST'>"
Content = Content .. "<input type='text' name='FormRadialX' value='" .. RadialX .. "'><input type='text' name='FormRadialZ' value='" .. RadialZ .. "'><input type='text' name='FormRadius' value='" .. Radius .. "'>" Content = Content .. "<input type='text' name='FormRadialX' value='" .. RadialX .. "'><input type='text' name='FormRadialZ' value='" .. RadialZ .. "'><input type='text' name='FormRadius' value='" .. Radius .. "'>"
Content = Content .. "<input type='submit' name='StartRadial' value='Start'>" Content = Content .. "<input type='submit' name='StartRadial' value='Start'>"

View File

@ -42,34 +42,33 @@ using namespace std;
cIniFile::cIniFile(const string & a_Path) : cIniFile::cIniFile(void) :
m_IsCaseInsensitive(true) 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 // Normally you would use ifstream, but the SGI CC compiler has
// a few bugs with ifstream. So ... fstream used. // a few bugs with ifstream. So ... fstream used.
fstream f; fstream f;
string line; AString line;
string keyname, valuename, value; AString keyname, valuename, value;
string::size_type pLeft, pRight; AString::size_type pLeft, pRight;
bool IsFromExampleRedirect = false; 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()) if (f.fail())
{ {
f.clear(); f.clear();
if (a_AllowExampleRedirect) if (a_AllowExampleRedirect)
{ {
// Retry with the .example.ini file instead of .ini: // Retry with the .example.ini file instead of .ini:
string ExPath(m_Path.substr(0, m_Path.length() - 4)); AString ExPath(a_FileName.substr(0, a_FileName.length() - 4));
ExPath.append(".example.ini"); ExPath.append(".example.ini");
f.open((FILE_IO_PREFIX + ExPath).c_str(), ios::in); f.open((FILE_IO_PREFIX + ExPath).c_str(), ios::in);
if (f.fail()) if (f.fail())
@ -91,7 +90,7 @@ bool cIniFile::ReadFile(bool a_AllowExampleRedirect)
// Note that the '\r' will be written to INI files from // Note that the '\r' will be written to INI files from
// Unix so that the created INI file can be read under Win32 // Unix so that the created INI file can be read under Win32
// without change. // without change.
unsigned int lineLength = line.length(); size_t lineLength = line.length();
if (lineLength == 0) if (lineLength == 0)
{ {
continue; continue;
@ -114,7 +113,7 @@ bool cIniFile::ReadFile(bool a_AllowExampleRedirect)
f.close(); f.close();
return false; return false;
} }
if ((pLeft = line.find_first_of(";#[=")) == string::npos) if ((pLeft = line.find_first_of(";#[=")) == AString::npos)
{ {
continue; continue;
} }
@ -124,7 +123,7 @@ bool cIniFile::ReadFile(bool a_AllowExampleRedirect)
case '[': case '[':
{ {
if ( if (
((pRight = line.find_last_of("]")) != string::npos) && ((pRight = line.find_last_of("]")) != AString::npos) &&
(pRight > pLeft) (pRight > pLeft)
) )
{ {
@ -147,11 +146,11 @@ bool cIniFile::ReadFile(bool a_AllowExampleRedirect)
{ {
if (names.size() == 0) if (names.size() == 0)
{ {
HeaderComment(line.substr(pLeft + 1)); AddHeaderComment(line.substr(pLeft + 1));
} }
else else
{ {
KeyComment(keyname, line.substr(pLeft + 1)); AddKeyComment(keyname, line.substr(pLeft + 1));
} }
break; break;
} }
@ -166,7 +165,7 @@ bool cIniFile::ReadFile(bool a_AllowExampleRedirect)
if (IsFromExampleRedirect) if (IsFromExampleRedirect)
{ {
WriteFile(); WriteFile(FILE_IO_PREFIX + a_FileName);
} }
return true; return true;
} }
@ -175,42 +174,42 @@ 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 // Normally you would use ofstream, but the SGI CC compiler has
// a few bugs with ofstream. So ... fstream used. // a few bugs with ofstream. So ... fstream used.
fstream f; 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()) if (f.fail())
{ {
return false; return false;
} }
// Write header comments. // Write header comments.
for (commentID = 0; commentID < comments.size(); ++commentID) size_t NumComments = comments.size();
for (size_t commentID = 0; commentID < NumComments; ++commentID)
{ {
f << ';' << comments[commentID] << iniEOL; f << ';' << comments[commentID] << iniEOL;
} }
if (comments.size()) if (NumComments > 0)
{ {
f << iniEOL; f << iniEOL;
} }
// Write keys and values. // Write keys and values.
for (keyID = 0; keyID < keys.size(); ++keyID) for (size_t keyID = 0; keyID < keys.size(); ++keyID)
{ {
f << '[' << names[keyID] << ']' << iniEOL; f << '[' << names[keyID] << ']' << iniEOL;
// Comments. // Comments.
for (commentID = 0; commentID < keys[keyID].comments.size(); ++commentID) for (size_t commentID = 0; commentID < keys[keyID].comments.size(); ++commentID)
{ {
f << ';' << keys[keyID].comments[commentID] << iniEOL; f << ';' << keys[keyID].comments[commentID] << iniEOL;
} }
// Values. // Values.
for (valueID = 0; valueID < keys[keyID].names.size(); ++valueID) for (size_t valueID = 0; valueID < keys[keyID].names.size(); ++valueID)
{ {
f << keys[keyID].names[valueID] << '=' << keys[keyID].values[valueID] << iniEOL; f << keys[keyID].names[valueID] << '=' << keys[keyID].values[valueID] << iniEOL;
} }
@ -225,14 +224,14 @@ bool cIniFile::WriteFile(void) const
long cIniFile::FindKey(const string & a_KeyName) const int cIniFile::FindKey(const AString & a_KeyName) const
{ {
string CaseKeyName = CheckCase(a_KeyName); AString CaseKeyName = CheckCase(a_KeyName);
for (unsigned keyID = 0; keyID < names.size(); ++keyID) for (size_t keyID = 0; keyID < names.size(); ++keyID)
{ {
if (CheckCase(names[keyID]) == CaseKeyName) if (CheckCase(names[keyID]) == CaseKeyName)
{ {
return long(keyID); return keyID;
} }
} }
return noID; return noID;
@ -242,19 +241,19 @@ long cIniFile::FindKey(const string & a_KeyName) const
long cIniFile::FindValue(unsigned const keyID, const string & a_ValueName) const int cIniFile::FindValue(const int keyID, const AString & a_ValueName) const
{ {
if (!keys.size() || (keyID >= keys.size())) if (!keys.size() || (keyID >= (int)keys.size()))
{ {
return noID; return noID;
} }
string CaseValueName = CheckCase(a_ValueName); AString CaseValueName = CheckCase(a_ValueName);
for (unsigned valueID = 0; valueID < keys[keyID].names.size(); ++valueID) for (size_t valueID = 0; valueID < keys[keyID].names.size(); ++valueID)
{ {
if (CheckCase(keys[keyID].names[valueID]) == CaseValueName) if (CheckCase(keys[keyID].names[valueID]) == CaseValueName)
{ {
return long(valueID); return int(valueID);
} }
} }
return noID; return noID;
@ -264,7 +263,7 @@ long cIniFile::FindValue(unsigned const keyID, const string & a_ValueName) const
unsigned cIniFile::AddKeyName(const string & keyname) int cIniFile::AddKeyName(const AString & keyname)
{ {
names.resize(names.size() + 1, keyname); names.resize(names.size() + 1, keyname);
keys.resize(keys.size() + 1); keys.resize(keys.size() + 1);
@ -275,9 +274,9 @@ unsigned cIniFile::AddKeyName(const string & keyname)
string cIniFile::KeyName(unsigned const keyID) const AString cIniFile::GetKeyName(const int keyID) const
{ {
if (keyID < names.size()) if (keyID < (int)names.size())
{ {
return names[keyID]; return names[keyID];
} }
@ -291,11 +290,11 @@ string cIniFile::KeyName(unsigned const keyID) const
unsigned cIniFile::NumValues(unsigned const keyID) int cIniFile::GetNumValues(const int keyID) const
{ {
if (keyID < keys.size()) if (keyID < (int)keys.size())
{ {
return keys[keyID].names.size(); return (int)keys[keyID].names.size();
} }
return 0; return 0;
} }
@ -304,23 +303,23 @@ unsigned cIniFile::NumValues(unsigned const keyID)
unsigned cIniFile::NumValues(const string & keyname) int cIniFile::GetNumValues(const AString & keyname) const
{ {
long keyID = FindKey(keyname); int keyID = FindKey(keyname);
if (keyID == noID) if (keyID == noID)
{ {
return 0; return 0;
} }
return keys[keyID].names.size(); return (int)keys[keyID].names.size();
} }
string cIniFile::ValueName(unsigned const keyID, unsigned const valueID) const AString cIniFile::GetValueName(const int keyID, const int valueID) const
{ {
if (keyID < keys.size() && valueID < keys[keyID].names.size()) if ((keyID < (int)keys.size()) && (valueID < (int)keys[keyID].names.size()))
{ {
return keys[keyID].names[valueID]; return keys[keyID].names[valueID];
} }
@ -331,23 +330,23 @@ string cIniFile::ValueName(unsigned const keyID, unsigned const valueID) const
string cIniFile::ValueName(const string & keyname, unsigned const valueID) const AString cIniFile::GetValueName(const AString & keyname, const int valueID) const
{ {
long keyID = FindKey(keyname); int keyID = FindKey(keyname);
if (keyID == noID) if (keyID == noID)
{ {
return ""; return "";
} }
return ValueName(keyID, valueID); return GetValueName(keyID, valueID);
} }
bool cIniFile::SetValue(unsigned const keyID, unsigned const valueID, const string & value) bool cIniFile::SetValue(const int keyID, const int valueID, const AString & value)
{ {
if ((keyID < keys.size()) && (valueID < keys[keyID].names.size())) if ((keyID < (int)keys.size()) && (valueID < (int)keys[keyID].names.size()))
{ {
keys[keyID].values[valueID] = value; keys[keyID].values[valueID] = value;
} }
@ -358,14 +357,14 @@ bool cIniFile::SetValue(unsigned const keyID, unsigned const valueID, const stri
bool cIniFile::SetValue(const string & keyname, const string & valuename, const string & value, bool const create) bool cIniFile::SetValue(const AString & keyname, const AString & valuename, const AString & value, bool const create)
{ {
long keyID = FindKey(keyname); int keyID = FindKey(keyname);
if (keyID == noID) if (keyID == noID)
{ {
if (create) if (create)
{ {
keyID = long(AddKeyName(keyname)); keyID = int(AddKeyName(keyname));
} }
else else
{ {
@ -373,7 +372,7 @@ bool cIniFile::SetValue(const string & keyname, const string & valuename, const
} }
} }
long valueID = FindValue(unsigned(keyID), valuename); int valueID = FindValue(int(keyID), valuename);
if (valueID == noID) if (valueID == noID)
{ {
if (!create) if (!create)
@ -403,7 +402,7 @@ bool cIniFile::SetValue(const string & keyname, const string & valuename, const
bool cIniFile::SetValueI(const string & keyname, const string & valuename, int const value, bool const create) bool cIniFile::SetValueI(const AString & keyname, const AString & valuename, const int value, bool const create)
{ {
AString Data; AString Data;
Printf(Data, "%d", value); Printf(Data, "%d", value);
@ -414,7 +413,7 @@ bool cIniFile::SetValueI(const string & keyname, const string & valuename, int c
bool cIniFile::SetValueF(const string & keyname, const string & valuename, double const value, bool const create) bool cIniFile::SetValueF(const AString & keyname, const AString & valuename, double const value, bool const create)
{ {
AString Data; AString Data;
Printf(Data, "%f", value); Printf(Data, "%f", value);
@ -425,7 +424,7 @@ bool cIniFile::SetValueF(const string & keyname, const string & valuename, doubl
bool cIniFile::SetValueV(const string & keyname, const string & valuename, char * format, ...) bool cIniFile::SetValueV(const AString & keyname, const AString & valuename, char * format, ...)
{ {
va_list args; va_list args;
va_start(args, format); va_start(args, format);
@ -440,9 +439,9 @@ bool cIniFile::SetValueV(const string & keyname, const string & valuename, char
string cIniFile::GetValue(unsigned const keyID, unsigned const valueID, const string & defValue) const AString cIniFile::GetValue(const int keyID, const int valueID, const AString & defValue) const
{ {
if ((keyID < keys.size()) && (valueID < keys[keyID].names.size())) if ((keyID < (int)keys.size()) && (valueID < (int)keys[keyID].names.size()))
{ {
return keys[keyID].values[valueID]; return keys[keyID].values[valueID];
} }
@ -453,15 +452,15 @@ string cIniFile::GetValue(unsigned const keyID, unsigned const valueID, const st
string cIniFile::GetValue(const string & keyname, const string & valuename, const string & defValue) const AString cIniFile::GetValue(const AString & keyname, const AString & valuename, const AString & defValue) const
{ {
long keyID = FindKey(keyname); int keyID = FindKey(keyname);
if (keyID == noID) if (keyID == noID)
{ {
return defValue; return defValue;
} }
long valueID = FindValue(unsigned(keyID), valuename); int valueID = FindValue(int(keyID), valuename);
if (valueID == noID) if (valueID == noID)
{ {
return defValue; return defValue;
@ -474,7 +473,7 @@ string cIniFile::GetValue(const string & keyname, const string & valuename, cons
int cIniFile::GetValueI(const string & keyname, const string & valuename, int const defValue) const int cIniFile::GetValueI(const AString & keyname, const AString & valuename, const int defValue) const
{ {
AString Data; AString Data;
Printf(Data, "%d", defValue); Printf(Data, "%d", defValue);
@ -485,7 +484,7 @@ int cIniFile::GetValueI(const string & keyname, const string & valuename, int co
double cIniFile::GetValueF(const string & keyname, const string & valuename, double const defValue) const double cIniFile::GetValueF(const AString & keyname, const AString & valuename, double const defValue) const
{ {
AString Data; AString Data;
Printf(Data, "%f", defValue); Printf(Data, "%f", defValue);
@ -498,14 +497,14 @@ double cIniFile::GetValueF(const string & keyname, const string & valuename, dou
AString cIniFile::GetValueSet(const AString & keyname, const AString & valuename, const AString & defValue) AString cIniFile::GetValueSet(const AString & keyname, const AString & valuename, const AString & defValue)
{ {
long keyID = FindKey(keyname); int keyID = FindKey(keyname);
if (keyID == noID) if (keyID == noID)
{ {
SetValue(keyname, valuename, defValue); SetValue(keyname, valuename, defValue);
return defValue; return defValue;
} }
long valueID = FindValue(unsigned(keyID), valuename); int valueID = FindValue(int(keyID), valuename);
if (valueID == noID) if (valueID == noID)
{ {
SetValue(keyname, valuename, defValue); SetValue(keyname, valuename, defValue);
@ -541,13 +540,13 @@ int cIniFile::GetValueSetI(const AString & keyname, const AString & valuename, c
bool cIniFile::DeleteValueByID(const unsigned keyID, const unsigned valueID) bool cIniFile::DeleteValueByID(const int keyID, const int valueID)
{ {
if (keyID < keys.size() && valueID < keys[keyID].names.size()) if ((keyID < (int)keys.size()) && (valueID < (int)keys[keyID].names.size()))
{ {
// This looks strange, but is neccessary. // This looks strange, but is neccessary.
vector<string>::iterator npos = keys[keyID].names.begin() + valueID; vector<AString>::iterator npos = keys[keyID].names.begin() + valueID;
vector<string>::iterator vpos = keys[keyID].values.begin() + valueID; vector<AString>::iterator vpos = keys[keyID].values.begin() + valueID;
keys[keyID].names.erase(npos, npos + 1); keys[keyID].names.erase(npos, npos + 1);
keys[keyID].values.erase(vpos, vpos + 1); keys[keyID].values.erase(vpos, vpos + 1);
return true; return true;
@ -559,15 +558,15 @@ bool cIniFile::DeleteValueByID(const unsigned keyID, const unsigned valueID)
bool cIniFile::DeleteValue(const string & keyname, const string & valuename) bool cIniFile::DeleteValue(const AString & keyname, const AString & valuename)
{ {
long keyID = FindKey(keyname); int keyID = FindKey(keyname);
if (keyID == noID) if (keyID == noID)
{ {
return false; return false;
} }
long valueID = FindValue(unsigned(keyID), valuename); int valueID = FindValue(int(keyID), valuename);
if (valueID == noID) if (valueID == noID)
{ {
return false; return false;
@ -580,15 +579,15 @@ bool cIniFile::DeleteValue(const string & keyname, const string & valuename)
bool cIniFile::DeleteKey(const string & keyname) bool cIniFile::DeleteKey(const AString & keyname)
{ {
long keyID = FindKey(keyname); int keyID = FindKey(keyname);
if (keyID == noID) if (keyID == noID)
{ {
return false; return false;
} }
vector<string>::iterator npos = names.begin() + keyID; vector<AString>::iterator npos = names.begin() + keyID;
vector<key>::iterator kpos = keys.begin() + keyID; vector<key>::iterator kpos = keys.begin() + keyID;
names.erase(npos, npos + 1); names.erase(npos, npos + 1);
keys.erase(kpos, kpos + 1); keys.erase(kpos, kpos + 1);
@ -611,7 +610,7 @@ void cIniFile::Clear(void)
void cIniFile::HeaderComment(const string & comment) void cIniFile::AddHeaderComment(const AString & comment)
{ {
comments.push_back(comment); comments.push_back(comment);
// comments.resize(comments.size() + 1, comment); // comments.resize(comments.size() + 1, comment);
@ -621,9 +620,9 @@ void cIniFile::HeaderComment(const string & comment)
string cIniFile::HeaderComment(unsigned const commentID) const AString cIniFile::GetHeaderComment(const int commentID) const
{ {
if (commentID < comments.size()) if (commentID < (int)comments.size())
{ {
return comments[commentID]; return comments[commentID];
} }
@ -634,11 +633,11 @@ string cIniFile::HeaderComment(unsigned const commentID) const
bool cIniFile::DeleteHeaderComment(unsigned commentID) bool cIniFile::DeleteHeaderComment(int commentID)
{ {
if (commentID < comments.size()) if (commentID < (int)comments.size())
{ {
vector<string>::iterator cpos = comments.begin() + commentID; vector<AString>::iterator cpos = comments.begin() + commentID;
comments.erase(cpos, cpos + 1); comments.erase(cpos, cpos + 1);
return true; return true;
} }
@ -649,9 +648,9 @@ bool cIniFile::DeleteHeaderComment(unsigned commentID)
unsigned cIniFile::NumKeyComments(unsigned const keyID) const int cIniFile::GetNumKeyComments(const int keyID) const
{ {
if (keyID < keys.size()) if (keyID < (int)keys.size())
{ {
return keys[keyID].comments.size(); return keys[keyID].comments.size();
} }
@ -662,21 +661,23 @@ unsigned cIniFile::NumKeyComments(unsigned const keyID) const
unsigned cIniFile::NumKeyComments(const string & keyname) const int cIniFile::GetNumKeyComments(const AString & keyname) const
{ {
long keyID = FindKey(keyname); int keyID = FindKey(keyname);
if (keyID == noID) if (keyID == noID)
{
return 0; return 0;
return keys[keyID].comments.size(); }
return (int)keys[keyID].comments.size();
} }
bool cIniFile::KeyComment(unsigned const keyID, const string & comment) bool cIniFile::AddKeyComment(const int keyID, const AString & comment)
{ {
if (keyID < keys.size()) if (keyID < (int)keys.size())
{ {
keys[keyID].comments.resize(keys[keyID].comments.size() + 1, comment); keys[keyID].comments.resize(keys[keyID].comments.size() + 1, comment);
return true; return true;
@ -688,23 +689,23 @@ bool cIniFile::KeyComment(unsigned const keyID, const string & comment)
bool cIniFile::KeyComment(const string & keyname, const string & comment) bool cIniFile::AddKeyComment(const AString & keyname, const AString & comment)
{ {
long keyID = FindKey(keyname); int keyID = FindKey(keyname);
if (keyID == noID) if (keyID == noID)
{ {
return false; return false;
} }
return KeyComment(unsigned(keyID), comment); return AddKeyComment(keyID, comment);
} }
string cIniFile::KeyComment(unsigned const keyID, unsigned const commentID) const AString cIniFile::GetKeyComment(const int keyID, const int commentID) const
{ {
if ((keyID < keys.size()) && (commentID < keys[keyID].comments.size())) if ((keyID < (int)keys.size()) && (commentID < (int)keys[keyID].comments.size()))
{ {
return keys[keyID].comments[commentID]; return keys[keyID].comments[commentID];
} }
@ -715,25 +716,25 @@ string cIniFile::KeyComment(unsigned const keyID, unsigned const commentID) cons
string cIniFile::KeyComment(const string & keyname, unsigned const commentID) const AString cIniFile::GetKeyComment(const AString & keyname, const int commentID) const
{ {
long keyID = FindKey(keyname); int keyID = FindKey(keyname);
if (keyID == noID) if (keyID == noID)
{ {
return ""; return "";
} }
return KeyComment(unsigned(keyID), commentID); return GetKeyComment(int(keyID), commentID);
} }
bool cIniFile::DeleteKeyComment(unsigned const keyID, unsigned const commentID) bool cIniFile::DeleteKeyComment(const int keyID, const int commentID)
{ {
if ((keyID < keys.size()) && (commentID < keys[keyID].comments.size())) if ((keyID < (int)keys.size()) && (commentID < (int)keys[keyID].comments.size()))
{ {
vector<string>::iterator cpos = keys[keyID].comments.begin() + commentID; vector<AString>::iterator cpos = keys[keyID].comments.begin() + commentID;
keys[keyID].comments.erase(cpos, cpos + 1); keys[keyID].comments.erase(cpos, cpos + 1);
return true; return true;
} }
@ -744,23 +745,23 @@ bool cIniFile::DeleteKeyComment(unsigned const keyID, unsigned const commentID)
bool cIniFile::DeleteKeyComment(const string & keyname, unsigned const commentID) bool cIniFile::DeleteKeyComment(const AString & keyname, const int commentID)
{ {
long keyID = FindKey(keyname); int keyID = FindKey(keyname);
if (keyID == noID) if (keyID == noID)
{ {
return false; return false;
} }
return DeleteKeyComment(unsigned(keyID), commentID); return DeleteKeyComment(int(keyID), commentID);
} }
bool cIniFile::DeleteKeyComments(unsigned const keyID) bool cIniFile::DeleteKeyComments(const int keyID)
{ {
if (keyID < keys.size()) if (keyID < (int)keys.size())
{ {
keys[keyID].comments.clear(); keys[keyID].comments.clear();
return true; return true;
@ -772,27 +773,27 @@ bool cIniFile::DeleteKeyComments(unsigned const keyID)
bool cIniFile::DeleteKeyComments(const string & keyname) bool cIniFile::DeleteKeyComments(const AString & keyname)
{ {
long keyID = FindKey(keyname); int keyID = FindKey(keyname);
if (keyID == noID) if (keyID == noID)
{ {
return false; return false;
} }
return DeleteKeyComments(unsigned(keyID)); return DeleteKeyComments(int(keyID));
} }
string cIniFile::CheckCase(const string & s) const AString cIniFile::CheckCase(const AString & s) const
{ {
if (!m_IsCaseInsensitive) if (!m_IsCaseInsensitive)
{ {
return s; return s;
} }
string res(s); AString res(s);
size_t len = res.length(); size_t len = res.length();
for (size_t i = 0; i < len; i++) for (size_t i = 0; i < len; i++)
{ {

View File

@ -36,21 +36,20 @@ class cIniFile
{ {
private: private:
bool m_IsCaseInsensitive; bool m_IsCaseInsensitive;
std::string m_Path;
struct key struct key
{ {
std::vector<std::string> names; std::vector<AString> names;
std::vector<std::string> values; std::vector<AString> values;
std::vector<std::string> comments; std::vector<AString> comments;
} ; } ;
std::vector<key> keys; std::vector<key> keys;
std::vector<std::string> names; std::vector<AString> names;
std::vector<std::string> comments; std::vector<AString> comments;
/// If the object is case-insensitive, returns s as lowercase; otherwise returns s as-is /// If the object is case-insensitive, returns s as lowercase; otherwise returns s as-is
std::string CheckCase(const std::string & s) const; AString CheckCase(const AString & s) const;
public: public:
enum errors enum errors
@ -58,79 +57,60 @@ public:
noID = -1, noID = -1,
}; };
/// Creates a new instance; sets m_Path to a_Path, but doesn't read the file /// Creates a new instance with no data
cIniFile(const std::string & a_Path = ""); cIniFile(void);
// Sets whether or not keynames and valuenames should be case sensitive. // Sets whether or not keynames and valuenames should be case sensitive.
// The default is case insensitive. // The default is case insensitive.
void CaseSensitive (void) { m_IsCaseInsensitive = false; } void CaseSensitive (void) { m_IsCaseInsensitive = false; }
void CaseInsensitive(void) { m_IsCaseInsensitive = true; } void CaseInsensitive(void) { m_IsCaseInsensitive = true; }
// Sets path of ini file to read and write from. /** Reads the contents of the specified ini file
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
If the file doesn't exist and a_AllowExampleRedirect is true, tries to read <basename>.example.ini, and 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. writes its contents as <basename>.ini, if successful.
Returns true if successful, false otherwise. 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 /// Writes data stored in class to the specified ini file
bool WriteFile(void) const; bool WriteFile(const AString & a_FileName) const;
/// Deletes all stored ini data (but doesn't touch the file) /// Deletes all stored ini data (but doesn't touch the file)
void Clear(void); void Clear(void);
void Reset(void) { Clear(); }
void Erase(void) { Clear(); } // OBSOLETE, this name is misguiding and will be removed from the interface
/// Returns index of specified key, or noID if not found /// Returns index of specified key, or noID if not found
long FindKey(const std::string & keyname) const; int FindKey(const AString & keyname) const;
/// Returns index of specified value, in the specified key, or noID if not found /// Returns index of specified value, in the specified key, or noID if not found
long FindValue(const unsigned keyID, const std::string & valuename) const; int FindValue(const int keyID, const AString & valuename) const;
/// Returns number of keys currently in the ini /// Returns number of keys currently in the ini
unsigned NumKeys (void) const {return names.size();} int GetNumKeys(void) const { return (int)keys.size(); }
unsigned GetNumKeys(void) const {return NumKeys();}
/// Add a key name /// Add a key name
unsigned AddKeyName(const std::string & keyname); int AddKeyName(const AString & keyname);
// Returns key names by index. // Returns key names by index.
std::string KeyName(const unsigned keyID) const; AString GetKeyName(const int keyID) const;
std::string GetKeyName(const unsigned keyID) const {return KeyName(keyID);}
// Returns number of values stored for specified key. // Returns number of values stored for specified key.
unsigned NumValues (const std::string & keyname); int GetNumValues(const AString & keyname) const;
unsigned GetNumValues(const std::string & keyname) {return NumValues(keyname);} int GetNumValues(const int keyID) const;
unsigned NumValues (const unsigned keyID);
unsigned GetNumValues(const unsigned keyID) {return NumValues(keyID);}
// Returns value name by index for a given keyname or keyID. // Returns value name by index for a given keyname or keyID.
std::string ValueName( const std::string & keyname, const unsigned valueID) const; AString GetValueName(const AString & keyname, const int valueID) const;
std::string GetValueName( const std::string & keyname, const unsigned valueID) const AString GetValueName(const int keyID, const int valueID) const;
{
return ValueName(keyname, valueID);
}
std::string ValueName (const unsigned keyID, const unsigned valueID) const;
std::string GetValueName(const unsigned keyID, const unsigned valueID) const
{
return ValueName(keyID, valueID);
}
// Gets value of [keyname] valuename =. // Gets value of [keyname] valuename =.
// Overloaded to return string, int, and double. // Overloaded to return string, int, and double.
// Returns defValue if key/value not found. // Returns defValue if key/value not found.
AString GetValue (const AString & keyname, const AString & valuename, const AString & defValue = "") const; AString GetValue (const AString & keyname, const AString & valuename, const AString & defValue = "") const;
AString GetValue (const unsigned keyID, const unsigned valueID, const AString & defValue = "") const; AString GetValue (const int keyID, const int valueID, const AString & defValue = "") const;
double GetValueF(const AString & keyname, const AString & valuename, const double defValue = 0) const; double GetValueF(const AString & keyname, const AString & valuename, const double defValue = 0) const;
int GetValueI(const AString & keyname, const AString & valuename, const int defValue = 0) const; int GetValueI(const AString & keyname, const AString & valuename, const int defValue = 0) const;
bool GetValueB(const AString & keyname, const AString & valuename, const bool defValue = false) const bool GetValueB(const AString & keyname, const AString & valuename, const bool defValue = false) const
{ {
return (GetValueI(keyname, valuename, int(defValue)) > 0); return (GetValueI(keyname, valuename, defValue ? 1 : 0) != 0);
} }
// Gets the value; if not found, write the default to the INI file // Gets the value; if not found, write the default to the INI file
@ -139,50 +119,54 @@ public:
int GetValueSetI(const AString & keyname, const AString & valuename, const int defValue = 0); int GetValueSetI(const AString & keyname, const AString & valuename, const int defValue = 0);
bool GetValueSetB(const AString & keyname, const AString & valuename, const bool defValue = false) bool GetValueSetB(const AString & keyname, const AString & valuename, const bool defValue = false)
{ {
return (GetValueSetI(keyname, valuename, defValue ? 1 : 0) > 0); return (GetValueSetI(keyname, valuename, defValue ? 1 : 0) != 0);
} }
// Sets value of [keyname] valuename =. // Sets value of [keyname] valuename =.
// Specify the optional paramter as false (0) if you do not want it to create // Specify the optional paramter as false (0) if you do not want it to create
// the key if it doesn't exist. Returns true if data entered, false otherwise. // the key if it doesn't exist. Returns true if data entered, false otherwise.
// Overloaded to accept string, int, and double. // Overloaded to accept string, int, and double.
bool SetValue( const unsigned keyID, const unsigned valueID, const std::string & value); bool SetValue( const int keyID, const int valueID, const AString & value);
bool SetValue( const std::string & keyname, const std::string & valuename, const std::string & value, const bool create = true); bool SetValue( const AString & keyname, const AString & valuename, const AString & value, const bool create = true);
bool SetValueI( const std::string & keyname, const std::string & valuename, const int value, const bool create = true); bool SetValueI( const AString & keyname, const AString & valuename, const int value, const bool create = true);
bool SetValueB( const std::string & keyname, const std::string & valuename, const bool value, const bool create = true) bool SetValueB( const AString & keyname, const AString & valuename, const bool value, const bool create = true)
{ {
return SetValueI( keyname, valuename, int(value), create); return SetValueI( keyname, valuename, int(value), create);
} }
bool SetValueF( const std::string & keyname, const std::string & valuename, const double value, const bool create = true); bool SetValueF( const AString & keyname, const AString & valuename, const double value, const bool create = true);
// tolua_end // tolua_end
bool SetValueV( const std::string & keyname, const std::string & valuename, char *format, ...); bool SetValueV( const AString & keyname, const AString & valuename, char *format, ...);
// tolua_begin // tolua_begin
// Deletes specified value. // Deletes specified value.
// Returns true if value existed and deleted, false otherwise. // Returns true if value existed and deleted, false otherwise.
bool DeleteValueByID( const unsigned keyID, const unsigned valueID ); bool DeleteValueByID(const int keyID, const int valueID);
bool DeleteValue( const std::string & keyname, const std::string & valuename); bool DeleteValue(const AString & keyname, const AString & valuename);
// Deletes specified key and all values contained within. // Deletes specified key and all values contained within.
// Returns true if key existed and deleted, false otherwise. // Returns true if key existed and deleted, false otherwise.
bool DeleteKey(const std::string & keyname); bool DeleteKey(const AString & keyname);
// Header comment functions. // Header comment functions.
// Header comments are those comments before the first key. // Header comments are those comments before the first key.
//
// Number of header comments. /// Returns the number of header comments
unsigned NumHeaderComments(void) {return comments.size();} int GetNumHeaderComments(void) {return (int)comments.size();}
// Add a header comment.
void HeaderComment(const std::string & comment); /// Adds a header comment
// Return a header comment. void AddHeaderComment(const AString & comment);
std::string HeaderComment(const unsigned commentID) const;
// Delete a header comment. /// Returns a header comment, or empty string if out of range
bool DeleteHeaderComment(unsigned commentID); AString GetHeaderComment(const int commentID) const;
// Delete all header comments.
void DeleteHeaderComments(void) {comments.clear();} /// Deletes a header comment. Returns true if successful
bool DeleteHeaderComment(int commentID);
/// Deletes all header comments
void DeleteHeaderComments(void) {comments.clear();}
// Key comment functions. // Key comment functions.
@ -190,26 +174,30 @@ public:
// defined within value names will be added to this list. Therefore, // defined within value names will be added to this list. Therefore,
// these comments will be moved to the top of the key definition when // these comments will be moved to the top of the key definition when
// the CIniFile::WriteFile() is called. // the CIniFile::WriteFile() is called.
//
// Number of key comments.
unsigned NumKeyComments( const unsigned keyID) const;
unsigned NumKeyComments( const std::string & keyname) const;
// Add a key comment. /// Get number of key comments
bool KeyComment(const unsigned keyID, const std::string & comment); int GetNumKeyComments(const int keyID) const;
bool KeyComment(const std::string & keyname, const std::string & comment);
// Return a key comment. /// Get number of key comments
std::string KeyComment(const unsigned keyID, const unsigned commentID) const; int GetNumKeyComments(const AString & keyname) const;
std::string KeyComment(const std::string & keyname, const unsigned commentID) const;
/// Add a key comment
bool AddKeyComment(const int keyID, const AString & comment);
/// Add a key comment
bool AddKeyComment(const AString & keyname, const AString & comment);
/// Return a key comment
AString GetKeyComment(const int keyID, const int commentID) const;
AString GetKeyComment(const AString & keyname, const int commentID) const;
// Delete a key comment. // Delete a key comment.
bool DeleteKeyComment(const unsigned keyID, const unsigned commentID); bool DeleteKeyComment(const int keyID, const int commentID);
bool DeleteKeyComment(const std::string & keyname, const unsigned commentID); bool DeleteKeyComment(const AString & keyname, const int commentID);
// Delete all comments for a key. // Delete all comments for a key.
bool DeleteKeyComments(const unsigned keyID); bool DeleteKeyComments(const int keyID);
bool DeleteKeyComments(const std::string & keyname); bool DeleteKeyComments(const AString & keyname);
}; };
// tolua_end // tolua_end

View File

@ -47,8 +47,8 @@ cAuthenticator::~cAuthenticator()
/// Read custom values from INI /// Read custom values from INI
void cAuthenticator::ReadINI(void) void cAuthenticator::ReadINI(void)
{ {
cIniFile IniFile("settings.ini"); cIniFile IniFile;
if (!IniFile.ReadFile()) if (!IniFile.ReadFile("settings.ini"))
{ {
return; return;
} }
@ -74,7 +74,7 @@ void cAuthenticator::ReadINI(void)
if (bSave) if (bSave)
{ {
IniFile.SetValueB("Authentication", "Authenticate", m_ShouldAuthenticate); IniFile.SetValueB("Authentication", "Authenticate", m_ShouldAuthenticate);
IniFile.WriteFile(); IniFile.WriteFile("settings.ini");
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/* /*
** Lua binding: AllToLua ** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 10/24/13 16:43:15. ** Generated automatically by tolua++-1.0.92 on 10/25/13 11:34:58.
*/ */
/* Exported function */ /* Exported function */

View File

@ -42,20 +42,20 @@ class cBlockIDMap
public: public:
cBlockIDMap(void) cBlockIDMap(void)
{ {
cIniFile Ini("items.ini"); cIniFile Ini;
if (!Ini.ReadFile()) if (!Ini.ReadFile("items.ini"))
{ {
return; return;
} }
long KeyID = Ini.FindKey("Items"); int KeyID = Ini.FindKey("Items");
if (KeyID == cIniFile::noID) if (KeyID == cIniFile::noID)
{ {
return; return;
} }
unsigned NumValues = Ini.GetNumValues(KeyID); int NumValues = Ini.GetNumValues(KeyID);
for (unsigned i = 0; i < NumValues; i++) for (int i = 0; i < NumValues; i++)
{ {
AString Name = Ini.ValueName(KeyID, i); AString Name = Ini.GetValueName(KeyID, i);
if (Name.empty()) if (Name.empty())
{ {
continue; continue;

View File

@ -1224,11 +1224,11 @@ void cPlayer::LoadPermissionsFromDisk()
m_Groups.clear(); m_Groups.clear();
m_Permissions.clear(); m_Permissions.clear();
cIniFile IniFile("users.ini"); cIniFile IniFile;
if( IniFile.ReadFile() ) if (IniFile.ReadFile("users.ini"))
{ {
std::string Groups = IniFile.GetValue(m_PlayerName, "Groups", ""); std::string Groups = IniFile.GetValue(m_PlayerName, "Groups", "");
if( Groups.size() > 0 ) if (!Groups.empty())
{ {
AStringVector Split = StringSplit( Groups, "," ); AStringVector Split = StringSplit( Groups, "," );
for( unsigned int i = 0; i < Split.size(); i++ ) for( unsigned int i = 0; i < Split.size(); i++ )
@ -1245,7 +1245,7 @@ void cPlayer::LoadPermissionsFromDisk()
} }
else else
{ {
LOGWARN("WARNING: Failed to read ini file users.ini"); LOGWARN("Failed to read the users.ini file. The player will be added only to the Default group.");
AddToGroup("Default"); AddToGroup("Default");
} }
ResolvePermissions(); ResolvePermissions();

View File

@ -75,8 +75,6 @@ bool cChunkGenerator::Start(cWorld * a_World, cIniFile & a_IniFile)
m_Generator->Initialize(a_World, a_IniFile); m_Generator->Initialize(a_World, a_IniFile);
a_IniFile.WriteFile();
return super::Start(); return super::Start();
} }

View File

@ -44,8 +44,8 @@ cGroupManager::cGroupManager()
: m_pState( new sGroupManagerState ) : m_pState( new sGroupManagerState )
{ {
LOGD("-- Loading Groups --"); LOGD("-- Loading Groups --");
cIniFile IniFile("groups.ini"); cIniFile IniFile;
if (!IniFile.ReadFile()) if (!IniFile.ReadFile("groups.ini"))
{ {
LOGWARNING("groups.ini inaccessible, no groups are defined"); LOGWARNING("groups.ini inaccessible, no groups are defined");
return; return;

View File

@ -55,18 +55,18 @@ cMonsterConfig::~cMonsterConfig()
void cMonsterConfig::Initialize() void cMonsterConfig::Initialize()
{ {
cIniFile MonstersIniFile("monsters.ini"); cIniFile MonstersIniFile;
if (!MonstersIniFile.ReadFile()) if (!MonstersIniFile.ReadFile("monsters.ini"))
{ {
LOGWARNING("%s: Cannot read monsters.ini file, monster attributes not available", __FUNCTION__); LOGWARNING("%s: Cannot read monsters.ini file, monster attributes not available", __FUNCTION__);
return; return;
} }
for (int i = (int)MonstersIniFile.NumKeys(); i >= 0; i--) for (int i = (int)MonstersIniFile.GetNumKeys(); i >= 0; i--)
{ {
sAttributesStruct Attributes; sAttributesStruct Attributes;
AString Name = MonstersIniFile.KeyName(i); AString Name = MonstersIniFile.GetKeyName(i);
Attributes.m_Name = Name; Attributes.m_Name = Name;
Attributes.m_AttackDamage = MonstersIniFile.GetValueF(Name, "AttackDamage", 0); Attributes.m_AttackDamage = MonstersIniFile.GetValueF(Name, "AttackDamage", 0);
Attributes.m_AttackRange = MonstersIniFile.GetValueF(Name, "AttackRange", 0); Attributes.m_AttackRange = MonstersIniFile.GetValueF(Name, "AttackRange", 0);

View File

@ -103,8 +103,8 @@ void cPluginManager::ReloadPluginsNow(void)
cServer::BindBuiltInConsoleCommands(); cServer::BindBuiltInConsoleCommands();
cIniFile IniFile("settings.ini"); cIniFile IniFile;
if (!IniFile.ReadFile()) if (!IniFile.ReadFile("settings.ini"))
{ {
LOGWARNING("cPluginManager: Can't find settings.ini, so can't load any plugins."); LOGWARNING("cPluginManager: Can't find settings.ini, so can't load any plugins.");
} }

View File

@ -116,8 +116,8 @@ void cRoot::Start(void)
m_Server = new cServer(); m_Server = new cServer();
LOG("Reading server config..."); LOG("Reading server config...");
cIniFile IniFile("settings.ini"); cIniFile IniFile;
if (!IniFile.ReadFile()) if (!IniFile.ReadFile("settings.ini"))
{ {
LOGWARNING("settings.ini inaccessible, all settings are reset to default values"); LOGWARNING("settings.ini inaccessible, all settings are reset to default values");
} }
@ -138,7 +138,7 @@ void cRoot::Start(void)
LOGERROR("Failure starting server, aborting..."); LOGERROR("Failure starting server, aborting...");
return; return;
} }
IniFile.WriteFile(); IniFile.WriteFile("settings.ini");
m_WebAdmin = new cWebAdmin(); m_WebAdmin = new cWebAdmin();
m_WebAdmin->Init(); m_WebAdmin->Init();
@ -247,7 +247,8 @@ void cRoot::LoadGlobalSettings()
void cRoot::LoadWorlds(void) void cRoot::LoadWorlds(void)
{ {
cIniFile IniFile("settings.ini"); IniFile.ReadFile(); cIniFile IniFile;
IniFile.ReadFile("settings.ini"); // Doesn't matter if success or not
// First get the default world // First get the default world
AString DefaultWorldName = IniFile.GetValueSet("Worlds", "DefaultWorld", "world"); AString DefaultWorldName = IniFile.GetValueSet("Worlds", "DefaultWorld", "world");

View File

@ -44,8 +44,7 @@ public:
cWebAdmin::cWebAdmin(void) : cWebAdmin::cWebAdmin(void) :
m_IsInitialized(false), m_IsInitialized(false),
m_TemplateScript("<webadmin_template>"), m_TemplateScript("<webadmin_template>")
m_IniFile("webadmin.ini")
{ {
} }
@ -86,19 +85,19 @@ void cWebAdmin::RemovePlugin( cWebPlugin * a_Plugin )
bool cWebAdmin::Init(void) bool cWebAdmin::Init(void)
{ {
if (!m_IniFile.ReadFile()) if (!m_IniFile.ReadFile("webadmin.ini"))
{ {
return false; return false;
} }
LOG("Initialising WebAdmin...");
if (!m_IniFile.GetValueSetB("WebAdmin", "Enabled", true)) if (!m_IniFile.GetValueSetB("WebAdmin", "Enabled", true))
{ {
// WebAdmin is disabled, bail out faking a success // WebAdmin is disabled, bail out faking a success
return true; return true;
} }
LOG("Initialising WebAdmin...");
AString PortsIPv4 = m_IniFile.GetValueSet("WebAdmin", "Port", "8080"); AString PortsIPv4 = m_IniFile.GetValueSet("WebAdmin", "Port", "8080");
AString PortsIPv6 = m_IniFile.GetValueSet("WebAdmin", "PortsIPv6", ""); AString PortsIPv6 = m_IniFile.GetValueSet("WebAdmin", "PortsIPv6", "");

View File

@ -444,8 +444,8 @@ void cWorld::Start(void)
m_SpawnZ = (double)((m_TickRand.randInt() % 1000) - 500); m_SpawnZ = (double)((m_TickRand.randInt() % 1000) - 500);
m_GameMode = eGameMode_Creative; m_GameMode = eGameMode_Creative;
cIniFile IniFile(m_IniFileName); cIniFile IniFile;
if (!IniFile.ReadFile()) if (!IniFile.ReadFile(m_IniFileName))
{ {
LOGWARNING("Cannot read world settings from \"%s\", defaults will be used.", m_IniFileName.c_str()); LOGWARNING("Cannot read world settings from \"%s\", defaults will be used.", m_IniFileName.c_str());
} }
@ -555,7 +555,7 @@ void cWorld::Start(void)
// Save any changes that the defaults may have done to the ini file: // Save any changes that the defaults may have done to the ini file:
if (!IniFile.WriteFile()) if (!IniFile.WriteFile(m_IniFileName))
{ {
LOGWARNING("Could not write world config to %s", m_IniFileName.c_str()); LOGWARNING("Could not write world config to %s", m_IniFileName.c_str());
} }