#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=X:\AutoIt\U2update.exe #AutoIt3Wrapper_UseUpx=y #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_UseX64=n #AutoIt3Wrapper_Run_Au3Stripper=y #AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs U2update.exe [CLD] XyWWWeb Jumbo U2 Update Utility #ce Global $sRevDate = "2024-08-08" #include ".\CryptoNG\CryptoNG.au3" ;; Credit: TheXman #include #include #include #include #include #include Global $sUserU2Dir = "", $sUserU2 = "", $sDummyU2 = "" Global $sUpdatesDir = "" Global $bNoZip = 1, $sArg = "" Global $bDoUpdate = 0, $bZippedUpD = 0, $bZippedUsr = 0 If $CmdLine[0] > 0 Then $sArg = $CmdLine[1] If $CmdLine[0] = 0 Or $sArg = "/?" Or $sArg = "-?" Or $sArg = "/h" _ Or $sArg = "-h" Or $sArg = "--help" Then Exit _ShowHelp() If $sArg = "/c" Then $bDoUpdate = 0; Check for update If $sArg = "/d" Or $sArg = "/u" Then $bDoUpdate = 1; Download update If $sArg = "/a" Then $bDoUpdate = 2; Apply update $sUserU2Dir = @ScriptDir If StringRight($sUserU2Dir, 1) = "\" Then $sUserU2Dir = StringTrimRight($sUserU2Dir, 1) $sUpdatesDir = $sUserU2Dir & "\U2UPDATE" _CreateDir($sUpdatesDir, "Updates directory") _CreateDir($sUpdatesDir & "\U2EXTRAS", "U2EXTRAS staging subdirectory") $sUserU2 = $sUpdatesDir & "\XYWWWEB.U2" Global $sZipUtil = $sUpdatesDir & "\7za.exe" If FileExists($sZipUtil) Then $bNoZip = 0 FileInstall("X:\xy4\7-Zip\7za.exe", $sZipUtil) Global $sU2Zip = $sUpdatesDir & "\XYWWEBU2.ZIP" Global $sExtrasZip = $sUpdatesDir & "\U2EXTRAS.ZIP" Global $sBaseURL = "https://ammaze.net/xywwweb/dls/" Global $xHashLa, $xU2chks Global $sTempDir, $aTmp, $sTmp0, $sTmp1 Global $h0, $h1, $h1a, $h2, $hI Global $sZipUpTime = StringRight(@YEAR, 2) & @MON & @MDAY & "T" & @HOUR & @MIN & @SEC $sTempDir = _TempFile($sUpdatesDir, "x", ".tmp", 7) _CreateDir($sTempDir, "temporary directory") $sDummyU2 = $sTempDir & "\DUMMY.U2" If FileExists($sUserU2) Then FileCopy($sUserU2, $sDummyU2, $FC_OVERWRITE) ConsoleWrite("Checking for updates...") $hI = InetGet($sBaseURL & "XYWWEBU2.ZIP", $sU2Zip, $INET_FORCERELOAD) If Not $hI Then _ConsoleEraseLine("Checking for updates...") ConsoleWrite("Cleaning up...") _CleanUp() _ConsoleEraseLine("Cleaning up...") ConsoleWrite(@CRLF & "Download failed! [XYWWEBU2.ZIP]" & @CRLF & _ "Check your Internet connection" & @CRLF) Exit -1 EndIf InetClose($hI) $hI = "" RunWait("cmd.exe /c " & $sZipUtil & " e -o" & $sTempDir & " -y " & $sU2Zip & " >nul", $sUpdatesDir, @SW_HIDE) $h0 = FileOpen($sTempDir & "\XYWWWEB.U2", $FO_READ) If $h0 < 0 Then _ConsoleEraseLine("Checking for updates...") ConsoleWrite("Cleaning up...") _CleanUp() _ConsoleEraseLine("Cleaning up...") ConsoleWrite(@CRLF & "Unexpected error opening file [" & $sTempDir & "\XYWWWEB.U2]" & @CRLF) Exit -2 EndIf $sTmp0 = FileRead($h0) FileClose($h0) If StringRight($sTmp0, 1) <> Chr(26) Then $sTmp0 &= Chr(26) $h1 = FileOpen($sTempDir & "\XYWWWEB.U2", $FO_OVERWRITE + $FO_BINARY) If $h1 < 0 Then _ConsoleEraseLine("Checking for updates...") ConsoleWrite("Cleaning up...") _CleanUp() _ConsoleEraseLine("Cleaning up...") ConsoleWrite(@CRLF & "Unexpected error opening file [" & $sTempDir & "\XYWWWEB.U2]" & @CRLF) Exit -3 EndIf FileWrite($h1, $sTmp0) FileClose($h1) EndIf If FileExists($sDummyU2) Then $h1a = FileOpen($sDummyU2, $FO_READ) If $h1a < 0 Then _ConsoleEraseLine("Checking for updates...") ConsoleWrite("Cleaning up...") _CleanUp() _ConsoleEraseLine("Cleaning up...") ConsoleWrite(@CRLF & "Unexpected error opening file [" & $sDummyU2 & "]" & @CRLF) Exit -4 EndIf $sTmp1 = FileRead($h1a) FileClose($h1a) If StringRight($sTmp1, 1) <> Chr(26) Then If StringInStr($sTmp1, Chr(26) & Chr(26)) Then $aTmp = StringSplit($sTmp1, Chr(26) & Chr(26), $STR_ENTIRESPLIT) $sTmp1 = $aTmp[1] & Chr(26) EndIf $h2 = FileOpen($sDummyU2, $FO_OVERWRITE + $FO_BINARY) If $h2 < 0 Then _ConsoleEraseLine("Checking for updates...") ConsoleWrite("Cleaning up...") _CleanUp() _ConsoleEraseLine("Cleaning up...") ConsoleWrite(@CRLF & "Unexpected error opening file [" & $sDummyU2 & "]" & @CRLF) Exit -5 EndIf FileWrite($h2, $sTmp1) FileClose($h2) EndIf $xU2chks = _CryptoNG_HashFile($CNG_BCRYPT_SHA256_ALGORITHM, $sTempDir & "\XYWWWEB.U2") $xHashLa = _CryptoNG_HashFile($CNG_BCRYPT_SHA256_ALGORITHM, $sDummyU2) If $xHashLa = $xU2chks Then _ConsoleEraseLine("Checking for updates...") If $bDoUpdate = 2 Then _ZipUpUserOldU2() _ZipUpApplyUpdates() _ConsoleWriteANSI("Done!" & @CRLF) If $bZippedUsr Then ConsoleWrite("Older U2 files were backed up to ") _ConsoleWriteANSI($sUserU2Dir & "\XYWWEBU2-" & $sZipUpTime & _ ".ZIP" & @CRLF) EndIf ConsoleWrite("Remember to re-LOAD XYWWWEB.U2 (or restart XyWrite)!" & @CRLF) Exit EndIf ConsoleWrite("Cleaning up...") _CleanUp() _ConsoleEraseLine("Cleaning up...") If $bDoUpdate < 2 Then _ _ConsoleWriteANSI("The XyWWWeb Jumbo U2 is up to date!" & @CRLF) Exit 0 EndIf EndIf ; Update available ; ---------------- If $bDoUpdate < 1 Then _ConsoleEraseLine("Checking for updates...") ConsoleWrite("Cleaning up...") _CleanUp() _CleanUpUpDatesDir() _ConsoleEraseLine("Cleaning up...") _ConsoleWriteANSI("A U2 update is available. To download it, command:" & @CRLF, 33, 7) _ConsoleWriteANSI(" " & @ScriptName & " /D" & @CRLF) Exit 1 EndIf ;; Copy user's existing setup if .\U2UPDATE is "empty" $sTmp0 = "changelog.pdf|QUICK-U2.TXT|readme-u2.pdf|REG-READ.ME|XYWWEBU2.REG|XYWWWEB.INF|XYWWWEB.U2" $aTmp = StringSplit($sTmp0, "|") For $i = 1 To $aTmp[0] If Not FileExists($sUpdatesDir & "\" & $aTmp[$i]) Then If FileExists($sUserU2Dir & "\" & $aTmp[$i]) Then FileCopy($sUserU2Dir & "\" & $aTmp[$i], $sUpdatesDir) EndIf Sleep(30) Next ;; Back up existing U2 setup If FileExists($sUpdatesDir & "\XYWWWEB.U2") Then _ZipUpOldUpdates() ;; We are done with DUMMY.U2, so delete it FileDelete($sDummyU2) ;; Copy new U2 files to U2 updates directory FileCopy($sTempDir & "\*", $sUpdatesDir, $FC_OVERWRITE) ;; Download U2EXTRAS.ZIP $hI = InetGet($sBaseURL & "U2EXTRAS.ZIP", $sExtrasZip, 1, 0) If Not $hI Then ConsoleWrite("Cleaning up...") _CleanUp() _ConsoleEraseLine("Cleaning up...") ConsoleWrite(@CRLF & "Download failed!" & _ @CRLF & "Check your Internet connection" & @CRLF) Exit -5 EndIf InetClose($hI) _ConsoleEraseLine("Checking for updates...") ConsoleWrite("Updating files") ;; Create .\U2EXTRAS subdirectory, if necessary ;; Unzip U2EXTRAS.ZIP _CreateDir($sUserU2Dir & "\U2EXTRAS", "U2EXTRAS subdirectory") RunWait("cmd.exe /c " & $sZipUtil & " e -o" & $sUpdatesDir & _ "\U2EXTRAS -y " & $sExtrasZip & " >nul &(for /f %a in ('dir/b " & _ $sUpdatesDir & "\U2EXTRAS') do if exist " & $sUpdatesDir & _ "\%a del/f/q " & $sUpdatesDir & "\%a) >nul", $sUpdatesDir, @SW_HIDE) ;; Apply Update (arg /A) If $bDoUpdate = 2 Then _ZipUpUserOldU2() _ZipUpApplyUpdates() ConsoleWrite("Cleaning up...") _CleanUp() _ConsoleEraseLine("Cleaning up...") _ConsoleWriteANSI("Done!" & @CRLF) If $bZippedUsr Then ConsoleWrite("Older U2 files were backed up to ") _ConsoleWriteANSI($sUpdatesDir & "\XYWWEBU2-" & $sZipUpTime & _ ".ZIP" & @CRLF) EndIf ConsoleWrite("Remember to re-LOAD XYWWWEB.U2 (or restart XyWrite)!" _ & @CRLF) Exit 3 EndIf ;; Closing instructions _ConsoleEraseLine("Updating files") ConsoleWrite("Cleaning up...") _CleanUp() _ConsoleEraseLine("Cleaning up...") _ConsoleWriteANSI("Update complete!" & @CRLF) ConsoleWrite("New files are saved in ") _ConsoleWriteANSI($sUpdatesDir) ConsoleWrite(" (they are NOT ""installed"")" & @CRLF) If $bZippedUpD Then ConsoleWrite("Older files were backed up to ") _ConsoleWriteANSI($sUpdatesDir & "\XYWWEBU2-" & $sZipUpTime & ".ZIP" & @CRLF) EndIf _ConsoleWriteANSI("To apply (""install"") the update, command:" & @CRLF, 96, 40) _ConsoleWriteANSI(" " & @ScriptName & " /A" & @CRLF) _ConsoleWriteANSI("or manually copy the new files in " & $sUserU2Dir & "\U2UPDATE to the XyWrite program" & @CRLF & " directory, overwriting the existing files. Also, copy subdirectory" & @CRLF & " " & $sUserU2Dir & "\U2EXTRAS to the XyWrite directory." & @CRLF, 96, 40) _ConsoleWriteANSI("If XyWrite is running, remember to re-LOAD XyWWWeb.U2 (or QUIT and restart XyWrite)!" & @CRLF, 96, 40) ConsoleWrite("If you are a first-time U2 user, please ") _ConsoleWriteANSI("READ ""readme-u2.pdf""." & @CRLF) ConsoleWrite("At a minimum, STARTUP.INT must include lines like:" & @CRLF & " BX load XYWWWEB.U2Q2 ;*;" & @CRLF & " JM 2.XyWebU2.intQ2 ;*;" & @CRLF & "where ""BX "", ""JM "" and ""Q2 "" are function calls created by commanding, e.g., ""PFUN BX""." & @CRLF & "Also, you MUST configure, in your .KBD file, a ""Helpkey"" to launch U2 routines." & @CRLF) _ConsoleWriteANSI("For detailed information on the Jumbo U2, see ""readme-u2.pdf""," & @CRLF & " and be sure to visit XyWWWeb at !" & @CRLF) Exit 2 ; Function Definitions ; -------------------- Func _CleanUp() Local $c = 0 While FileExists($sTempDir) RunWait("cmd.exe /c cd/d " & $sUpdatesDir & " &del/f/q " & $sTempDir & "\* >nul 2>nul &rd/s/q " & $sTempDir & " >nul 2>nul", $sUpdatesDir, @SW_HIDE) If $c > 300 Then ExitLoop Sleep(200) $c += 1 WEnd If $bNoZip Then FileDelete($sZipUtil) Return EndFunc ;==>CleanUp Func _CleanUpUpDatesDir() Local $c = 0 _ConsoleEraseLine(50) While FileExists($sUpdatesDir) RunWait("cmd.exe /c cd/d " & $sUserU2Dir & " &del/f/q " & $sUpdatesDir & "\* >nul 2>nul &rd/s/q " & $sUpdatesDir & " >nul 2>nul", $sUserU2Dir, @SW_HIDE) If $c > 300 Then ExitLoop Sleep(200) $c += 1 WEnd Return EndFunc ;==>_CleanUpUpDatesDir Func _ConsoleEraseLine($vIn) ; Erase one line (only) from console output ; Line to be erased must not terminate with Cr|Lf! If StringRight(String($vIn), 1) = @LF Then Return Local $sOut = "" If Not IsInt($vIn) Then $vIn = StringLen(String($vIn)) For $i = 1 To $vIn $sOut &= Chr(8) & " " & Chr(8) Next ConsoleWrite($sOut) Return EndFunc ;==>_ConsoleErase Func _ConsoleWriteANSI($sTxt, $iFg1 = 33, $iBg1 = 1, $iFg0 = 22, $iBg0 = 0) ; Write colorful text to the console ("TYPE tmp_file" method) ; Default color - Bright Yellow on Black background Local $h, $sTmpFn = _TempFile(@ScriptDir) $h = FileOpen($sTmpFn, $FO_BINARY + $FO_OVERWRITE) If $h < 0 Then Return ConsoleWrite($sTxt) If Not FileWrite($h, Chr(27) & "[" & $iFg1 & "m" & Chr(27) & _ "[" & $iBg1 & "m" & $sTxt & Chr(27) & "[" & $iFg0 & "m" & _ Chr(27) & "[" & $iBg0 & "m") Then FileClose($h) Return ConsoleWrite($sTxt) EndIf FileClose($h) _RunDos("type " & $sTmpFn) FileDelete($sTmpFn) EndFunc ;==>_ConsoleWriteANSI Func _CreateDir($sDirName, $sLabel = $sDirName) Local $sMsg = "" If Not FileExists($sDirName) Then If Not DirCreate($sDirName) Then _CleanUp() _ConsoleEraseLine(50) $sMsg = "Error creating " & $sLabel & "!" If $sDirName <> $sLabel Then $sMsg &= "[" & $sDirName & "]" _ConsoleWriteANSI($sMsg & @CRLF, 96, 40) Exit 2 EndIf EndIf EndFunc ;==>_CreateDir Func _ShowHelp() _ConsoleWriteANSI(@ScriptName & " -- C.L.Distefano rev. " & $sRevDate & @CRLF) _ConsoleWriteANSI("Update the XyWWWeb Jumbo U2 to the latest release" & @CRLF) ConsoleWrite("Requires Windows XP SP3 or later and an Internet connection" & @CRLF) _ConsoleWriteANSI(">>> Locate " & @ScriptName & " in XyWrite's main program directory <<<" & @CRLF, 96, 40) _ConsoleWriteANSI(@ScriptName & " saves updated U2 files to a ""staging"" subdirectory," & @CRLF & " .\U2UPDATES (created by " & @ScriptName & ", if necessary). Updates" & @CRLF & " are NOT applied unless and until you either copy them manually" & @CRLF & " to Editor's directory or issue ""U2update.exe /A"" (see Usage, below)" & @CRLF, 96, 40) ConsoleWrite("Usage:" & @CRLF & "1) Check for U2 updates:" & @CRLF) _ConsoleWriteANSI(" " & @ScriptName & " /C" & @CRLF, 40, 1) ConsoleWrite("2) Check for updates and download update if available" & @CRLF) _ConsoleWriteANSI(" " & @ScriptName & " /D" & @CRLF, 40, 1) ConsoleWrite("3) Check for, download and APPLY updates" & @CRLF) _ConsoleWriteANSI(" " & @ScriptName & " /A" & @CRLF, 40, 1) ConsoleWrite("4) Show this Help:" & @CRLF) _ConsoleWriteANSI(" " & @ScriptName & " /?|/H", 40, 1) ConsoleWrite(" (or no arg)" & @CRLF) ConsoleWrite("Note: Before updating, " & @ScriptName & " backs up existing U2 files" & @CRLF & " to XYWWEBU2-T.ZIP" & @CRLF) _ConsoleWriteANSI("For detailed info on the Jumbo U2, visit XyWWWeb at" & @CRLF) _ConsoleWriteANSI(" " & @CRLF) Return EndFunc ;==>_ShowHelp Func _ZipUpApplyUpdates() ;; Back up user's installed U2 files and apply new updates Local $sTmp = "changelog.pdf|QUICK-U2.TXT|readme-u2.pdf|REG-READ.ME|XYWWEBU2.REG|XYWWWEB.INF|XYWWWEB.U2" Local $aTmp = StringSplit($sTmp, "|") _ConsoleEraseLine(50) ConsoleWrite("Applying updates...") _ZipUpUserOldU2() For $i = 1 To $aTmp[0] FileCopy($sUpdatesDir & "\" & $aTmp[$i], $sUserU2Dir, $FC_OVERWRITE) Sleep(30) Next If Not FileExists($sUserU2Dir & "\U2EXTRAS") Then _CreateDir($sUserU2Dir & "\U2EXTRAS", "U2EXTRAS subdirectory") FileCopy($sUpdatesDir & "\U2EXTRAS\*", $sUserU2Dir & "\U2EXTRAS", $FC_OVERWRITE) RunWait("cmd.exe /c (for /f %a in ('dir/b " & $sUserU2Dir & "\U2EXTRAS') do if exist " & $sUpdatesDir & "\%a del/f/q " & $sUpdatesDir & "\%a) >nul 2>nul", $sUpdatesDir, @SW_HIDE) _ConsoleEraseLine("Applying updates...") EndFunc ;==>_ZipUpApplyUpdates Func _ZipUpOldUpdates() ;; Back up existing U2 update files If FileGetSize($sUpdatesDir & "\XYWWWEB.U2") > 1024 Then RunWait("cmd.exe /c (" & $sZipUtil & " a " & $sUpdatesDir & "\XYWWEBU2-" & $sZipUpTime & ".ZIP " & $sUpdatesDir & "\XYWWWEB.U2 " & $sUpdatesDir & "\XYWWWEB.INF " & $sUpdatesDir & "\XYWWEBU2.REG " & $sUpdatesDir & "\changelog.pdf " & $sUpdatesDir & "\REG-READ.ME " & $sUpdatesDir & "\readme-u2.pdf " & $sUpdatesDir & "\QUICK-U2.TXT >nul 2>nul)", $sUpdatesDir, @SW_HIDE) $bZippedUpD = 1 EndIf EndFunc ;==>_ZipUpOldUpdates Func _ZipUpUserOldU2() ;; Back up user's installed U2 files If FileExists($sUserU2Dir & "\XYWWWEB.U2") Then If FileGetSize($sUserU2Dir & "\XYWWWEB.U2") > 1024 Then RunWait("cmd.exe /c (" & $sZipUtil & " a " & $sUserU2Dir & "\XYWWEBU2-" & $sZipUpTime & ".ZIP " & $sUserU2Dir & "\XYWWWEB.U2 " & $sUserU2Dir & "\XYWWWEB.INF " & $sUserU2Dir & "\XYWWEBU2.REG " & $sUserU2Dir & "\changelog.pdf " & $sUserU2Dir & "\REG-READ.ME " & $sUserU2Dir & "\readme-u2.pdf " & $sUserU2Dir & "\QUICK-U2.TXT >nul 2>nul)", $sUpdatesDir, @SW_HIDE) $bZippedUsr = 1 EndIf EndIf EndFunc ;==>_ZipUpUserOldU2 ;