1
0

cIniFile doesn't store filename internally anymore.

This commit is contained in:
madmaxoft 2013-10-25 11:15:44 +02:00
parent c875b88758
commit 9e9198e090
14 changed files with 56 additions and 213 deletions

View File

@ -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;

View File

@ -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);

View File

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

View File

@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 10/24/13 16:43:14.
** Generated automatically by tolua++-1.0.92 on 10/25/13 10:38:50.
*/
#ifndef __cplusplus
@ -345,59 +345,6 @@ static int tolua_AllToLua_cIniFile_new00_local(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
/* method: new of class cIniFile */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_new01
static int tolua_AllToLua_cIniFile_new01(lua_State* tolua_S)
{
tolua_Error tolua_err;
if (
!tolua_isusertable(tolua_S,1,"cIniFile",0,&tolua_err) ||
!tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
)
goto tolua_lerror;
else
{
const std::string a_Path = ((const std::string) tolua_tocppstring(tolua_S,2,0));
{
cIniFile* tolua_ret = (cIniFile*) Mtolua_new((cIniFile)(a_Path));
tolua_pushusertype(tolua_S,(void*)tolua_ret,"cIniFile");
tolua_pushcppstring(tolua_S,(const char*)a_Path);
}
}
return 2;
tolua_lerror:
return tolua_AllToLua_cIniFile_new00(tolua_S);
}
#endif //#ifndef TOLUA_DISABLE
/* method: new_local of class cIniFile */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_new01_local
static int tolua_AllToLua_cIniFile_new01_local(lua_State* tolua_S)
{
tolua_Error tolua_err;
if (
!tolua_isusertable(tolua_S,1,"cIniFile",0,&tolua_err) ||
!tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
)
goto tolua_lerror;
else
{
const std::string a_Path = ((const std::string) tolua_tocppstring(tolua_S,2,0));
{
cIniFile* tolua_ret = (cIniFile*) Mtolua_new((cIniFile)(a_Path));
tolua_pushusertype(tolua_S,(void*)tolua_ret,"cIniFile");
tolua_register_gc(tolua_S,lua_gettop(tolua_S));
tolua_pushcppstring(tolua_S,(const char*)a_Path);
}
}
return 2;
tolua_lerror:
return tolua_AllToLua_cIniFile_new00_local(tolua_S);
}
#endif //#ifndef TOLUA_DISABLE
/* method: CaseSensitive of class cIniFile */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_CaseSensitive00
static int tolua_AllToLua_cIniFile_CaseSensitive00(lua_State* tolua_S)
@ -460,101 +407,6 @@ static int tolua_AllToLua_cIniFile_CaseInsensitive00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
/* method: Path of class cIniFile */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_Path00
static int tolua_AllToLua_cIniFile_Path00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cIniFile",0,&tolua_err) ||
!tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0);
const std::string newPath = ((const std::string) tolua_tocppstring(tolua_S,2,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Path'", NULL);
#endif
{
self->Path(newPath);
tolua_pushcppstring(tolua_S,(const char*)newPath);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'Path'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: Path of class cIniFile */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_Path01
static int tolua_AllToLua_cIniFile_Path01(lua_State* tolua_S)
{
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"const cIniFile",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
{
const cIniFile* self = (const cIniFile*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Path'", NULL);
#endif
{
const std::string tolua_ret = (const std::string) self->Path();
tolua_pushcppstring(tolua_S,(const char*)tolua_ret);
}
}
return 1;
tolua_lerror:
return tolua_AllToLua_cIniFile_Path00(tolua_S);
}
#endif //#ifndef TOLUA_DISABLE
/* method: SetPath of class cIniFile */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_SetPath00
static int tolua_AllToLua_cIniFile_SetPath00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cIniFile",0,&tolua_err) ||
!tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0);
const std::string newPath = ((const std::string) tolua_tocppstring(tolua_S,2,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetPath'", NULL);
#endif
{
self->SetPath(newPath);
tolua_pushcppstring(tolua_S,(const char*)newPath);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'SetPath'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: ReadFile of class cIniFile */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_ReadFile00
static int tolua_AllToLua_cIniFile_ReadFile00(lua_State* tolua_S)
@ -563,24 +415,27 @@ static int tolua_AllToLua_cIniFile_ReadFile00(lua_State* tolua_S)
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cIniFile",0,&tolua_err) ||
!tolua_isboolean(tolua_S,2,1,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
!tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
!tolua_isboolean(tolua_S,3,1,&tolua_err) ||
!tolua_isnoobj(tolua_S,4,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0);
bool a_AllowExampleRedirect = ((bool) tolua_toboolean(tolua_S,2,true));
const AString a_FileName = ((const AString) tolua_tocppstring(tolua_S,2,0));
bool a_AllowExampleRedirect = ((bool) tolua_toboolean(tolua_S,3,true));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'ReadFile'", NULL);
#endif
{
bool tolua_ret = (bool) self->ReadFile(a_AllowExampleRedirect);
bool tolua_ret = (bool) self->ReadFile(a_FileName,a_AllowExampleRedirect);
tolua_pushboolean(tolua_S,(bool)tolua_ret);
tolua_pushcppstring(tolua_S,(const char*)a_FileName);
}
}
return 1;
return 2;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'ReadFile'.",&tolua_err);
@ -597,22 +452,25 @@ static int tolua_AllToLua_cIniFile_WriteFile00(lua_State* tolua_S)
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"const cIniFile",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
!tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
const cIniFile* self = (const cIniFile*) tolua_tousertype(tolua_S,1,0);
const AString a_FileName = ((const AString) tolua_tocppstring(tolua_S,2,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'WriteFile'", NULL);
#endif
{
bool tolua_ret = (bool) self->WriteFile();
bool tolua_ret = (bool) self->WriteFile(a_FileName);
tolua_pushboolean(tolua_S,(bool)tolua_ret);
tolua_pushcppstring(tolua_S,(const char*)a_FileName);
}
}
return 1;
return 2;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'WriteFile'.",&tolua_err);
@ -29487,14 +29345,8 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"new",tolua_AllToLua_cIniFile_new00);
tolua_function(tolua_S,"new_local",tolua_AllToLua_cIniFile_new00_local);
tolua_function(tolua_S,".call",tolua_AllToLua_cIniFile_new00_local);
tolua_function(tolua_S,"new",tolua_AllToLua_cIniFile_new01);
tolua_function(tolua_S,"new_local",tolua_AllToLua_cIniFile_new01_local);
tolua_function(tolua_S,".call",tolua_AllToLua_cIniFile_new01_local);
tolua_function(tolua_S,"CaseSensitive",tolua_AllToLua_cIniFile_CaseSensitive00);
tolua_function(tolua_S,"CaseInsensitive",tolua_AllToLua_cIniFile_CaseInsensitive00);
tolua_function(tolua_S,"Path",tolua_AllToLua_cIniFile_Path00);
tolua_function(tolua_S,"Path",tolua_AllToLua_cIniFile_Path01);
tolua_function(tolua_S,"SetPath",tolua_AllToLua_cIniFile_SetPath00);
tolua_function(tolua_S,"ReadFile",tolua_AllToLua_cIniFile_ReadFile00);
tolua_function(tolua_S,"WriteFile",tolua_AllToLua_cIniFile_WriteFile00);
tolua_function(tolua_S,"Clear",tolua_AllToLua_cIniFile_Clear00);

View File

@ -1,6 +1,6 @@
/*
** 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 10:38:51.
*/
/* Exported function */

View File

@ -42,8 +42,8 @@ class cBlockIDMap
public:
cBlockIDMap(void)
{
cIniFile Ini("items.ini");
if (!Ini.ReadFile())
cIniFile Ini;
if (!Ini.ReadFile("items.ini"))
{
return;
}

View File

@ -1224,11 +1224,11 @@ void cPlayer::LoadPermissionsFromDisk()
m_Groups.clear();
m_Permissions.clear();
cIniFile IniFile("users.ini");
if( IniFile.ReadFile() )
cIniFile IniFile;
if (IniFile.ReadFile("users.ini"))
{
std::string Groups = IniFile.GetValue(m_PlayerName, "Groups", "");
if( Groups.size() > 0 )
if (!Groups.empty())
{
AStringVector Split = StringSplit( Groups, "," );
for( unsigned int i = 0; i < Split.size(); i++ )
@ -1245,7 +1245,7 @@ void cPlayer::LoadPermissionsFromDisk()
}
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");
}
ResolvePermissions();

View File

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

View File

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

View File

@ -55,9 +55,9 @@ cMonsterConfig::~cMonsterConfig()
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__);
return;

View File

@ -103,8 +103,8 @@ void cPluginManager::ReloadPluginsNow(void)
cServer::BindBuiltInConsoleCommands();
cIniFile IniFile("settings.ini");
if (!IniFile.ReadFile())
cIniFile IniFile;
if (!IniFile.ReadFile("settings.ini"))
{
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();
LOG("Reading server config...");
cIniFile IniFile("settings.ini");
if (!IniFile.ReadFile())
cIniFile IniFile;
if (!IniFile.ReadFile("settings.ini"))
{
LOGWARNING("settings.ini inaccessible, all settings are reset to default values");
}
@ -138,7 +138,7 @@ void cRoot::Start(void)
LOGERROR("Failure starting server, aborting...");
return;
}
IniFile.WriteFile();
IniFile.WriteFile("settings.ini");
m_WebAdmin = new cWebAdmin();
m_WebAdmin->Init();
@ -247,7 +247,8 @@ void cRoot::LoadGlobalSettings()
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
AString DefaultWorldName = IniFile.GetValueSet("Worlds", "DefaultWorld", "world");

View File

@ -44,8 +44,7 @@ public:
cWebAdmin::cWebAdmin(void) :
m_IsInitialized(false),
m_TemplateScript("<webadmin_template>"),
m_IniFile("webadmin.ini")
m_TemplateScript("<webadmin_template>")
{
}
@ -86,19 +85,19 @@ void cWebAdmin::RemovePlugin( cWebPlugin * a_Plugin )
bool cWebAdmin::Init(void)
{
if (!m_IniFile.ReadFile())
if (!m_IniFile.ReadFile("webadmin.ini"))
{
return false;
}
LOG("Initialising WebAdmin...");
if (!m_IniFile.GetValueSetB("WebAdmin", "Enabled", true))
{
// WebAdmin is disabled, bail out faking a success
return true;
}
LOG("Initialising WebAdmin...");
AString PortsIPv4 = m_IniFile.GetValueSet("WebAdmin", "Port", "8080");
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_GameMode = eGameMode_Creative;
cIniFile IniFile(m_IniFileName);
if (!IniFile.ReadFile())
cIniFile IniFile;
if (!IniFile.ReadFile(m_IniFileName))
{
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:
if (!IniFile.WriteFile())
if (!IniFile.WriteFile(m_IniFileName))
{
LOGWARNING("Could not write world config to %s", m_IniFileName.c_str());
}