--- a/QTfrontend/main.cpp Fri Nov 30 18:19:52 2012 +0400
+++ b/QTfrontend/main.cpp Tue Dec 04 09:15:55 2012 +0400
@@ -90,9 +90,9 @@
bool checkForDir(const QString & dir)
{
- QDir tmpdir;
- if (!tmpdir.exists(dir))
- if (!tmpdir.mkdir(dir))
+ QDir tmpdir(dir);
+ if (!tmpdir.exists())
+ if (!tmpdir.mkpath(dir))
{
QMessageBox directoryMsg(QApplication::activeWindow());
directoryMsg.setIcon(QMessageBox::Warning);
@@ -105,8 +105,37 @@
return true;
}
+bool checkForFile(const QString & file)
+{
+ QFile tmpfile(file);
+ if (!tmpfile.exists())
+ return tmpfile.open(QFile::WriteOnly);
+ else
+ return true;
+}
+
+#ifdef __APPLE__
+static CocoaInitializer *cocoaInit = NULL;
+// Function to be called at end of program's termination on OS X to release
+// the NSAutoReleasePool contained within the CocoaInitializer.
+void releaseCocoaPool(void)
+{
+ if (cocoaInit != NULL)
+ {
+ delete cocoaInit;
+ cocoaInit = NULL;
+ }
+}
+#endif
+
int main(int argc, char *argv[])
{
+#ifdef __APPLE__
+ // This creates the autoreleasepool that prevents leaking, and destroys it only on exit
+ cocoaInit = new CocoaInitializer();
+ atexit(releaseCocoaPool);
+#endif
+
HWApplication app(argc, argv);
FileEngineHandler engine(argv[0]);
@@ -232,6 +261,8 @@
engine.setWriteDir(cfgdir->absolutePath());
engine.mountPacks();
+ checkForFile("physfs://hedgewars.ini");
+
QTranslator Translator;
{
QSettings settings("physfs://hedgewars.ini", QSettings::IniFormat);
@@ -254,10 +285,6 @@
registry_hklm.setValue("Software/Hedgewars/Path", bindir->absolutePath().replace("/", "\\"));
}
#endif
-#ifdef __APPLE__
- // this creates the autoreleasepool that prevents leaking
- CocoaInitializer initializer;
-#endif
QString style = "";
QString fname;