QTfrontend/M3InstallController.m
author nemo
Sun, 14 Aug 2011 23:52:45 -0400
changeset 5569 8313952b2811
parent 3697 d5b30d6373fc
child 6479 4f08821cbff5
permissions -rw-r--r--
suggestion of mikade's - delete old mines if the collision array shows signs of filling up. This is kind of an edge case, esp now that array is up to 1024, but should prevent (easiest) way to crash by collision array overflow (endless mines/minestrikes).
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
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 2606
diff changeset
     3
2400
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.
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 2606
diff changeset
     5
2400
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
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 2606
diff changeset
     7
2400
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:
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 2606
diff changeset
    16
2400
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.
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 2606
diff changeset
    19
2400
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.
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 2606
diff changeset
    28
2400
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
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    36
@implementation M3InstallController
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    37
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    38
- (id) init {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    39
	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
    40
		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
    41
		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
    42
		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];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 2606
diff changeset
    43
		alert = [[NSAlert alertWithMessageText:title
2400
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    44
								 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
    45
							   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
    46
								   otherButton:nil
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    47
					 informativeTextWithFormat:body] retain];
2437
10e4b5fc0d93 fix sound by smaxx and other stuff by me
koda
parents: 2400
diff changeset
    48
		//[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
    49
	}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    50
	return self;
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    51
}
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
- (void)displayInstaller {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    54
	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
    55
	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
    56
		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
    57
		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
    58
			[self installApp];
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    59
		}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    60
		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
    61
			[[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
    62
		}
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
- (void)installApp {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    67
	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
    68
	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
    69
	NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 2606
diff changeset
    70
2400
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    71
	//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
    72
	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
    73
		[[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
    74
	}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    75
	//Delete the app that is installed
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 2606
diff changeset
    76
	if ([[NSFileManager defaultManager] copyPath:[[NSBundle mainBundle] bundlePath] toPath:appsPath
2400
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    77
										  handler:nil]) {
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 2606
diff changeset
    78
		NSRunAlertPanel([NSString stringWithFormat:NSLocalizedString(@"%@ installed successfully", @"App Name installed successfully"), appName],
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 2606
diff changeset
    79
						[NSString stringWithFormat:NSLocalizedString(@"%@ was installed in /Applications", @"App Name was installed in /Applications"), appName],
2400
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    80
						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
    81
	} else {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    82
		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
    83
			[[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
    84
		}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    85
		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
    86
												handler:nil]) {
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 2606
diff changeset
    87
		NSRunAlertPanel([NSString stringWithFormat:NSLocalizedString(@"%@ installed successfully", @"AppName installed successfully"), appName],
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 2606
diff changeset
    88
				[NSString stringWithFormat:NSLocalizedString(@"%@ was installed in %@", @"App Name was installed in %@"), appName, [[NSString stringWithString:@"~/Applications"] stringByExpandingTildeInPath]],
2400
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    89
						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
    90
		} else {
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 2606
diff changeset
    91
			NSRunAlertPanel([NSString stringWithFormat:NSLocalizedString(@"Could not install %@", @"Could not install App Name"), appName],
2400
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    92
							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
    93
		}
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
@end