Salome HOME
Update configuration files till Salome V3.2.4
[tools/install.git] / src / main.cxx
1 //  File      : main.cxx 
2 //  Created   : Thu Dec 18 12:01:00 2002
3 //  Author    : Vadim SANDLER, Open CASCADE SAS (vadim.sandler@opencascade.com)
4 //  Project   : SALOME
5 //  Module    : Installation Wizard
6 //  Copyright : 2002-2006 CEA
7
8 #include "globals.h"
9
10 #include "SALOME_InstallWizard.hxx"
11 #include <qapplication.h>
12 #include <qfile.h>
13 #include <qmessagebox.h>
14
15 // ================================================================
16 /*!
17  *  MessageOutput
18  *  Qt's messages handler funcion
19  */
20 // ================================================================
21 void MessageOutput( QtMsgType type, 
22 #ifdef QT_DEBUG
23                     const char* msg
24 #else
25                     const char*
26 #endif
27                     )
28 {
29   switch ( type ) {
30   case QtDebugMsg:
31     ___DEBUG___( msg );
32     break;
33   case QtWarningMsg:
34     ___WARNING___( msg );
35     break;
36   case QtFatalMsg:
37     ___FATAL___( msg );
38     break;
39   }
40 }
41
42 // ================================================================
43 /*!
44  *  main
45  *  Program starts here
46  */
47 // ================================================================
48 int main( int argc, char **argv )
49 {
50   qInstallMsgHandler( MessageOutput );
51
52   QString xmlFileName;
53   QString targetDirPath;
54   QString tmpDirPath;
55   bool has_xml    = false;
56   bool has_target = false;
57   bool has_tmp    = false;
58   for( int i = 1; i < argc; i++ ) {
59     QString a = QString( argv[i] );
60     if ( a == "--version" || a == "-v" ) {
61       printf("SALOME Installation Wizard version %d.%d.%d ",
62              ( __IW_VERSION__ / 10000 ),
63              ( __IW_VERSION__ / 100 % 100 ),
64              ( __IW_VERSION__ % 100 ) );
65       printf("(Qt version %d.%d.%d)\n",
66              ( QT_VERSION >> 16 ) & 0xFF,
67              ( QT_VERSION >> 8  ) & 0xFF,
68              ( QT_VERSION       ) & 0xFF );
69       return 0;
70     }
71     else if ( a == "--target" || a == "-d" ) {
72       has_target = true;
73       if ( i < argc-1 && !QString( argv[i+1] ).startsWith("-") ) {
74         targetDirPath = argv[i+1]; 
75         i++;
76       }
77       else {
78         tmpDirPath = QString::null;
79       }
80     }
81     else if ( a == "--tmp" || a == "-t" ) {
82       has_tmp = true;
83       if ( i < argc-1 && !QString( argv[i+1] ).startsWith("-") ) {
84         tmpDirPath = argv[i+1]; 
85         i++;
86       }
87       else {
88         tmpDirPath = QString::null;
89       }
90     }
91     else if ( a == "--file" || a == "-f" ) {
92       has_xml = true;
93       if ( i < argc-1 && !QString( argv[i+1] ).startsWith("-") ) {
94         xmlFileName = argv[i+1]; 
95         i++;
96       }
97       else {
98         xmlFileName = QString::null;
99       }
100     }
101   }
102   if ( has_xml && xmlFileName.isEmpty() ) {
103     printf("Please specify the configuration XML file!\n");
104     return 1;
105   }
106   if ( has_target && targetDirPath.isEmpty() ) {
107     printf("Please specify the target directory path!\n");
108     return 1;
109   }
110   if ( has_tmp && tmpDirPath.isEmpty() ) {
111     printf("Please specify the temprary directory path!\n");
112     return 1;
113   }
114
115   if ( xmlFileName.isEmpty() )
116     xmlFileName = "config.xml";
117
118   QApplication a( argc, argv );
119   a.setFont( QFont( "Sans", 12 ) );
120
121   int result = -1;
122   QFile xmlfile(xmlFileName);
123   if ( xmlfile.exists() ) {
124     SALOME_InstallWizard wizard(xmlFileName, targetDirPath, tmpDirPath);
125     a.setMainWidget( &wizard );
126     wizard.show();
127     result = a.exec();
128   }
129   else {
130     QMessageBox::critical( 0, 
131                            QObject::tr( "Error" ), 
132                            QObject::tr( "Can't open config file:\n%1\n\nQuitting...").arg( xmlFileName ), 
133                            QMessageBox::Ok,
134                            QMessageBox::NoButton, 
135                            QMessageBox::NoButton );
136   }
137   return result;
138 }
139