This repository has been archived by the owner on Jul 15, 2019. It is now read-only.
forked from Yi-Kai/KeyKey
-
Notifications
You must be signed in to change notification settings - Fork 142
/
TakaoUpdate.m
137 lines (120 loc) · 5.18 KB
/
TakaoUpdate.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
/*
Copyright (c) 2012, Yahoo! Inc. All rights reserved.
Copyrights licensed under the New BSD License. See the accompanying LICENSE
file for terms.
*/
// [AUTO_HEADER]
#import "TakaoUpdate.h"
#import "TakaoHelper.h"
@implementation TakaoUpdate
- (void)dealloc
{
if (_task)
[_task terminate];
[_task release];
[super dealloc];
}
- (void)_getVersionInfo
{
id ovService;
// @try {
ovService = [NSConnection rootProxyForConnectionWithRegisteredName:OPENVANILLA_DO_CONNECTION_NAME host:nil];
// }
// @catch(NSException *e) {
// NSLog(@"Exceptions raise on retreiving version info");
// [_currentVersionTextField setStringValue:@""];
// [_latestVersionTextField setStringValue:@""];
// [_latestCheckTextField setStringValue:@""];
// return;
// }
if (ovService) {
[ovService setProtocolForProxy:@protocol(OpenVanillaService)];
NSString *version = [ovService version];
if (version)
[_currentVersionTextField setStringValue:version];
else
[_currentVersionTextField setStringValue:@""];
NSString *latestVersion = [ovService latestVersion];
if (latestVersion)
[_latestVersionTextField setStringValue:latestVersion];
else
[_latestVersionTextField setStringValue:@""];
NSString *latestCheck = [ovService latestCheck];
if (latestCheck)
[_latestCheckTextField setStringValue:latestCheck];
else
[_latestCheckTextField setStringValue:@""];
}
else {
[_currentVersionTextField setStringValue:@""];
[_latestVersionTextField setStringValue:@""];
[_latestCheckTextField setStringValue:@""];
}
}
- (void)awakeFromNib
{
[_checkProgressIndicator setHidden:YES];
[self _getVersionInfo];
}
- (void)launchDownload:(NSString *)actionURL signatureURL:(NSString *)signatureURL changeLogURL:(NSString *)changeLogURL
{
if (_task) {
if ([_task isRunning])
return;
else
[_task release];
}
NSString *supportPath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
NSString *commandPath = [supportPath stringByAppendingString:@"/DownloadUpdate.app/Contents/MacOS/DownloadUpdate"];
#else
NSString *commandPath = [supportPath stringByAppendingString:@"/DownloadUpdateTiger.app/Contents/MacOS/DownloadUpdateTiger"];
#endif
NSArray *arguments = [NSArray arrayWithObjects:actionURL, signatureURL, ((changeLogURL && [changeLogURL length]) ? changeLogURL : @"(null)"),nil];
_task = [NSTask launchedTaskWithLaunchPath:commandPath arguments:arguments];
[_task retain];
[_task launch];
[_task waitUntilExit];
}
#pragma mark Interface Builder actions
- (IBAction)checkUpdateNow:(id)sender
{
[_checkProgressIndicator startAnimation:self];
[_checkProgressIndicator setHidden:NO];
NSDictionary *updateDictionary;
id ovService = [NSConnection rootProxyForConnectionWithRegisteredName:OPENVANILLA_DO_CONNECTION_NAME host:nil];
if (ovService) {
[ovService setProtocolForProxy:@protocol(OpenVanillaService)];
updateDictionary = [ovService shouldUpdate];
[_checkProgressIndicator stopAnimation:self];
[_checkProgressIndicator setHidden:YES];
// NSLog(@"update dict: %@", [updateDictionary description]);
NSString *status = [updateDictionary valueForKey:@"Status"];
if ([status isEqualToString:@"Error"]) {
NSAlert *alert = [NSAlert alertWithMessageText:LFLSTR(@"Unable to check for update via the Internet.") defaultButton:LFLSTR(@"OK") alternateButton:nil otherButton:nil informativeTextWithFormat:LFLSTR(@"Please check your Internet connection and try again.")];
[alert beginSheetModalForWindow:_window modalDelegate:self didEndSelector:nil contextInfo:nil];
}
else if ([status isEqualToString:@"No"]) {
NSAlert *alert = [NSAlert alertWithMessageText:LFLSTR(@"You are now using the newest version.") defaultButton:LFLSTR(@"OK") alternateButton:nil otherButton:nil informativeTextWithFormat:LFLSTR(@"You need not to update your software")];
[alert beginSheetModalForWindow:_window modalDelegate:self didEndSelector:nil contextInfo:nil];
}
else if ([status isEqualToString:@"Yes"]) {
NSString *actionURL = [updateDictionary objectForKey:@"ActionURL"];
NSString *signatureURL = [updateDictionary objectForKey:@"SignatureURL"];
NSString *changeLogURL = [updateDictionary objectForKey:@"ChangeLogURL"];
[self launchDownload:actionURL signatureURL:signatureURL changeLogURL:changeLogURL];
}
else {
NSAlert *alert = [NSAlert alertWithMessageText:LFLSTR(@"Unable to check for update via the Internet.") defaultButton:LFLSTR(@"OK") alternateButton:nil otherButton:nil informativeTextWithFormat:LFLSTR(@"Unknown errors happened, please try again.")];
[alert beginSheetModalForWindow:_window modalDelegate:self didEndSelector:nil contextInfo:nil];
}
}
else {
[_checkProgressIndicator stopAnimation:self];
[_checkProgressIndicator setHidden:YES];
NSAlert *alert = [NSAlert alertWithMessageText:LFLSTR(@"Unable to check for update via the Internet.") defaultButton:LFLSTR(@"OK") alternateButton:nil otherButton:nil informativeTextWithFormat:LFLSTR(@"If you are nor running Yahoo! KeyKey, you are not able to check for update.")];
[alert runModal];
}
[self _getVersionInfo];
}
@end