equal
deleted
inserted
replaced
44 #endif |
44 #endif |
45 #ifndef _WIN32 |
45 #ifndef _WIN32 |
46 #include <signal.h> |
46 #include <signal.h> |
47 #endif |
47 #endif |
48 |
48 |
|
49 // Program resources |
|
50 #ifdef __APPLE__ |
|
51 static CocoaInitializer * cocoaInit = NULL; |
|
52 #endif |
|
53 static FileEngineHandler * engine = NULL; |
49 |
54 |
50 //Determines the day of easter in year |
55 //Determines the day of easter in year |
51 //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++ |
52 QDate calculateEaster(long year) |
57 QDate calculateEaster(long year) |
53 { |
58 { |
122 return tmpfile.open(QFile::WriteOnly); |
127 return tmpfile.open(QFile::WriteOnly); |
123 else |
128 else |
124 return true; |
129 return true; |
125 } |
130 } |
126 |
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 { |
127 #ifdef __APPLE__ |
136 #ifdef __APPLE__ |
128 static CocoaInitializer *cocoaInit = NULL; |
|
129 // Function to be called at end of program's termination on OS X to release |
|
130 // the NSAutoReleasePool contained within the CocoaInitializer. |
|
131 void releaseCocoaPool(void) |
|
132 { |
|
133 if (cocoaInit != NULL) |
137 if (cocoaInit != NULL) |
134 { |
138 { |
135 delete cocoaInit; |
139 delete cocoaInit; |
136 cocoaInit = NULL; |
140 cocoaInit = NULL; |
137 } |
141 } |
138 } |
142 #endif |
139 #endif |
143 if (engine != NULL) |
|
144 { |
|
145 delete engine; |
|
146 engine = NULL; |
|
147 } |
|
148 } |
140 |
149 |
141 int main(int argc, char *argv[]) |
150 int main(int argc, char *argv[]) |
142 { |
151 { |
143 #ifdef __APPLE__ |
152 #ifdef __APPLE__ |
144 // This creates the autoreleasepool that prevents leaking, and destroys it only on exit |
153 // This creates the autoreleasepool that prevents leaking, and destroys it only on exit |
145 cocoaInit = new CocoaInitializer(); |
154 cocoaInit = new CocoaInitializer(); |
146 atexit(releaseCocoaPool); |
155 atexit(closeResources); |
147 #endif |
156 #endif |
148 |
157 |
149 #ifndef _WIN32 |
158 #ifndef _WIN32 |
150 signal(SIGINT, &terminateFrontend); |
159 signal(SIGINT, &terminateFrontend); |
151 #endif |
160 #endif |
163 splash->move(splashCenter); |
172 splash->move(splashCenter); |
164 splash->setPixmap(pixmap); |
173 splash->setPixmap(pixmap); |
165 splash->show(); |
174 splash->show(); |
166 #endif |
175 #endif |
167 |
176 |
168 FileEngineHandler engine(argv[0]); |
177 engine = new FileEngineHandler(argv[0]); |
169 |
178 |
170 app.setAttribute(Qt::AA_DontShowIconsInMenus,false); |
179 app.setAttribute(Qt::AA_DontShowIconsInMenus,false); |
171 |
180 |
172 QStringList arguments = app.arguments(); |
181 QStringList arguments = app.arguments(); |
173 QMap<QString, QString> parsedArgs; |
182 QMap<QString, QString> parsedArgs; |
278 missingMsg.exec(); |
287 missingMsg.exec(); |
279 return 1; |
288 return 1; |
280 } |
289 } |
281 |
290 |
282 // setup PhysFS |
291 // setup PhysFS |
283 engine.mount(datadir->absolutePath()); |
292 engine->mount(datadir->absolutePath()); |
284 engine.mount(cfgdir->absolutePath() + "/Data"); |
293 engine->mount(cfgdir->absolutePath() + "/Data"); |
285 engine.mount(cfgdir->absolutePath()); |
294 engine->mount(cfgdir->absolutePath()); |
286 engine.setWriteDir(cfgdir->absolutePath()); |
295 engine->setWriteDir(cfgdir->absolutePath()); |
287 engine.mountPacks(); |
296 engine->mountPacks(); |
288 |
297 |
289 checkForFile("physfs://hedgewars.ini"); |
298 checkForFile("physfs://hedgewars.ini"); |
290 |
299 |
291 QTranslator Translator; |
300 QTranslator Translator; |
292 { |
301 { |