Skip to content

Commit

Permalink
Add support for portable LibreWolf
Browse files Browse the repository at this point in the history
  • Loading branch information
ltguillaume committed Jan 24, 2022
1 parent 92884de commit 3def8ab
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
57 changes: 41 additions & 16 deletions LibreWolf-WinUpdater.ahk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; LibreWolf WinUpdater - https://github.com/ltGuillaume/LibreWolf-WinUpdater
;@Ahk2Exe-SetFileVersion 1.0.0
;@Ahk2Exe-SetFileVersion 1.1.0

;@Ahk2Exe-Bin Unicode 64*
;@Ahk2Exe-SetDescription LibreWolf WinUpdater
Expand All @@ -11,6 +11,7 @@

Global ExeFile = "librewolf.exe"
Global IniFile = A_ScriptDir "\LibreWolf-WinUpdater.ini"
Global IsPortable

; Strings
_Title = LibreWolf WinUpdater
Expand All @@ -23,6 +24,7 @@ _DownloadSetupError = Could not download the LibreWolf setup file.
_SilentUpdateError = Silent update did not complete.`nDo you want to run the interactive installer?
_NewVersionFound = A new version has been found.`nStart the update by closing LibreWolf.
_NoNewVersion = No new version found
_ExtractionError = Could not extract archive of portable version.
_IsUpdated = LibreWolf has just been updated from
_To = to

Expand All @@ -37,7 +39,13 @@ If !A_IsCompiled
Menu, Tray, Icon, %A_ScriptDir%\LibreWolf-WinUpdater.ico

; Get the path to LibreWolf
IniRead, Path, %IniFile%, Settings, Path, %ProgramFiles%\LibreWolf\%ExeFile%
If FileExist(A_ScriptDir "\LibreWolf-Portable.exe") {
; Portable LibreWolf is present
IsPortable := True
Path := A_ScriptDir "\LibreWolf\librewolf.exe"
} Else
IniRead, Path, %IniFile%, Settings, Path, %ProgramFiles%\LibreWolf\%ExeFile%

CheckPath:
If !FileExist(Path) {
MsgBox, 48, %_Title%, %_GetPathError%
Expand Down Expand Up @@ -67,9 +75,9 @@ If !File

; Compare versions
ReleaseInfo := File.Read(64)
;MsgBox, Release = %ReleaseInfo% | Version = %Version%
;MsgBox, Release = %ReleaseInfo% | Version = %CurrentVersion%
If InStr(ReleaseInfo, CurrentVersion) {
IniWrite, %_NoNewVersion%, %IniFile%, Data, LastResult
IniWrite, %_NoNewVersion%, %IniFile%, Log, LastResult
Exit
}

Expand All @@ -82,19 +90,30 @@ If ErrorLevel {
}

; Get setup file URL
Download := File.Read(4096)
SetupFile = LibreWolf-Update.exe
RegExMatch(Download, "i)https://gitlab.com/librewolf-community/browser/windows/uploads/.*?\.exe", DownloadUrl)
;MsgBox, Downloading`n%DownloadUrl%`nto`n%SetupFile%
If !DownloadUrl
Download := File.Read(4096)
Extension := IsPortable ? "zip" : "exe"
SetupFile := "LibreWolf-Update." Extension
RegExMatch(Download, "i)" Extension """,""url"":""(https://gitlab.com/librewolf-community/browser/windows/uploads/.*?\." Extension ")", DownloadUrl)
;MsgBox, Downloading`n%DownloadUrl1%`nto`n%SetupFile%
If !DownloadUrl1
Die(_FindUrlError)

; Download setup file
UrlDownloadToFile, %DownloadUrl%, %SetupFile%
UrlDownloadToFile, %DownloadUrl1%, %SetupFile%
If !FileExist(SetupFile)
Die(_DownloadSetupError)

; Run setup
; Extract archive of portable version
If IsPortable {
RunWait, powershell.exe Expand-Archive ""%SetupFile%"" LibreWolf-Extracted
If ErrorLevel
Die(_ExtractionError)
Loop, Files, LibreWolf-Extracted\*, D
FileMoveDir, %A_LoopFilePath%, %A_ScriptDir%, 2
Goto, Report
}

; Or run silent setup
RunWait, %SetupFile% /S,, UseErrorLevel
If ErrorLevel {
MsgBox, 52, %_Title%, %_SilentUpdateError%
Expand All @@ -103,27 +122,33 @@ If ErrorLevel {
}

; Report update if completed
Report:
FileGetVersion, NewVersion, %Path%
StringLeft, NewVersion, NewVersion, InStr(NewVersion, ".",, -1) - 1
If NewVersion = %CurrentVersion%
Exit
IniWrite, %CurrentVersion%, %IniFile%, Data, LastUpdateFrom
IniWrite, %NewVersion%, %IniFile%, Data, LastUpdateTo
IniWrite, %_IsUpdated% v%CurrentVersion% %_To% v%NewVersion%, %IniFile%, Data, LastResult
FormatTime, CurrentTime
IniWrite, %CurrentTime%, %IniFile%, Log, LastUpdate
IniWrite, %CurrentVersion%, %IniFile%, Log, LastUpdateFrom
IniWrite, %NewVersion%, %IniFile%, Log, LastUpdateTo
IniWrite, %_IsUpdated% v%CurrentVersion% %_To% v%NewVersion%, %IniFile%, Log, LastResult
TrayTip,, %_IsUpdated%`nv%CurrentVersion% %_To%`nv%NewVersion%,, 16
Sleep, 10000

; Clean up
Exit:
FormatTime, CurrentTime
IniWrite, %CurrentTime%, %IniFile%, Data, LastRun
IniWrite, %CurrentTime%, %IniFile%, Log, LastRun
Sleep, 2000
If ReleaseFile
FileDelete, %ReleaseFile%
If SetupFile
FileDelete, %SetupFile%
If IsPortable
FileDelete, LibreWolf-Extracted

Die(Error) {
IniWrite, %Error%, %IniFile%, Data, LastResult
IniWrite, %Error%, %IniFile%, Log, LastResult
If (A_Args[1] <> "/Scheduled")
MsgBox, 48, %_Title%, %Error%
Exit
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ An attempt to make updating LibreWolf for Windows much easier.

## Getting started
1. Having installed LibreWolf, you can run `LibreWolf-WinUpdater.exe` to check for a new version, then download and install it immediately. If LibreWolf is running, the updater will notify you of the new version, and update as soon as you close the browser (again, notifying you). The last result can be found in `LibreWolf-WinUpdater.ini`.
If you place `LibreWolf-WinUpdater.exe` in the same folder as `LibreWolf-Portable.exe`, it will update the __portable version__, too.
2. Afterwards, you can right-click on `ScheduledTask-Create.ps1` and choose `Run with PowerShell` to create a scheduled task that checks for updates every 4 hours, and at logon. When run from a scheduled task, error messages will only be saved in `LibreWolf-WinUpdater.ini` (no dialogs will be shown). The updater will now run as administrator, so that the installer can be run silently.
3. You can remove the scheduled task by running `ScheduledTask-Remove.ps1`.

Expand Down

0 comments on commit 3def8ab

Please sign in to comment.