Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / tools / make_alias_file / make_alias_file.cpp
blobdf35be9cb098d8a087f445058a8d3beaa8bebda1
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (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 Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 // misc
22 #include "nel/misc/types_nl.h"
23 #include "nel/misc/sheet_id.h"
24 #include "nel/misc/config_file.h"
26 #include "nel/georges/u_form.h"
27 #include "nel/georges/u_form_elm.h"
28 #include "nel/georges/load_form.h"
30 // std
31 #include <string>
32 #include <vector>
35 #include <iostream>
39 using namespace NLMISC;
40 using namespace std;
45 /**
46 * Class to manage a sheet.
47 * \author Stephane Coutelas
48 * \author Nevrax France
49 * \date 2003
51 class CSheet
54 public:
56 /// Alias
57 string Alias;
59 public:
61 /// Constructor
62 CSheet() {}
64 /// Load the values using the george sheet
65 void readGeorges (const CSmartPtr<NLGEORGES::UForm> &form, const CSheetId &sheetId);
67 /// Load/Save the values using the serial system
68 void serial (NLMISC::IStream &s);
70 /**
71 * Event to implement any action when the sheet is no longer existent.
72 * This method is called when a sheet have been read from the packed sheet
73 * and the associated sheet file no more exist in the directories.
75 void removed() {}
77 static uint getVersion();
79 private :
81 static const uint _Version;
84 uint const CSheet::_Version = 1;
88 //-----------------------------------------------
89 // readGeorges
91 //-----------------------------------------------
92 void CSheet::readGeorges (const CSmartPtr<NLGEORGES::UForm> &form, const CSheetId &sheetId)
94 // Load the form with given sheet id
95 if (form)
97 if( !form->getRootNode().getValueByName(Alias, "Alias", NLGEORGES::UFormElm::NoEval) )
105 //-----------------------------------------------
106 // serial
108 //-----------------------------------------------
109 void CSheet::serial (NLMISC::IStream &s)
111 s.serial( Alias );
116 //-----------------------------------------------
117 // getVersion
119 //-----------------------------------------------
120 uint CSheet::getVersion ()
122 //return CSheetManager::_AliasFilenameVersion;
123 return 1;
129 //-----------------------------------------------
130 // displayHelp
132 //-----------------------------------------------
133 void displayHelp()
135 cout<<"This tool creates a packed file which associates sheet id with sheet alias"<<endl;
136 cout<<"Vars used in make_alias_file.cfg :"<<endl;
137 cout<<" - SheetPaths : the paths where to find the sheets"<<endl;
138 cout<<" - AliasFilename : name used for alias file (default is 'alias.packed_sheets')"<<endl;
139 cout<<" - Extensions : the extensions list of sheets to read"<<endl;
140 cout<<endl;
141 cout<<"MAKE_ALIAS_FILE"<<endl;
143 } // displayHelp //
150 //-----------------------------------------------
151 // MAIN
153 //-----------------------------------------------
154 int main( int argc, char ** argv )
156 // get the output filename
157 if( argc > 1 )
159 displayHelp();
160 return EXIT_FAILURE;
163 // load the cfg
164 CConfigFile configFile;
165 string configFileName = "make_alias_file.cfg";
166 if(!CFile::fileExists(configFileName))
168 nlwarning("Config file %s not found",configFileName.c_str());
169 return 1;
171 configFile.load(configFileName);
174 // read the sheet paths
175 vector<string> sheetPaths;
178 CConfigFile::CVar& cvSheetPaths = configFile.getVar("SheetPaths");
179 sint i;
180 for( i = 0; i< (sint)cvSheetPaths.size(); ++i)
182 sheetPaths.push_back(NLMISC::expandEnvironmentVariables(cvSheetPaths.asString(i)));
185 catch(const EUnknownVar &)
187 nlwarning("var 'SheetPaths' not found");
190 // add the sheet paths
191 cout<<"adding the sheet paths ..."<<endl;
192 vector<string>::iterator itPath;
193 for( itPath = sheetPaths.begin(); itPath != sheetPaths.end(); ++itPath )
195 CPath::addSearchPath(*itPath,true,false);
198 // read the name that will be used for packed file
199 string aliasFilename = "alias.packed_sheets";
202 CConfigFile::CVar &cvAliasFilename = configFile.getVar("AliasFilename");
203 aliasFilename = cvAliasFilename.asString();
205 catch(const EUnknownVar &)
207 nlwarning("var 'AliasFilename' not found");
210 // read the extensions list of sheets to read
211 vector<string> extensions;
214 CConfigFile::CVar& cvExtensions = configFile.getVar("Extensions");
215 sint i;
216 for( i = 0; i< (sint)cvExtensions.size(); ++i)
218 extensions.push_back( cvExtensions.asString(i) );
221 catch(const EUnknownVar &)
223 nlwarning("var 'Extensions' not found");
226 // load form and create packed sheets
227 cout<<"reading the sheets ..."<<endl;
228 map<CSheetId, CSheet> sheetMap;
229 bool updatePackedSheet = true;
230 createDebug(); // needed to init WarningLog
231 loadForm (extensions, aliasFilename, sheetMap, updatePackedSheet);
232 cout<<"finished."<<endl;
234 // display the content of the map
236 map<CSheetId, CSheet>::iterator itAlias;
237 for( itAlias = sheetMap.begin(); itAlias != sheetMap.end(); ++itAlias )
239 nlinfo("sheet %s alias = %s",(*itAlias).first.toString().c_str(),(*itAlias).second.Alias.c_str());
243 return EXIT_SUCCESS;
245 } // main //