@@ -67,6 +67,7 @@ + (void) setParams:(NSMutableDictionary *)params {
67
67
_params = params;
68
68
}
69
69
70
+
70
71
// Runs a script, given the script path, and args array.
71
72
int RunScript (NSString * launchPath, NSArray * argsArray, BOOL waitUntilExit)
72
73
{
@@ -172,9 +173,39 @@ + (void) RunAppUpdate{
172
173
else {
173
174
int pid = [self getCurrentProcessID ];
174
175
NSString * pidString = [NSString stringWithFormat: @" %d " , pid];
175
- pArgs = [NSArray arrayWithObjects: shPath, scriptPath, @" -a" , bracketsAppName, @" -b" , installDir, @" -l" , logFilePath, @" -m" , mountPoint, @" -t" , updateDir, @" -p" , pidString, @" &" , nil ];
176
-
177
- retval = RunScript (nohupPath, pArgs, false );
176
+ BOOL isAdmin = NO ;
177
+
178
+ NSString *installDirPath = installDir;
179
+ installDirPath = [installDirPath stringByAppendingString: @" /" ];
180
+ NSString *bracketsAppPath = installDirPath;
181
+ bracketsAppPath = [bracketsAppPath stringByAppendingString: bracketsAppName];
182
+
183
+ NSFileManager *fm = [NSFileManager defaultManager ];
184
+ if ([fm isWritableFileAtPath: installDirPath] && [fm isWritableFileAtPath: bracketsAppPath] )
185
+ {
186
+ isAdmin = YES ;
187
+ }
188
+
189
+
190
+ /* Build the Apple Script String*/
191
+ NSAppleEventDescriptor *returnDescriptor = NULL ;
192
+ NSString * appleScriptString;
193
+
194
+ appleScriptString = [NSString stringWithFormat: @" do shell script \" %@ %@ %@ -a %@ -b '%@ ' -l '%@ ' -m %@ -t '%@ ' -p %@ > /dev/null 2>&1 &\" " , nohupPath, shPath, scriptPath, bracketsAppName, installDir, logFilePath, mountPoint, updateDir, pidString];
195
+
196
+ if (!isAdmin) {
197
+ appleScriptString = [appleScriptString stringByAppendingString: @" with administrator privileges" ];
198
+ }
199
+
200
+ NSAppleScript *theScript = [[NSAppleScript alloc ] initWithSource: appleScriptString];
201
+
202
+ NSDictionary *theError = nil ;
203
+
204
+ returnDescriptor = [theScript executeAndReturnError: &theError];
205
+ if (returnDescriptor == NULL ) {
206
+ NSString *logStr = @" ERROR: scriptexecution Failed error: BA_06" ;
207
+ [logStr writeToFile: installStatusFilePath atomically: YES encoding: NSUTF8StringEncoding error: nil ];
208
+ }
178
209
}
179
210
}
180
211
}
0 commit comments