这是实现程序界面语言切换的一个非常简单的方法,所有界面、菜单、对话框的文字都是用变量调用。程序启动时自动检测是否有更高级版本并提示用户(还可以再加入询问用户是否下载该升级,若获许可则下载并自动安装/替换升级版本等功能)。检测升级的方法是在服务器上放置某个含有升级信息的文件(比如INI文件,所谓升级信息指的是日期、版本等可供比较的字串),要检测时先下载该文件其后读取文件内容并比较版本等信息,若发现比当前程序高级则定义为升级可用,否则没有升级。在编写这个脚本时发现一个问题,使用一次URLDownloadToFile这个命令后脚本将自动使用IE缓存,因此再次检测升级时如果升级有效将不能成功检测到(脚本仍然认为升级信息和前一次的一样)。为了保证检测升级是实时只好把检测动作改为Reload,我自己是不太满意这个做法,但目前还没有更好的方案。
下面是个简单的模板,适当修改一下即可
;##########################
#SingleInstance ignore
curver = 1.0 ; 声明当前版本
IfNotExist, set.ini
IniWrite, CN, set.ini, MenuLang, Lang
else
IniRead, lang, set.ini, MenuLang, Lang
If lang = EN
{
About = &About
Language = &Language
Update = &Update
Exit = E&xit
Error = Unexpectable error occurred`nPlease contact me by E-mail: [url=mailto:yonken@163.com]yonken@163.com[/url]
TipName = My Application
UpTipTitle1 = Update Available!
UpTipTitle2 = Update not necessary!
UpTipContent1 = Update Available!`nThe latest version is
UpTipContent2 = You already have the latest version!`nCurrent version is
AboutTitle = About My Application
AboutContent = Application v1.0`nAll Rights Reserved (C) 2005 by Yonken`nE-mail: [url=mailto:yonken@163.com]yonken@163.com[/url]
}
Else
{
About = 关于(&A)
Language = 语言(&L)
Update = 升级(&U)
Exit = 退出(&X)
Error = 出现意外错误`n请与我联系 E-mail: [url=mailto:yonken@163.com]yonken@163.com[/url]
TipName = 某某软件
UpTipTitle1 = 赶快升级
UpTipTitle2 = 尚无升级
UpTipContent1 = 检测到程序已经有更新了!`n最新的版本是
UpTipContent2 = 已经是最新版本了!`n当前版本是
AboutTitle = 关于 某某软件
AboutContent = 某某软件 1.0`n版权所有 (C) 2005 by 非常郁闷的流星`nE-mail: [url=mailto:yonken@163.com]yonken@163.com[/url]
}
Gosub, CheckUPD
Menu, Tray, NoStandard
Menu, LangSet, add, 中文(&C)
Menu, LangSet, add, &English
Menu, tray, add, %Language%, :LangSet
Menu, tray, add, %About%
Menu, tray, add, %Update%
Menu, tray, add, %Exit%
Menu, tray, Tip, %TipName%
Return
中文(&C):
IniWrite, CN, set.ini, MenuLang, Lang
Reload
Return
&English:
IniWrite, EN, set.ini, MenuLang, Lang
Reload
Return
&About:
关于(&A):
MsgBox, 0, %AboutTitle%, %AboutContent%
Return
&Update:
升级(&U):
Reload
Return
CheckUPD:
URLDownloadToFile, http://127.0.0.1/update/version.dat, %Temp%/version.dat
IniRead, newver, %Temp%/version.dat, Version, ModelVer
If newver = ERROR
MsgBox, 0, %TipName%, %error%
Else If newver > %curver%
TrayTip, %UpTipTitle1%, %UpTipContent1% %newver%, 10, 1
Else
TrayTip, %UpTipTitle2%, %UpTipContent2% %curver%, 10, 1
Return
#x::
E&xit:
退出(&X):
IfExist, %Temp%/version.dat
FileDelete, %Temp%/version.dat
ExitApp
;##########################
简单实现AutoHotkey的升级检测 [转]
运行时自动检测
脚本代码如下:
;########################################
; AutoHotkey Updater
;
; AutoHotkey Version: 1.0.38.02
; Language: Chinese
; Platform: WinXP SP2
; Author: Yonken <yonken@163.com>
;
; Script Function:
; Check Update of AutoHotkey.
;
#SingleInstance ignore
Menu, Tray, NoStandard
Menu, tray, add, 关于(&A)
Menu, tray, add, 版本信息(&I)
Menu, tray, add, 检查更新(&U)
Menu, tray, add, 退出程序(&X)
Menu, Tray, Default, 版本信息(&I)
Menu, tray, Tip, AutoHotkey 升级伴侣
RegRead, dir, HKEY_LOCAL_MACHINE, SOFTWARE/AutoHotkey, InstallDir
RegRead, curver, HKEY_LOCAL_MACHINE, SOFTWARE/AutoHotkey, Version
FileGetVersion, filecurver, %dir%/AutoHotkey.exe
FileGetTime, filecurdate, %dir%/AutoHotkey.exe
If dir =
dir = 未知
If curver =
curver = 未知
If filecurver =
filecurver = 未知
If ErrorLevel
filecurdate = 未知
;################# 重要部分 #################
UrlDownloadToFile, http://www.autohotkey.com/download/CurrentVersion.txt, %TMP%/ver.txt
FileReadLine, newver, %TMP%/ver.txt, 1
FileReadLine, newdate, %TMP%/ver.txt, 2
FileReadLine, newsize, %TMP%/ver.txt, 3
FormatTime, filecurdate, %filecurdate%, yyyy年MMMMd日 HH:mm:ss
FormatTime, newdate, %newdate%, yyyy年MMMMd日 HH:mm:ss
SizeKB = %newsize%
SizeKB /=1024
If curver = 未知
{
If filecurver = 未知
Gosub, NotFound
Else
{
curver = %filecurver%
Gosub, update
}
}
Else if filecurver = 未知
Gosub, NotFound
Else
Gosub, update
Return
;################# 重要部分 #################
NotFound:
MsgBox, 4, 错误, 无法检测软件位置`n请确定您已经正确安装了 AutoHotkey`n`n您要下载 AutoHotkey 吗?
IfMsgBox, Yes
Gosub, Download
IfMsgBox, No
ExitApp
Return
update:
If newver > %curver%
{
TrayTip, 赶快升级, 检测到 AutoHotkey 已经有更新了, 10, 1
MsgBox, 4, 升级, 有更新了!`n最新版本是 %newver%,要升级吗?
IfMsgBox, Yes
Gosub, Download
}
Else
TrayTip, 没有更新, 当前版本:%newver% 已经是最新版本了, 10, 1
Return
关于(&A):
Gui, -0x20000
Gui, Add, Button, Default x79 y87 w59 h28 gConfirm, 确定
Gui, Add, Text, cBlue x14 y5 w193 h66 +Center, AutoHotkey 升级伴侣 1.0`n`n版权所有(C) 2005 Yonken 编写
Gui, Add, Button, x20 y43 w179 h20 gBlog, http://yonken.blogcn.com
Gui, Add, Button, x21 y63 w179 h20 gMail, yonken@163.com
Gui, Show, h121 w229, 关于 AutoHotkey 升级伴侣
Return
版本信息(&I):
Gui, 2:Add, GroupBox, x6 y10 w410 h120, 当前版本信息
Gui, 2:Add, GroupBox, x6 y150 w410 h120, 升级版本信息
Gui, 2:Add, Text, x16 y40 w130 h20 +Left, AutoHotkey 程序路径:
Gui, 2:Add, Text, x16 y70 w130 h20 +Left, AutoHotkey 当前版本:
Gui, 2:Add, Text, x16 y100 w130 h20 +Left, AutoHotkey 安装日期:
Gui, 2:Add, Text, x16 y180 w130 h20 +Left, AutoHotkey 最新版本:
Gui, 2:Add, Text, x16 y210 w130 h20 +Left, 最新版本发布日期:
Gui, 2:Add, Button, x16 y280 w70 h30 gDownload, 下载(&D)
Gui, 2:Add, Button, x106 y280 w110 h30 gDownWeb, 官方下载页面(&W)
Gui, 2:Add, Button, x236 y280 w80 h30 gHomepage, 官方网站(&H)
Gui, 2:Add, Button, Default x336 y280 w70 h30 gClose, 关闭(&C)
Gui, 2:Add, Text, x16 y240 w130 h20 +Left, 文件大小:
Gui, 2:Add, Edit, ReadOnly x156 y40 w250 h20, %dir%
Gui, 2:Add, Text, x156 y70 w250 h20, %curver%
Gui, 2:Add, Text, x156 y100 w250 h20, %filecurdate%
Gui, 2:Add, Text, x156 y180 w250 h20, %newver%
Gui, 2:Add, Text, x156 y210 w250 h20, %newdate%
Gui, 2:Add, Text, x156 y240 w250 h20, %newsize% 字节 即 %SizeKB% 千字节
Gui, 2:Show, x319 y165 h321 w426, AutoHotkey 版本信息
Return
检查更新(&U):
Reload
Return
#x::
退出程序(&X):
ExitApp
Confirm:
Close:
GuiClose:
GuiEscape:
Gui, Destroy
Return
Download:
Run, http://home.tampabay.rr.com/kodi/ahk/AutoHotkeyInstall.exe
Return
DownWeb:
Run, http://www.autohotkey.com/download/
Return
Homepage:
Run, http://www.autohotkey.com/
Return
Blog:
Run, http://yonken.blogcn.com
Return
Mail:
Run, mailto:yonken@163.com
Return
;########################################