34 #include "hwconsts.h" |
33 #include "hwconsts.h" |
35 #include "newnetclient.h" |
34 #include "newnetclient.h" |
36 |
35 |
37 #include "DataManager.h" |
36 #include "DataManager.h" |
38 #include "FileEngine.h" |
37 #include "FileEngine.h" |
|
38 #include "MessageDialog.h" |
39 |
39 |
40 #ifdef _WIN32 |
40 #ifdef _WIN32 |
41 #include <Shlobj.h> |
41 #include <Shlobj.h> |
42 #elif defined __APPLE__ |
42 #elif defined __APPLE__ |
43 #include "CocoaInitializer.h" |
43 #include "CocoaInitializer.h" |
44 #endif |
|
45 #ifndef _WIN32 |
|
46 #include <signal.h> |
|
47 #endif |
44 #endif |
48 |
45 |
49 // Program resources |
46 // Program resources |
50 #ifdef __APPLE__ |
47 #ifdef __APPLE__ |
51 static CocoaInitializer * cocoaInit = NULL; |
48 static CocoaInitializer * cocoaInit = NULL; |
92 else if (calculateEaster(date.year()) == date) |
89 else if (calculateEaster(date.year()) == date) |
93 season = SEASON_EASTER; |
90 season = SEASON_EASTER; |
94 else |
91 else |
95 season = SEASON_NONE; |
92 season = SEASON_NONE; |
96 } |
93 } |
97 #ifndef _WIN32 |
94 |
98 void terminateFrontend(int signal) |
|
99 { |
|
100 Q_UNUSED(signal); |
|
101 |
|
102 QCoreApplication::exit(0); |
|
103 } |
|
104 #endif |
|
105 |
95 |
106 bool checkForDir(const QString & dir) |
96 bool checkForDir(const QString & dir) |
107 { |
97 { |
108 QDir tmpdir(dir); |
98 QDir tmpdir(dir); |
109 if (!tmpdir.exists()) |
99 if (!tmpdir.exists()) |
110 if (!tmpdir.mkpath(dir)) |
100 if (!tmpdir.mkpath(dir)) |
111 { |
101 { |
112 QMessageBox directoryMsg(QApplication::activeWindow()); |
102 MessageDialog::ShowErrorMessage(HWApplication::tr("Cannot create directory %1").arg(dir)); |
113 directoryMsg.setIcon(QMessageBox::Warning); |
|
114 directoryMsg.setWindowTitle(QMessageBox::tr("Main - Error")); |
|
115 directoryMsg.setText(QMessageBox::tr("Cannot create directory %1").arg(dir)); |
|
116 directoryMsg.setWindowModality(Qt::WindowModal); |
|
117 directoryMsg.exec(); |
|
118 return false; |
103 return false; |
119 } |
104 } |
120 return true; |
105 return true; |
121 } |
|
122 |
|
123 bool checkForFile(const QString & file) |
|
124 { |
|
125 QFile tmpfile(file); |
|
126 if (!tmpfile.exists()) |
|
127 return tmpfile.open(QFile::WriteOnly); |
|
128 else |
|
129 return true; |
|
130 } |
106 } |
131 |
107 |
132 // Guaranteed to be the last thing ran in the application's life time. |
108 // Guaranteed to be the last thing ran in the application's life time. |
133 // Closes resources that need to exist as long as possible. |
109 // Closes resources that need to exist as long as possible. |
134 void closeResources(void) |
110 void closeResources(void) |
152 // Since we're calling this first, closeResources() will be the last thing called after main() returns. |
128 // Since we're calling this first, closeResources() will be the last thing called after main() returns. |
153 atexit(closeResources); |
129 atexit(closeResources); |
154 |
130 |
155 #ifdef __APPLE__ |
131 #ifdef __APPLE__ |
156 cocoaInit = new CocoaInitializer(); // Creates the autoreleasepool preventing cocoa object leaks on OS X. |
132 cocoaInit = new CocoaInitializer(); // Creates the autoreleasepool preventing cocoa object leaks on OS X. |
157 #endif |
|
158 |
|
159 #ifndef _WIN32 |
|
160 signal(SIGINT, &terminateFrontend); |
|
161 #endif |
133 #endif |
162 |
134 |
163 HWApplication app(argc, argv); |
135 HWApplication app(argc, argv); |
164 |
136 |
165 QLabel *splash = NULL; |
137 QLabel *splash = NULL; |
166 #if defined Q_WS_WIN |
138 #if defined Q_WS_WIN |
167 QPixmap pixmap(":res/splash.png"); |
139 QPixmap pixmap(":res/splash.png"); |
168 splash = new QLabel(0, Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint); |
140 splash = new QLabel(0, Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint); |
169 splash->setAttribute(Qt::WA_TranslucentBackground); |
141 splash->setAttribute(Qt::WA_TranslucentBackground); |
170 const QRect deskSize = QApplication::desktop()->screenGeometry(-1); |
142 const QRect deskSize = HWApplication::desktop()->screenGeometry(-1); |
171 QPoint splashCenter = QPoint( (deskSize.width() - pixmap.width())/2, |
143 QPoint splashCenter = QPoint( (deskSize.width() - pixmap.width())/2, |
172 (deskSize.height() - pixmap.height())/2 ); |
144 (deskSize.height() - pixmap.height())/2 ); |
173 splash->move(splashCenter); |
145 splash->move(splashCenter); |
174 splash->setPixmap(pixmap); |
146 splash->setPixmap(pixmap); |
175 splash->show(); |
147 splash->show(); |
274 checkForDir(cfgdir->absolutePath() + "/VideoTemp"); |
246 checkForDir(cfgdir->absolutePath() + "/VideoTemp"); |
275 } |
247 } |
276 |
248 |
277 datadir->cd(bindir->absolutePath()); |
249 datadir->cd(bindir->absolutePath()); |
278 datadir->cd(*cDataDir); |
250 datadir->cd(*cDataDir); |
279 if(!datadir->cd("Data")) |
251 if (!datadir->cd("Data")) |
280 { |
252 { |
281 QMessageBox missingMsg(QApplication::activeWindow()); |
253 MessageDialog::ShowFatalMessage(HWApplication::tr("Failed to open data directory:\n%1\n\nPlease check your installation!").arg(datadir->absolutePath()+"/Data")); |
282 missingMsg.setIcon(QMessageBox::Critical); |
|
283 missingMsg.setWindowTitle(QMessageBox::tr("Main - Error")); |
|
284 missingMsg.setText(QMessageBox::tr("Failed to open data directory:\n%1\n\n" |
|
285 "Please check your installation!"). |
|
286 arg(datadir->absolutePath()+"/Data")); |
|
287 missingMsg.setWindowModality(Qt::WindowModal); |
|
288 missingMsg.exec(); |
|
289 return 1; |
254 return 1; |
290 } |
255 } |
291 |
256 |
292 // setup PhysFS |
257 // setup PhysFS |
293 engine->mount(datadir->absolutePath()); |
258 engine->mount(datadir->absolutePath()); |
294 engine->mount(cfgdir->absolutePath() + "/Data"); |
259 engine->mount(cfgdir->absolutePath() + "/Data"); |
295 engine->mount(cfgdir->absolutePath()); |
260 engine->mount(cfgdir->absolutePath()); |
296 engine->setWriteDir(cfgdir->absolutePath()); |
261 engine->setWriteDir(cfgdir->absolutePath()); |
297 engine->mountPacks(); |
262 engine->mountPacks(); |
298 |
263 |
299 checkForFile("physfs://hedgewars.ini"); |
264 DataManager::ensureFileExists("physfs://hedgewars.ini"); |
300 |
265 |
301 QTranslator Translator; |
266 QTranslator Translator; |
302 { |
267 { |
303 QSettings settings("physfs://hedgewars.ini", QSettings::IniFormat); |
268 QSettings settings("physfs://hedgewars.ini", QSettings::IniFormat); |
304 QString cc = settings.value("misc/locale", QString()).toString(); |
269 QString cc = settings.value("misc/locale", QString()).toString(); |
353 QFile & file = (extFile.exists() ? extFile : resFile); |
318 QFile & file = (extFile.exists() ? extFile : resFile); |
354 |
319 |
355 if (file.open(QIODevice::ReadOnly | QIODevice::Text)) |
320 if (file.open(QIODevice::ReadOnly | QIODevice::Text)) |
356 style.append(file.readAll()); |
321 style.append(file.readAll()); |
357 |
322 |
|
323 qWarning("Starting Hedgewars %s-r%d (%s)", qPrintable(*cVersionString), cRevisionString->toInt(), qPrintable(*cHashString)); |
|
324 |
358 app.form = new HWForm(NULL, style); |
325 app.form = new HWForm(NULL, style); |
359 app.form->show(); |
326 app.form->show(); |
360 if(splash) |
327 if(splash) |
361 splash->close(); |
328 splash->close(); |
|
329 if (app.urlString) |
|
330 app.fakeEvent(); |
362 return app.exec(); |
331 return app.exec(); |
363 } |
332 } |