[7272] Trailing whitespace cleaning
[getmangos.git] / src / shared / vmap / DebugCmdLogger.cpp
blob080afa3fb7abd7fcf88a9da5860de59620d3291f
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "DebugCmdLogger.h"
21 using namespace G3D;
23 namespace VMAP
26 bool CommandFileRW::appendCmd(const Command&
27 #ifdef _DEBUG
28 pCommand
29 #endif
32 #ifdef _DEBUG
33 bool result = false;
34 if(iWritingEnabled || pCommand.isCoreCmd())
36 FILE* f = fopen(iFileName.c_str(), "ab");
37 if(f)
39 result = true;
40 if(fwrite(&pCommand, sizeof(Command), 1, f) != 1) { result = false; }
41 fclose(f);
44 else
46 result = true;
48 return result;
49 #else
50 return true;
51 #endif
54 //=========================================================
56 bool CommandFileRW::appendCmds(const Array<Command>&
57 #ifdef _DEBUG
58 pCmdArray
59 #endif
62 #ifdef _DEBUG
63 bool result = false;
64 if(iWritingEnabled)
66 FILE* f;
67 if(resetfile)
68 f = fopen(iFileName.c_str(), "wb");
69 else
70 f = fopen(iFileName.c_str(), "ab");
71 resetfile = false;
73 if(f)
75 result = true;
76 for(int i=0; i<pCmdArray.size(); ++i)
78 if(fwrite(&pCmdArray[i], sizeof(Command), 1, f) != 1) { result = false; break; }
80 fclose(f);
83 else
85 result = true;
87 return result;
88 #else
89 return true;
90 #endif
93 //=========================================================
95 bool CommandFileRW::getNewCommands(Array<Command>& pCmdArray)
97 bool result = false;
98 FILE* f = fopen(iFileName.c_str(), "rb");
99 if(f)
101 Command cmd;
102 if(fseek(f, iLastPos, SEEK_SET) == 0) { result = true; }
103 while(result)
105 if(fread(&cmd, sizeof(Command), 1, f) != 1)
107 result = false;
109 iLastPos = ftell(f);
110 if(cmd.getType() == STOP)
112 break;
114 pCmdArray.append(cmd);
116 fclose(f);
118 if(result)
120 iCommandArray.append(pCmdArray);
122 return(result);
124 //========================================================