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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
/**
* @file MacUpdaterAppDelegate.mm
* @brief
*
* $LicenseInfo:firstyear=2006&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#import "MacUpdaterAppDelegate.h"
#include "llvfs_objc.h"
#include <string.h>
#include <boost/filesystem.hpp>
@implementation MacUpdaterAppDelegate
MacUpdaterAppDelegate *gWindow;
bool gCancelled = false;
bool gFailure =false;
//@synthesize window = _window;
- (void)setWindow:(NSWindow *)window
{
_window = window;
}
- (NSWindow *)window
{
return _window;
}
- (id)init
{
self = [super init];
if (self) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
mAnimated = false;
mProgressPercentage = 0.0;
NSArray *arguments = [[NSProcessInfo processInfo] arguments];
[self parse_args:arguments];
gWindow = self;
mUpdater.doUpdate();
[pool drain];
[pool release];
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
std::string* NSToString( NSString *ns_str )
{
return ( new std::string([ns_str UTF8String]) );
}
- (void) setProgress:(int)cur max:(int) max
{
bool indeterminate = false;
if (max==0)
{
indeterminate = true;
}
else
{
double percentage = ((double)cur / (double)max) * 100.0;
[mProgressBar setDoubleValue:percentage];
}
[mProgressBar setIndeterminate:indeterminate];
}
- (void) setProgressText:(const std::string& )str
{
[mProgressText setStringValue:[NSString stringWithUTF8String:str.c_str()]];
}
void sendDone()
{
[ [ (id) gWindow window ] close];
}
void sendStopAlert()
{
[ gWindow stopAlert ];
}
void setProgress(int cur, int max)
{
[ (id) gWindow setProgress:cur max:max];
}
void setProgressText(const std::string& str)
{
[ (id) gWindow setProgressText:str];
}
void sendProgress(int cur, int max, const std::string str)
{
setProgress(cur,max);
setProgressText(str);
}
bool copyDir(const std::string& src_dir, const std::string& dest_dir)
{
NSString* file = [NSString stringWithCString:src_dir.c_str()
encoding:[NSString defaultCStringEncoding]];
NSString* toParent = [NSString stringWithCString:dest_dir.c_str()
encoding:[NSString defaultCStringEncoding]];
NSError* error = nil;
bool result = [[NSFileManager defaultManager] copyItemAtPath: file toPath: toParent error:&error];
if (!result) {
NSLog(@"Error during copy: %@", [error localizedDescription]);
}
return result;
}
- (int) parse_args:(NSArray *) args
{
int i;
int argc = [args count];
mUpdater.mApplicationPath = NSToString( [args objectAtIndex:0] );
for( i = 1; i < argc; i++ )
{
NSString* ns_arg = [args objectAtIndex:i];
const char *arg = [ns_arg UTF8String];
if ((!strcmp(arg, "-url")) && (i < argc))
{
mUpdater.mUpdateURL = NSToString( [args objectAtIndex:(++i)] );
}
else if ((!strcmp(arg, "-name")) && (i < argc))
{
mUpdater.mProductName = NSToString( [args objectAtIndex:(++i)] );
}
else if ((!strcmp(arg, "-bundleid")) && (i < argc))
{
mUpdater.mBundleID = NSToString( [args objectAtIndex:(++i)] );
}
else if ((!strcmp(arg, "-dmg")) && (i < argc))
{
mUpdater.mDmgFile = NSToString( [args objectAtIndex:(++i)] );
}
else if ((!strcmp(arg, "-marker")) && (i < argc))
{
mUpdater.mMarkerPath = NSToString( [args objectAtIndex:(++i)] );
}
}
return 0;
}
bool isDirWritable(const std::string& dir_name)
{
NSString *fullPath = [NSString stringWithCString:dir_name.c_str()
encoding:[NSString defaultCStringEncoding]];
NSFileManager *fm = [NSFileManager defaultManager];
bool result = [fm isWritableFileAtPath:fullPath];
return result;
}
std::string* getUserTrashFolder()
{
NSString *trash_str=[NSHomeDirectory() stringByAppendingPathComponent:@".Trash"];
return NSToString( trash_str );
}
bool isFSRefViewerBundle(const std::string& targetURL)
{
bool result = false;
NSString *fullPath = [NSString stringWithCString:targetURL.c_str()
encoding:[NSString defaultCStringEncoding]];
NSBundle *targetBundle = [NSBundle bundleWithPath:fullPath];
NSString *targetBundleStr = [targetBundle bundleIdentifier];
NSString *sourceBundleStr = [NSString stringWithCString:mUpdater.mBundleID->c_str()
encoding:[NSString defaultCStringEncoding]];
result = [targetBundleStr isEqualToString:sourceBundleStr];
if(!result)
{
std::cout << "Target bundle ID mismatch." << std::endl;
}
return result;
}
- (IBAction)cancel:(id)sender
{
gCancelled = true;
sendDone();
}
- (void)stopAlert
{
NSAlert *alert = [[NSAlert alloc] init];
[alert setAlertStyle:NSInformationalAlertStyle];
[alert setMessageText:@"Error"];
[alert setInformativeText:@"An error occurred while updating Second Life. Please download the latest version from www.secondlife.com."];
[alert beginSheetModalForWindow:_window
modalDelegate:self
didEndSelector:@selector(stopAlertDidEnd:returnCode:
contextInfo:)
contextInfo:nil];
}
- (void)stopAlertDidEnd:(NSAlert *)alert
returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
[alert release];
}
@end
|