25 #include <QRegExp> |
25 #include <QRegExp> |
26 #include <QMap> |
26 #include <QMap> |
27 #include <QSettings> |
27 #include <QSettings> |
28 #include <QStringListModel> |
28 #include <QStringListModel> |
29 #include <QDate> |
29 #include <QDate> |
|
30 #include <QDesktopWidget> |
|
31 #include <QLabel> |
30 |
32 |
31 #include "hwform.h" |
33 #include "hwform.h" |
32 #include "hwconsts.h" |
34 #include "hwconsts.h" |
33 #include "newnetclient.h" |
35 #include "newnetclient.h" |
34 |
36 |
35 #include "DataManager.h" |
37 #include "DataManager.h" |
36 #include "FileEngine.h" |
38 #include "FileEngine.h" |
37 |
39 |
38 #ifdef _WIN32 |
40 #ifdef _WIN32 |
39 #include <Shlobj.h> |
41 #include <Shlobj.h> |
40 #endif |
42 #elif defined __APPLE__ |
|
43 #include "CocoaInitializer.h" |
|
44 #endif |
|
45 #ifndef _WIN32 |
|
46 #include <signal.h> |
|
47 #endif |
|
48 |
|
49 // Program resources |
41 #ifdef __APPLE__ |
50 #ifdef __APPLE__ |
42 #include "CocoaInitializer.h" |
51 static CocoaInitializer * cocoaInit = NULL; |
43 #endif |
52 #endif |
44 |
53 static FileEngineHandler * engine = NULL; |
45 |
54 |
46 //Determines the day of easter in year |
55 //Determines the day of easter in year |
47 //from http://aa.usno.navy.mil/faq/docs/easter.php,adapted to C/C++ |
56 //from http://aa.usno.navy.mil/faq/docs/easter.php,adapted to C/C++ |
48 QDate calculateEaster(long year) |
57 QDate calculateEaster(long year) |
49 { |
58 { |
110 return tmpfile.open(QFile::WriteOnly); |
127 return tmpfile.open(QFile::WriteOnly); |
111 else |
128 else |
112 return true; |
129 return true; |
113 } |
130 } |
114 |
131 |
|
132 // Guaranteed to be the last thing ran in the application's life time. |
|
133 // Closes resources that need to exist as long as possible. |
|
134 void closeResources(void) |
|
135 { |
115 #ifdef __APPLE__ |
136 #ifdef __APPLE__ |
116 static CocoaInitializer *cocoaInit = NULL; |
|
117 // Function to be called at end of program's termination on OS X to release |
|
118 // the NSAutoReleasePool contained within the CocoaInitializer. |
|
119 void releaseCocoaPool(void) |
|
120 { |
|
121 if (cocoaInit != NULL) |
137 if (cocoaInit != NULL) |
122 { |
138 { |
123 delete cocoaInit; |
139 delete cocoaInit; |
124 cocoaInit = NULL; |
140 cocoaInit = NULL; |
125 } |
141 } |
126 } |
142 #endif |
127 #endif |
143 if (engine != NULL) |
|
144 { |
|
145 delete engine; |
|
146 engine = NULL; |
|
147 } |
|
148 } |
128 |
149 |
129 int main(int argc, char *argv[]) |
150 int main(int argc, char *argv[]) |
130 { |
151 { |
|
152 // Since we're calling this first, closeResources() will be the last thing called after main() returns. |
|
153 atexit(closeResources); |
|
154 |
131 #ifdef __APPLE__ |
155 #ifdef __APPLE__ |
132 // This creates the autoreleasepool that prevents leaking, and destroys it only on exit |
156 cocoaInit = new CocoaInitializer(); // Creates the autoreleasepool preventing cocoa object leaks on OS X. |
133 cocoaInit = new CocoaInitializer(); |
157 #endif |
134 atexit(releaseCocoaPool); |
158 |
|
159 #ifndef _WIN32 |
|
160 signal(SIGINT, &terminateFrontend); |
135 #endif |
161 #endif |
136 |
162 |
137 HWApplication app(argc, argv); |
163 HWApplication app(argc, argv); |
138 |
164 |
139 FileEngineHandler engine(argv[0]); |
165 QLabel *splash = NULL; |
|
166 #if defined Q_WS_WIN |
|
167 QPixmap pixmap(":res/splash.png"); |
|
168 splash = new QLabel(0, Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint); |
|
169 splash->setAttribute(Qt::WA_TranslucentBackground); |
|
170 const QRect deskSize = QApplication::desktop()->screenGeometry(-1); |
|
171 QPoint splashCenter = QPoint( (deskSize.width() - pixmap.width())/2, |
|
172 (deskSize.height() - pixmap.height())/2 ); |
|
173 splash->move(splashCenter); |
|
174 splash->setPixmap(pixmap); |
|
175 splash->show(); |
|
176 #endif |
|
177 |
|
178 engine = new FileEngineHandler(argv[0]); |
140 |
179 |
141 app.setAttribute(Qt::AA_DontShowIconsInMenus,false); |
180 app.setAttribute(Qt::AA_DontShowIconsInMenus,false); |
142 |
181 |
143 QStringList arguments = app.arguments(); |
182 QStringList arguments = app.arguments(); |
144 QMap<QString, QString> parsedArgs; |
183 QMap<QString, QString> parsedArgs; |
251 missingMsg.exec(); |
288 missingMsg.exec(); |
252 return 1; |
289 return 1; |
253 } |
290 } |
254 |
291 |
255 // setup PhysFS |
292 // setup PhysFS |
256 engine.mount(datadir->absolutePath()); |
293 engine->mount(datadir->absolutePath()); |
257 engine.mount(cfgdir->absolutePath() + "/Data"); |
294 engine->mount(cfgdir->absolutePath() + "/Data"); |
258 engine.mount(cfgdir->absolutePath()); |
295 engine->mount(cfgdir->absolutePath()); |
259 engine.setWriteDir(cfgdir->absolutePath()); |
296 engine->setWriteDir(cfgdir->absolutePath()); |
260 engine.mountPacks(); |
297 engine->mountPacks(); |
261 |
298 |
262 checkForFile("physfs://hedgewars.ini"); |
299 checkForFile("physfs://hedgewars.ini"); |
263 |
300 |
264 QTranslator Translator; |
301 QTranslator Translator; |
265 { |
302 { |