Replaced most FILE operations with a cFile object
git-svn-id: http://mc-server.googlecode.com/svn/trunk@196 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
b834841aa1
commit
f4583fda98
@ -1,7 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
class cCriticalSection;
|
|
||||||
class cEvent;
|
|
||||||
class cChunk;
|
class cChunk;
|
||||||
class cChunkLoader
|
class cChunkLoader
|
||||||
{
|
{
|
||||||
|
@ -198,3 +198,34 @@ int cFile::Tell (void) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// Returns the size of file, in bytes, or -1 for failure; asserts if not open
|
||||||
|
int cFile::GetSize(void) const
|
||||||
|
{
|
||||||
|
assert(IsOpen());
|
||||||
|
|
||||||
|
if (!IsOpen())
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CurPos = ftell(m_File);
|
||||||
|
if (CurPos < 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (fseek(m_File, 0, SEEK_END) != 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
int res = ftell(m_File);
|
||||||
|
if (fseek(m_File, CurPos, SEEK_SET) != 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -80,6 +80,9 @@ public:
|
|||||||
/// Returns the current position (bytes from file start) or -1 for failure; asserts if not open
|
/// Returns the current position (bytes from file start) or -1 for failure; asserts if not open
|
||||||
int Tell (void) const;
|
int Tell (void) const;
|
||||||
|
|
||||||
|
/// Returns the size of file, in bytes, or -1 for failure; asserts if not open
|
||||||
|
int GetSize(void) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifdef USE_STDIO_FILE
|
#ifdef USE_STDIO_FILE
|
||||||
FILE * m_File;
|
FILE * m_File;
|
||||||
|
@ -33,6 +33,17 @@ void cFileFormatUpdater::UpdatePlayersOfWorld( const char* a_WorldName )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define READ(File, Var) \
|
||||||
|
if (File.Read(&Var, sizeof(Var)) != sizeof(Var)) \
|
||||||
|
{ \
|
||||||
|
LOGERROR("ERROR READING \"%s\" FROM FILE \"%s\"", #Var, a_FileName); \
|
||||||
|
return; \
|
||||||
|
}
|
||||||
|
|
||||||
// Converts player binary files to human readable JSON
|
// Converts player binary files to human readable JSON
|
||||||
void cFileFormatUpdater::PlayerBINtoJSON( const char* a_FileName )
|
void cFileFormatUpdater::PlayerBINtoJSON( const char* a_FileName )
|
||||||
{
|
{
|
||||||
@ -43,33 +54,30 @@ void cFileFormatUpdater::PlayerBINtoJSON( const char* a_FileName )
|
|||||||
const unsigned int NumInventorySlots = 45; // At this time the player inventory has/had 45 slots
|
const unsigned int NumInventorySlots = 45; // At this time the player inventory has/had 45 slots
|
||||||
cItem IventoryItems[ NumInventorySlots ];
|
cItem IventoryItems[ NumInventorySlots ];
|
||||||
|
|
||||||
FILE* f;
|
cFile f;
|
||||||
#ifdef _WIN32
|
if (!f.Open(a_FileName, cFile::fmRead))
|
||||||
if( fopen_s(&f, a_FileName, "rb" ) == 0 ) // no error
|
|
||||||
#else
|
|
||||||
if( (f = fopen(a_FileName, "rb" ) ) != 0 ) // no error
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// First read player position, rotation and health
|
// First read player position, rotation and health
|
||||||
if( fread( &PlayerPos.x, sizeof(double), 1, f) != 1 ) { LOGERROR("ERROR READING FROM FILE %s", a_FileName); fclose(f); return; }
|
READ(f, PlayerPos.x);
|
||||||
if( fread( &PlayerPos.y, sizeof(double), 1, f) != 1 ) { LOGERROR("ERROR READING FROM FILE %s", a_FileName); fclose(f); return; }
|
READ(f, PlayerPos.y);
|
||||||
if( fread( &PlayerPos.z, sizeof(double), 1, f) != 1 ) { LOGERROR("ERROR READING FROM FILE %s", a_FileName); fclose(f); return; }
|
READ(f, PlayerPos.z);
|
||||||
if( fread( &PlayerRot.x, sizeof(float), 1, f) != 1 ) { LOGERROR("ERROR READING FROM FILE %s", a_FileName); fclose(f); return; }
|
READ(f, PlayerRot.x);
|
||||||
if( fread( &PlayerRot.y, sizeof(float), 1, f) != 1 ) { LOGERROR("ERROR READING FROM FILE %s", a_FileName); fclose(f); return; }
|
READ(f, PlayerRot.y);
|
||||||
if( fread( &PlayerRot.z, sizeof(float), 1, f) != 1 ) { LOGERROR("ERROR READING FROM FILE %s", a_FileName); fclose(f); return; }
|
READ(f, PlayerRot.z);
|
||||||
if( fread( &PlayerHealth, sizeof(short), 1, f) != 1 ) { LOGERROR("ERROR READING FROM FILE %s", a_FileName); fclose(f); return; }
|
READ(f, PlayerHealth);
|
||||||
|
|
||||||
|
|
||||||
for(unsigned int i = 0; i < NumInventorySlots; i++)
|
for(unsigned int i = 0; i < NumInventorySlots; i++)
|
||||||
{
|
{
|
||||||
cItem & Item = IventoryItems[i];
|
cItem & Item = IventoryItems[i];
|
||||||
if( fread( &Item.m_ItemID, sizeof(Item.m_ItemID), 1, f) != 1 ) { LOGERROR("ERROR READING INVENTORY FROM FILE"); return; }
|
READ(f, Item.m_ItemID);
|
||||||
if( fread( &Item.m_ItemCount, sizeof(Item.m_ItemCount), 1, f) != 1 ) { LOGERROR("ERROR READING INVENTORY FROM FILE"); return; }
|
READ(f, Item.m_ItemCount);
|
||||||
if( fread( &Item.m_ItemHealth, sizeof(Item.m_ItemHealth), 1, f)!= 1 ) { LOGERROR("ERROR READING INVENTORY FROM FILE"); return; }
|
READ(f, Item.m_ItemHealth);
|
||||||
}
|
|
||||||
|
|
||||||
fclose(f);
|
|
||||||
}
|
}
|
||||||
|
f.Close();
|
||||||
|
|
||||||
// Loaded all the data, now create the JSON data
|
// Loaded all the data, now create the JSON data
|
||||||
Json::Value JSON_PlayerPosition;
|
Json::Value JSON_PlayerPosition;
|
||||||
@ -105,24 +113,25 @@ void cFileFormatUpdater::PlayerBINtoJSON( const char* a_FileName )
|
|||||||
std::string FileNameJson = FileNameWithoutExt + ".json";
|
std::string FileNameJson = FileNameWithoutExt + ".json";
|
||||||
|
|
||||||
// Write to file
|
// Write to file
|
||||||
#ifdef _WIN32
|
if (!f.Open(FileNameJson.c_str(), cFile::fmWrite))
|
||||||
if( fopen_s(&f, FileNameJson.c_str(), "wb" ) == 0 ) // no error
|
|
||||||
#else
|
|
||||||
if( (f = fopen(FileNameJson.c_str(), "wb" ) ) != 0 ) // no error
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
if( fwrite( JsonData.c_str(), JsonData.size(), 1, f ) != 1 ) { LOGERROR("ERROR WRITING PLAYER JSON TO FILE %s", FileNameJson.c_str() ); return; }
|
return;
|
||||||
fclose( f );
|
|
||||||
}
|
}
|
||||||
|
if (f.Write(JsonData.c_str(), JsonData.size()) != JsonData.size())
|
||||||
|
{
|
||||||
|
LOGERROR("ERROR WRITING PLAYER JSON TO FILE \"%s\"", FileNameJson.c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
f.Close();
|
||||||
|
|
||||||
// Delete old format file, only do this when conversion has succeeded
|
// Delete old format file, only do this when conversion has succeeded
|
||||||
if( std::remove( a_FileName ) != 0 )
|
if (std::remove(a_FileName) != 0)
|
||||||
{
|
{
|
||||||
LOGERROR("COULD NOT DELETE FILE %s", a_FileName );
|
LOGERROR("COULD NOT DELETE old format file \"%s\"", a_FileName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGINFO("Successfully converted binary to Json %s", FileNameJson.c_str() );
|
LOGINFO("Successfully converted binary to Json \"%s\"", FileNameJson.c_str() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -764,6 +764,10 @@ void cPlayer::LoadPermissionsFromDisk()
|
|||||||
ResolvePermissions();
|
ResolvePermissions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cPlayer::LoadFromDisk() // TODO - This should also get/set/whatever the correct world for this player
|
bool cPlayer::LoadFromDisk() // TODO - This should also get/set/whatever the correct world for this player
|
||||||
{
|
{
|
||||||
LoadPermissionsFromDisk();
|
LoadPermissionsFromDisk();
|
||||||
@ -778,21 +782,22 @@ bool cPlayer::LoadFromDisk() // TODO - This should also get/set/whatever the cor
|
|||||||
char SourceFile[128];
|
char SourceFile[128];
|
||||||
sprintf_s(SourceFile, 128, "players/%s.json", m_pState->PlayerName.c_str() );
|
sprintf_s(SourceFile, 128, "players/%s.json", m_pState->PlayerName.c_str() );
|
||||||
|
|
||||||
FILE* f;
|
cFile f;
|
||||||
#ifdef _WIN32
|
if (!f.Open(SourceFile, cFile::fmRead))
|
||||||
if( fopen_s(&f, SourceFile, "rb" ) == 0 ) // no error
|
|
||||||
#else
|
|
||||||
if( (f = fopen(SourceFile, "rb" ) ) != 0 ) // no error
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
// Get file size
|
return false;
|
||||||
fseek (f , 0 , SEEK_END);
|
}
|
||||||
long FileSize = ftell (f);
|
|
||||||
rewind(f);
|
|
||||||
|
|
||||||
char* buffer = new char[ FileSize ];
|
// Get file size
|
||||||
if( fread( buffer, FileSize, 1, f) != 1 ) { LOGERROR("ERROR READING FROM FILE %s", SourceFile); fclose(f); return false; }
|
long FileSize = f.GetSize();
|
||||||
fclose(f);
|
|
||||||
|
char * buffer = new char[FileSize];
|
||||||
|
if (f.Read(buffer, FileSize) != FileSize )
|
||||||
|
{
|
||||||
|
LOGERROR("ERROR READING FROM FILE \"%s\"", SourceFile);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
f.Close();
|
||||||
|
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
Json::Reader reader;
|
Json::Reader reader;
|
||||||
@ -827,10 +832,12 @@ bool cPlayer::LoadFromDisk() // TODO - This should also get/set/whatever the cor
|
|||||||
m_pState->LoadedWorldName = root.get("world", "world").asString();
|
m_pState->LoadedWorldName = root.get("world", "world").asString();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cPlayer::SaveToDisk()
|
bool cPlayer::SaveToDisk()
|
||||||
{
|
{
|
||||||
cMakeDir::MakeDir("players");
|
cMakeDir::MakeDir("players");
|
||||||
@ -867,23 +874,24 @@ bool cPlayer::SaveToDisk()
|
|||||||
char SourceFile[128];
|
char SourceFile[128];
|
||||||
sprintf_s(SourceFile, 128, "players/%s.json", m_pState->PlayerName.c_str() );
|
sprintf_s(SourceFile, 128, "players/%s.json", m_pState->PlayerName.c_str() );
|
||||||
|
|
||||||
FILE* f;
|
cFile f;
|
||||||
#ifdef _WIN32
|
if (!f.Open(SourceFile, cFile::fmWrite))
|
||||||
if( fopen_s(&f, SourceFile, "wb" ) == 0 ) // no error
|
|
||||||
#else
|
|
||||||
if( (f = fopen(SourceFile, "wb" ) ) != 0 ) // no error
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
if( fwrite( JsonData.c_str(), JsonData.size(), 1, f ) != 1 ) { LOGERROR("ERROR WRITING PLAYER JSON TO FILE %s", SourceFile ); return false; }
|
LOGERROR("ERROR WRITING PLAYER \"%s\" TO FILE \"%s\" - cannot open file", m_pState->PlayerName.c_str(), SourceFile);
|
||||||
fclose(f);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOGERROR("ERROR WRITING PLAYER %s TO FILE %s", m_pState->PlayerName.c_str(), SourceFile);
|
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
if (f.Write(JsonData.c_str(), JsonData.size()) != JsonData.size())
|
||||||
|
{
|
||||||
|
LOGERROR("ERROR WRITING PLAYER JSON TO FILE \"%s\"", SourceFile);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const char* cPlayer::GetName()
|
const char* cPlayer::GetName()
|
||||||
{
|
{
|
||||||
return m_pState->PlayerName.c_str();
|
return m_pState->PlayerName.c_str();
|
||||||
|
@ -19,35 +19,56 @@
|
|||||||
|
|
||||||
|
|
||||||
typedef std::list< cRecipeChecker::Recipe* > RecipeList;
|
typedef std::list< cRecipeChecker::Recipe* > RecipeList;
|
||||||
|
|
||||||
struct cRecipeChecker::sRecipeCheckerState
|
struct cRecipeChecker::sRecipeCheckerState
|
||||||
{
|
{
|
||||||
RecipeList Recipes;
|
RecipeList Recipes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cRecipeChecker* cRecipeChecker::GetRecipeChecker()
|
cRecipeChecker* cRecipeChecker::GetRecipeChecker()
|
||||||
{
|
{
|
||||||
LOGWARN("WARNING: Using deprecated function cRecipeChecker::GetRecipeChecker() use cRoot::Get()->GetRecipeChecker() instead!");
|
LOGWARN("WARNING: Using deprecated function cRecipeChecker::GetRecipeChecker() use cRoot::Get()->GetRecipeChecker() instead!");
|
||||||
return cRoot::Get()->GetRecipeChecker();
|
return cRoot::Get()->GetRecipeChecker();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cRecipeChecker::Recipe::~Recipe()
|
cRecipeChecker::Recipe::~Recipe()
|
||||||
{
|
{
|
||||||
delete [] Slots;
|
delete [] Slots;
|
||||||
Slots = 0;
|
Slots = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cRecipeChecker::~cRecipeChecker()
|
cRecipeChecker::~cRecipeChecker()
|
||||||
{
|
{
|
||||||
ClearRecipes();
|
ClearRecipes();
|
||||||
delete m_pState;
|
delete m_pState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cRecipeChecker::cRecipeChecker()
|
cRecipeChecker::cRecipeChecker()
|
||||||
: m_pState( new sRecipeCheckerState )
|
: m_pState( new sRecipeCheckerState )
|
||||||
{
|
{
|
||||||
ReloadRecipes();
|
ReloadRecipes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cRecipeChecker::ClearRecipes()
|
void cRecipeChecker::ClearRecipes()
|
||||||
{
|
{
|
||||||
while( m_pState->Recipes.size() > 0 )
|
while( m_pState->Recipes.size() > 0 )
|
||||||
@ -57,6 +78,10 @@ void cRecipeChecker::ClearRecipes()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PrintRecipe( std::vector< cRecipeChecker::RecipeSlot > & RecipeSlots )
|
void PrintRecipe( std::vector< cRecipeChecker::RecipeSlot > & RecipeSlots )
|
||||||
{
|
{
|
||||||
LOG("Recipe:");
|
LOG("Recipe:");
|
||||||
@ -67,6 +92,10 @@ void PrintRecipe( std::vector< cRecipeChecker::RecipeSlot > & RecipeSlots )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PrintNear( std::ifstream & f, int a_History = 64 )
|
void PrintNear( std::ifstream & f, int a_History = 64 )
|
||||||
{
|
{
|
||||||
f.clear();
|
f.clear();
|
||||||
@ -91,35 +120,15 @@ void PrintNear( std::ifstream & f, int a_History = 64 )
|
|||||||
LOGERROR("Error near: \"%s\"", Near.c_str() );
|
LOGERROR("Error near: \"%s\"", Near.c_str() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cRecipeChecker::ReloadRecipes()
|
void cRecipeChecker::ReloadRecipes()
|
||||||
{
|
{
|
||||||
LOG("--Loading recipes--");
|
LOG("--Loading recipes--");
|
||||||
ClearRecipes();
|
ClearRecipes();
|
||||||
|
|
||||||
/*
|
|
||||||
char a_File[] = "recipes.txt";
|
|
||||||
|
|
||||||
FILE* f = 0;
|
|
||||||
#ifdef _WIN32
|
|
||||||
if( fopen_s(&f, a_File, "rb" ) == 0 ) // no error
|
|
||||||
#else
|
|
||||||
if( (f = fopen(a_File, "rb" )) != 0 ) // no error
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
char c;
|
|
||||||
while( fread( &c, sizeof(char), 1, f) == 1 )
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LOG("Could not open file for recipes: %s", a_File);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
std::ifstream f;
|
std::ifstream f;
|
||||||
|
|
||||||
char a_File[] = "recipes.txt";
|
char a_File[] = "recipes.txt";
|
||||||
@ -361,19 +370,13 @@ void cRecipeChecker::ReloadRecipes()
|
|||||||
}
|
}
|
||||||
f.close();
|
f.close();
|
||||||
|
|
||||||
LOG("Found %i recipes", m_pState->Recipes.size() );
|
LOG("--Done loading recipes, found %i recipes", m_pState->Recipes.size() );
|
||||||
// for(RecipeList::iterator itr = m_pState->Recipes.begin(); itr != m_pState->Recipes.end(); ++itr )
|
|
||||||
// {
|
|
||||||
// LOG("Recipe for %i times %i", (*itr)->Result.m_ItemCount, (*itr)->Result.m_ItemID );
|
|
||||||
// for(unsigned int j = 0; j < (*itr)->NumItems; j++)
|
|
||||||
// {
|
|
||||||
// RecipeSlot Slot = (*itr)->Slots[j];
|
|
||||||
// LOG("%i %i %i %i", Slot.x, Slot.y, Slot.Item.m_ItemID, Slot.Item.m_ItemCount );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
LOG("--Done loading recipes--");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cItem cRecipeChecker::CookIngredients( cItem* a_Items, int a_Width, int a_Height, bool a_bConsumeIngredients /* = false */ )
|
cItem cRecipeChecker::CookIngredients( cItem* a_Items, int a_Width, int a_Height, bool a_bConsumeIngredients /* = false */ )
|
||||||
{
|
{
|
||||||
int iLeft = 999, iTop = 999;
|
int iLeft = 999, iTop = 999;
|
||||||
@ -459,3 +462,7 @@ cItem cRecipeChecker::CookIngredients( cItem* a_Items, int a_Width, int a_Height
|
|||||||
}
|
}
|
||||||
return cItem();
|
return cItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -245,6 +245,10 @@ void cWebAdmin::Request_Handler(webserver::http_request* r)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cWebAdmin::Init( int a_Port )
|
bool cWebAdmin::Init( int a_Port )
|
||||||
{
|
{
|
||||||
m_Port = a_Port;
|
m_Port = a_Port;
|
||||||
@ -289,45 +293,44 @@ void *cWebAdmin::ListenThread( void *lpParam )
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::string cWebAdmin::GetTemplate()
|
std::string cWebAdmin::GetTemplate()
|
||||||
{
|
{
|
||||||
std::string retVal = "";
|
std::string retVal = "";
|
||||||
|
|
||||||
char SourceFile[] = "webadmin/template.html";
|
char SourceFile[] = "webadmin/template.html";
|
||||||
|
|
||||||
FILE* f;
|
cFile f;
|
||||||
#ifdef _WIN32
|
if (!f.Open(SourceFile, cFile::fmRead))
|
||||||
if( fopen_s(&f, SourceFile, "rb" ) == 0 ) // no error
|
|
||||||
#else
|
|
||||||
if( (f = fopen(SourceFile, "rb" ) ) != 0 ) // no error
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
// obtain file size:
|
|
||||||
fseek (f , 0 , SEEK_END);
|
|
||||||
long lSize = ftell (f);
|
|
||||||
rewind (f);
|
|
||||||
|
|
||||||
// allocate memory to contain the whole file:
|
|
||||||
char* buffer = (char*) malloc (sizeof(char)*lSize);
|
|
||||||
|
|
||||||
// copy the file into the buffer:
|
|
||||||
size_t result = fread (buffer, 1, lSize, f);
|
|
||||||
if ((long)result != lSize)
|
|
||||||
{
|
|
||||||
LOG ("WEBADMIN: Could not read file %s", SourceFile);
|
|
||||||
free( buffer );
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
retVal.assign( buffer, lSize );
|
// obtain file size:
|
||||||
|
int lSize = f.GetSize();
|
||||||
|
|
||||||
free( buffer );
|
// allocate memory to contain the whole file:
|
||||||
fclose(f);
|
std::auto_ptr<char> buffer(new char[lSize]); // auto_ptr deletes the memory in its destructor
|
||||||
|
|
||||||
|
// copy the file into the buffer:
|
||||||
|
if (f.Read(buffer.get(), lSize) != lSize)
|
||||||
|
{
|
||||||
|
LOG ("WEBADMIN: Could not read file \"%s\"", SourceFile);
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
retVal.assign(buffer.get(), lSize );
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cWebAdmin::RemovePlugin( lua_State* L )
|
void cWebAdmin::RemovePlugin( lua_State* L )
|
||||||
{
|
{
|
||||||
for( PluginList::iterator itr = m_Plugins.begin(); itr != m_Plugins.end(); )
|
for( PluginList::iterator itr = m_Plugins.begin(); itr != m_Plugins.end(); )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user