Skip to content

Commit

Permalink
v2 beta.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Nigh committed Nov 3, 2021
1 parent 1a9849d commit 70ac70b
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 120 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# AHK auto update template
# AHK v2.0 auto update template

![](logo.png)

`logo.png`(modified) from https://www.pngrepo.com/

`icon.ico` is converted from the `logo.png` at https://cloudconvert.com/png-to-ico with `48x48` dimension

> tested on Autohotkey 1.1.33.07
> tested on Autohotkey 2.0-beta.3
## how it works

Expand All @@ -17,17 +17,18 @@ Then the script would download the file and check if there is newer version. If
## Setup

### `update.ahk`
- set `version` in `outputVersion()`
- set `downloadUrlBase` to your release URL
- `binaryFilename` should be same as the name in `distribution.ahk`
- the `update_log` would be shown once through the `msgbox` after success update

### `meta.ahk`
- set `version`
- set `ahkFilename` to your script name, it would compile `%ahkFilename%.ahk` to `%binaryFilename%.exe`
- set `downloadUrl` to your github release URL

### `distribution.ahk`
- set `appName` to your script name, it would compile `%appName%.ahk` to `%appName%.exe`
> The **requirements** of using the `distribution.ahk` is:
; `autohotkey` in PATH
; `ahk2exe` in PATH
; `mpress` in `ahk2exe` path
; # ahk2exe.exe in PATH [1.1.34.00_Beta_8]
; # AutoHotkey64.exe in PATH [v2.0-beta.3]
; # mpress in ahk2exe path

### `icon.ico`
- put your icon in the same directory.
Expand Down
49 changes: 28 additions & 21 deletions app.ahk
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetWorkingDir(A_ScriptDir)
#SingleInstance force
#include meta.ahk

;@Ahk2Exe-IgnoreBegin
_exit(ThisHotkey){
ExitApp
}
_reload(ThisHotkey){
Reload
}
Hotkey("F5", _exit)
Hotkey("F6", _reload)
;@Ahk2Exe-IgnoreEnd

outputVersion()

if A_IsCompiled
Expand All @@ -17,46 +27,43 @@ if(0)
UAC()
}
#include update.ahk
menu()
OnExit, trueExit
setTray()
OnExit(trueExit)

; ===============================================================
; ===============================================================
; your code below

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

GuiClose:
ExitApp
trueExit:
ExitApp
trueExit(ExitReason, ExitCode){
ExitApp
}

#If debug
F5::ExitApp
F6::Reload
#If
; ===============================================================
; ===============================================================

UAC()
{
full_command_line := DllCall("GetCommandLine", "str")
if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{

if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)")) {
try
{
if A_IsCompiled
Run *RunAs "%A_ScriptFullPath%" /restart
Run '*RunAs "' A_ScriptFullPath '" /restart'
else
Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
Run '*RunAs "' A_AhkPath '" /restart "' A_ScriptFullPath '"'
}
ExitApp
}
}
#include menu.ahk
#include tray.ahk
72 changes: 45 additions & 27 deletions distribution.ahk
Original file line number Diff line number Diff line change
@@ -1,61 +1,79 @@
; # requirements:
; # autohotkey in PATH
; # ahk2exe in PATH
; # ahk2exe.exe in PATH [1.1.34.00_Beta_8]
; # AutoHotkey64.exe in PATH [v2.0-beta.3]
; # mpress in ahk2exe path

#SingleInstance, Force
SetWorkingDir, %A_ScriptDir%
#SingleInstance Force
SetWorkingDir(A_ScriptDir)

#include meta.ahk

if FileExist(binaryFilename)
{
FileDelete, % binaryFilename
FileDelete(binaryFilename)
}

if FileExist(versionFilename)
{
FileDelete, % versionFilename
FileDelete(versionFilename)
}

if InStr(FileExist("dist"), "D")
{
FileRemoveDir, dist, 1
If (ErrorLevel)
try
{
MsgBox, % "removing dist`nERROR CODE=" ErrorLevel
DirDelete("dist", 1)
}
catch as e
{
MsgBox("removing dist`nERROR CODE=" . e.Message)
ExitApp
}
}

FileCreateDir, dist
DirCreate("dist")

RunWait, ahk2exe.exe /in updater.ahk /out updater.exe /compress 1
If (ErrorLevel)
try
{
RunWait("ahk2exe.exe /in updater.ahk /out updater.exe /base `"" A_AhkPath "`" /compress 1")
}
catch as e
{
MsgBox, % "updater.ahk`nERROR CODE=" ErrorLevel
MsgBox("updater.ahk`nERROR CODE=" . e.Message)
ExitApp
}
RunWait, ahk2exe.exe /in %ahkFilename% /out %binaryFilename% /icon icon.ico /compress 1
If (ErrorLevel)

try
{
RunWait("ahk2exe.exe /in " ahkFilename " /out " binaryFilename " /base `"" A_AhkPath "`" /icon icon.ico /compress 1")
}
catch as e
{
MsgBox, % ahkFilename "`nERROR CODE=" ErrorLevel
MsgBox(ahkFilename . "`nERROR CODE=" . e.Message)
ExitApp
}
RunWait, autohotkey.exe .\%ahkFilename% --out=version
If (ErrorLevel)

try
{
RunWait("AutoHotkey64.exe .\" . ahkFilename . " --out=version")
}
catch as e
{
MsgBox, % "get version`nERROR CODE=" ErrorLevel
MsgBox("get version`nERROR CODE=" . e.Message)
ExitApp
}
RunWait, powershell -command "Compress-Archive -Path .\%binaryFilename% -DestinationPath %downloadFilename%",, Hide
If (ErrorLevel)

try
{
RunWait("powershell -command `"Compress-Archive -Path .\" binaryFilename " -DestinationPath " downloadFilename '"',, "Hide")
}
catch as e
{
MsgBox, % "compress`nERROR CODE=" ErrorLevel
MsgBox("compress`nERROR CODE=" . e.Message)
ExitApp
}
FileDelete, %binaryFilename%
FileDelete, updater.exe
FileMove, %downloadFilename%, dist\%downloadFilename%, 1
FileMove, %versionFilename%, dist\%versionFilename%, 1
MsgBox, Build Finished
FileDelete(binaryFilename)
FileDelete("updater.exe")
FileMove(downloadFilename, "dist\" downloadFilename, 1)
FileMove(versionFilename, "dist\" versionFilename, 1)
MsgBox("Build Finished")
21 changes: 0 additions & 21 deletions menu.ahk

This file was deleted.

4 changes: 2 additions & 2 deletions meta.ahk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

FileEncoding, UTF-8
FileEncoding("UTF-8")
appName:="auto upgrader"
version:="0.2.0"
version:="0.2.2"
versionFilename:="version.txt"
ahkFilename:="app.ahk"
binaryFilename:="app.exe"
Expand Down
25 changes: 25 additions & 0 deletions tray.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@


setTray()
{
global version, trueExit
donate(ItemName, ItemPos, MyMenu){
Run("https://ko-fi.com/xianii")
}
pages(ItemName, ItemPos, MyMenu){
Run("https://github.com/Nigh/ahk-autoupdate-template")
}
donothing(ItemName, ItemPos, MyMenu){
}
trayExit(ItemName, ItemPos, MyMenu){
trueExit("","")
}
tray := A_TrayMenu
tray.delete
tray.add("v" . version, donothing)
tray.add()
tray.add("Github 页面", pages)
tray.add("Donate 捐助", donate)
tray.add("Exit", trayExit)
tray.ClickCount := 1
}
Loading

0 comments on commit 70ac70b

Please sign in to comment.