Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / src / georges / header.cpp
blob62ba0e888063ebca1d582e10c072d0d33ce7a529
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
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"
28 #ifdef DEBUG_NEW
29 #define new DEBUG_NEW
30 #endif
32 using namespace NLMISC;
34 namespace NLGEORGES
37 // ***************************************************************************
39 void warning (bool exception, const char *format, ... );
41 // ***************************************************************************
43 CFileHeader::CFileHeader ()
45 MajorVersion = 0;
46 MinorVersion = 0;
47 State = Modified;
50 // ***************************************************************************
52 void CFileHeader::write (xmlNodePtr node) const
54 // Georges version system
55 char tmp[512];
56 smprintf (tmp, 512, "%d.%d", MajorVersion, MinorVersion);
57 xmlSetProp (node, (const xmlChar*)"Version", (const xmlChar*)tmp);
59 // State
60 if (State == Modified)
61 xmlSetProp (node, (const xmlChar*)"State", (const xmlChar*)"modified");
62 else
63 xmlSetProp (node, (const xmlChar*)"State", (const xmlChar*)"checked");
65 // Comments of the form
66 if (!Comments.empty ())
68 // Create a new node
69 xmlNodePtr child = xmlNewChild ( node, NULL, (const xmlChar*)"COMMENTS", NULL);
70 xmlNodePtr textNode = xmlNewText ((const xmlChar *)Comments.c_str());
71 xmlAddChild (child, textNode);
74 // Logs
75 if (!Log.empty ())
77 // Create a new node
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)
88 time_t t;
89 time (&t);
90 if (!Log.empty())
91 Log += "\n";
92 Log += ctime(&t);
93 Log.resize (Log.size()-1);
94 Log += " (";
95 Log += IThread::getCurrentThread ()->getUserName ();
96 Log += ") ";
97 Log += log;
100 // ***************************************************************************
102 void CFileHeader::setComments (const std::string &comments)
104 Comments = comments;
107 // ***************************************************************************
109 void CFileHeader::read (xmlNodePtr root)
111 // Get the version
112 const char *value = (const char*)xmlGetProp (root, (xmlChar*)"Version");
113 if (value)
115 // Read the version
116 if (sscanf (value, "%d.%d", &MajorVersion, &MinorVersion) != 2)
118 // Delete the value
119 xmlFree ((void*)value);
121 // Throw exception
122 warning (true, "read", "XML Syntax error in TYPE block line %d, the Version argument is invalid.",
123 (sint)root->line);
126 // Delete the value
127 xmlFree ((void*)value);
129 else
131 // Set default
132 MajorVersion = 0;
133 MinorVersion = 0;
136 // Get the version
137 value = (const char*)xmlGetProp (root, (xmlChar*)"State");
138 if (value)
140 // Read the version
141 if (strcmp (value, "modified") == 0)
143 State = Modified;
145 else if (strcmp (value, "checked") == 0)
147 State = Checked;
149 else
151 // Delete the value
152 xmlFree ((void*)value);
154 // Throw exception
155 warning (true, "read", "XML Syntax error in TYPE block line %d, the State argument is invalid.",
156 (sint)root->line);
159 // Delete the value
160 xmlFree ((void*)value);
162 else
164 // Set default
165 State = Modified;
168 // Look for the comment node
169 Comments.clear();
170 xmlNodePtr node = CIXml::getFirstChildNode (root, "COMMENTS");
171 if (node)
173 // Get a text node
174 node = CIXml::getFirstChildNode (node, XML_TEXT_NODE);
176 if (node)
178 // Get content
179 const char *comments = (const char*)xmlNodeGetContent (node);
180 if (comments)
182 Comments = comments;
184 // Delete the value
185 xmlFree ((void*)comments);
190 // Look for the log node
191 Log.clear();
192 node = CIXml::getFirstChildNode (root, "LOG");
193 if (node)
195 // Get a text node
196 node = CIXml::getFirstChildNode (node, XML_TEXT_NODE);
198 if (node)
200 // Get content
201 const char *log = (const char*)xmlNodeGetContent (node);
202 if (log)
204 Log = log;
206 // Delete the value
207 xmlFree ((void*)log);
213 // ***************************************************************************
215 const char *CFileHeader::getStateString (TState state)
217 if (state == Modified)
218 return "Modified";
219 else
220 return "Checked";
223 // ***************************************************************************
225 void CFileHeader::warning (bool exception, const std::string &function, const char *format, ... ) const
227 // Make a buffer string
228 va_list args;
229 va_start( args, format );
230 char buffer[1024];
231 vsnprintf( buffer, 1024, format, args );
232 va_end( args );
234 // Set the warning
235 NLGEORGES::warning (exception, "(CFileHeader::%s) : %s", function.c_str(), buffer);
238 // ***************************************************************************
240 } // NLGEORGES