Files
TCPlayerbotCore/src/shared/vmap/DebugCmdLogger.cpp
T

132 lines
3.3 KiB
C++
Raw Normal View History

/*
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
2008-10-14 11:57:03 -05:00
*
* Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/>
2008-10-02 16:23:55 -05:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2008-10-14 11:57:03 -05:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2008-10-02 16:23:55 -05:00
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
2008-10-14 11:57:03 -05:00
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2008-10-02 16:23:55 -05:00
*/
#include <cstdio>
2008-10-02 16:23:55 -05:00
#include "DebugCmdLogger.h"
#include <stdio.h>
2008-10-02 16:23:55 -05:00
using namespace G3D;
namespace VMAP
{
bool CommandFileRW::appendCmd(const Command&
2008-10-02 16:23:55 -05:00
#ifdef _DEBUG
pCommand
#endif
)
{
#ifdef _DEBUG
bool result = false;
if(iWritingEnabled || pCommand.isCoreCmd())
{
FILE* f = fopen(iFileName.c_str(), "ab");
if(f)
{
result = true;
if(fwrite(&pCommand, sizeof(Command), 1, f) != 1) { result = false; }
fclose(f);
}
}
else
{
result = true;
}
return result;
#else
return true;
#endif
}
//=========================================================
bool CommandFileRW::appendCmds(const Array<Command>&
2008-10-02 16:23:55 -05:00
#ifdef _DEBUG
pCmdArray
#endif
)
{
#ifdef _DEBUG
bool result = false;
if(iWritingEnabled)
{
FILE* f;
if(resetfile)
f = fopen(iFileName.c_str(), "wb");
else
f = fopen(iFileName.c_str(), "ab");
resetfile = false;
if(f)
{
result = true;
for(int i=0; i<pCmdArray.size(); ++i)
{
if(fwrite(&pCmdArray[i], sizeof(Command), 1, f) != 1) { result = false; break; }
}
fclose(f);
}
}
else
{
result = true;
}
return result;
#else
return true;
#endif
}
//=========================================================
bool CommandFileRW::getNewCommands(Array<Command>& pCmdArray)
{
bool result = false;
2009-05-06 16:27:07 -05:00
FILE* f = fopen(iFileName.c_str(), "rb");
if(f)
2008-10-02 16:23:55 -05:00
{
Command cmd;
2009-05-06 16:27:07 -05:00
if(fseek(f, iLastPos, SEEK_SET) == 0) { result = true; }
2008-10-02 16:23:55 -05:00
while(result)
{
2009-05-06 16:27:07 -05:00
if(fread(&cmd, sizeof(Command), 1, f) != 1)
2008-10-02 16:23:55 -05:00
{
result = false;
}
2009-05-06 16:27:07 -05:00
iLastPos = ftell(f);
2008-10-02 16:23:55 -05:00
if(cmd.getType() == STOP)
{
break;
}
pCmdArray.append(cmd);
}
2009-05-06 16:27:07 -05:00
fclose(f);
2008-10-02 16:23:55 -05:00
}
if(result)
{
iCommandArray.append(pCmdArray);
}
return(result);
}
//========================================================
}
2009-02-17 20:07:49 -06:00