277
|
1 |
/*
|
|
2 |
* Hedgewars, a worms-like game
|
486
|
3 |
* Copyright (c) 2005-2007 Andrey Korotaev <unC0Rr@gmail.com>
|
277
|
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 |
QDir mydir("${HEDGEWARS_BINDIR}");
|
|
60 |
mydir.cd("bin");
|
|
61 |
|
|
62 |
bindir = new QDir(mydir);
|
|
63 |
cfgdir = new QDir();
|
|
64 |
|
|
65 |
cfgdir->setPath(cfgdir->homePath());
|
|
66 |
if (checkForDir(cfgdir->absolutePath() + "/.hedgewars"))
|
|
67 |
{
|
|
68 |
checkForDir(cfgdir->absolutePath() + "/.hedgewars/Demos");
|
|
69 |
}
|
|
70 |
cfgdir->cd(".hedgewars");
|
|
71 |
|
490
|
72 |
datadir = new QDir(mydir);
|
|
73 |
datadir->cd("${HEDGEWARS_DATADIR}");
|
277
|
74 |
if(!datadir->cd("hedgewars/Data")) {
|
|
75 |
QMessageBox::critical(0, QMessageBox::tr("Error"),
|
|
76 |
QMessageBox::tr("Failed to open data directory:\n%1\n"
|
|
77 |
"Please check your installation").
|
|
78 |
arg(datadir->absolutePath()+"/hedgewars/Data"));
|
|
79 |
return 1;
|
|
80 |
}
|
|
81 |
|
400
|
82 |
QTranslator Translator;
|
|
83 |
Translator.load(datadir->absolutePath() + "/Locale/hedgewars_" + QLocale::system().name());
|
|
84 |
app.installTranslator(&Translator);
|
|
85 |
|
321
|
86 |
Themes = new QStringList();
|
|
87 |
QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg");
|
|
88 |
if (themesfile.open(QIODevice::ReadOnly)) {
|
|
89 |
QTextStream stream(&themesfile);
|
|
90 |
QString str;
|
|
91 |
while (!stream.atEnd())
|
|
92 |
{
|
|
93 |
Themes->append(stream.readLine());
|
|
94 |
}
|
|
95 |
themesfile.close();
|
|
96 |
} else {
|
|
97 |
QMessageBox::critical(0, "Error", "Cannot access themes.cfg", "OK");
|
|
98 |
}
|
|
99 |
|
277
|
100 |
HWForm *Form = new HWForm();
|
|
101 |
Form->show();
|
|
102 |
return app.exec();
|
|
103 |
}
|