QTfrontend/main.cpp.in
changeset 596 38bdde6a54c1
parent 595 5ee863f2f568
child 597 ec5f057ab268
equal deleted inserted replaced
595:5ee863f2f568 596:38bdde6a54c1
     1 /*
       
     2  * Hedgewars, a worms-like game
       
     3  * Copyright (c) 2005-2007 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 <QTextStream>
       
    26 #include "hwform.h"
       
    27 #include "hwconsts.h"
       
    28 
       
    29 QDir * bindir;
       
    30 QDir * cfgdir;
       
    31 QDir * datadir;
       
    32 QStringList * Themes;
       
    33 
       
    34 bool checkForDir(const QString & dir)
       
    35 {
       
    36 	QDir tmpdir;
       
    37 	if (!tmpdir.exists(dir))
       
    38 		if (!tmpdir.mkdir(dir))
       
    39 		{
       
    40 			QMessageBox::critical(0,
       
    41 					QObject::tr("Error"),
       
    42 					QObject::tr("Cannot create directory %1").arg(dir),
       
    43 					QObject::tr("OK"));
       
    44 			return false;
       
    45 		}
       
    46 	return true;
       
    47 }
       
    48 
       
    49 int main(int argc, char *argv[])
       
    50 {
       
    51 	QApplication app(argc, argv);
       
    52 
       
    53 	QDateTime now = QDateTime::currentDateTime();
       
    54 	QDateTime zero;
       
    55 	srand(now.secsTo(zero));
       
    56 
       
    57 	Q_INIT_RESOURCE(hedgewars);
       
    58 
       
    59 	QDir mydir("${HEDGEWARS_BINDIR}");
       
    60 	mydir.cd("bin");
       
    61 
       
    62 	bindir = new QDir(mydir);
       
    63 	cfgdir = new QDir();
       
    64 
       
    65 	cfgdir->setPath(cfgdir->homePath());
       
    66 	if (checkForDir(cfgdir->absolutePath() + "/.hedgewars"))
       
    67 	{
       
    68 		checkForDir(cfgdir->absolutePath() + "/.hedgewars/Demos");
       
    69 		checkForDir(cfgdir->absolutePath() + "/.hedgewars/Saves");
       
    70 	}
       
    71 	cfgdir->cd(".hedgewars");
       
    72 
       
    73 	datadir = new QDir(mydir);
       
    74 	datadir->cd("${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 	QTranslator Translator;
       
    84 	Translator.load(datadir->absolutePath() + "/Locale/hedgewars_" + QLocale::system().name());
       
    85 	app.installTranslator(&Translator);
       
    86 
       
    87 	Themes = new QStringList();
       
    88 	QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg");
       
    89 	if (themesfile.open(QIODevice::ReadOnly)) {
       
    90 		QTextStream stream(&themesfile);
       
    91 		QString str;
       
    92 		while (!stream.atEnd())
       
    93 		{
       
    94 			Themes->append(stream.readLine());
       
    95 		}
       
    96 		themesfile.close();
       
    97 	} else {
       
    98 		QMessageBox::critical(0, "Error", "Cannot access themes.cfg", "OK");
       
    99 	}
       
   100 
       
   101 	HWForm *Form = new HWForm();
       
   102 	Form->show();
       
   103 	return app.exec();
       
   104 }