579
|
1 |
/*
|
1066
|
2 |
* Hedgewars, a free turn based strategy game
|
579
|
3 |
* Copyright (c) 2005-2007 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>
|
|
25 |
#include <QTextStream>
|
1146
|
26 |
#include <QDesktopWidget>
|
|
27 |
|
579
|
28 |
#include "hwform.h"
|
|
29 |
#include "hwconsts.h"
|
|
30 |
|
|
31 |
bool checkForDir(const QString & dir)
|
|
32 |
{
|
|
33 |
QDir tmpdir;
|
|
34 |
if (!tmpdir.exists(dir))
|
|
35 |
if (!tmpdir.mkdir(dir))
|
|
36 |
{
|
|
37 |
QMessageBox::critical(0,
|
|
38 |
QObject::tr("Error"),
|
|
39 |
QObject::tr("Cannot create directory %1").arg(dir),
|
|
40 |
QObject::tr("OK"));
|
|
41 |
return false;
|
|
42 |
}
|
|
43 |
return true;
|
|
44 |
}
|
|
45 |
|
|
46 |
int main(int argc, char *argv[])
|
|
47 |
{
|
|
48 |
QApplication app(argc, argv);
|
|
49 |
|
|
50 |
QDateTime now = QDateTime::currentDateTime();
|
|
51 |
QDateTime zero;
|
|
52 |
srand(now.secsTo(zero));
|
|
53 |
|
|
54 |
Q_INIT_RESOURCE(hedgewars);
|
|
55 |
|
1146
|
56 |
QString imgAddr=":/res/Background.png";
|
|
57 |
QImage bgrndIm(imgAddr);
|
|
58 |
QRect deskSz=qApp->desktop()->screenGeometry();
|
|
59 |
bgrndIm=bgrndIm.scaled(deskSz.width()-deskSz.left(), deskSz.height()-deskSz.top(),
|
|
60 |
Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
|
61 |
if (bgrndIm.save(QDir::tempPath()+"/hedgewarsScaledBgrnd.png")) {
|
|
62 |
imgAddr=QDir::tempPath()+"/hedgewarsScaledBgrnd.png";
|
|
63 |
}
|
|
64 |
|
|
65 |
qApp->setStyleSheet
|
|
66 |
(QString(
|
|
67 |
".HWForm{"
|
|
68 |
"background-image: url(\"%1\");"
|
|
69 |
"background-position: bottom center;"
|
|
70 |
//" background-origin: content;"
|
1147
|
71 |
"background-repeat: no-repeat;"
|
|
72 |
"background-color: #3f095f;"
|
1146
|
73 |
"}"
|
1149
|
74 |
"PageMain > QPushButton{"
|
|
75 |
"border: solid transparent;"
|
|
76 |
"}"
|
1146
|
77 |
).arg(imgAddr)
|
|
78 |
);
|
|
79 |
|
579
|
80 |
bindir->cd("bin"); // workaround over NSIS installer
|
|
81 |
|
|
82 |
cfgdir->setPath(cfgdir->homePath());
|
|
83 |
if (checkForDir(cfgdir->absolutePath() + "/.hedgewars"))
|
|
84 |
{
|
|
85 |
checkForDir(cfgdir->absolutePath() + "/.hedgewars/Demos");
|
|
86 |
checkForDir(cfgdir->absolutePath() + "/.hedgewars/Saves");
|
|
87 |
}
|
|
88 |
cfgdir->cd(".hedgewars");
|
|
89 |
|
|
90 |
datadir->cd(bindir->absolutePath());
|
|
91 |
datadir->cd(*cDataDir);
|
|
92 |
if(!datadir->cd("hedgewars/Data")) {
|
|
93 |
QMessageBox::critical(0, QMessageBox::tr("Error"),
|
|
94 |
QMessageBox::tr("Failed to open data directory:\n%1\n"
|
|
95 |
"Please check your installation").
|
|
96 |
arg(datadir->absolutePath()+"/hedgewars/Data"));
|
|
97 |
return 1;
|
|
98 |
}
|
|
99 |
|
|
100 |
QTranslator Translator;
|
|
101 |
Translator.load(datadir->absolutePath() + "/Locale/hedgewars_" + QLocale::system().name());
|
|
102 |
app.installTranslator(&Translator);
|
|
103 |
|
|
104 |
Themes = new QStringList();
|
|
105 |
QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg");
|
|
106 |
if (themesfile.open(QIODevice::ReadOnly)) {
|
|
107 |
QTextStream stream(&themesfile);
|
|
108 |
QString str;
|
|
109 |
while (!stream.atEnd())
|
|
110 |
{
|
|
111 |
Themes->append(stream.readLine());
|
|
112 |
}
|
|
113 |
themesfile.close();
|
|
114 |
} else {
|
|
115 |
QMessageBox::critical(0, "Error", "Cannot access themes.cfg", "OK");
|
|
116 |
}
|
|
117 |
|
|
118 |
HWForm *Form = new HWForm();
|
|
119 |
Form->show();
|
|
120 |
return app.exec();
|
|
121 |
}
|