Skip to content

Commit c6d6446

Browse files
authored
add Updater (#21)
* package resource to exe * use ahk instead of makefile to build * add 2k res * v0.1.2 * use powershell to compress * add update mirror * add updater for better upgrade experience
1 parent 4ade219 commit c6d6446

File tree

13 files changed

+190
-67
lines changed

13 files changed

+190
-67
lines changed

GenshinFishing.ahk

Lines changed: 55 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,22 @@ SetBatchLines, -1
88

99
update_log:="
1010
(
11-
Update Log
12-
更新日志
13-
> 增加了3840x2160分辨率支持
14-
> Added support for 3840x2160 resolution
15-
> 更改了MSXML2方法, 应该能解决一些升级报错的问题
16-
> Changed MSXML2 method, should solve some upgrade issues
17-
18-
Resolution support below
19-
当前版本分辨率支持如下
20-
1280x720
21-
1600x900
22-
1920x1080
23-
3840x2160
11+
12+
> 增加了 2560x1440 分辨率支持
13+
> Added support for 2560x1440 resolution
14+
> 将资源打包至二进制
15+
> Package resources to exe
16+
> 优化了自动升级功能
17+
> Optimised the automatic upgrade function
18+
2419
)"
2520
2621
if A_IsCompiled
2722
debug:=0
2823
Else
2924
debug:=1
3025

31-
version:="0.1.1"
26+
version:="0.2.0"
3227
if A_Args.Length() > 0
3328
{
3429
for n, param in A_Args
@@ -51,14 +46,19 @@ UAC()
5146
IniRead, logLevel, setting.ini, update, log, 0
5247
IniRead, lastUpdate, setting.ini, update, last, 0
5348
IniRead, autoUpdate, setting.ini, update, autoupdate, 1
49+
IniRead, updateMirror, setting.ini, update, mirror, "fastgit"
50+
IniWrite, % updateMirror, setting.ini, update, mirror
5451
IniRead, debugmode, setting.ini, update, debug, 0
5552
Gosub, log_init
5653
log("Start at " A_YYYY "-" A_MM "-" A_DD)
5754
today:=A_MM . A_DD
55+
IfExist, updater.exe
56+
{
57+
FileDelete, updater.exe
58+
}
5859
if(autoUpdate) {
5960
if(lastUpdate!=today) {
6061
log("Getting Update",0)
61-
MsgBox,,Update,Getting Update`n获取最新版本,2
6262
update()
6363
} else {
6464
IniRead, version_str, setting.ini, update, ver, "0"
@@ -70,14 +70,9 @@ if(autoUpdate) {
7070
}
7171
} else {
7272
log("Update Skiped",0)
73-
MsgBox,,Update,Update Skiped`n跳过升级`n`nCurrent version`n当前版本`nv%version%,2
73+
; MsgBox,,Update,Update Skiped`n跳过升级`n`nCurrent version`n当前版本`nv%version%,2
7474
}
7575

76-
#Include, Gdip_ImageSearch.ahk
77-
#Include, Gdip.ahk
78-
79-
pToken := Gdip_Startup()
80-
8176
img_list:=Object("bar",Object("filename","bar.png")
8277
,"casting",Object("filename","casting.png")
8378
,"cur",Object("filename","cur.png")
@@ -94,6 +89,13 @@ img_list:=Object("bar",Object("filename","bar.png")
9489
; msgbox, % k "`n" v.path "`nw[" v.w "]`nh[" v.h "]"
9590
; }
9691

92+
; #Include, Gdip_ImageSearch.ahk
93+
; #Include, Gdip.ahk
94+
; pToken := Gdip_Startup()
95+
96+
#include, fileinstalls.ahk
97+
98+
9799
DllCall("QueryPerformanceFrequency", "Int64P", freq)
98100
freq/=1000
99101
CoordMode, Pixel, Client
@@ -162,8 +164,8 @@ if(genshin_hwnd)
162164
; Gdip_SaveBitmapToFile(pBitmap, "output.jpg")
163165
; MsgBox, DONE
164166

165-
hdc := GetDC(genshin_hwnd)
166-
CreateCompatibleDC(hdc)
167+
; hdc := GetDC(genshin_hwnd)
168+
; CreateCompatibleDC(hdc)
167169
; Gdip_GraphicsFromHDC
168170
; Gdip_CreateBitmapFromHBITMAP
169171
; Gdip_SetBitmapToClipboard
@@ -185,23 +187,23 @@ dLinePt(p)
185187

186188
getState:
187189
; k:=(((winW**2)+(winH**2))**0.5)/(((1920**2)+(1080**2))**0.5)
188-
ImageSearch, iconX, iconY, winW-dLinePt(0.167), winH-dLinePt(0.084), winW, winH, % "*32 *TransFuchsia ./assets/" winW winH "/" img_list.ready.filename
190+
ImageSearch, iconX, iconY, winW-dLinePt(0.167), winH-dLinePt(0.084), winW, winH, % "*32 *TransFuchsia " A_Temp "/genshinfishing/" winW winH "/" img_list.ready.filename
189191
if(!ErrorLevel){
190192
state:="ready"
191193
statePredict:=state
192194
stateUnknownStart := 0
193195
log("state->" statePredict, 1)
194196
return
195197
}
196-
ImageSearch, iconX, iconY, winW-dLinePt(0.167), winH-dLinePt(0.084), winW, winH, % "*32 *TransFuchsia ./assets/" winW winH "/" img_list.reel.filename
198+
ImageSearch, iconX, iconY, winW-dLinePt(0.167), winH-dLinePt(0.084), winW, winH, % "*32 *TransFuchsia " A_Temp "/genshinfishing/" winW winH "/" img_list.reel.filename
197199
if(!ErrorLevel){
198200
state:="reel"
199201
statePredict:=state
200202
stateUnknownStart := 0
201203
log("state->" statePredict, 1)
202204
return
203205
}
204-
ImageSearch, iconX, iconY, winW-dLinePt(0.167), winH-dLinePt(0.084), winW, winH, % "*32 *TransFuchsia ./assets/" winW winH "/" img_list.casting.filename
206+
ImageSearch, iconX, iconY, winW-dLinePt(0.167), winH-dLinePt(0.084), winW, winH, % "*32 *TransFuchsia " A_Temp "/genshinfishing/" winW winH "/" img_list.casting.filename
205207
if(!ErrorLevel){
206208
state:="casting"
207209
statePredict:=state
@@ -235,11 +237,11 @@ getClientSize(genshin_hwnd, winW, winH)
235237

236238
if(oldWinW!=winW || oldWinH!=winH) {
237239
log("Get dimension=" winW "x" winH,1)
238-
if(InStr(FileExist("./assets/" winW winH), "D")) {
240+
if(InStr(FileExist(A_Temp "/genshinfishing/" winW winH), "D")) {
239241
fileCount:=0
240242
for k, v in img_list
241243
{
242-
if(FileExist("./assets/" winW winH "/" v.filename)) {
244+
if(FileExist(A_Temp "/genshinfishing/" winW winH "/" v.filename)) {
243245
fileCount += 1
244246
}
245247
}
@@ -301,7 +303,7 @@ if(statePredict=="unknown" || statePredict=="ready")
301303
} else if(statePredict=="reel") {
302304
DllCall("QueryPerformanceCounter", "Int64P", startTime)
303305
if(barY<2) {
304-
ImageSearch, _, barY, barR_left, barR_top, barR_right, barR_bottom, % "*20 *TransFuchsia ./assets/" winW winH "/" img_list.bar.filename
306+
ImageSearch, _, barY, barR_left, barR_top, barR_right, barR_bottom, % "*20 *TransFuchsia " A_Temp "/genshinfishing/" winW winH "/" img_list.bar.filename
305307
if(ErrorLevel){
306308
if(barY == 0) {
307309
barY := 1
@@ -321,9 +323,9 @@ if(statePredict=="unknown" || statePredict=="ready")
321323
DllCall("QueryPerformanceCounter", "Int64P", endTime)
322324
} else {
323325
if(leftX > 0) {
324-
ImageSearch, leftX, leftY, leftX-delta_left, barY-delta_top, leftX+delta_right, barY+delta_bottom, % "*16 *TransFuchsia ./assets/" winW winH "/" img_list.left.filename
326+
ImageSearch, leftX, leftY, leftX-delta_left, barY-delta_top, leftX+delta_right, barY+delta_bottom, % "*16 *TransFuchsia " A_Temp "/genshinfishing/" winW winH "/" img_list.left.filename
325327
} else {
326-
ImageSearch, leftX, leftY, barS_left, barY-delta_top, barS_right, barY+delta_bottom, % "*16 *TransFuchsia ./assets/" winW winH "/" img_list.left.filename
328+
ImageSearch, leftX, leftY, barS_left, barY-delta_top, barS_right, barY+delta_bottom, % "*16 *TransFuchsia " A_Temp "/genshinfishing/" winW winH "/" img_list.left.filename
327329
}
328330
if(ErrorLevel){
329331
leftX := 0
@@ -334,9 +336,9 @@ if(statePredict=="unknown" || statePredict=="ready")
334336
}
335337

336338
if(rightX > 0) {
337-
ImageSearch, rightX, rightY, rightX-delta_left, barY-delta_top, rightX+delta_right, barY+delta_bottom, % "*16 *TransFuchsia ./assets/" winW winH "/" img_list.right.filename
339+
ImageSearch, rightX, rightY, rightX-delta_left, barY-delta_top, rightX+delta_right, barY+delta_bottom, % "*16 *TransFuchsia " A_Temp "/genshinfishing/" winW winH "/" img_list.right.filename
338340
} else {
339-
ImageSearch, rightX, rightY, barS_left, barY-delta_top, barS_right, barY+delta_bottom, % "*16 *TransFuchsia ./assets/" winW winH "/" img_list.right.filename
341+
ImageSearch, rightX, rightY, barS_left, barY-delta_top, barS_right, barY+delta_bottom, % "*16 *TransFuchsia " A_Temp "/genshinfishing/" winW winH "/" img_list.right.filename
340342
}
341343
if(ErrorLevel){
342344
rightX := 0
@@ -347,9 +349,9 @@ if(statePredict=="unknown" || statePredict=="ready")
347349
}
348350

349351
if(curX > 0) {
350-
ImageSearch, curX, curY, curX-delta_left, barY-delta_top, curX+delta_right, barY+delta_bottom, % "*16 *TransFuchsia ./assets/" winW winH "/" img_list.cur.filename
352+
ImageSearch, curX, curY, curX-delta_left, barY-delta_top, curX+delta_right, barY+delta_bottom, % "*16 *TransFuchsia " A_Temp "/genshinfishing/" winW winH "/" img_list.cur.filename
351353
} else {
352-
ImageSearch, curX, curY, barS_left, barY-delta_top, barS_right, barY+delta_bottom, % "*16 *TransFuchsia ./assets/" winW winH "/" img_list.cur.filename
354+
ImageSearch, curX, curY, barS_left, barY-delta_top, barS_right, barY+delta_bottom, % "*16 *TransFuchsia " A_Temp "/genshinfishing/" winW winH "/" img_list.cur.filename
353355
}
354356
if(ErrorLevel){
355357
curX := 0
@@ -423,20 +425,27 @@ F5::ExitApp
423425
F6::Reload
424426
#If
425427

428+
updateSite:=""
429+
426430
update(){
427431
global
428432
req := ComObjCreate("MSXML2.ServerXMLHTTP")
429-
; https://download.fastgit.org/Nigh/Genshin-fishing/releases/latest/download/version.txt
430-
; https://github.com/Nigh/Genshin-fishing/releases/latest/download/version.txt
431-
req.open("GET", "https://download.fastgit.org/Nigh/Genshin-fishing/releases/latest/download/version.txt", true)
433+
if(updateMirror=="fastgit") {
434+
updateSite:="https://download.fastgit.org"
435+
} else if(updateMirror=="cnpmjs") {
436+
updateSite:="https://github.com.cnpmjs.org"
437+
} else {
438+
updateSite:="https://github.com"
439+
}
440+
req.open("GET", updateSite "/Nigh/Genshin-fishing/releases/latest/download/version.txt", true)
432441
req.onreadystatechange := Func("updateReady")
433442
req.send()
434443
}
435444

436445
; with MSXML2.ServerXMLHTTP method, there would be multiple callback called
437446
updateReqDone:=0
438447
updateReady(){
439-
global req, version, updateReqDone
448+
global req, version, updateReqDone, updateSite
440449
log("update req.readyState=" req.readyState, 1)
441450
if (req.readyState != 4){ ; Not done yet.
442451
return
@@ -455,17 +464,20 @@ updateReady(){
455464
MsgBox, 0x24, Download, % "Found new version " req.responseText ", download?`n`n发现新版本 " req.responseText " 是否下载?"
456465
IfMsgBox Yes
457466
{
458-
UrlDownloadToFile, https://download.fastgit.org/Nigh/Genshin-fishing/releases/latest/download/GenshinFishing.zip, ./GenshinFishing.zip
467+
UrlDownloadToFile, % updateSite "/Nigh/Genshin-fishing/releases/latest/download/GenshinFishing.zip", ./GenshinFishing.zip
459468
if(ErrorLevel) {
460-
MsgBox, 16,, % "Download failed`n下载失败"
469+
log("Err[" ErrorLevel "]Download failed", 0)
470+
MsgBox, 16,, % "Err" ErrorLevel "`n`nDownload failed`n下载失败"
461471
} else {
462-
MsgBox, ,, % "File saved as GenshinFishing.zip`n更新下载完成 GenshinFishing.zip`n`nProgram will exit now`n软件即将退出", 2
472+
MsgBox, ,, % "File saved as GenshinFishing.zip`n更新下载完成 GenshinFishing.zip`n`nProgram will restart now`n软件即将重启", 3
463473
IniWrite, % A_MM A_DD, setting.ini, update, last
474+
FileInstall, updater.exe, updater.exe, 1
475+
Run, updater.exe
464476
ExitApp
465477
}
466478
}
467479
} else {
468-
MsgBox, ,, % "Current version: v" version "`n`nIt is the latest version`n`n软件已是最新版本", 2
480+
; MsgBox, ,, % "Current version: v" version "`n`nIt is the latest version`n`n软件已是最新版本", 2
469481
IniWrite, % A_MM A_DD, setting.ini, update, last
470482
}
471483
} else {

Makefile

Lines changed: 0 additions & 24 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ The following image settings have been tested to work properly:
2525
| ----------------- | ------------ |
2626
| 3840 x 2160 ||
2727
| 1920 x 1080 ||
28+
| 2560 x 1440 ||
2829
| 1600 x 900 ||
2930
| 1440 x 900 ||
3031
| 1366 x 768 ||

assets/25601440/bar.png

135 Bytes
Loading

assets/25601440/casting.png

561 Bytes
Loading

assets/25601440/cur.png

190 Bytes
Loading

assets/25601440/left.png

281 Bytes
Loading

assets/25601440/ready.png

1.87 KB
Loading

assets/25601440/reel.png

535 Bytes
Loading

assets/25601440/right.png

211 Bytes
Loading

0 commit comments

Comments
 (0)