QTfrontend/M3InstallController.m
author unc0rr
Fri, 12 Nov 2010 19:48:38 +0300
branchmbait-rope_AI
changeset 2563 b1513722f966
parent 2437 10e4b5fc0d93
child 2606 ed687a8d081f
permissions -rw-r--r--
And this one
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2400
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
     1
/*****************************************************************
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
     2
 M3InstallController.m
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
     3
 
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
     4
 Created by Martin Pilkington on 02/06/2007.
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
     5
 
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
     6
 Copyright (c) 2006-2009 M Cubed Software
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
     7
 
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
     8
 Permission is hereby granted, free of charge, to any person
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
     9
 obtaining a copy of this software and associated documentation
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    10
 files (the "Software"), to deal in the Software without
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    11
 restriction, including without limitation the rights to use,
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    12
 copy, modify, merge, publish, distribute, sublicense, and/or sell
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    13
 copies of the Software, and to permit persons to whom the
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    14
 Software is furnished to do so, subject to the following
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    15
 conditions:
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    16
 
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    17
 The above copyright notice and this permission notice shall be
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    18
 included in all copies or substantial portions of the Software.
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    19
 
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    20
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    21
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    22
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    23
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    24
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    25
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    26
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    27
 OTHER DEALINGS IN THE SOFTWARE.
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    28
 
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    29
 *****************************************************************/
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    30
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    31
#import "M3InstallController.h"
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    32
#import "NSWorkspace_RBAdditions.h"
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    33
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    34
#import <Foundation/Foundation.h>
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    35
#import <Foundation/NSObjCRuntime.h>
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    36
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    37
@implementation M3InstallController
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    38
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    39
- (id) init {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    40
	if (self = [super init]) {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    41
		NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    42
		NSString *title = [NSString stringWithFormat:NSLocalizedString(@"%@ is currently running from a disk image", @"AppName is currently running from a disk image"), appName];
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    43
		NSString *body = [NSString stringWithFormat:NSLocalizedString(@"Would you like to install %@ in your applications folder before quitting?", @"Would you like to install App Name in your applications folder before quitting?"), appName];
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    44
		alert = [[NSAlert alertWithMessageText:title 
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    45
								 defaultButton:NSLocalizedString(@"Install", @"Install")
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    46
							   alternateButton:NSLocalizedString(@"Don't Install", @"Don't Install")
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    47
								   otherButton:nil
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    48
					 informativeTextWithFormat:body] retain];
2437
10e4b5fc0d93 fix sound by smaxx and other stuff by me
koda
parents: 2400
diff changeset
    49
		//[alert setShowsSuppressionButton:YES];
2400
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    50
	}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    51
	return self;
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    52
}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    53
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    54
- (void)displayInstaller {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    55
	NSString *imageFilePath = [[[NSWorkspace sharedWorkspace] propertiesForPath:[[NSBundle mainBundle] bundlePath]] objectForKey:NSWorkspace_RBimagefilepath];
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    56
	if (imageFilePath && ![imageFilePath isEqualToString:[NSString stringWithFormat:@"/Users/.%@/%@.sparseimage", NSUserName(), NSUserName()]] && ![[NSUserDefaults standardUserDefaults] boolForKey:@"M3DontAskInstallAgain"]) {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    57
		NSInteger returnValue = [alert runModal];
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    58
		if (returnValue == NSAlertDefaultReturn) {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    59
			[self installApp];
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    60
		}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    61
		if ([[alert suppressionButton] state] == NSOnState) {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    62
			[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"M3DontAskInstallAgain"];
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    63
		}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    64
	}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    65
}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    66
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    67
- (void)installApp {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    68
	NSString *appsPath = [[NSString stringWithString:@"/Applications"] stringByAppendingPathComponent:[[[NSBundle mainBundle] bundlePath] lastPathComponent]];
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    69
	NSString *userAppsPath = [[[NSString stringWithString:@"~/Applications"] stringByAppendingPathComponent:[[[NSBundle mainBundle] bundlePath] lastPathComponent]] stringByExpandingTildeInPath];
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    70
	NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    71
	
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    72
	//Delete the app that is installed
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    73
	if ([[NSFileManager defaultManager] fileExistsAtPath:appsPath]) {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    74
		[[NSFileManager defaultManager] removeFileAtPath:appsPath handler:nil];
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    75
	}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    76
	//Delete the app that is installed
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    77
	if ([[NSFileManager defaultManager] copyPath:[[NSBundle mainBundle] bundlePath] toPath:appsPath 
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    78
										  handler:nil]) {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    79
		NSRunAlertPanel([NSString stringWithFormat:NSLocalizedString(@"%@ installed successfully", @"App Name installed successfully"), appName], 
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    80
						[NSString stringWithFormat:NSLocalizedString(@"%@ was installed in /Applications", @"App Name was installed in /Applications"), appName], 
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    81
						NSLocalizedString(@"Quit", @"Quit"), nil, nil);
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    82
	} else {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    83
		if ([[NSFileManager defaultManager] fileExistsAtPath:userAppsPath]) {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    84
			[[NSFileManager defaultManager] removeFileAtPath:userAppsPath handler:nil];
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    85
		}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    86
		if ([[NSFileManager defaultManager] copyPath:[[NSBundle mainBundle] bundlePath] toPath:userAppsPath
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    87
												handler:nil]) {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    88
		NSRunAlertPanel([NSString stringWithFormat:NSLocalizedString(@"%@ installed successfully", @"AppName installed successfully"), appName], 
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    89
				[NSString stringWithFormat:NSLocalizedString(@"%@ was installed in %@", @"App Name was installed in %@"), appName, [[NSString stringWithString:@"~/Applications"] stringByExpandingTildeInPath]], 
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    90
						NSLocalizedString(@"Quit", @"Quit"), nil, nil);
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    91
		} else {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    92
			NSRunAlertPanel([NSString stringWithFormat:NSLocalizedString(@"Could not install %@", @"Could not install App Name"), appName], 
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    93
							NSLocalizedString(@"An error occurred when installing", @"An error occurred when installing"), NSLocalizedString(@"Quit", @"Quit"), nil, nil);
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    94
		}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    95
	}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    96
}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    97
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    98
@end