QTfrontend/main.cpp
author unc0rr
Sat, 25 Nov 2006 12:45:18 +0000
changeset 275 7cb230cd2b1d
permissions -rw-r--r--
Don't configure main.cpp, just hwconsts.h
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
275
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
     1
/*
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
     2
 * Hedgewars, a worms-like game
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
     3
 * Copyright (c) 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com>
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
     4
 *
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
     8
 *
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    12
 * GNU General Public License for more details.
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    13
 *
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    17
 */
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    18
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    19
#include <QApplication>
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    20
#include <QTranslator>
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    21
#include <QLocale>
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    22
#include <QMessageBox>
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    23
#include <QFileInfo>
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    24
#include <QDateTime>
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    25
#include "hwform.h"
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    26
#include "hwconsts.h"
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    27
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    28
QDir * bindir;
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    29
QDir * cfgdir;
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    30
QDir * datadir;
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    31
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    32
bool checkForDir(const QString & dir)
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    33
{
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    34
	QDir tmpdir;
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    35
	if (!tmpdir.exists(dir))
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    36
		if (!tmpdir.mkdir(dir))
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    37
		{
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    38
			QMessageBox::critical(0,
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    39
					QObject::tr("Error"),
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    40
					QObject::tr("Cannot create directory %1").arg(dir),
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    41
					QObject::tr("OK"));
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    42
			return false;
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    43
		}
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    44
	return true;
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    45
}
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    46
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    47
int main(int argc, char *argv[])
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    48
{
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    49
	QApplication app(argc, argv);
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    50
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    51
	QDateTime now = QDateTime::currentDateTime();
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    52
	QDateTime zero;
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    53
	srand(now.secsTo(zero));
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    54
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    55
	Q_INIT_RESOURCE(hedgewars);
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    56
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    57
	QTranslator Translator;
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    58
	Translator.load(":/translations/hedgewars_" + QLocale::system().name());
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    59
	app.installTranslator(&Translator);
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    60
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    61
	QDir mydir(cBinDir);
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    62
	mydir.cd("bin");
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    63
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    64
	bindir = new QDir(cBinDir);
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    65
	cfgdir = new QDir();
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    66
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    67
	cfgdir->setPath(cfgdir->homePath());
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    68
	if (checkForDir(cfgdir->absolutePath() + "/.hedgewars"))
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    69
	{
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    70
		checkForDir(cfgdir->absolutePath() + "/.hedgewars/Demos");
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    71
	}
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    72
	cfgdir->cd(".hedgewars");
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    73
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    74
	datadir = new QDir("${HEDGEWARS_DATADIR}");
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    75
	if(!datadir->cd("hedgewars/Data")) {
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    76
		QMessageBox::critical(0, QMessageBox::tr("Error"),
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    77
			QMessageBox::tr("Failed to open data directory:\n%1\n"
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    78
					"Please check your installation").
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    79
					arg(datadir->absolutePath()+"/hedgewars/Data"));
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    80
		return 1;
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    81
	}
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    82
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    83
	HWForm *Form = new HWForm();
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    84
	Form->show();
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    85
	return app.exec();
7cb230cd2b1d Don't configure main.cpp, just hwconsts.h
unc0rr
parents:
diff changeset
    86
}