Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 57 additions & 3 deletions appshell/update_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ + (void) setParams:(NSMutableDictionary *)params {
_params = params;
}


// Runs a script, given the script path, and args array.
int RunScript(NSString* launchPath, NSArray* argsArray, BOOL waitUntilExit)
{
Expand Down Expand Up @@ -172,9 +173,62 @@ + (void) RunAppUpdate{
else {
int pid = [self getCurrentProcessID];
NSString* pidString = [NSString stringWithFormat:@"%d", pid];
pArgs = [NSArray arrayWithObjects:shPath, scriptPath, @"-a", bracketsAppName, @"-b", installDir, @"-l", logFilePath, @"-m", mountPoint, @"-t", updateDir, @"-p", pidString, @"&", nil];

retval = RunScript(nohupPath, pArgs, false);
BOOL isAdmin = false;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BOOL isAdmin = NO or bool isAdmin = false


NSString *installDirPath = installDir;
installDirPath = [installDirPath stringByAppendingString:@"/"];
NSString *bracketsAppPath = installDirPath;
bracketsAppPath = [bracketsAppPath stringByAppendingString:bracketsAppName];

NSFileManager *fm = [NSFileManager defaultManager];
if([fm isWritableFileAtPath:installDirPath] && [fm isWritableFileAtPath:bracketsAppPath] )
{
isAdmin = true;
}


/*Build the Apple Script String*/
NSAppleEventDescriptor *returnDescriptor = NULL;
NSString * appleScriptString = @"do shell script \"";
appleScriptString = [appleScriptString stringByAppendingString:nohupPath];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer an [NSString stringWithFormat:]

appleScriptString = [appleScriptString stringByAppendingString:@" "];
appleScriptString = [appleScriptString stringByAppendingString:shPath];
appleScriptString = [appleScriptString stringByAppendingString:@" "];
appleScriptString = [appleScriptString stringByAppendingString:scriptPath];
appleScriptString = [appleScriptString stringByAppendingString:@" -a "];
appleScriptString = [appleScriptString stringByAppendingString:bracketsAppName];
appleScriptString = [appleScriptString stringByAppendingString:@" -b "];
appleScriptString = [appleScriptString stringByAppendingString:@"'"];
appleScriptString = [appleScriptString stringByAppendingString:installDir];
appleScriptString = [appleScriptString stringByAppendingString:@"'"];
appleScriptString = [appleScriptString stringByAppendingString:@" -l "];
appleScriptString = [appleScriptString stringByAppendingString:@"'"];
appleScriptString = [appleScriptString stringByAppendingString:logFilePath];
appleScriptString = [appleScriptString stringByAppendingString:@"'"];
appleScriptString = [appleScriptString stringByAppendingString:@" -m "];
appleScriptString = [appleScriptString stringByAppendingString:mountPoint];
appleScriptString = [appleScriptString stringByAppendingString:@" -t "];
appleScriptString = [appleScriptString stringByAppendingString:@"'"];
appleScriptString = [appleScriptString stringByAppendingString:updateDir];
appleScriptString = [appleScriptString stringByAppendingString:@"'"];
appleScriptString = [appleScriptString stringByAppendingString:@" -p "];
appleScriptString = [appleScriptString stringByAppendingString:pidString];
appleScriptString = [appleScriptString stringByAppendingString:@" > /dev/null 2>&1 &"];
appleScriptString = [appleScriptString stringByAppendingString:@"\""];

if(!isAdmin) {
appleScriptString = [appleScriptString stringByAppendingString:@" with administrator privileges"];
}

NSAppleScript *theScript = [[NSAppleScript alloc] initWithSource:appleScriptString];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

theScript string needs be freed. But anyways since this in the destruction sequence I guess we can live with it.


NSDictionary *theError = nil;

returnDescriptor = [theScript executeAndReturnError: &theError];
if(returnDescriptor == NULL) {
NSString *logStr = @"ERROR: scriptexecution Failed error: BA_06 ";
[logStr writeToFile:installStatusFilePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions installer/mac/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ function updateBrackets(){
printInfo "Unmounted the DMG and attempying to open Brackets ..."
fi

rm -rf "$TEMP_DIR/$APP_NAME"
open -a "$APP_DIR/$APP_NAME"
exitStatus=$?
if [ $exitStatus -ne 0 ]
Expand Down