QTfrontend/main.cpp.in
author displacer
Thu, 16 Aug 2007 15:16:56 +0000
changeset 572 302ad5c3836d
parent 533 eebb7684ac22
permissions -rw-r--r--
gcc 4.3 related patch - missing header added :)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
277
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
     1
/*
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
     2
 * Hedgewars, a worms-like game
486
7ea71cd3acd5 - Change proto version to 4
unc0rr
parents: 400
diff changeset
     3
 * Copyright (c) 2005-2007 Andrey Korotaev <unC0Rr@gmail.com>
277
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
     4
 *
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
     8
 *
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    12
 * GNU General Public License for more details.
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    13
 *
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    17
 */
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    18
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    19
#include <QApplication>
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    20
#include <QTranslator>
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    21
#include <QLocale>
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    22
#include <QMessageBox>
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    23
#include <QFileInfo>
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    24
#include <QDateTime>
321
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    25
#include <QTextStream>
277
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    26
#include "hwform.h"
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    27
#include "hwconsts.h"
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    28
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    29
QDir * bindir;
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    30
QDir * cfgdir;
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    31
QDir * datadir;
321
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    32
QStringList * Themes;
277
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    33
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    34
bool checkForDir(const QString & dir)
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    35
{
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    36
	QDir tmpdir;
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    37
	if (!tmpdir.exists(dir))
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    38
		if (!tmpdir.mkdir(dir))
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    39
		{
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    40
			QMessageBox::critical(0,
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    41
					QObject::tr("Error"),
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    42
					QObject::tr("Cannot create directory %1").arg(dir),
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    43
					QObject::tr("OK"));
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    44
			return false;
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    45
		}
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    46
	return true;
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    47
}
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    48
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    49
int main(int argc, char *argv[])
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    50
{
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    51
	QApplication app(argc, argv);
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    52
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    53
	QDateTime now = QDateTime::currentDateTime();
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    54
	QDateTime zero;
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    55
	srand(now.secsTo(zero));
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    56
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    57
	Q_INIT_RESOURCE(hedgewars);
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    58
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    59
	QDir mydir("${HEDGEWARS_BINDIR}");
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    60
	mydir.cd("bin");
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    61
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    62
	bindir = new QDir(mydir);
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    63
	cfgdir = new QDir();
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    64
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    65
	cfgdir->setPath(cfgdir->homePath());
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    66
	if (checkForDir(cfgdir->absolutePath() + "/.hedgewars"))
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    67
	{
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    68
		checkForDir(cfgdir->absolutePath() + "/.hedgewars/Demos");
533
eebb7684ac22 Save saves in Save directory
unc0rr
parents: 490
diff changeset
    69
		checkForDir(cfgdir->absolutePath() + "/.hedgewars/Saves");
277
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    70
	}
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    71
	cfgdir->cd(".hedgewars");
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    72
490
4cddbd75a79b Fix for NSIS .lnk workaround
unc0rr
parents: 486
diff changeset
    73
	datadir = new QDir(mydir);
4cddbd75a79b Fix for NSIS .lnk workaround
unc0rr
parents: 486
diff changeset
    74
	datadir->cd("${HEDGEWARS_DATADIR}");
277
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    75
	if(!datadir->cd("hedgewars/Data")) {
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    76
		QMessageBox::critical(0, QMessageBox::tr("Error"), 
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    77
			QMessageBox::tr("Failed to open data directory:\n%1\n"
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    78
					"Please check your installation").
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    79
					arg(datadir->absolutePath()+"/hedgewars/Data"));
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    80
		return 1;
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    81
	}
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    82
400
450ff6326084 Ooops, forgot this :)
unc0rr
parents: 321
diff changeset
    83
	QTranslator Translator;
450ff6326084 Ooops, forgot this :)
unc0rr
parents: 321
diff changeset
    84
	Translator.load(datadir->absolutePath() + "/Locale/hedgewars_" + QLocale::system().name());
450ff6326084 Ooops, forgot this :)
unc0rr
parents: 321
diff changeset
    85
	app.installTranslator(&Translator);
450ff6326084 Ooops, forgot this :)
unc0rr
parents: 321
diff changeset
    86
321
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    87
	Themes = new QStringList();
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    88
	QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg");
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    89
	if (themesfile.open(QIODevice::ReadOnly)) {
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    90
		QTextStream stream(&themesfile);
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    91
		QString str;
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    92
		while (!stream.atEnd())
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    93
		{
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    94
			Themes->append(stream.readLine());
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    95
		}
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    96
		themesfile.close();
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    97
	} else {
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    98
		QMessageBox::critical(0, "Error", "Cannot access themes.cfg", "OK");
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    99
	}
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
   100
277
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
   101
	HWForm *Form = new HWForm();
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
   102
	Form->show();
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
   103
	return app.exec();
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
   104
}