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