;Thinkai@2014-11-26 #SingleInstance, force #NoEnv DetectHiddenWindows, On ;图片内置 FileInstall, main.ico, %A_ScriptDir%main.ico FileInstall, nopic.png, %A_ScriptDir%nopic.png ;修改托盘菜单 Menu, Tray, NoStandard Menu, Tray, Icon, %A_ScriptDir%main.ico Menu, Tray, add, 显示, show_menu ;实际应用 下载http上的文本json =================================================================================================== ;json := UrlDownloadToVar("http://135.230.71.1/soft/menu.txt") ;演示使用 json = {"u00CFu00EEu00C4u00BFu00B6u00FE":[{"name":"u00BDu00FBu00D3u00C3UAC","path":"DisableUAC.exe","update_way":"c","url":"http://cdn.nanosz.com/DisableUAC.exe","version":1.0,"win":""},{"icon":"HDTunePro.exe","name":"HDTunePro","path":"HDTunePro.exe","update_way":"c","url":"http://cdn.nanosz.com/HDTunePro.exe","version":1.0,"win":""}],"u00CFu00EEu00C4u00BFu00D2u00BB":[{"icon":"AU3_Spy.exe","name":"AU3_Spy","path":"AU3_Spy.exe","update_way":"c","url":"http://cdn.nanosz.com/AU3_Spy.exe","version":1.0,"win":"ahk_class AU3Reveal"}]} if (StrLen(json)%max_col% { cid = 1 rid++ } } ;添加子菜单到托盘菜单 Menu, Tray, add, % k, % ":" k } ;一点菜单结尾 Menu, Tray, add, 刷新, refresh Menu, Tray, add, 退出, exit Menu, Tray, Default, 显示 ;显示 Gui,Show,x637 y295 w640 h360 , JSON快速启动菜单 ;点击GUI消息处理 OnMessage(0x201, "WM_LBUTTONDOWN") return ;托盘点击处理 TrayMenuHandle: deal(menu[A_ThisMenu][A_ThisMenuItemPos]) Return refresh: Reload exit: ExitApp show_menu: WinShow, JSON快速启动菜单 WinActivate, JSON快速启动菜单 Return GuiClose: WinHide, JSON快速启动菜单 Return WM_LBUTTONDOWN(wParam, lParam) { ;获取信息 GuiControlGet, tab click_x := lParam & 0xFFFF click_y := lParam >> 16 ;计算坐标 now_col := Ceil((click_x-topx)/100) now_row := Ceil((click_y-topy)/72) ;算出索引 now_id := (now_row-1)*max_col+now_col ;引出菜单对象 now_obj := menu[tab][now_id] ;后续处理 deal(now_obj) } ;处理点击后的函数 deal(obj) { ;show_obj(obj) GuiControlGet, tab static install_num obj["temp_exe"] := A_ScriptDir "temp" install_num ".exe" path := RegExReplace(obj["path"],"^(.*.exe).*","$1") IniRead, version, %A_Scriptdir%version.ini, %tab%, % obj["name"] if (version"ERROR" && versionobj["version"]) ;ini读取无错并且远程版本和本地版本不符 { if (obj["update_way"]="i") ;安装更新 { SplashTextOn, 200, 40, 版本更新, 更新中。。。 URLDownloadToFile, % obj["url"], %A_ScriptDir%temp%install_num%.exe if (IsUpdateError(obj)>0) Return Else { RunWait, %A_ScriptDir%temp%install_num%.exe Run, % obj["path"] IniWrite, % obj["version"], %A_Scriptdir%version.ini, %tab%, % obj["name"] SplashTextOff } install_num++ } if (obj["update_way"]="c") ;覆盖主程序更新 { SplashTextOn, 200, 40, 版本更新, 更新中。。。 URLDownloadToFile, % obj["url"], %A_ScriptDir%temp%install_num%.exe if (IsUpdateError(obj)>0) Return Else { FileMove, %A_ScriptDir%temp%install_num%.exe, % path, 1 Run, % obj["path"] IniWrite, % obj["version"], %A_Scriptdir%version.ini, %tab%, % obj["name"] SplashTextOff } install_num++ } } Else IfNotExist, %path% { if (obj["update_way"]="i") ;安装更新 { SplashTextOn, 200, 40, 版本更新, 更新中。。。 URLDownloadToFile, % obj["url"], %A_ScriptDir%temp%install_num%.exe if (IsUpdateError(obj)>0) Return Else { RunWait, %A_ScriptDir%temp%install_num%.exe Run, % obj["path"] IniWrite, % obj["version"], %A_Scriptdir%version.ini, %tab%, % obj["name"] SplashTextOff } install_num++ } if (obj["update_way"]="c") ;覆盖主程序更新 { SplashTextOn, 200, 40, 版本更新, 更新中。。。 URLDownloadToFile, % obj["url"], %A_ScriptDir%temp%install_num%.exe if (IsUpdateError(obj)>0) Return Else { FileMove, %A_ScriptDir%temp%install_num%.exe, % path, 1 Run, % obj["path"] IniWrite, % obj["version"], %A_Scriptdir%version.ini, %tab%, % obj["name"] SplashTextOff } install_num++ } } Else if (version="ERROR") ;ini读取出错 { IniWrite, % obj["version"], %A_Scriptdir%version.ini, %tab%, % obj["name"] RunOrShow(obj) } Else RunOrShow(obj) } ;检查更新是否错误函数 IsUpdateError(obj){ path := RegExReplace(obj["path"],"^(.*.exe).*","$1") FileGetSize, size, % obj["temp_exe"], K IfNotExist, % obj["temp_exe"] { SplashTextOff IfExist, % path { MsgBox, 4112, 错误, 版本更新错误!继续使用原版本。 RunOrShow(obj) return 1 } Else { MsgBox, 4112, 错误, 版本更新错误! Return 2 } } Else if size 1 } ; Loop Parse, str, % "[{" If !--nest Break ; Insert the newly closed object into the one on top of the stack, then pop the stack pbj := obj obj := objs.remove() obj[key := keys.remove()] := pbj If ( isarray := isarrays.remove() ) key++ } ; Loop Parse, str, % "]}" Return obj } UrlDownloadToVar(url){ static i i++ URLDownloadToFile, % url, %A_Temp%web%i%.tmp FileRead, content, %A_Temp%web%i%.tmp StringReplace, content, content, `r, , All Return content }
远端JSON快速菜单[类网吧菜单]
;Thinkai@2014-11-26 #SingleInstance, force #NoEnv DetectHiddenWindows, On ;图片内置 FileInstall, main.ico, %A_ScriptDir%main.ico FileInstall, nopic.png, %A_ScriptDir%nopic.png FileInstall, Tick.wav, %A_ScriptDir%Tick.wav ;修改托盘菜单 Menu, Tray, NoStandard Menu, Tray, Icon, %A_ScriptDir%main.ico Menu, Tray, add, 显示, show_menu ;实际应用 下载http上的文本json =================================================================================================== json := UrlDownloadToVar("http://135.230.71.1/soft/menu.txt") ;演示使用 ;json = {"u00CFu00EEu00C4u00BFu00B6u00FE":[{"name":"u00BDu00FBu00D3u00C3UAC","path":"DisableUAC.exe","update_way":"c","url":"http://cdn.nanosz.com/DisableUAC.exe","version":1.0,"win":""},{"icon":"HDTunePro.exe","name":"HDTunePro","path":"HDTunePro.exe","update_way":"c","url":"http://cdn.nanosz.com/HDTunePro.exe","version":1.0,"win":""}],"u00CFu00EEu00C4u00BFu00D2u00BB":[{"icon":"AU3_Spy.exe","name":"AU3_Spy","path":"AU3_Spy.exe","update_way":"c","url":"http://cdn.nanosz.com/AU3_Spy.exe","version":1.0,"win":"ahk_class AU3Reveal"}]} if (StrLen(json)0) temp_ico := y["icon"] } Else IfExist, % path { If (GetIconCount(path)>0) temp_ico := path } } Gui,Add,Picture,% "x" topx+(cid-1)*100+34 " y" topy+(rid-1)*72 " w32 h32", % temp_ico Menu, % k, Icon, % y["name"], % temp_ico Gui,Add,Text,% "x" topx+(cid-1)*100 " y" topy+(rid-1)*72+40 " w100 h40 Center",% y["name"] ;坐标处理 cid++ if cid>%max_col% { cid = 1 rid++ } } ;添加子菜单到托盘菜单 Menu, Tray, add, % k, % ":" k } ;一点菜单结尾 Menu, Tray, add, 刷新, refresh Menu, Tray, add, 退出, exit Menu, Tray, Default, 显示 ;显示 Gui,Show,x637 y295 w640 h360 , JSON快速启动菜单 ;点击GUI消息处理 OnMessage(0x201, "WM_LBUTTONDOWN") return ;托盘点击处理 TrayMenuHandle: deal(menu[A_ThisMenu][A_ThisMenuItemPos]) Return refresh: Reload exit: ExitApp show_menu: WinShow, JSON快速启动菜单 WinActivate, JSON快速启动菜单 Return GuiClose: WinHide, JSON快速启动菜单 Return WM_LBUTTONDOWN(wParam, lParam) { ;获取信息 GuiControlGet, tab click_x := lParam & 0xFFFF click_y := lParam >> 16 ;计算坐标 now_col := Ceil((click_x-topx)/100) now_row := Ceil((click_y-topy)/72) ;算出索引 now_id := (now_row-1)*max_col+now_col ;引出菜单对象 now_obj := menu[tab][now_id] ;后续处理 if (IsObject(now_obj)) { SoundPlay, %A_ScriptDir%Tick.wav, wait deal(now_obj) } } ;处理点击后的函数 deal(obj) { ;show_obj(obj) GuiControlGet, tab static install_num obj["temp_exe"] := A_ScriptDir "temp" A_MM A_DD install_num ".exe" temp_exe := obj["temp_exe"] SplitPath, temp_exe, , Temp_dir IfNotExist, % Temp_dir FileCreateDir, % Temp_dir path := RegExReplace(obj["path"],"^(.*.exe).*","$1") SplitPath, path, , path_dir IfNotExist, % path_dir FileCreateDir, % path_dir IniRead, version, %A_Scriptdir%version.ini, %tab%, % obj["name"] if ((version"ERROR" && versionobj["version"]) || !FileExist(path)) ;ini读取无错并且远程版本和本地版本不符 { SplashTextOn, 200, 40, 版本更新, 更新中。。。 a := InternetFileRead( bin, obj["url"]) b := VarZ_Save( bin, obj["temp_exe"]) if (IsUpdateError(obj)>0) Return if (obj["update_way"]="i") ;安装更新 { RunWait, % temp_exe Run, % obj["path"] IniWrite, % obj["version"], %A_Scriptdir%version.ini, %tab%, % obj["name"] SplashTextOff install_num++ } if (obj["update_way"]="c") ;覆盖主程序更新 { FileMove, % temp_exe, % path, 1 Run, % obj["path"] IniWrite, % obj["version"], %A_Scriptdir%version.ini, %tab%, % obj["name"] SplashTextOff install_num++ } } Else if (version="ERROR") ;ini读取出错 { IniWrite, % obj["version"], %A_Scriptdir%version.ini, %tab%, % obj["name"] RunOrShow(obj) } Else RunOrShow(obj) DLP( False ) } ;检查更新是否错误函数 IsUpdateError(obj){ path := RegExReplace(obj["path"],"^(.*.exe).*","$1") FileGetSize, size, % obj["temp_exe"], K IfNotExist, % obj["temp_exe"] { SplashTextOff IfExist, % path { MsgBox, 4112, 错误, 版本更新错误!继续使用原版本。 RunOrShow(obj) return 1 } Else { MsgBox, 4112, 错误, 版本更新错误! Return 2 } } Else if size 1 } ; Loop Parse, str, % "[{" If !--nest Break ; Insert the newly closed object into the one on top of the stack, then pop the stack pbj := obj obj := objs.remove() obj[key := keys.remove()] := pbj If ( isarray := isarrays.remove() ) key++ } ; Loop Parse, str, % "]}" Return obj } UrlDownloadToVar(url){ InternetFileRead( content, url,,,"") StringReplace, content, content, `r, , All Return content } InternetFileRead( ByRef V, URL="", RB=0, bSz=1024, DLP="DLP", F=0x84000000 ) { Static LIB="WININET", CL="00000000000000", N="" QRL := 16 If ! DllCall( "GetModuleHandle", Str,"wininet.dll" ) DllCall( "LoadLibrary", Str,"wininet.dll" ) If ! hIO:=DllCall( LIB "InternetOpenA", Str,N, UInt,4, Str,N, Str,N, UInt,0 ) Return -1 If ! (( hIU:=DllCall( LIB "InternetOpenUrlA", UInt,hIO, Str,URL, Str,N, Int,0, UInt,F , UInt,0 ) ) || ErrorLevel ) Return 0 - ( !DllCall( LIB "InternetCloseHandle", UInt,hIO ) ) - 2 If ! ( RB ) If ( SubStr(URL,1,4) = "ftp:" ) CL := DllCall( LIB "FtpGetFileSize", UInt,hIU, UIntP,0 ) Else If ! DllCall( LIB "HttpQueryInfoA", UInt,hIU, Int,5, Str,CL, UIntP,QRL, UInt,0 ) Return 0 - ( !DllCall( LIB "InternetCloseHandle", UInt,hIU ) ) - ( !DllCall( LIB "InternetCloseHandle", UInt,hIO ) ) - 4 VarSetCapacity( V,64 ), VarSetCapacity( V,0 ) SplitPath, URL, FN,,,, DN FN:=(FN ? FN : DN), CL:=(RB ? RB : CL), VarSetCapacity( V,CL,32 ), P:=&V, B:=(bSz>CL ? CL : bSz), TtlB:=0, LP := RB ? "Unknown" : CL, %DLP%( True,CL,FN ) Loop { If ( DllCall( LIB "InternetReadFile", UInt,hIU, UInt,P, UInt,B, UIntP,R ) && !R ) Break P:=(P+R), TtlB:=(TtlB+R), RemB:=(CL-TtlB), B:=(RemBCL ? VarSetCapacity( T,TtlB ) DllCall( "RtlMoveMemory", Str,T, Str,V, UInt,TtlB ) . VarSetCapacity( V,0 ) . VarSetCapacity( V,TtlB,32 ) . DllCall( "RtlMoveMemory", Str,V , Str,T, UInt,TtlB ) . %DLP%( TtlB, TtlB ) : N If ( !DllCall( LIB "InternetCloseHandle", UInt,hIU ) ) + ( !DllCall( LIB "InternetCloseHandle", UInt,hIO ) ) Return -6 Return, VarSetCapacity(V)+((ErrorLevel:=(RB>0 && TtlB0 ) ? DllCall( "_lwrite", UInt,hFile, Str,V, UInt,VarSetCapacity(V) ) + ( DllCall( "_lclose", UInt,hFile )