@ -300,7 +300,7 @@ UInt32 SelfPatcherStream::Write(UInt32 byteCount, const void* buffer) {
SetBytesRemaining ( 0 ) ;
SetTimeRemaining ( 0 ) ;
} else {
SetBytesRemaining ( totalBytes - byteCount ) ;
SetBytesRemaining ( totalBytes - progress ) ;
DWORD bytesPerSec = ( progress ) / max ( TimeGetSecondsSince2001Utc ( ) - startTime , 1 ) ;
SetTimeRemaining ( ( totalBytes - progress ) / max ( bytesPerSec , 1 ) ) ;
}
@ -434,6 +434,7 @@ void plSelfPatcher::ICheckAndRequest(PatcherWork*& wk)
wk - > fFlags | = kRequestNewPatcher ;
LogMsg ( kLogDebug , L " plSelfPatcher::ICheckAndRequest: File '%s' needs to be downloaded. " , wk - > fEntry . clientName ) ;
SelfPatcherStream : : totalBytes + = ( wk - > fEntry . zipSize ! = 0 ) ? wk - > fEntry . zipSize : wk - > fEntry . fileSize ;
wk - > fType = kDownload ;
IEnqueueWork ( wk , isPatcher ) ;
}
@ -457,7 +458,6 @@ void plSelfPatcher::IDownloadFile(PatcherWork*& wk)
SetText ( " Downloading update... " ) ;
}
SelfPatcherStream : : totalBytes + = ( wk - > fEntry . zipSize ! = 0 ) ? wk - > fEntry . zipSize : wk - > fEntry . fileSize ;
SelfPatcherStream * s = NEWZERO ( SelfPatcherStream ) ;
if ( ! s - > Open ( wk - > fEntry . clientName , L " wb " ) ) {
LogMsg ( kLogError , L " plSelfPatcher::IDownloadFile: Failed to create file: %s, errno: %u " , wk - > fEntry . clientName , errno ) ;
@ -517,10 +517,6 @@ HANDLE plSelfPatcher::ICreateProcess(const wchar* path, const wchar* args, bool
// launched by Windows (such as errors) to deadlock the UI quite horribly. Further,
// ShellExecuteExW pops up that weird "do you want to run this file you downloaded from the internet?"
// box, which we can't actually interact with due to the above.
wchar exePath [ MAX_PATH ] ;
PathGetCurrentDirectory ( exePath , arrsize ( exePath ) ) ;
PathAddFilename ( exePath , exePath , path , arrsize ( exePath ) ) ;
if ( ! forceShell ) {
STARTUPINFOW si ;
PROCESS_INFORMATION pi ;
@ -529,9 +525,8 @@ HANDLE plSelfPatcher::ICreateProcess(const wchar* path, const wchar* args, bool
si . cb = sizeof ( si ) ;
wchar cmdline [ MAX_PATH ] ;
const wchar * exeFilename = PathFindFilename ( path ) ;
StrPrintf ( cmdline , arrsize ( cmdline ) , L " %s %s " , exeFilename , args ) ;
BOOL result = CreateProcessW ( exePath ,
StrPrintf ( cmdline , arrsize ( cmdline ) , L " %s %s " , path , args ) ;
BOOL result = CreateProcessW ( path ,
cmdline ,
NULL ,
NULL ,
@ -543,12 +538,11 @@ HANDLE plSelfPatcher::ICreateProcess(const wchar* path, const wchar* args, bool
& pi ) ;
CloseHandle ( pi . hThread ) ;
if ( result ! = FALSE ) {
free ( exePath ) ;
return pi . hProcess ;
} else {
wchar * error = FormatSystemError ( ) ;
LogMsg ( kLogError , L " plSelfPatcher::ICreateProcess: CreateProcessW failed for '%s': %u %s " ,
exeP ath, GetLastError ( ) , error ) ;
p ath, GetLastError ( ) , error ) ;
LocalFree ( error ) ;
// Purposefully falling through to ShellExecuteExW
}
@ -560,16 +554,15 @@ HANDLE plSelfPatcher::ICreateProcess(const wchar* path, const wchar* args, bool
info . fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NOASYNC | SEE_MASK_FLAG_NO_UI ;
info . hwnd = fLauncherInfo - > dialog ;
// Not explicitly setting lpVerb to L"runas" because this seemingly breaks msiexec.
info . lpFile = exeP ath;
info . lpFile = p ath;
info . lpParameters = args ;
if ( ShellExecuteExW ( & info ) = = FALSE ) {
wchar * error = FormatSystemError ( ) ;
LogMsg ( kLogError , L " plSelfPatcher::ICreateProcess: ShellExecuteExW failed for '%s': %u %s " ,
exeP ath, GetLastError ( ) , error ) ;
p ath, GetLastError ( ) , error ) ;
LocalFree ( error ) ;
}
free ( exePath ) ;
return info . hProcess ;
}