QTfrontend/main.cpp.in
changeset 277 04a613bab65c
child 321 1148eeb0557e
equal deleted inserted replaced
276:283363b1a789 277:04a613bab65c
       
     1 /*
       
     2  * Hedgewars, a worms-like game
       
     3  * Copyright (c) 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com>
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License as published by
       
     7  * the Free Software Foundation; version 2 of the License
       
     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 General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program; if not, write to the Free Software
       
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
       
    17  */
       
    18 
       
    19 #include <QApplication>
       
    20 #include <QTranslator>
       
    21 #include <QLocale>
       
    22 #include <QMessageBox>
       
    23 #include <QFileInfo>
       
    24 #include <QDateTime>
       
    25 #include "hwform.h"
       
    26 #include "hwconsts.h"
       
    27 
       
    28 QDir * bindir;
       
    29 QDir * cfgdir;
       
    30 QDir * datadir;
       
    31 
       
    32 bool checkForDir(const QString & dir)
       
    33 {
       
    34 	QDir tmpdir;
       
    35 	if (!tmpdir.exists(dir))
       
    36 		if (!tmpdir.mkdir(dir))
       
    37 		{
       
    38 			QMessageBox::critical(0,
       
    39 					QObject::tr("Error"),
       
    40 					QObject::tr("Cannot create directory %1").arg(dir),
       
    41 					QObject::tr("OK"));
       
    42 			return false;
       
    43 		}
       
    44 	return true;
       
    45 }
       
    46 
       
    47 int main(int argc, char *argv[])
       
    48 {
       
    49 	QApplication app(argc, argv);
       
    50 
       
    51 	QDateTime now = QDateTime::currentDateTime();
       
    52 	QDateTime zero;
       
    53 	srand(now.secsTo(zero));
       
    54 
       
    55 	Q_INIT_RESOURCE(hedgewars);
       
    56 
       
    57 	QTranslator Translator;
       
    58 	Translator.load(":/translations/hedgewars_" + QLocale::system().name());
       
    59 	app.installTranslator(&Translator);
       
    60 
       
    61 	QDir mydir("${HEDGEWARS_BINDIR}");
       
    62 	mydir.cd("bin");
       
    63 
       
    64 	bindir = new QDir(mydir);
       
    65 	cfgdir = new QDir();
       
    66 
       
    67 	cfgdir->setPath(cfgdir->homePath());
       
    68 	if (checkForDir(cfgdir->absolutePath() + "/.hedgewars"))
       
    69 	{
       
    70 		checkForDir(cfgdir->absolutePath() + "/.hedgewars/Demos");
       
    71 	}
       
    72 	cfgdir->cd(".hedgewars");
       
    73 
       
    74 	datadir = new QDir("${HEDGEWARS_DATADIR}");
       
    75 	if(!datadir->cd("hedgewars/Data")) {
       
    76 		QMessageBox::critical(0, QMessageBox::tr("Error"), 
       
    77 			QMessageBox::tr("Failed to open data directory:\n%1\n"
       
    78 					"Please check your installation").
       
    79 					arg(datadir->absolutePath()+"/hedgewars/Data"));
       
    80 		return 1;
       
    81 	}
       
    82 
       
    83 	HWForm *Form = new HWForm();
       
    84 	Form->show();
       
    85 	return app.exec();
       
    86 }