1 // Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
20 File: ResourceExporter.cxx
23 Copyright (C) CEA 2005
25 This tool provides command-line interface allowing to modify user preferences.
26 The tool can be used by the compilation procedures in order to set default preferences for the module.
29 ResourceExporter <parameters-list>
30 Parameters have the following format:
31 '<section>:<name>=<new_value>' - to set <new_value> for the user
32 preference <name> from the <section> section;
33 '<section>:<name>+=<value>[|<separator>]' - the <value> is appended to the current value
34 of the preference <name> from the <section> section;
35 separator is used to concatenate old and new values,
36 by default comma (',') symbol is used
37 '-<section>:<name>' - to remove user preference <name> from the <section>
38 section. Note that only use preference file is
39 influenced, you may need to use '<section>:<name>=""'
41 The number of parameters is limeted only by maximum possible length of the command line.
44 #include "SUIT_ResourceMgr.h"
47 #include <qstringlist.h>
48 #include <qapplication.h>
52 \return the SALOME version number
54 static QString salomeVersion()
56 QString path( ::getenv( "GUI_ROOT_DIR" ) );
57 if ( !path.isEmpty() )
58 path += QDir::separator();
59 path += QString( "bin/salome/VERSION" );
62 if ( !vf.open( IO_ReadOnly ) )
66 vf.readLine( line, 1024 );
72 while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
73 line.remove( line.length() - 1, 1 );
76 int idx = line.findRev( ":" );
78 ver = line.mid( idx + 1 ).stripWhiteSpace();
84 print the help information
88 std::cout << "" << std::endl;
89 std::cout << "ResourceExporter: provides command-line interface to modify user preferences." << std::endl;
90 std::cout << "" << std::endl;
91 std::cout << "Usage:" << std::endl;
92 std::cout << " ResourceExporter <parameters-list>" << std::endl;
93 std::cout << "Parameters have the following format:" << std::endl;
94 std::cout << " '<section>:<name>=<new_value>' - to set <new_value> for the user " << std::endl;
95 std::cout << " preference <name> from the <section> section;" << std::endl;
96 std::cout << " '<section>:<name>+=<value>[|<separator>]' - the <value> is appended to the current value " << std::endl;
97 std::cout << " of the preference <name> from the <section> section;" << std::endl;
98 std::cout << " separator is used to concatenate old and new values," << std::endl;
99 std::cout << " by default comma (',') symbol is used" << std::endl;
100 std::cout << " '-<section>:<name>' - to remove user preference <name> from the <section>" << std::endl;
101 std::cout << " section. Note that only use preference file is " << std::endl;
102 std::cout << " influenced, you may need to use '<section>:<name>=""'" << std::endl;
103 std::cout << " option" << std::endl;
104 std::cout << "The number of parameters is limeted only by maximum possible length of the command line." << std::endl;
105 std::cout << "" << std::endl;
109 application main() function
111 int main( int argc, char** argv )
113 QApplication app( argc, argv );
115 SUIT_ResourceMgr* resMgr = new SUIT_ResourceMgr( QString( "SalomeApp" ), QString( "%1Config" ) );
116 resMgr->setVersion( salomeVersion() );
117 resMgr->setCurrentFormat( QString( "xml" ) );
118 resMgr->loadLanguage();
119 for ( int i = 1; i < argc; i ++ ) {
120 QString anArg = QString( argv[i] ).stripWhiteSpace();
121 if ( anArg.startsWith( "-" ) ) {
122 anArg.remove( 0, 1 );
123 if ( anArg.contains( ":" ) ) {
124 QStringList vals = QStringList::split( ":", anArg );
125 QString section = vals[ 0 ].stripWhiteSpace();
126 QString param = vals[ 1 ].stripWhiteSpace();
127 if ( section.isEmpty() || param.isEmpty() ) continue;
128 resMgr->remove( section, param );
131 else if ( anArg.contains( "+=" ) ) {
132 QStringList vals = QStringList::split( "+=", anArg );
133 if ( vals[ 0 ].contains( ":" ) ) {
134 QStringList vals1 = QStringList::split( ":", vals[ 0 ] );
135 QString section = vals1[ 0 ].stripWhiteSpace();
136 QString param = vals1[ 1 ].stripWhiteSpace();
137 QString newValue = vals [ 1 ].stripWhiteSpace();
138 QString separ = ","; // default separator
139 if ( newValue.contains( "|" ) ) {
140 QStringList vals2 = QStringList::split( "|", newValue );
141 newValue = vals2[ 0 ].stripWhiteSpace();
142 separ = vals2[ 1 ].stripWhiteSpace();
144 if ( section.isEmpty() || param.isEmpty() || newValue.isEmpty() || separ.isEmpty() ) continue;
145 QString value = resMgr->stringValue( section, param );
146 QStringList valsOld = QStringList::split( separ, value );
147 QStringList valsNew = QStringList::split( separ, newValue );
148 for ( int i = 0; i < valsNew.count(); i++ )
149 if ( !valsOld.contains( valsNew[i] ) )
150 valsOld.append( valsNew[i] );
151 resMgr->setValue( section, param, valsOld.join( separ ) );
154 else if ( anArg.contains( "=" ) ) {
155 QStringList vals = QStringList::split( "=", anArg );
156 if ( vals[ 0 ].contains( ":" ) ) {
157 QStringList vals1 = QStringList::split( ":", vals[ 0 ] );
158 QString section = vals1[ 0 ].stripWhiteSpace();
159 QString param = vals1[ 1 ].stripWhiteSpace();
160 QString value = vals [ 1 ].stripWhiteSpace();
161 if ( section.isEmpty() || param.isEmpty() ) continue;
162 resMgr->setValue( section, param, value );