QTfrontend/main.cpp.in
author displacer
Thu, 11 Jan 2007 22:04:08 +0000
changeset 317 e95340dbfc1d
parent 277 04a613bab65c
child 321 1148eeb0557e
permissions -rw-r--r--
start all clients
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
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
     3
 * Copyright (c) 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com>
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>
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    25
#include "hwform.h"
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    26
#include "hwconsts.h"
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    27
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    28
QDir * bindir;
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    29
QDir * cfgdir;
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    30
QDir * datadir;
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    31
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    32
bool checkForDir(const QString & dir)
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    33
{
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    34
	QDir tmpdir;
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    35
	if (!tmpdir.exists(dir))
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    36
		if (!tmpdir.mkdir(dir))
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    37
		{
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    38
			QMessageBox::critical(0,
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    39
					QObject::tr("Error"),
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    40
					QObject::tr("Cannot create directory %1").arg(dir),
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    41
					QObject::tr("OK"));
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    42
			return false;
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    43
		}
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    44
	return true;
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    45
}
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    46
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    47
int main(int argc, char *argv[])
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    48
{
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    49
	QApplication app(argc, argv);
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    50
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    51
	QDateTime now = QDateTime::currentDateTime();
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    52
	QDateTime zero;
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    53
	srand(now.secsTo(zero));
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    54
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    55
	Q_INIT_RESOURCE(hedgewars);
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    56
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    57
	QTranslator Translator;
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    58
	Translator.load(":/translations/hedgewars_" + QLocale::system().name());
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    59
	app.installTranslator(&Translator);
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    60
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    61
	QDir mydir("${HEDGEWARS_BINDIR}");
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    62
	mydir.cd("bin");
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    63
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    64
	bindir = new QDir(mydir);
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    65
	cfgdir = new QDir();
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    66
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    67
	cfgdir->setPath(cfgdir->homePath());
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    68
	if (checkForDir(cfgdir->absolutePath() + "/.hedgewars"))
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    69
	{
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    70
		checkForDir(cfgdir->absolutePath() + "/.hedgewars/Demos");
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    71
	}
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    72
	cfgdir->cd(".hedgewars");
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    73
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    74
	datadir = new QDir("${HEDGEWARS_DATADIR}");
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
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    83
	HWForm *Form = new HWForm();
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    84
	Form->show();
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    85
	return app.exec();
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    86
}