QTfrontend/main.cpp
changeset 579 94db15de0392
child 1066 1f1b3686a2b0
equal deleted inserted replaced
578:6b0af3860192 579:94db15de0392
       
     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 bool checkForDir(const QString & dir)
       
    30 {
       
    31 	QDir tmpdir;
       
    32 	if (!tmpdir.exists(dir))
       
    33 		if (!tmpdir.mkdir(dir))
       
    34 		{
       
    35 			QMessageBox::critical(0,
       
    36 					QObject::tr("Error"),
       
    37 					QObject::tr("Cannot create directory %1").arg(dir),
       
    38 					QObject::tr("OK"));
       
    39 			return false;
       
    40 		}
       
    41 	return true;
       
    42 }
       
    43 
       
    44 int main(int argc, char *argv[])
       
    45 {
       
    46 	QApplication app(argc, argv);
       
    47 
       
    48 	QDateTime now = QDateTime::currentDateTime();
       
    49 	QDateTime zero;
       
    50 	srand(now.secsTo(zero));
       
    51 
       
    52 	Q_INIT_RESOURCE(hedgewars);
       
    53 
       
    54 	bindir->cd("bin"); // workaround over NSIS installer
       
    55 
       
    56 	cfgdir->setPath(cfgdir->homePath());
       
    57 	if (checkForDir(cfgdir->absolutePath() + "/.hedgewars"))
       
    58 	{
       
    59 		checkForDir(cfgdir->absolutePath() + "/.hedgewars/Demos");
       
    60 		checkForDir(cfgdir->absolutePath() + "/.hedgewars/Saves");
       
    61 	}
       
    62 	cfgdir->cd(".hedgewars");
       
    63 
       
    64 	datadir->cd(bindir->absolutePath());
       
    65 	datadir->cd(*cDataDir);
       
    66 	if(!datadir->cd("hedgewars/Data")) {
       
    67 		QMessageBox::critical(0, QMessageBox::tr("Error"),
       
    68 			QMessageBox::tr("Failed to open data directory:\n%1\n"
       
    69 					"Please check your installation").
       
    70 					arg(datadir->absolutePath()+"/hedgewars/Data"));
       
    71 		return 1;
       
    72 	}
       
    73 
       
    74 	QTranslator Translator;
       
    75 	Translator.load(datadir->absolutePath() + "/Locale/hedgewars_" + QLocale::system().name());
       
    76 	app.installTranslator(&Translator);
       
    77 
       
    78 	Themes = new QStringList();
       
    79 	QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg");
       
    80 	if (themesfile.open(QIODevice::ReadOnly)) {
       
    81 		QTextStream stream(&themesfile);
       
    82 		QString str;
       
    83 		while (!stream.atEnd())
       
    84 		{
       
    85 			Themes->append(stream.readLine());
       
    86 		}
       
    87 		themesfile.close();
       
    88 	} else {
       
    89 		QMessageBox::critical(0, "Error", "Cannot access themes.cfg", "OK");
       
    90 	}
       
    91 
       
    92 	HWForm *Form = new HWForm();
       
    93 	Form->show();
       
    94 	return app.exec();
       
    95 }