From 59abcac7dae0713e71aa06266f68c6f43e388256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Mon, 4 Feb 2013 23:12:43 +0000 Subject: [PATCH] A patch from stopiccot http://forum.vcmi.eu/viewtopic.php?p=8340#8340 --- lib/VCMIDirs.h | 14 ++++++++++++-- osx/osx-vcmibuilder/vcmibuilder/AppDelegate.m | 19 ++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/VCMIDirs.h b/lib/VCMIDirs.h index 612626f3d..877d25d90 100644 --- a/lib/VCMIDirs.h +++ b/lib/VCMIDirs.h @@ -17,7 +17,6 @@ using namespace boost::filesystem; #endif - /// Where to find the various VCMI files. This is mostly useful for linux. class VCMIDirs { public: @@ -31,10 +30,21 @@ public: try { #ifdef ANDROID UserPath = DATA_DIR; +#elif defined(__APPLE__) + // This is Cocoa code that should be normally used to get path to Application Support folder but can't use it here for now... + // NSArray* urls = [[NSFileManager defaultManager] URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask]; + // UserPath = path([urls[0] path] + "/vcmi").string(); + + // ...so here goes a bit of hardcode instead + std::string home_dir = "."; + if (getenv("HOME") != NULL ) + home_dir = getenv("HOME"); + + UserPath = path(home_dir + "/Library/Application Support/vcmi").string(); #else // Find vcmi user directory and create it if necessary std::string home_dir = "."; - if( getenv("HOME") != NULL ) + if (getenv("HOME") != NULL ) home_dir = getenv("HOME"); UserPath = path(home_dir + "/.vcmi").string(); diff --git a/osx/osx-vcmibuilder/vcmibuilder/AppDelegate.m b/osx/osx-vcmibuilder/vcmibuilder/AppDelegate.m index a0c917c68..c4694950a 100644 --- a/osx/osx-vcmibuilder/vcmibuilder/AppDelegate.m +++ b/osx/osx-vcmibuilder/vcmibuilder/AppDelegate.m @@ -7,6 +7,10 @@ installationCompleted = NO; outputDir = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/../../Data"]; tempDir = NSTemporaryDirectory(); + + // Output to Application Support + //NSArray* appSupportDirs = [[NSFileManager defaultManager] URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask]; + //outputDir = [[appSupportDirs[0] path] stringByAppendingString:@"/vcmi"]; } - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)sender @@ -243,7 +247,20 @@ [self.installButton setTitle:@"Run VCMI"]; [self.progressIndicator stopAnimation:self]; - [NSApp requestUserAttention:NSCriticalRequest]; + // Notify user that installation completed + NSUserNotification* notification = [[NSUserNotification alloc] init]; + if (notification != nil) { + // On OS X 10.8 and newer use notification center + [notification setTitle:@"VCMI"]; + [notification setInformativeText:@"Installation completed"]; + [notification setDeliveryDate:[NSDate dateWithTimeInterval:0 sinceDate:[NSDate date]]]; + [notification setSoundName:NSUserNotificationDefaultSoundName]; + NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter]; + [center scheduleNotification:notification]; + } else { + // On older OS X version force dock icon to jump + [NSApp requestUserAttention:NSCriticalRequest]; + } // Hide all progress related controls [self.progressIndicator setHidden:YES];