1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "stdgeorges.h"
22 #include "nel/misc/thread.h"
23 #include "nel/misc/i_xml.h"
24 #include "nel/misc/common.h"
26 #include "nel/georges/header.h"
32 using namespace NLMISC
;
37 // ***************************************************************************
39 void warning (bool exception
, const char *format
, ... );
41 // ***************************************************************************
43 CFileHeader::CFileHeader ()
50 // ***************************************************************************
52 void CFileHeader::write (xmlNodePtr node
) const
54 // Georges version system
56 smprintf (tmp
, 512, "%d.%d", MajorVersion
, MinorVersion
);
57 xmlSetProp (node
, (const xmlChar
*)"Version", (const xmlChar
*)tmp
);
60 if (State
== Modified
)
61 xmlSetProp (node
, (const xmlChar
*)"State", (const xmlChar
*)"modified");
63 xmlSetProp (node
, (const xmlChar
*)"State", (const xmlChar
*)"checked");
65 // Comments of the form
66 if (!Comments
.empty ())
69 xmlNodePtr child
= xmlNewChild ( node
, NULL
, (const xmlChar
*)"COMMENTS", NULL
);
70 xmlNodePtr textNode
= xmlNewText ((const xmlChar
*)Comments
.c_str());
71 xmlAddChild (child
, textNode
);
78 xmlNodePtr child
= xmlNewChild ( node
, NULL
, (const xmlChar
*)"LOG", NULL
);
79 xmlNodePtr textNode
= xmlNewText ((const xmlChar
*)Log
.c_str());
80 xmlAddChild (child
, textNode
);
84 // ***************************************************************************
86 void CFileHeader::addLog (const std::string
&log
)
93 Log
.resize (Log
.size()-1);
95 Log
+= IThread::getCurrentThread ()->getUserName ();
100 // ***************************************************************************
102 void CFileHeader::setComments (const std::string
&comments
)
107 // ***************************************************************************
109 void CFileHeader::read (xmlNodePtr root
)
112 const char *value
= (const char*)xmlGetProp (root
, (xmlChar
*)"Version");
116 if (sscanf (value
, "%d.%d", &MajorVersion
, &MinorVersion
) != 2)
119 xmlFree ((void*)value
);
122 warning (true, "read", "XML Syntax error in TYPE block line %d, the Version argument is invalid.",
127 xmlFree ((void*)value
);
137 value
= (const char*)xmlGetProp (root
, (xmlChar
*)"State");
141 if (strcmp (value
, "modified") == 0)
145 else if (strcmp (value
, "checked") == 0)
152 xmlFree ((void*)value
);
155 warning (true, "read", "XML Syntax error in TYPE block line %d, the State argument is invalid.",
160 xmlFree ((void*)value
);
168 // Look for the comment node
170 xmlNodePtr node
= CIXml::getFirstChildNode (root
, "COMMENTS");
174 node
= CIXml::getFirstChildNode (node
, XML_TEXT_NODE
);
179 const char *comments
= (const char*)xmlNodeGetContent (node
);
185 xmlFree ((void*)comments
);
190 // Look for the log node
192 node
= CIXml::getFirstChildNode (root
, "LOG");
196 node
= CIXml::getFirstChildNode (node
, XML_TEXT_NODE
);
201 const char *log
= (const char*)xmlNodeGetContent (node
);
207 xmlFree ((void*)log
);
213 // ***************************************************************************
215 const char *CFileHeader::getStateString (TState state
)
217 if (state
== Modified
)
223 // ***************************************************************************
225 void CFileHeader::warning (bool exception
, const std::string
&function
, const char *format
, ... ) const
227 // Make a buffer string
229 va_start( args
, format
);
231 vsnprintf( buffer
, 1024, format
, args
);
235 NLGEORGES::warning (exception
, "(CFileHeader::%s) : %s", function
.c_str(), buffer
);
238 // ***************************************************************************