root/trunk/src/shared/vmap/DebugCmdLogger.cpp @ 102

Revision 102, 3.3 kB (checked in by yumileroy, 17 years ago)

[svn] Fixed copyright notices to comply with GPL.

Original author: w12x
Date: 2008-10-23 03:29:52-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include "DebugCmdLogger.h"
22
23using namespace G3D;
24
25namespace VMAP
26{
27
28    bool CommandFileRW::appendCmd(const Command& 
29#ifdef _DEBUG
30        pCommand
31#endif
32        )
33    {
34        #ifdef _DEBUG
35        bool result = false;
36        if(iWritingEnabled || pCommand.isCoreCmd())
37        {
38            FILE* f = fopen(iFileName.c_str(), "ab");
39            if(f)
40            {
41                result = true;
42                if(fwrite(&pCommand, sizeof(Command), 1, f) != 1) { result = false; }
43                fclose(f);
44            }
45        }
46        else
47        {
48            result = true;
49        }
50        return result;
51        #else
52        return true;
53        #endif
54    }
55
56    //=========================================================
57
58    bool CommandFileRW::appendCmds(const Array<Command>& 
59#ifdef _DEBUG
60        pCmdArray
61#endif
62        )
63    {
64        #ifdef _DEBUG
65        bool result = false;
66        if(iWritingEnabled)
67        {
68            FILE* f;
69            if(resetfile)
70                f = fopen(iFileName.c_str(), "wb");
71            else
72                f = fopen(iFileName.c_str(), "ab");
73            resetfile = false;
74
75            if(f)
76            {
77                result = true;
78                for(int i=0; i<pCmdArray.size(); ++i)
79                {
80                    if(fwrite(&pCmdArray[i], sizeof(Command), 1, f) != 1) { result = false; break; }
81                }
82                fclose(f);
83            }
84        }
85        else
86        {
87            result = true;
88        }
89        return result;
90        #else
91        return true;
92        #endif
93    }
94
95    //=========================================================
96
97    bool CommandFileRW::getNewCommands(Array<Command>& pCmdArray)
98    {
99        bool result = false;
100        FILE* f = fopen(iFileName.c_str(), "rb");
101        if(f)
102        {
103            Command cmd;
104            if(fseek(f, iLastPos, SEEK_SET) == 0) { result = true; }
105            while(result)
106            {
107                if(fread(&cmd, sizeof(Command), 1, f) != 1)
108                {
109                    result = false;
110                }
111                iLastPos = ftell(f);
112                if(cmd.getType() == STOP)
113                {
114                    break;
115                }
116                pCmdArray.append(cmd);
117            }
118            fclose(f);
119        }
120        if(result)
121        {
122            iCommandArray.append(pCmdArray);
123        }
124        return(result);
125    }
126    //========================================================
127}
Note: See TracBrowser for help on using the browser.