forked from rentzsch/clicktoflash
/
CTFWhitelistWindowController.m
executable file
·137 lines (111 loc) · 3.77 KB
/
CTFWhitelistWindowController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#import "CTFWhitelistWindowController.h"
#import "SparkleManager.h"
NSString *kCTFCheckForUpdates = @"CTFCheckForUpdates";
@implementation CTFWhitelistWindowController
- (id)init
{
NSBundle *myBundle = [NSBundle bundleForClass:[self class]];
NSString *nibPath = [myBundle pathForResource:@"WhitelistPanel" ofType:@"nib"];
if (nibPath == nil) {
[self dealloc];
return nil;
}
self = [super initWithWindowNibPath: nibPath owner: self];
return self;
}
- (void)windowDidLoad
{
[_checkNowButton setEnabled:[[SparkleManager sharedManager] canUpdate]];
}
- (IBAction)checkForUpdates:(id)sender;
{
[[SparkleManager sharedManager] checkForUpdates];
}
- (IBAction)automaticallyCheckForUpdatesDidChange:(id)sender;
{
[[SparkleManager sharedManager] setAutomaticallyChecksForUpdates:[sender state]];
}
- (NSString *)versionString
{
NSBundle *CTFBundle = [NSBundle bundleWithIdentifier:@"com.github.rentzsch.clicktoflash"];
return [CTFBundle objectForInfoDictionaryKey: @"CFBundleShortVersionString"];
}
- (IBAction)uninstallClickToFlash:(id)sender;
{
[NSApp beginSheet:confirmUninstallSheet
modalForWindow:[self window]
modalDelegate:self
didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo:nil];
}
- (IBAction)cancelUninstall:(id)sender;
{
[confirmUninstallSheet orderOut:sender];
[NSApp endSheet:confirmUninstallSheet returnCode:0];
}
- (IBAction)approveUninstall:(id)sender;
{
[confirmUninstallSheet orderOut:sender];
[NSApp endSheet:confirmUninstallSheet returnCode:1];
}
- (void)sheetDidEnd:(NSWindow *)sheet
returnCode:(int)returnCode
contextInfo:(void *)contextInfo;
{
if (returnCode == 1) {
NSString *userPluginPath = [@"~/Library/Internet Plug-ins/ClickToFlash.webplugin" stringByExpandingTildeInPath];
BOOL isDirectory = NO;
BOOL userPluginExists = [[NSFileManager defaultManager] fileExistsAtPath:userPluginPath
isDirectory:&isDirectory];
BOOL succeeded = NO;
if (userPluginExists && isDirectory) {
// we'll move the plugin to the trash, instead of just obstinately
// deleting it
succeeded = [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation
source:[@"~/Library/Internet Plug-ins/" stringByExpandingTildeInPath]
destination:nil
files:[NSArray arrayWithObject:@"ClickToFlash.webplugin"]
tag:nil];
}
if (succeeded) {
[NSApp beginSheet:successfulUninstallationSheet
modalForWindow:[self window]
modalDelegate:self
didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo:nil];
} else {
// there are three ways to get here:
// 1. either userPluginExists equals NO, in which case the plugin is
// installed for all users and we can't guarantee that we can
// uninstall it, so we'll just fail
// 2. an item exists at the correct path, but it's a file not a
// folder, so it's not ClickToFlash
// 3. the plugin exists, but for some reason we couldn't move
// it to the trash
[NSApp beginSheet:failedUninstallationSheet
modalForWindow:[self window]
modalDelegate:self
didEndSelector:@selector(resultSheetDidEnd:returnCode:contextInfo:)
contextInfo:nil];
}
} else {
// uninstallation was cancelled
}
}
- (IBAction)dismissSuccessSheet:(id)sender;
{
[successfulUninstallationSheet orderOut:sender];
[NSApp endSheet:successfulUninstallationSheet returnCode:0];
}
- (IBAction)dismissFailureSheet:(id)sender;
{
[failedUninstallationSheet orderOut:sender];
[NSApp endSheet:failedUninstallationSheet returnCode:0];
}
- (void)returnSheetDidEnd:(NSWindow *)sheet
returnCode:(int)returnCode
contextInfo:(void *)contextInfo;
{
// nothing to see here!
}
@end