1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
4 // This file is part of Scorched3D.
6 // Scorched3D 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.
11 // Scorched3D 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.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #include <console/ConsoleImpl.h>
22 #include <console/ConsoleFileReader.h>
23 #include <console/Console.h>
24 #include <common/FileLines.h>
25 #include <common/DefinesString.h>
26 #include <XML/XMLFile.h>
27 #include <XML/XMLParser.h>
30 bool ConsoleFileReader::loadFileIntoConsole(const std::string
&fileName
,
31 std::string
&errorMessage
)
34 if (!file
.readFile(fileName
))
36 errorMessage
= file
.getParserError();
39 if (!file
.getRootNode()) return true;
41 // Itterate all of the commands in the file
42 std::list
<XMLNode
*>::iterator childrenItor
;
43 for (childrenItor
= file
.getRootNode()->getChildren().begin();
44 childrenItor
!= file
.getRootNode()->getChildren().end();
47 XMLNode
*currentNode
= (*childrenItor
);
48 if (strcmp(currentNode
->getName(), "command")==0)
50 Console::instance()->addLine(true, currentNode
->getContent());
56 void ConsoleFileReader::saveConsoleIntoFile(const std::string
&filename
)
59 filelines
.addLine("<commands source=\"Scorched3D\">");
61 std::deque
<ConsoleLine
*> &lines
=
62 ((ConsoleImpl
*) Console::instance())->getLines();
63 std::deque
<ConsoleLine
*>::iterator itor
;
64 for (itor
= lines
.begin();
68 std::string cleanLine
;
69 std::string
dirtyLine(LangStringUtil::convertFromLang((*itor
)->getLine()));
70 XMLNode::removeSpecialChars(dirtyLine
, cleanLine
);
71 if ((*itor
)->getLineType() != ConsoleLine::eNone
)
73 filelines
.addLine(S3D::formatStringBuffer(" <command>%s</command>",
78 filelines
.addLine(S3D::formatStringBuffer(" <!-- %s -->",
83 filelines
.addLine("</commands>");
84 filelines
.writeFile(filename
);