Skip to content

Commit

Permalink
Merge pull request #4 from Nigh/fmt
Browse files Browse the repository at this point in the history
script reformat
  • Loading branch information
Nigh authored Sep 24, 2023
2 parents a03fc45 + 1dc59ab commit 58997a6
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 74 deletions.
10 changes: 5 additions & 5 deletions app.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SetWorkingDir(A_ScriptDir)
#include prod.ahk

; if you need admin privilege, enable it.
if(0)
if (0)
{
UAC()
}
Expand All @@ -19,19 +19,19 @@ OnExit(trueExit)
; ===============================================================
; your code below

mygui:=Gui("-DPIScale -AlwaysOnTop -Owner +OwnDialogs")
mygui := Gui("-DPIScale -AlwaysOnTop -Owner +OwnDialogs")
myGui.OnEvent("Close", myGui_Close)
mygui.SetFont("s32 Q5", "Verdana")
mygui.Add("Text","w640 Center","AHKv2-AutoUpdate-Template")
mygui.Add("Text", "w640 Center", "AHKv2-AutoUpdate-Template")
mygui.SetFont("s12 Q5", "Verdana")
mygui.Add("Text","w640 Center","v" . version)
mygui.Add("Text", "w640 Center", "v" . version)
mygui.Show()
Return

mygui_Close(thisGui) {
trueExit(0, 0)
}
trueExit(ExitReason, ExitCode){
trueExit(ExitReason, ExitCode) {
ExitApp
}

Expand Down
2 changes: 1 addition & 1 deletion distribution.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ catch as e

try
{
RunWait("powershell -command `"Compress-Archive -Path .\" binaryFilename " -DestinationPath " downloadFilename '"',, "Hide")
RunWait("powershell -command `"Compress-Archive -Path .\" binaryFilename " -DestinationPath " downloadFilename '"', , "Hide")
}
catch as e
{
Expand Down
17 changes: 8 additions & 9 deletions meta.ahk
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

FileEncoding("UTF-8")
appName:="auto upgrader"
version:="0.3.4"
versionFilename:="version.txt"
ahkFilename:="app.ahk"
binaryFilename:="app.exe"
downloadFilename:="app.zip"
downloadUrl:="/Nigh/ahk-autoupdate-template/releases/latest/download/"
update_log:="
appName := "auto upgrader"
version := "0.3.4"
versionFilename := "version.txt"
ahkFilename := "app.ahk"
binaryFilename := "app.exe"
downloadFilename := "app.zip"
downloadUrl := "/Nigh/ahk-autoupdate-template/releases/latest/download/"
update_log := "
(
Replaced compiler binary source
Removed dead GitHub mirror
Expand Down
9 changes: 4 additions & 5 deletions prod.ahk
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@

;@Ahk2Exe-IgnoreBegin
if A_Args.Length > 0
{
for n, param in A_Args
{
RegExMatch(param, "--out=(\w+)", &outName)
if(outName[1]=="version") {
f := FileOpen(versionFilename,"w","UTF-8-RAW")
if (outName[1] == "version") {
f := FileOpen(versionFilename, "w", "UTF-8-RAW")
f.Write(version)
f.Close()
ExitApp
}
}
}
_exit(ThisHotkey){
_exit(ThisHotkey) {
ExitApp
}
_reload(ThisHotkey){
_reload(ThisHotkey) {
Reload
}
Hotkey("F5", _exit)
Expand Down
12 changes: 5 additions & 7 deletions tray.ahk
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@


gotoWebpage_maker(page)
gotoWebpage_maker(page)
{
webpage(*){
webpage(*) {
Run(page)
}
return webpage
Expand All @@ -11,12 +9,12 @@ gotoWebpage_maker(page)
setTray()
{
global version, trueExit
trayExit(*){
trueExit("","")
trayExit(*) {
trueExit("", "")
}
tray := A_TrayMenu
tray.delete
tray.add("v" . version, (*)=>{})
tray.add("v" . version, (*) => {})
tray.add()
tray.add("Github 页面", gotoWebpage_maker("https://github.com/Nigh/ahk-autoupdate-template"))
tray.add("Donate 捐助", gotoWebpage_maker("https://ko-fi.com/xianii"))
Expand Down
91 changes: 45 additions & 46 deletions update.ahk
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@

#include meta.ahk
#include meta.ahk

if FileExist("updater.exe") {
FileDelete("updater.exe")
}
if !FileExist("setting.ini") {
IniWrite(version, "setting.ini", "update", "ver")
}
lastUpdate:=IniRead("setting.ini", "update", "last", 0)
autoUpdate:=IniRead("setting.ini", "update", "autoupdate", 1)
updateMirror:=IniRead("setting.ini", "update", "mirror", 1)
lastUpdate := IniRead("setting.ini", "update", "last", 0)
autoUpdate := IniRead("setting.ini", "update", "autoupdate", 1)
updateMirror := IniRead("setting.ini", "update", "mirror", 1)
IniWrite(updateMirror, "setting.ini", "update", "mirror")
mirrorList:=[
mirrorList := [
"https://github.com",
"https://ghproxy.com/https://github.com",
]
updatemirrorTried:=Array()
today:=A_MM . A_DD
if(autoUpdate) {
if(lastUpdate!=today) {
updatemirrorTried := Array()
today := A_MM . A_DD
if (autoUpdate) {
if (lastUpdate != today) {
get_latest_version()
} else {
version_str:=IniRead("setting.ini", "update", "ver", "0")
if(version_str!=version) {
version_str := IniRead("setting.ini", "update", "ver", "0")
if (version_str != version) {
IniWrite(version, "setting.ini", "update", "ver")
MsgBox(version . "`nUpdate log`n`n" . update_log)
}
}
} else {
TrayTip "Update Skiped`n`nCurrent version`nv" version,"Update", 1
TrayTip "Update Skiped`n`nCurrent version`nv" version, "Update", 1
}

updateTimeout(*)
Expand All @@ -37,16 +36,16 @@ updateTimeout(*)
Return
}

get_latest_version(){
get_latest_version() {
global
req := ComObject("MSXML2.ServerXMLHTTP")
updateMirror:=IsNumber(updateMirror)?updateMirror+0:1
if(updateMirror > mirrorList.Length or updateMirror <= 0) {
updateMirror := IsNumber(updateMirror) ? updateMirror + 0 : 1
if (updateMirror > mirrorList.Length or updateMirror <= 0) {
updateMirror := 1
}
updateSite:=mirrorList[updateMirror]
updateSite := mirrorList[updateMirror]
; MsgBox("GET:" . mirrorList[updateMirror] . downloadUrl . versionFilename)
updateReqDone:=0
updateReqDone := 0
req.open("GET", mirrorList[updateMirror] . downloadUrl . versionFilename, true)
req.onreadystatechange := updateReady
req.send()
Expand All @@ -63,16 +62,16 @@ tryNextUpdate()
For k, v in mirrorList
{
local tested
tested:=False
tested := False
for , p in updatemirrorTried
{
if(p=k) {
tested:=True
if (p = k) {
tested := True
break
}
}
if not tested {
updateMirror:=k
updateMirror := k
get_latest_version()
Return
}
Expand All @@ -81,40 +80,40 @@ tryNextUpdate()
}
; with MSXML2.ServerXMLHTTP method, there would be multiple callback called

updateReady(){
updateReady() {
global req, version, updateReqDone, downloadUrl, downloadFilename, mirrorList, updateMirror, updatemirrorTried
; log("update req.readyState=" req.readyState, 1)
if(req.readyState != 4){ ; Not done yet.
return
if (req.readyState != 4) { ; Not done yet.
return
}
if(updateReqDone){
if (updateReqDone) {
; log("state already changed", 1)
Return
}
updateReqDone := 1
; log("update req.status=" req.status, 1)
if(req.status == 200 and StrLen(req.responseText)<=64){ ; OK.
if (req.status == 200 and StrLen(req.responseText) <= 64) { ; OK.
SetTimer(updateTimeout, 0)
; MsgBox % "Latest version: " req.responseText
; MsgBox % "Latest version: " req.responseText
RegExMatch(version, "(\d+)\.(\d+)\.(\d+)", &verNow)
RegExMatch(req.responseText, "^(\d+)\.(\d+)\.(\d+)$", &verNew)
if((verNew[1]>verNow[1])
|| (verNew[1]==verNow[1] && ((verNew[2]>verNow[2])
|| (verNew[2]==verNow[2] && verNew[3]>verNow[3])))){
result:=MsgBox("Found new version " . req.responseText . ", download?", "Download", 0x2024)
if result = "Yes"
{
try {
Download(mirrorList[updateMirror] . downloadUrl . downloadFilename, "./" . downloadFilename)
MsgBox("Download finished`nProgram will restart now",, "T3")
todayUpdated()
FileInstall("updater.exe", "updater.exe", 1)
Run("updater.exe")
ExitApp
} catch as e {
TrayTip "An exception was thrown!`nSpecifically: " . e.Message, "upgrade failed", 0x3
}
}
if ((verNew[1] > verNow[1])
|| (verNew[1] == verNow[1] && ((verNew[2] > verNow[2])
|| (verNew[2] == verNow[2] && verNew[3] > verNow[3])))) {
result := MsgBox("Found new version " . req.responseText . ", download?", "Download", 0x2024)
if result = "Yes"
{
try {
Download(mirrorList[updateMirror] . downloadUrl . downloadFilename, "./" . downloadFilename)
MsgBox("Download finished`nProgram will restart now", , "T3")
todayUpdated()
FileInstall("updater.exe", "updater.exe", 1)
Run("updater.exe")
ExitApp
} catch as e {
TrayTip "An exception was thrown!`nSpecifically: " . e.Message, "upgrade failed", 0x3
}
}
} else {
todayUpdated()
}
Expand All @@ -123,6 +122,6 @@ updateReady(){
}
}

todayUpdated(){
todayUpdated() {
IniWrite(A_MM . A_DD, "setting.ini", "update", "last")
}
2 changes: 1 addition & 1 deletion updater.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SetWorkingDir(A_ScriptDir)

#include meta.ahk

RunWait('powershell -command "Expand-Archive -Force ' downloadFilename ' ."',,"Hide")
RunWait('powershell -command "Expand-Archive -Force ' downloadFilename ' ."', , "Hide")
FileDelete(downloadFilename)
Run(binaryFilename)

Expand Down

0 comments on commit 58997a6

Please sign in to comment.