Skip to content

Commit

Permalink
Fixed problems with the new updater
Browse files Browse the repository at this point in the history
Fixed prompts not being displayed or ignored
Fixed update found message wrongly being displayed when running from source
Fixed missing update failed message
Fixed update found message although no update available when UniExtract's subfolders contain additional files placed by the user (such as plugins)
Fixed UniExtract not restarting without elevated permissions after update
Removed opening changelog after update
  • Loading branch information
Bioruebe committed Apr 24, 2018
1 parent f208120 commit 30af0fb
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 60 deletions.
4 changes: 2 additions & 2 deletions English.ini
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ UPDATE_PROMPT = "A new update is available for %1.%n%nDo you want to download it
FILE_COPY = "To process the file %1 correctly, a copy have to be created. Depending on the file size, this can take some time.%n%nPlease ensure that there is enough free space available and click OK to continue."
FILE_DELETE = "The file %1 has sucessfully been extracted. Do you want %name to delete the original file?%n%nNote: It can be possible that the extracted files are not usable. Please only click Yes if you are sure, the extraction worked like imagined.%n(This message can be deactivated in the options.)"
BATCH_DUPLICATE = "The file %1 is already in the batch queue.%n%nShall it be added again and therefore extracted twice?"
NO_FREE_SPACE = "Warning:%nThe output drive has less free space than the input file's size.%n%nFree space:%t%1 MB%nSpace needed:%t>%2 MB%nDifference:%t~%3 MB"
NO_FREE_SPACE = "Warning:%nThe output drive %1 has less free space than the input file's size.%n%nFree space:%t%2 MB%nSpace needed:%t>%3 MB%nDifference:%t~%4 MB"
CONTEXT_DANGEROUS = "Warning:%nChanging file associations can be dangerous. E.g. changing .exe standard commands may result in applictions not being able to run at all. Please make sure you know what you are doing.%n%nDo you really want to continue?"
ELEVATION_REQUIRED = "Access denied.%n%n%name will now restart with elevated rights. Please try again afterwards."
ACCESS_DENIED = "Access denied.%n%n%name is already executed with elevated rights. Please ensure you have the premissions necessary to perform the action and try again."
Expand Down Expand Up @@ -266,7 +266,7 @@ EXTRACT_FAILED = "%1 could not be extracted.%nIt appears to be a(n) %2, which is
NOT_PACKED = "%1 could not be extracted, the file is not packed but %n%n%2"
DOWNLOAD_FAILED = "The file %1 could not be downloaded. Please ensure that you are connected to the internet and try again."
UPDATECHECK_FAILED = "Checking for updates failed. Please ensure that you are connected to the internet and try again."
UPDATE_FAILED = "Some files failed to update.%n%nPlease try again later or update manually."
UPDATE_FAILED = "Some files failed to update.%n%nPlease try again later or redownload %name."
FEEDBACK_EMPTY = "Please try to give as much information as possible to ensure fast handling of your feedback."
FEEDBACK_ERROR = "Sending feedback failed. Please try again later, manually send an email or use the forum to submit your report. Thank you"
BATCH_FINISH = "Batch processing has finished, but not all files could be extracted successfully. The following files resulted in an error:%n%n%1%nFor further information please read the appropriate files in the log directory (only available if logging is activated)."
Expand Down
129 changes: 83 additions & 46 deletions UniExtract.au3
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Const $PACKER_UPX = "UPX", $PACKER_ASPACK = "Aspack"
Const $RESULT_UNKNOWN = 0, $RESULT_SUCCESS = 1, $RESULT_FAILED = 2, $RESULT_CANCELED = 3
Const $UNICODE_NONE = 0, $UNICODE_MOVE = 1, $UNICODE_COPY = 2
Const $UPDATE_ALL = 0, $UPDATE_HELPER = 1, $UPDATE_MAIN = 2
Const $UPDATEMSG_PROMPT = 0, $UPDATEMSG_SILENT = 1, $UPDATEMSG_FOUND_ONLY = 2
Const $STATUS_SYNTAX = "syntax", $STATUS_FILEINFO = "fileinfo", $STATUS_UNKNOWNEXE = "unknownexe", $STATUS_UNKNOWNEXT = "unknownext", _
$STATUS_INVALIDFILE = "invalidfile", $STATUS_INVALIDDIR = "invaliddir", $STATUS_NOTPACKED = "notpacked", $STATUS_BATCH = "batch", _
$STATUS_NOTSUPPORTED = "notsupported", $STATUS_MISSINGEXE = "missingexe", $STATUS_TIMEOUT = "timeout", $STATUS_PASSWORD = "password", _
Expand Down Expand Up @@ -134,15 +135,14 @@ Global $trayX = -1, $trayY = -1
; Global variables
Dim $file, $filename, $filenamefull, $filedir, $fileext, $initoutdir, $outdir, $filetype = "", $initdirsize
Dim $prompt, $return, $Output, $hMutex
Dim $gaDropFiles[1], $queueArray[1]
Dim $About, $Type, $win7, $silent, $iUnicodeMode = False, $reg64 = ""
Dim $debug = "", $guimain = False, $success = $RESULT_UNKNOWN, $TBgui = 0, $isofile = 0
Dim $debug = "", $guimain = False, $success = $RESULT_UNKNOWN, $TBgui = 0, $isofile = 0, $sArcTypeOverride = 0
Dim $test, $test7z, $testzip, $testie, $testinno
Dim $innofailed, $arjfailed, $7zfailed, $zipfailed, $iefailed, $isfailed, $isofailed, $tridfailed, $gamefailed, $unpackfailed, $exefailed
Dim $oldpath, $oldoutdir, $sUnicodeName, $createdir
Dim $FS_GUI = False, $idTrayStatusExt, $BatchBut
Dim $isexe = False, $Message, $run = 0, $runtitle, $DeleteOrigFileOpt[3]
Dim $queueArray[0], $aTridDefinitions[0][0], $aFileDefinitions[0][0]
Dim $gaDropFiles[1], $queueArray[0], $aTridDefinitions[0][0], $aFileDefinitions[0][0]

; Check if OS is 64 bit version
If @OSArch == "X64" Or @OSArch == "IA64" Then
Expand Down Expand Up @@ -380,6 +380,9 @@ Func StartExtraction()
$testie = False
$filetype = ""

; If an extractor is specified via command line parameter, we simply use that without scanning
If $sArcTypeOverride Then Return extract($sArcTypeOverride, $sArcTypeOverride & " " & t('TERM_FILE'))

; Extract contents from known file types

; UniExtract uses four methods of detection (in order):
Expand Down Expand Up @@ -539,16 +542,13 @@ Func ParseCommandLine()
ElseIf $cmdline[1] = "/afterupdate" Then
_AfterUpdate()

ElseIf $cmdline[1] = "/changelog" Then
_ShowChangelog()
$prompt = 1

ElseIf $cmdline[1] = "/update" Then
CheckUpdate()
terminate($STATUS_SILENT)

ElseIf $cmdline[1] = "/updatehelper" Then
CheckUpdate(False, False, $UPDATE_HELPER)
CheckUpdate($UPDATEMSG_SILENT, False, $UPDATE_HELPER)
$prompt = 1

ElseIf $cmdline[1] = "/plugins" Then
$prompt = 1
Expand Down Expand Up @@ -579,6 +579,13 @@ Func ParseCommandLine()
; When executed from context menu, opening the outdir is not wanted
$OpenOutDir = 0
EndIf

If $cmdline[0] > 2 And StringLeft($cmdline[3], 6) = "/type=" Then
$sArcTypeOverride = StringTrimLeft($cmdline[3], 6)
If StringLen($sArcTypeOverride) < 1 Then
; TODO: Display type select GUI
EndIf
EndIf
Else
$prompt = 1
EndIf
Expand Down Expand Up @@ -3365,9 +3372,10 @@ Func HasFreeSpace($sPath = $outdir, $fModifier = 1)
If $freeSpace < $fileSize Then
Local $diff = Round(Abs($freeSpace - $fileSize), 2)
Cout("Not enough free space available: " & $freeSpace & " MB, needed: " & $fileSize & " MB, difference: " & $diff & " MB.")
If $silentmode Then terminate($STATUS_FAILED, '', "Not enough free space available: " & $freeSpace & " MB, needed: " & $fileSize & " MB, difference: " & $diff & " MB.")
Local $Msg = t('NO_FREE_SPACE', CreateArray(StringLeft($sPath, 1), $freeSpace, $fileSize, $diff))
If $silentmode Then terminate($STATUS_FAILED, '', $Msg)

$return = MsgBox($iTopmost + 48 + 2, $name, t('NO_FREE_SPACE', CreateArray($freeSpace, $fileSize, $diff)))
$return = MsgBox($iTopmost + 48 + 2, $name, $Msg)
If $return = 4 Then ; Retry
Return HasFreeSpace($sPath)
ElseIf $return = 3 Then ; Cancel
Expand Down Expand Up @@ -3634,7 +3642,7 @@ Func terminate($status, $fname = '', $sFileType = '')

; Check for updates
If $status <> $STATUS_SILENT Then
If Not $silentmode Then CheckUpdate(True, True)
If Not $silentmode Then CheckUpdate($UPDATEMSG_FOUND_ONLY, True)
SendStats($status, $sFileType)
EndIf

Expand Down Expand Up @@ -4459,11 +4467,14 @@ EndFunc

; Check for new version
; $silent is used for automatic update check, supressing any error and 'no update found' messages
Func CheckUpdate($silent = False, $bCheckInterval = False, $iMode = $UPDATE_ALL)
Func CheckUpdate($silent = $UPDATEMSG_PROMPT, $bCheckInterval = False, $iMode = $UPDATE_ALL)
If @NumParams > 1 And $bCheckInterval And _DateDiff("D", $lastupdate, _NowCalc()) < $updateinterval Then Return
If @NumParams < 3 Then $iMode = $UPDATE_ALL
If @NumParams < 1 Then
$silent = $UPDATEMSG_PROMPT
$iMode = $UPDATE_ALL
EndIf
$ret2 = $silentmode
If $silent Then $silentmode = 1
If $silent == $UPDATEMSG_SILENT Then $silentmode = 1

Local $return = 0, $found = False
Cout("Checking for update")
Expand All @@ -4478,45 +4489,73 @@ Func CheckUpdate($silent = False, $bCheckInterval = False, $iMode = $UPDATE_ALL)

; UniExtract main executable - calling the updater is always necessary, because an executable file cannot overwrite itself while running
If $iMode <> $UPDATE_HELPER Then
If ($aReturn[0])[1] <> FileGetSize(@ScriptFullPath) Then
If ($aReturn[0])[1] <> FileGetSize(@Compiled? @ScriptFullPath: StringReplace(@ScriptFullPath, "au3", "exe")) Then
Cout("Update available")
$found = True
; $Because FFMPEG uses the same update message, we cannot use the %name constant here
If Prompt(48 + 4, 'UPDATE_PROMPT', CreateArray($name, $version, $return, $aReturn[0] > 2? $aReturn[2]: ""), 0) Then
If ShellExecute(CanAccess(@ScriptDir)? $sUpdaterNoAdmin: $sUpdaterNoAdmin, "/main") Then Exit
If Not ShellExecute(CanAccess(@ScriptDir)? $sUpdaterNoAdmin: $sUpdaterNoAdmin, "/main") Then MsgBox($iTopmost + 16, $title, t('UPDATE_FAILED'))
Exit
Else
; If the user does not want to install the main update, let's not bother him with more 'update found' messages
;~ $iMode = $UPDATE_MAIN
EndIf
EndIf
EndIf

; Other files - we can overwrite the files without a seperate updater
If $iMode <> $UPDATE_MAIN Then
Local $sPath, $ret, $size
For $i = 1 To UBound($aReturn) - 1
$ret = $aReturn[$i]
If $ret[0] = "def/" Then ContinueLoop ; User might have own defs, which means different size - we don't want to always display update message
$sPath = @ScriptDir & "\" & $ret[0]
$size = _UpdateGetSize($sPath)

If $size <> $ret[1] Then
If Not Prompt(48 + 4, 'UPDATE_PROMPT', t('UPDATE_TERM_PROGRAM_FILES'), 0) Then ExitLoop
If Not CanAccess($bindir) Then Exit ShellExecute($sUpdater, "/helper")
$found = True
If Not _UpdateHelpers($aReturn) And Not $ret2 Then MsgBox($iTopmost + 16, $title, t('UPDATE_FAILED'))
ExitLoop
EndIf
Next
If CheckUpdateHelpers($aReturn) And Prompt(48 + 4, 'UPDATE_PROMPT', t('UPDATE_TERM_PROGRAM_FILES'), 0) Then
If Not CanAccess($bindir) Then Exit ShellExecute($sUpdater, "/helper")
$found = True
If Not _UpdateHelpers($aReturn) And Not $ret2 Then MsgBox($iTopmost + 16, $title, t('UPDATE_FAILED'))
EndIf
If _UpdateFFmpeg() Then $found = True
EndIf

If $found = False And $silent = False Then MsgBox($iTopmost + 64, $name, t('UPDATE_CURRENT'))
If $found = False Then
SendStats("CheckUpdate", 0)
If $silent == $UPDATEMSG_PROMPT Then MsgBox($iTopmost + 64, $name, t('UPDATE_CURRENT'))
EndIf
Cout("Check for updates finished")

If $silent Then $silentmode = $ret2
If $silent == $UPDATEMSG_SILENT Then $silentmode = $ret2
If IsAdmin() Then RestartWithoutAdminRights()
EndFunc

; Compare program files with server index to find if any file has an updated version available
Func CheckUpdateHelpers($aFiles)
Local $i = 1, $iSize = UBound($aFiles)

While $i < $iSize
$a = $aFiles[$i]
$i += 1
$sPath = @ScriptDir & "\" & $a[0]
If $sPath == @ScriptFullPath Then ContinueLoop

;~ Cout($sPath)
$size = _UpdateGetSize($sPath)
If $size == $a[1] Then ContinueLoop
Cout($a[0] & ": " & $size & " - " & $a[1])

; If it's a file and the size differs, update necessary
If StringRight($a[0], 1) <> "/" Then Return True

; Directory
If Not FileExists($sPath) Then Return True

$aReturn = _UpdateGetIndex($a[0])
If Not IsArray($aReturn) Then ContinueLoop

_ArrayAdd($aFiles, $aReturn)
$iSize = UBound($aFiles)
WEnd

Return False
EndFunc

; Download updated program files and display status
Func _UpdateHelpers($aFiles)
Local $success = True
Local $sText = t('TERM_DOWNLOADING') & "... "

Local $hGUI = GUICreate($title, 434, 130, -1, -1, $WS_POPUPWINDOW, -1, $guimain)
Expand All @@ -4527,7 +4566,7 @@ Func _UpdateHelpers($aFiles)
_GuiSetColor()
GUISetState(@SW_SHOW)

Local $i = 0, $iSize = UBound($aFiles), $iProgress = 0, $sURL, $iBytesReceived, $iBytesTotal
Local $i = 0, $iSize = UBound($aFiles), $iProgress = 0, $success = True, $iBytesReceived

While $i < $iSize
; Update progress
Expand Down Expand Up @@ -4577,6 +4616,7 @@ Func _UpdateHelpers($aFiles)
EndIf
WEnd

SendStats("UpdateHelpers", 1)
GUIDelete($hGUI)
Return $success
EndFunc
Expand Down Expand Up @@ -4654,13 +4694,6 @@ Func _UpdateCheckFailed()
Return False
EndFunc

; Display most recent changelog
Func _ShowChangelog()
$1 = FileGetTime("changelog_minor.txt", 0, 1)
$2 = FileGetTime("changelog.txt", 0, 1)
ShellExecute(@ScriptDir & "\" & ($1 > $2? "changelog_minor.txt": "changelog.txt"))
EndFunc

; Perform special actions after update, e.g. delete files
Func _AfterUpdate()
; Remove unused files
Expand All @@ -4675,17 +4708,21 @@ Func _AfterUpdate()
FileDelete($langdir & "Chinese.ini")
FileDelete($bindir & "MediaInfo64.dll")
FileDelete($bindir & "extract.exe")
FileDelete($bindir & "dmgextractor.jar")
DirRemove($bindir & "unrpa", 1)
DirRemove($bindir ^ "file\contrib\file\5.03\file-5.03"
DirRemove($bindir & "file\contrib\file\5.03\file-5.03", 1)

; Move files
FileMove(@ScriptDir & "\UniExtractUpdater.exe.new", @ScriptDir & "\UniExtractUpdater.exe", 1)
FileMove($bindir & "x86\sqlite3.dll", @ScriptDir)
FileMove($bindir & "x64\sqlite3.dll", @ScriptDir & "\sqlite3_x64.dll")

SendStats("UpdateMain", 1)

; Update helpers
CheckUpdate(True, False, $UPDATE_HELPER)

RestartWithoutAdminRights(" /changelog")
RestartWithoutAdminRights()
EndFunc

; Start updater to download FFmpeg
Expand Down Expand Up @@ -5189,7 +5226,7 @@ Func GUI_OK()
EndFunc ;==>GUI_OK

; Set file to extract and target directory
Func GUI_OK_Set($Msg = False)
Func GUI_OK_Set($bMsg = False)
$file = EnvParse(GUICtrlRead($filecont))
If FileExists($file) Then
If EnvParse(GUICtrlRead($dircont)) == "" Then
Expand All @@ -5198,7 +5235,7 @@ Func GUI_OK_Set($Msg = False)
$outdir = EnvParse(GUICtrlRead($dircont))
EndIf
Return 1
ElseIf $Msg Then
ElseIf $bMsg Then
If $file <> '' Then $file &= ' ' & t('DOES_NOT_EXIST')
MsgBox($iTopmost + 48, $title, t('INVALID_FILE_SELECTED', $file))
EndIf
Expand Down
6 changes: 3 additions & 3 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//If this file is not displayed correctly, open it with notepad++

2.0.0 (2017):
2.0.0 (2018):
Added filter for specific files to file selection dialog (GUI only)
Added option not to display extraction status box
Added option to open destination folder after extraction
Expand Down Expand Up @@ -166,12 +166,12 @@
Replaced tee with mtee/wintee (adds support for unicode and longer filenames, smaller)
Updated translations for English, German, French, Finnish, Portuguese (Portugal), Portuguese (Brazilian), Russian, Japanese (partly), Chinese (Simplified), Swedish, Bulgarian, Ukrainian, Chinese (Traditional), Greek
Updated AutoIt to 3.3.14.1 and source code to fit new AutoIt version
Updated 7zip to 15.14
Updated 7zip to 18.01
Updated innounp to 0.45
Updated KGB archiver to 2 beta 2
Updated lzop to 1.03
Updated PEiD to 0.95; Database files to 2012/04/24
Updated TrID to 2.10; Definitions to 2014/11/04
Updated TrID to 2.10; Definitions to 2018
Updated unrar to 5.31 Beta 1
Updated upx to 3.91
Updated many other extractors to the newest version
Expand Down
5 changes: 3 additions & 2 deletions changelog_minor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ RC 1:
Added support for Mole Box executables
Added support for NScripter version 2 archives using ns2dec
Added support for Smile Game Builder archives
Added support for UNC paths
Added 'Open Log Directory' menu item
Added 'Open Configuration File' menu item
Added support for UNC paths
Added detection support for encrypted fsb files
Added check on start to make sure a language file exists
Fixed MS SFX hotfix extraction
Expand Down Expand Up @@ -49,6 +49,7 @@ RC 1:
Replaced Unreal Engine package extractor with Umodel
Removed redundant 64-bit MediaInfo dll
Removed option to toggle support for game packages from settings GUI
Updated 7zip to 18.01
Updated EnigmaVB unpacker to 0.44, changed logic to use new command line parameter
Updated Exeinfo PE to 0.0.4.8
Updated unrar to 5.50
Expand Down Expand Up @@ -98,8 +99,8 @@ Beta 4:
Fixed .sit extraction
Fixed crash when trying to extract wise installers
Fixed swf extraction ignoring some images and sounds
Updated language files for Portuguese, Russian, Swedish, Italian
Removed DMGExtractor and replaced it with 7z
Updated language files for Portuguese, Russian, Swedish, Italian
Updated 7zip to 16.04
Updated ExeInfoPE to 0.0.4.3
Updated fsbext to 0.3.5
Expand Down
2 changes: 1 addition & 1 deletion helper_binaries_info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Binaries:
(Success Evaluation|Fast Detection|Percentage Indicator)
Name Files Version Features License Author Website

7Zip x86\7z.exe 16.04 o o - GNU LGPL Igor Pavlov http://www.7-zip.org/
7Zip x86\7z.exe 18.01 o o - GNU LGPL Igor Pavlov http://www.7-zip.org/
x64\7z.exe ------- --------- (+ unRAR restriction) ------- -------
x86\7z.dll ------- --------- ------- ------- -------
x64\7z.dll ------- --------- ------- ------- -------
Expand Down
Binary file modified lang/German.ini
Binary file not shown.
2 changes: 1 addition & 1 deletion support/CreateUpdatePackage.au3
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ FileWrite($hFile, _ArrayToString($aSnapshot, "|"))
FileClose($hFile)
FileCopy($sSnapshotFile, $aVersion[0] & ".csv", $FC_OVERWRITE)

; Write data to stdout stream if enabled in options
; Write data to stdout stream
Func Cout($Data)
Local $Output = @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC & @TAB & $Data & @CRLF; & @CRLF
ConsoleWrite($Output)
Expand Down
5 changes: 0 additions & 5 deletions todo.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//If this file is not displayed correctly, open it with notepad++

// Language:
update language files
check control size for other languages

// Unpacker changes:
Expand All @@ -16,13 +15,9 @@ lz
http://tlwiki.org/index.php?title=Tools


// New formats


// Extraction logic updates
Add cleanup function call if necessary
Disable _Run function's pattern search for extractors that do not provide percentage indicators
Use definition files instead of hardcoded mapping if possible
Additional file types for arc_conv, ffmpeg


Expand Down

0 comments on commit 30af0fb

Please sign in to comment.