这是一个拆分excel发邮件的半成品,因为换API方式所以记录下。
Gui, main:Add, button, x0 y0 w100 h20 gaddtab, 添加表格数据源 gui, main:add, Button, x100 y0 w100 h20, 设置收件人信息 gui, main:add, Button, x200 y0 w100 h20, 设置发件人信息 gui, main:add, Button, x300 y0 w100 h20, 开始发送 gui, main:add, Progress, x0 y20 w600 h20 vprg, 10 Gui, main:Add, ListView, x0 y40 w600 h300 vlv, 文件|Sheet|拆分依据字段|输出文件名前缀|目标Sheet Gui, main:Add, StatusBar, , 等待用户操作 Gui, main:show, , Excel数据拆分发邮件 Gui, main:Default LV_ModifyCol(1,150) LV_ModifyCol(2,120) LV_ModifyCol(3,120) LV_ModifyCol(4,120) LV_ModifyCol(5,120) SB_SetParts(400,200) return addtab: FileSelectFile, file, , , 选择一个表格, Excel文件(*.xls;*.xlsx) IfExist % file { SplitPath, file, , , , name SB_SetText("读取文件:" file) a := new excel() a.open(file) sheet := a.sheets() for k,v in sheet { SB_SetText("等待用户设置数据源") isguideok := false Gui, guide:Destroy Gui, guide:add, text, x0 y0 w100 h20, % "文件:" Gui, guide:add, text, x0 y20 w100 h20, % "Sheet:" Gui, guide:add, text, x100 y0 w300 h20, % guidefile:=file Gui, guide:add, text, x100 y20 w300 h20, % guidesheet:=v f = field := a.fields(A_index) for x,y in field f .= f ? "|" y : y Gui, guide:add, text, x0 y40 w100 h20, 拆分依据字段: Gui, guide:add, DropDownList, x100 y40 w300 vguideddl, % f Gui, guide:add, text, x0 y60 w100 h20, 输出文件名前缀: Gui, guide:add, Edit, x100 y60 w300 h20 vguideprefix, % name Gui, guide:add, text, x0 y80 w100 h20, 目标Sheet: Gui, guide:add, Edit, x100 y80 w300 h20 vguidedstsheet, % v Gui, guide:add, Button, x0 y100 w200 h20 gconfirm, 确认 Gui, guide:add, Button, x200 y100 w200 h20 gjump, 跳过 Gui, guide:Show, , % "数据源导入向导——" name while(!isguideok) Sleep, 100 Gui, guide:Destroy SB_SetText("数据源设置完毕") } a.close() } return confirm: Gui, guide:Submit, NoHide if !guideddl { MsgBox, 4112, 错误, 拆分依据字段不能为空! return } Gui, main:Default LV_Add("",guidefile,guidesheet,guideddl,guideprefix,guidedstsheet) isguideok := true return jump: isguideok := true return guideGuiClose: return mainGuiClose: ExitApp class excel { ;static conn __New() ;新建 { this.conn:= ComObjCreate("Excel.Application") this.conn.Visible := false ;false } open(file) ;打开文件 { IfExist % file this.conn.Workbooks.Open(file) } close() ;关闭文件 { this.conn.Workbooks.close() } sheets() ;获取所有Sheet { s := [] loop % this.conn.ActiveWorkbook.Sheets.Count s.insert(this.conn.ActiveWorkbook.Sheets(A_index).Name) return s } fields(sheet) ;获取指定sheet的字段 sheet为id或者具体名称 { c := [] loop % this.conn.ActiveWorkbook.Sheets(sheet).Columns.Count { try { x := this.conn.ActiveWorkbook.Sheets(sheet).Cells(1,A_index).Value if !x break c.insert(x) } catch e break } return c /* col_id := ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"] loop % this.conn.ActiveWorkbook.Sheets(sheet).Columns.Count { col := col_id[floor(A_index/26)] col_id[mod(A_index,26)] try { x:=excel.ActiveWorkbook.Sheets(sheet).Range(col "1").Value if !x break colname.insert(x) } catch e break } */ } setfields(sheet,fields) ;设置字段 即第一列信息 { return this.insertrow(sheet,1,fields) } setformat(sheet,range,format) ;设置某一区域的单元格格式 { this.conn.ActiveWorkbook.Sheets(sheet).Range(range).NumberFormat := format } insertrow(sheet,rowid,values) ;插入一列 { for k,v in values this.conn.ActiveWorkbook.Sheets(sheet).Cells(rowid,A_index).Value := v } }
;Thinkai@2015-10-25 Gui, Add, Tab, x0 y0 w800 h500 vtab Gui, Show, , 输出excel数据到GUI FileSelectFile, file, , , 选择一个表格, Excel文件(*.xls;*.xlsx) IfNotExist % file ExitApp conn := ComObjCreate("ADODB.connection") ;初始化COM conn.Open("Provider=Microsoft.Ace.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" file) ;打开连接 ;conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;HDR=Yes';Data Source=" file) ;打开连接 2003方式 ;通过OpenSchema方法获取表信息 rs := conn.OpenSchema(20) ;SchemaEnum 参考 http://www.w3school.com.cn/ado/app_schemaenum.asp table_info := [] rs.MoveFirst() while !rs.EOF ;有效Sheet { t_name := RegExReplace(rs.("TABLE_NAME").value,"\$$","") q := conn.Execute("select top 1 * from [" t_name "$]") if (q.Fields(0).Name="F1" && q.Fields.Count=1) ;排除空表格 { rs.MoveNext() continue } table_info[t_name] := [] for field in q.Fields ;获取按顺序排列的字段 table_info[t_name].insert(field.Name) q.close() rs.MoveNext() } ;生成Listview for t,c in table_info { ;创建tab及listview GuiControl, , tab, % t Gui, Tab, % A_index cols = for k,v in c cols .= cols ? "|" v : v Gui, Add, ListView, % "x10 y30 w780 h460 vlv" A_Index, % cols Gui, ListView, % "lv" A_Index ;获取表格数据 data := GetTable("select * from [" t "$]") for k,v in data LV_Add("",v*) LV_ModifyCol() ;自动调整列宽 } rs.close() conn.close() return GuiClose: ExitApp GetTable(sql){ ;Adodb通用的获取数据数组的函数 global conn t := [] query := conn.Execute(sql) fetchedArray := query.GetRows() ;取出数据(二维数组) colSize := fetchedArray.MaxIndex(1) + 1 ;列最大值 tips:从0开始 所以要+1 rowSize := fetchedArray.MaxIndex(2) + 1 ;行最大值 tips:从0开始 所以要+1 loop, % rowSize { i := (y := A_index) - 1 t[y] := [] loop, % colSize { j := (x := A_index) - 1 t[y][x] := fetchedArray[j,i] ;取出二维数组内值 } } query.close() return t }
;预配置项 url_l = http://www.qisuu.com/soft/sort01/index_ id = 2 ;初始页码 maxid = 255 ;最大页码 url_r = .html site = http://www.qisuu.com kind = 玄幻奇幻 ;分类 1玄幻奇幻_289 2武侠仙侠_211 3女频言情_792 4现代都市_255 5历史军事_141 6游戏竞技_99 7科幻灵异_154 #NoEnv OnExit, exit ;初始化连接数据库 以便反复查询 DBFileName := A_ScriptDir . "qisuu.db" global DB DB := new SQLiteDB If !DB.OpenDB(DBFileName) { MsgBox, 16, SQLite错误, % "消息:`t" . DB.ErrorMsg . "`n代码:`t" . DB.ErrorCode ExitApp } ;首先检查初始化 if !IsObject(Query("select 1 from sqlite_master where name='novel'")) ;检查novel表 Exec("CREATE TABLE ""novel"" ( ""kind"" TEXT(255), ""name"" TEXT(255), ""author"" TEXT(255), ""size"" TEXT(255), ""class"" TEXT(255), ""url"" TEXT(255), ""image"" TEXT(255), ""description"" TEXT(255), ""download"" TEXT(255), ""creat_date"" TEXT(50), ""id"" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)") Loop % maxid-id { list := URLDownloadToVar(url_l id url_r,"gb2312") ;抓取小说列表 a := StrSplit(list,"`n","`r") ;分割行为数组 a_id = 465 ;直接跳到正文 Loop { a_id++ if (a_id>a.maxindex()) break ;抓取文章信息 if (RegExMatch(a[a_id],"s+<[^>]*>作者:([^<]*)<[^>]*>大小:([^<]*)<[^>]*>等级:<em class=""lstar(d)""><[^>]*><[^>]*>更新:([^<]*)<[^>]*>",b) || RegExMatch(a[a_id],"s+<[^>]*>作者:<[^>]*>([^<]*)<[^>]*><[^>]*>大小:([^<]*)<[^>]*>等级:<em class=""lstar(d)""><[^>]*><[^>]*>更新:([^<]*)<[^>]*>",b)) { author:=b1,size:=b2,class=b3,creat_date:=b4 a_id++ if (RegExMatch(a[a_id],"s+<a href=""([^""]*)""><img src=""([^""]*)""><[^>]*><[^>]*>([^<]*)<[^>]*><[^>]*><[^>]*>",c) || RegExMatch(a[a_id],"s+<a href=""([^""]*)""><img src=""([^""]*)"">([^<]*)<[^>]*>",c)) { url:=site c1,image:=site c2,name:=c3 a_id++ RegExMatch(a[a_id],"s+<div class=""u"">([^<]*)</div>",f) description := f1 page := URLDownloadToVar(url,"gb2312") ;获取详细页的下载地址 d := StrSplit(page,"`n","`r") Loop % d.maxindex() { if RegExMatch(d[A_Index],"s+<a class=""downButton"" href='([^']*)' title=""[^""]*"">RAR格式下载</a>",e) { download:=e1 ToolTip % id "页:" name Exec("INSERT INTO ""novel"" (""kind"", ""name"", ""author"", ""size"", ""class"", ""url"", ""image"", ""description"", ""download"", ""creat_date"") VALUES ('" kind "','" name "','" author "','" size "','" class "','" url "','" image "','" description "','" download "','" creat_date "')") ;插入数据库 break } } } } } id++ } MsgBox, Ok exit: DB.CloseDB() DB = ExitApp
说明:非标准控件应该抓不到,适配标准控件。按F12开启关闭监控,可以自己改热键。
F12:: kg := !kg ;反转 if kg SetTimer, monitor, 100 ;100毫秒 0.1秒 else { SetTimer, monitor, Off ToolTip } return monitor: MouseGetPos, Ox, Oy, Owin, Octr_class ;输出xy和窗口句柄 控件类 ControlGetText, Octr_text, %Octr_class%, ahk_id %Owin% ControlGet, Octr_id, Hwnd, , %Octr_class%, ahk_id %Owin% Octr_textshort := StrLen(Octr_text) < 20 ? Octr_text : SubStr(Octr_text,1,20) "..." ToolTip, 坐标:%Ox%`,%Oy%`n窗口句柄:%Owin%`n控件文字:%Octr_textshort%`n控件类:%Octr_class%`n控件句柄:%Octr_id% return
GetChooseFile(ParseLink:=1){ ;可选参数 1解析lnk 其他不解析 默认解析 ClipSave := ClipboardAll ;转存当前剪切板 Send, ^c Sleep, 100 Paths := Clipboard Clipboard := ClipSave Paths2 = Loop, Parse, Paths, `n, `r ;解析获取的字符串 { if (ParseLink=1 && RegExMatch(A_LoopField,"\.lnk$")) { FileGetShortcut, % A_LoopField, t Paths2 .= t "`n" } else Paths2 .= A_LoopField "`n" } return Paths2 }
Gui, Add, Button, x0 y0 w100 h20 ga, 粘贴数据A(少) Gui, Add, Button, x100 y0 w100 h20 gb, 粘贴数据B(多) Gui, Add, Button, x200 y0 w100 h20 gc, 提交 Gui, Add, text, x0 y20 w300 h20, 选择筛选关键字段 Gui, Add, DDL, x0 y40 w300 vkey, Gui, Add, text, x0 y60 w300 h20, Gui, Add, Edit, x0 y80 w300 h200 vshow, Gui, Add, StatusBar, x0 y280 Gui, Show, , Excel追加数据提取(去重) return a: data_a := StrSplit(Clipboard,"`n","`r") ;按行分割成数组 SB_SetText("数据A粘贴成功!") x := StrSplit(data_a[1],"`t") ;获取字段 y = for k,v in x y .= v ? "|" k "_" v : "" GuiControl,, key, % y return b: data_b := StrSplit(Clipboard,"`n","`r") SB_SetText("数据B粘贴成功!") return c: SB_SetText("") GuiControlGet, key if !key { MsgBox, 4112, 错误, 未选择关键字段 return } d := StrSplit(key,"_") ;获取关键字段id key_num := d[1] SB_SetText("生成数据A哈希") hash_a := [] for k,v in data_a { if A_index>1 { if RegExMatch(v,"^[A-Za-z0-9]+$") ;纯数字字母组合直接加入提高效率 hash_a["" v] := A_Index ;加""强制转成文本 else ;复杂值获取MD5 hash_a[MD5(StrSplit(v,"`t")[key_num],"CP0")] := A_index } } SB_SetText("生成数据B哈希") hash_b := [] for k,v in data_b { if A_index>1 { if RegExMatch(v,"^[A-Za-z0-9]+$") hash_b["" v] := A_Index else hash_b[MD5(StrSplit(v,"`t")[key_num],"CP0")] := A_index } } out := data_a[1] SB_SetText("去重") for k,v in hash_b { if !hash_a[k] ;数据A中不存在此关键字段值 out .= "`n" data_b[v] } GuiControl, , show, % out Clipboard := out SB_SetText("完成,结果已复制到剪切板") data_a:="",data_b:="",hash_a:="",hash_a:="",x:="",y:="",key_num:="",out:="" GuiControl, , key, | return GuiClose: ExitApp
环境说明:
Elastix 2.5
ln -s /var/spool/asterisk/monitor /var/www/html/
接口文件(php):
<?php $con=mysql_connect("localhost","root","passwd"); if(!$con) echo "没有连接成功!"; mysql_select_db("asteriskcdrdb", $con); mysql_query("SET NAMES UTF8"); if(isset($_GET["phone"])){ $phone=$_GET["phone"]; if(isset($_GET["date"])){ $calldate=$_GET["date"]; $q = "SELECT * FROM `cdr` WHERE `dst`='$phone' and cast(`calldate` as date)='$calldate' order by `calldate` desc limit 100"; //此处注意dst和src }else{ $q = "SELECT * FROM `cdr` WHERE `dst`='$phone' order by `calldate` desc limit 100"; } $result = mysql_query($q, $con); if(mysql_num_rows($result)>0){ while($obj=mysql_fetch_object($result)){ $obj->src; $obj->dst; $obj->channel; $obj->billsec; $obj->calldate; $recordingfile = $obj->recordingfile; if($recordingfile){ $a = explode("-",$recordingfile);; $subdir = substr($a[3],0,4)."/".substr($a[3],4,2)."/".substr($a[3],6,2); $uri = "/monitor/$subdir/$recordingfile"; }else{ $uri=''; } echo $obj->src.",".$obj->dst.",".$obj->channel.",".$obj->dstchannel.",".$obj->disposition.",".$obj->billsec.",".$obj->calldate.",".$uri."\n"; } } } mysql_free_result($result); mysql_close($con); ?>
客户端程序(Autohotkey):
FileCreateDir, %A_ScriptDir%\sox FileCreateDir, c:\temp\ FileInstall, libgomp-1.dll, %A_ScriptDir%\sox\libgomp-1.dll FileInstall, pthreadgc2.dll, %A_ScriptDir%\sox\pthreadgc2.dll FileInstall, sox.exe, %A_ScriptDir%\sox\sox.exe FileInstall, zlib1.dll, %A_ScriptDir%\sox\zlib1.dll gui, Add, text, x0 y0 w60 h20, 号码 gui, Add, edit, x60 y0 w140 h20 vphone, Gui, Add, Checkbox, x200 y0 w100 h20 vcd, 呼叫时间 Gui, add, DateTime, x300 y0 w200 h20 vdate, Gui, Add, Button, x500 y0 w100 h20 Default gsearch, 查询 Gui, Add, Button, x600 y0 w100 h20 glisten, 听取所选 gui, add, ListView, x0 y20 w700 h300, 被叫|主叫|通道|目标通道|状态|通话时长|呼叫时间|录音链接 Gui, Add, ActiveX, x0 w700 h100 vwmp, {6BF52A52-394A-11D3-B153-00C04F79FAA6} gui, show, , 本地呼叫系统录音听取 GuiControl, , cd, 1 wmp.Settings.Volume := 100 return search: Gui, Submit, NoHide if cd=1 { FormatTime, calldate, % date, yyyy-MM-dd search_url := "http://192.168.1.2/monitor.php?phone=" phone "&date=" calldate } else search_url := "http://192.168.1.2/monitor.php?phone=" phone result := URLDownloadToVar(search_url) LV_Delete() loop, Parse, result, `n, `r { obj := StrSplit(A_LoopField,",") LV_Add("",obj*) } LV_ModifyCol() return listen: FocusedRowNumber := LV_GetNext(0, "F") if not FocusedRowNumber { MsgBox, 4144, 提示, 您未选择任何一条记录! Return } LV_GetText(uri, FocusedRowNumber, 8) if uri { url := "http://192.168.1.2" uri if RegExMatch(uri,".*/(.*)\.gsm$",m) { URLDownloadToFile, % url, % "c:\temp\" m1 ".gsm" RunWait, %A_ScriptDir%\sox\sox.exe c:\temp\%m1%.gsm c:\temp\%m1%.wav rate -v, , hide } else { RegExMatch(uri,".*/(.*)\.wav$",m) URLDownloadToFile, % url, % "c:\temp\" m1 ".wav" } wmp.Url := "c:\temp\" m1 ".wav" } else MsgBox, 64, 提示, 录音链接不存在! return GuiClose: ExitApp
EVfilterPath(path){ pattern = (.*)path:("|)[^"]*("|)\s(.*) ControlGetText, search_string, Edit1, ahk_class EVERYTHING if RegExMatch(search_string,pattern,m) ControlSetText, Edit1, % m1 "path:""" path """ " m4, ahk_class EVERYTHING else ControlSetText, Edit1, % "path:""" path """ " search_string, ahk_class EVERYTHING }
Autohotkey示例:
Gui Add, ActiveX, xm w700 h100 vwmp, {6BF52A52-394A-11D3-B153-00C04F79FAA6} Gui Show ;wmp.Settings.AutoStart := 0 wmp.Settings.Volume := 100 wmp.Url := "D:\我的文档\My Music\brave.mp3"
AAuto示例:
import win.ui; import fsys.dlg; /*DSG{{*/ var winform = ..win.form(text="AAuto Form";right=322;bottom=157) winform.add( static={cls="static";left=5;top=5;right=314;bottom=153;db=1;dl=1;dr=1;dt=1;edge=1;transparent=1;z=1} ) /*}}*/ //创建控件 var wmplay = winform.static.createEmbed("{6BF52A52-394A-11d3-B153-00C04F79FAA6}"); var filepath=fsys.dlg.open("mp3音乐|*.mp3","打开"); wmplay._object.Url = filepath; winform.show() win.loopMessage();
#NoEnv ;首先你要在ftp创建upload文件夹 FileInstall, ftp_upload.exe, ftp_upload.exe Gui, add, edit, x0 y0 w300 h20 vpath, Gui, Add, Button, x300 y0 w100 h20 gsfile, 浏览 Gui, add, edit, x0 y20 w300 h20 vdpath, Gui, Add, Button, x300 y20 w100 h20 gupload, 上传获取URL gui, show, , Nano云文件外链(FTP上传) ;定义你的ftp用户名密码 result := FtpOpen("ftp.nanoyun.com",,"xxxxx/xxxxxcdn","xxxxxxxpass") if result = 0 { MsgBox, 4112, 错误, 无法连接到服务器 ExitApp } return sfile: FileSelectFile, path, , , 选择要上传的文件, (*jpg;*.png;*.gif;*.zip;*.rar;*.zip;*.7z;*.ahk;*.aau;*.exe) ;允许上传的文件类型 if path { IfNotInString, path, %A_Space% GuiControl, , path, % path else { FileCopy, % path, % npath := RegExReplace(path," ","_") GuiControl, , path, % npath } GuiControl, , dpath, } return upload: Gui, Submit, NoHide if path { FileDelete, result.txt SplitPath, path, , , ext md5 := FileMD5(path) /* 外部工具方案 RunWait, % ComSpec " /c ftp_upload.exe ftp.nanoyun.com user pass " path " /upload/" md5 "." ext " >result.txt", , Hide FileRead, result, result.txt if result MsgBox, 64, 提示, % result */ result := FtpPutFile(path, "/upload/" md5 "." ext, 2) if result = 0 { MsgBox, 4112, 错误, 上传遇到错误! return } MsgBox, 64, 提示, % result "`n已复制到剪切板!" GuiControl, , dpath, % Clipboard := "http://cdn.ywwx.com.cn/upload/" md5 "." ext ;此处是你的外链网址 需要修改 } return GuiClose: FtpClose() ExitApp ;ftp函数集 FtpCreateDirectory(DirName) { ;创建目录 global ic_hInternet r := DllCall("wininet\FtpCreateDirectoryA", "uint", ic_hInternet, "str", DirName) If (ErrorLevel != 0 or r = 0) return 0 else return 1 } FtpRemoveDirectory(DirName) { ;移除目录 global ic_hInternet r := DllCall("wininet\FtpRemoveDirectoryA", "uint", ic_hInternet, "str", DirName) If (ErrorLevel != 0 or r = 0) return 0 else return 1 } FtpSetCurrentDirectory(DirName) { ;设置当前目录 global ic_hInternet r := DllCall("wininet\FtpSetCurrentDirectoryA", "uint", ic_hInternet, "str", DirName) If (ErrorLevel != 0 or r = 0) return 0 else return 1 } FtpPutFile(LocalFile, NewRemoteFile="", Flags=0) { ;上传文件 ;Flags: ;FTP_TRANSFER_TYPE_UNKNOWN = 0 (Defaults to FTP_TRANSFER_TYPE_BINARY) ;FTP_TRANSFER_TYPE_ASCII = 1 文本方式 ;FTP_TRANSFER_TYPE_BINARY = 2 二进制方式 If NewRemoteFile= NewRemoteFile := LocalFile global ic_hInternet r := DllCall("wininet\FtpPutFileA" , "uint", ic_hInternet , "str", LocalFile , "str", NewRemoteFile , "uint", Flags , "uint", 0) ;dwContext If (ErrorLevel != 0 or r = 0) return 0 else return 1 } FtpGetFile(RemoteFile, NewFile="", Flags=0) { ;下载文件 ;Flags: ;FTP_TRANSFER_TYPE_UNKNOWN = 0 (Defaults to FTP_TRANSFER_TYPE_BINARY) ;FTP_TRANSFER_TYPE_ASCII = 1 ;FTP_TRANSFER_TYPE_BINARY = 2 If NewFile= NewFile := RemoteFile global ic_hInternet r := DllCall("wininet\FtpGetFileA" , "uint", ic_hInternet , "str", RemoteFile , "str", NewFile , "int", 1 ;do not overwrite existing files , "uint", 0 ;dwFlagsAndAttributes , "uint", Flags , "uint", 0) ;dwContext If (ErrorLevel != 0 or r = 0) return 0 else return 1 } FtpGetFileSize(FileName, Flags=0) { ;获取文件大小 ;Flags: ;FTP_TRANSFER_TYPE_UNKNOWN = 0 (Defaults to FTP_TRANSFER_TYPE_BINARY) ;FTP_TRANSFER_TYPE_ASCII = 1 ;FTP_TRANSFER_TYPE_BINARY = 2 global ic_hInternet fof_hInternet := DllCall("wininet\FtpOpenFileA" , "uint", ic_hInternet , "str", FileName , "uint", 0x80000000 ;dwAccess: GENERIC_READ , "uint", Flags , "uint", 0) ;dwContext If (ErrorLevel != 0 or fof_hInternet = 0) return -1 FileSize := DllCall("wininet\FtpGetFileSize", "uint", fof_hInternet, "uint", 0) DllCall("wininet\InternetCloseHandle", "UInt", fof_hInternet) return, FileSize } FtpDeleteFile(FileName) { ;删除文件 global ic_hInternet r := DllCall("wininet\FtpDeleteFileA", "uint", ic_hInternet, "str", FileName) If (ErrorLevel != 0 or r = 0) return 0 else return 1 } FtpRenameFile(Existing, New) { ;重命名文件 global ic_hInternet r := DllCall("wininet\FtpRenameFileA", "uint", ic_hInternet, "str", Existing, "str", New) If (ErrorLevel != 0 or r = 0) return 0 else return 1 } FtpOpen(Server, Port=21, Username=0, Password=0 ,Proxy="", ProxyBypass="") { ;打开ftp连接 IfEqual, Username, 0, SetEnv, Username, anonymous IfEqual, Password, 0, SetEnv, Password, anonymous If (Proxy != "") AccessType=3 Else AccessType=1 ;#define INTERNET_OPEN_TYPE_PRECONFIG 0 // use registry configuration ;#define INTERNET_OPEN_TYPE_DIRECT 1 // direct to net ;#define INTERNET_OPEN_TYPE_PROXY 3 // via named proxy ;#define INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY 4 // prevent using java/script/INS global ic_hInternet, io_hInternet, hModule hModule := DllCall("LoadLibrary", "str", "wininet.dll") io_hInternet := DllCall("wininet\InternetOpenA" , "str", A_ScriptName ;lpszAgent , "UInt", AccessType , "str", Proxy , "str", ProxyBypass , "UInt", 0) ;dwFlags If (ErrorLevel != 0 or io_hInternet = 0) { FtpClose() return 0 } ic_hInternet := DllCall("wininet\InternetConnectA" , "uint", io_hInternet , "str", Server , "uint", Port , "str", Username , "str", Password , "uint" , 1 ;dwService (INTERNET_SERVICE_FTP = 1) , "uint", 0 ;dwFlags , "uint", 0) ;dwContext If (ErrorLevel != 0 or ic_hInternet = 0) return 0 else return 1 } FtpClose() { ;关闭ftp连接 global ic_hInternet, io_hInternet, hModule DllCall("wininet\InternetCloseHandle", "UInt", ic_hInternet) DllCall("wininet\InternetCloseHandle", "UInt", io_hInternet) DllCall("FreeLibrary", "UInt", hModule) } FileMD5(filename) ;计算文件MD5值 { return CalcFileHash(filename, 0x8003, 64 * 1024) } CalcFileHash(filename, algid, continue = 0, byref hash = 0, byref hashlength = 0) ;计算文件hash { fpos := "" if (!(f := FileOpen(filename, "r"))) { return } f.pos := 0 if (!continue && f.length > 0x7fffffff) { return } if (!continue) { VarSetCapacity(data, f.length, 0) f.rawRead(&data, f.length) f.pos := oldpos return CalcAddrHash(&data, f.length, algid, hash, hashlength) } hashlength := 0 while (f.pos < f.length) { readlength := (f.length - fpos > continue) ? continue : f.length - f.pos VarSetCapacity(data, hashlength + readlength, 0) DllCall("RtlMoveMemory", "Ptr", &data, "Ptr", &hash, "Ptr", hashlength) f.rawRead(&data + hashlength, readlength) h := CalcAddrHash(&data, hashlength + readlength, algid, hash, hashlength) } return h } CalcAddrHash(addr, length, algid, byref hash = 0, byref hashlength = 0) { static h := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f"] static b := h.minIndex() hProv := hHash := o := "" if (DllCall("advapi32\CryptAcquireContext", "Ptr*", hProv, "Ptr", 0, "Ptr", 0, "UInt", 24, "UInt", 0xf0000000)) { if (DllCall("advapi32\CryptCreateHash", "Ptr", hProv, "UInt", algid, "UInt", 0, "UInt", 0, "Ptr*", hHash)) { if (DllCall("advapi32\CryptHashData", "Ptr", hHash, "Ptr", addr, "UInt", length, "UInt", 0)) { if (DllCall("advapi32\CryptGetHashParam", "Ptr", hHash, "UInt", 2, "Ptr", 0, "UInt*", hashlength, "UInt", 0)) { VarSetCapacity(hash, hashlength, 0) if (DllCall("advapi32\CryptGetHashParam", "Ptr", hHash, "UInt", 2, "Ptr", &hash, "UInt*", hashlength, "UInt", 0)) { loop % hashlength { v := NumGet(hash, A_Index - 1, "UChar") o .= h[(v >> 4) + b] h[(v & 0xf) + b] } } } } DllCall("advapi32\CryptDestroyHash", "Ptr", hHash) } DllCall("advapi32\CryptReleaseContext", "Ptr", hProv, "UInt", 0) } return o }
50 queries in 1.650 seconds |