277
|
1 |
/*
|
|
2 |
* Hedgewars, a worms-like game
|
|
3 |
* Copyright (c) 2005, 2006 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>
|
321
|
25 |
#include <QTextStream>
|
277
|
26 |
#include "hwform.h"
|
|
27 |
#include "hwconsts.h"
|
|
28 |
|
|
29 |
QDir * bindir;
|
|
30 |
QDir * cfgdir;
|
|
31 |
QDir * datadir;
|
321
|
32 |
QStringList * Themes;
|
277
|
33 |
|
|
34 |
bool checkForDir(const QString & dir)
|
|
35 |
{
|
|
36 |
QDir tmpdir;
|
|
37 |
if (!tmpdir.exists(dir))
|
|
38 |
if (!tmpdir.mkdir(dir))
|
|
39 |
{
|
|
40 |
QMessageBox::critical(0,
|
|
41 |
QObject::tr("Error"),
|
|
42 |
QObject::tr("Cannot create directory %1").arg(dir),
|
|
43 |
QObject::tr("OK"));
|
|
44 |
return false;
|
|
45 |
}
|
|
46 |
return true;
|
|
47 |
}
|
|
48 |
|
|
49 |
int main(int argc, char *argv[])
|
|
50 |
{
|
|
51 |
QApplication app(argc, argv);
|
|
52 |
|
|
53 |
QDateTime now = QDateTime::currentDateTime();
|
|
54 |
QDateTime zero;
|
|
55 |
srand(now.secsTo(zero));
|
|
56 |
|
|
57 |
Q_INIT_RESOURCE(hedgewars);
|
|
58 |
|
|
59 |
QTranslator Translator;
|
|
60 |
Translator.load(":/translations/hedgewars_" + QLocale::system().name());
|
|
61 |
app.installTranslator(&Translator);
|
|
62 |
|
|
63 |
QDir mydir("${HEDGEWARS_BINDIR}");
|
|
64 |
mydir.cd("bin");
|
|
65 |
|
|
66 |
bindir = new QDir(mydir);
|
|
67 |
cfgdir = new QDir();
|
|
68 |
|
|
69 |
cfgdir->setPath(cfgdir->homePath());
|
|
70 |
if (checkForDir(cfgdir->absolutePath() + "/.hedgewars"))
|
|
71 |
{
|
|
72 |
checkForDir(cfgdir->absolutePath() + "/.hedgewars/Demos");
|
|
73 |
}
|
|
74 |
cfgdir->cd(".hedgewars");
|
|
75 |
|
|
76 |
datadir = new QDir("${HEDGEWARS_DATADIR}");
|
|
77 |
if(!datadir->cd("hedgewars/Data")) {
|
|
78 |
QMessageBox::critical(0, QMessageBox::tr("Error"),
|
|
79 |
QMessageBox::tr("Failed to open data directory:\n%1\n"
|
|
80 |
"Please check your installation").
|
|
81 |
arg(datadir->absolutePath()+"/hedgewars/Data"));
|
|
82 |
return 1;
|
|
83 |
}
|
|
84 |
|
321
|
85 |
Themes = new QStringList();
|
|
86 |
QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg");
|
|
87 |
if (themesfile.open(QIODevice::ReadOnly)) {
|
|
88 |
QTextStream stream(&themesfile);
|
|
89 |
QString str;
|
|
90 |
while (!stream.atEnd())
|
|
91 |
{
|
|
92 |
Themes->append(stream.readLine());
|
|
93 |
}
|
|
94 |
themesfile.close();
|
|
95 |
} else {
|
|
96 |
QMessageBox::critical(0, "Error", "Cannot access themes.cfg", "OK");
|
|
97 |
}
|
|
98 |
|
277
|
99 |
HWForm *Form = new HWForm();
|
|
100 |
Form->show();
|
|
101 |
return app.exec();
|
|
102 |
}
|