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

Revision 2, 3.2 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
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.
8 *
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.
13 *
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
17 */
18
19#include "DebugCmdLogger.h"
20
21using namespace G3D;
22
23namespace VMAP
24{
25
26    bool CommandFileRW::appendCmd(const Command& 
27#ifdef _DEBUG
28        pCommand
29#endif
30        )
31    {
32        #ifdef _DEBUG
33        bool result = false;
34        if(iWritingEnabled || pCommand.isCoreCmd())
35        {
36            FILE* f = fopen(iFileName.c_str(), "ab");
37            if(f)
38            {
39                result = true;
40                if(fwrite(&pCommand, sizeof(Command), 1, f) != 1) { result = false; }
41                fclose(f);
42            }
43        }
44        else
45        {
46            result = true;
47        }
48        return result;
49        #else
50        return true;
51        #endif
52    }
53
54    //=========================================================
55
56    bool CommandFileRW::appendCmds(const Array<Command>& 
57#ifdef _DEBUG
58        pCmdArray
59#endif
60        )
61    {
62        #ifdef _DEBUG
63        bool result = false;
64        if(iWritingEnabled)
65        {
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;
72
73            if(f)
74            {
75                result = true;
76                for(int i=0; i<pCmdArray.size(); ++i)
77                {
78                    if(fwrite(&pCmdArray[i], sizeof(Command), 1, f) != 1) { result = false; break; }
79                }
80                fclose(f);
81            }
82        }
83        else
84        {
85            result = true;
86        }
87        return result;
88        #else
89        return true;
90        #endif
91    }
92
93    //=========================================================
94
95    bool CommandFileRW::getNewCommands(Array<Command>& pCmdArray)
96    {
97        bool result = false;
98        FILE* f = fopen(iFileName.c_str(), "rb");
99        if(f)
100        {
101            Command cmd;
102            if(fseek(f, iLastPos, SEEK_SET) == 0) { result = true; }
103            while(result)
104            {
105                if(fread(&cmd, sizeof(Command), 1, f) != 1)
106                {
107                    result = false;
108                }
109                iLastPos = ftell(f);
110                if(cmd.getType() == STOP)
111                {
112                    break;
113                }
114                pCmdArray.append(cmd);
115            }
116            fclose(f);
117        }
118        if(result)
119        {
120            iCommandArray.append(pCmdArray);
121        }
122        return(result);
123    }
124    //========================================================
125}
Note: See TracBrowser for help on using the browser.