#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Date.au3>
#include <File.au3>
#include <Array.au3>
#include <FTPEx.au3>
#include <WinAPI.au3>
#include <GuiToolTip.au3>
#include <GuiTab.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("RZX日志备份器", 387, 346, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Group1 = GUICtrlCreateGroup("本地备份设置", 8, 8, 369, 89)
GUICtrlSetFont(-1, 9, 400, 0, "黑体")
$Button1 = GUICtrlCreateButton("浏览", 328, 31, 41, 22)
GUICtrlSetOnEvent(-1, "Button1Click")
$Label1 = GUICtrlCreateLabel("RZX日志目录", 16, 32, 75, 21)
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
$Input1 = GUICtrlCreateInput("", 96, 32, 225, 20)
$Label2 = GUICtrlCreateLabel("本地备份目录", 16, 64, 76, 21)
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
$input2 = GUICtrlCreateInput("", 96, 64, 225, 20)
$Button2 = GUICtrlCreateButton("浏览", 328, 63, 41, 22)
GUICtrlSetOnEvent(-1, "Button2Click")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("异地备份设置", 8, 112, 369, 89)
GUICtrlSetFont(-1, 9, 400, 0, "黑体")
$Label3 = GUICtrlCreateLabel("异地备份目录", 16, 136, 76, 21)
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
$Input3 = GUICtrlCreateInput("请输入FTP地址或共享路径", 104, 136, 225, 20)
;GUICtrlSetFont(-1, 9, 400, 0, "宋体")
GUICtrlSetColor(-1, 0xC0C0C0)
GUICtrlSetOnEvent(-1, "Input3Change")
$Label4 = GUICtrlCreateLabel("用户名", 16, 168, 40, 21)
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
$Input4 = GUICtrlCreateInput("", 56, 168, 97, 20)
$Label5 = GUICtrlCreateLabel("密码", 168, 168, 28, 21)
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
$Input5 = GUICtrlCreateInput("", 199, 168, 97, 20, $ES_PASSWORD)
$Button3 = GUICtrlCreateButton("测试连接", 312, 168, 57, 22)
GUICtrlSetOnEvent(-1, "Button3Click")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("计划任务设置", 8, 216, 369, 73)
GUICtrlSetFont(-1, 9, 400, 0, "黑体")
$Label6 = GUICtrlCreateLabel("保存", 16, 240, 28, 16)
$Combo1 = GUICtrlCreateCombo("", 48, 232, 41, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
$Label7 = GUICtrlCreateLabel("天内的日志文件", 88, 240, 88, 16)
$Label8 = GUICtrlCreateLabel("每天", 16, 264, 28, 16)
GUICtrlCreateInput("", 48, 256, 49, 20, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
$Label9 = GUICtrlCreateLabel("点自动备份日志", 96, 264, 88, 16)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
If _WinAPI_GetFocus() = GUICtrlGetHandle($Input3) And GUICtrlRead($Input3) = "请输入FTP地址或共享路径" Then
GUICtrlSetData($Input3, "")
GUICtrlSetColor($Input3, 0x000000)
ElseIf _WinAPI_GetFocus() <> GUICtrlGetHandle($Input3) And GUICtrlRead($Input3) = "" Then
GUICtrlSetColor($Input3, 0xC0C0C0)
GUICtrlSetData($Input3, "请输入FTP地址或共享路径")
EndIf
Sleep(100)
WEnd
Func Input3Change()
$pos = ControlGetPos("RZX日志备份器", "", $Input3)
If GUICtrlRead($Input3) <> "" Then
If StringInStr(GUICtrlRead($Input3), "ftp", 0, 1, 1, 3) = 0 Or StringInStr(GUICtrlRead($Input3), "\", 0, 1, 1, 2) Then GUICtrlSetTip($Input3, "请输入FTP地址或UNC共享路径", "输入错误", 3, 1)
EndIf
EndFunc ;==>Input3Change
Func Click()
MsgBox(0, 0, 0)
EndFunc ;==>Click
Func Button1Click()
GUISetState(@SW_DISABLE, $Form1)
GUICtrlSetData($Input1, FileSelectFolder("指定RZX日志目录", "D:", 1, "", $Form1))
GUISetState(@SW_ENABLE, $Form1)
EndFunc ;==>Button1Click
Func Button2Click()
GUISetState(@SW_DISABLE, $Form1)
GUICtrlSetData($input2, FileSelectFolder("指定日志备份目录", "D:", 1, "", $Form1))
GUISetState(@SW_ENABLE, $Form1)
EndFunc ;==>Button2Click
Func Button3Click()
If StringInStr(StringLeft(GUICtrlRead($Input3), 3), "\") Then
RunWait(@ComSpec & " /c net use " & GUICtrlRead($Input3) & " " & GUICtrlRead($Input5) & " /user:" & GUICtrlRead($Input4), "", @SW_HIDE)
If FileExists(GUICtrlRead($Input3)) Then
MsgBox(0, 0, "通过")
Else
MsgBox(48, 0, "不存在")
EndIf
ElseIf StringInStr(StringLeft(GUICtrlRead($Input3), 3), "ftp") Then
If StringInStr(StringMid(GUICtrlRead($Input3), 7), ":") = 0 Then
$Address = StringMid(GUICtrlRead($Input3), 7)
$Port = 21
Else
$Address = StringLeft(StringMid(GUICtrlRead($Input3), 7), StringInStr(StringMid(GUICtrlRead($Input3), 7), ":") - 1)
$Port = StringMid(StringMid(GUICtrlRead($Input3), 7), StringInStr(StringMid(GUICtrlRead($Input3), 7), ":") + 1)
EndIf
MsgBox(0, 0, $Address)
MsgBox(0, 0, $Port)
$Open = _FTP_Open("BackupFTP")
$Conn = _FTP_Connect($Open, $Address, GUICtrlRead($Input4), GUICtrlRead($Input5), 0, $Port)
If @error Then
MsgBox(0, 0, "NO")
Else
MsgBox(0, 0, $Conn)
EndIf
EndIf
EndFunc ;==>Button3Click
Func Form1Close()
Exit
EndFunc ;==>Form1Close
$SourcePath = IniRead("RZXbackup.dll", "set", "SourcePath", "D:\RZX")
$BackupPath = IniRead("RZXbackup.dll", "set", "BackupPath", "D:\Bak")
$NetPath = IniRead("RZXbackup.dll", "set", "NetPath", "d:")
$User = IniRead("RZXbackup.dll", "set", "User", "")
$PassWord = IniRead("RZXbackup.dll", "set", "PassWord", "")
$KeepDays = IniRead("RZXbackup.ini", "set", "KeepDays", "10")
Dim $BackupFileList[$KeepDays + 1] = [$KeepDays]
For $i = 1 To $KeepDays
$BackupFileList[$i] = "Z_" & StringReplace(_DateAdd("d", -$i, _NowCalcDate()), "/", "") & ".log"
Next
DelCopyFile($BackupPath)
Func DelCopyFile($Path)
$Array = _FileListToArray($Path, "*.log", 1)
If $Array <> 0 Then
For $i = 1 To $Array[0]
_ArraySearch($BackupFileList, $Array[$i])
If @error = 6 And $Array[$i] <> "Z_" & StringReplace(_NowCalcDate(), "/", "") & ".log" Then FileDelete($Path & "" & $Array[$i])
Next
If $Path <> $SourcePath Then
For $i = 1 To $BackupFileList[0]
_ArraySearch($Array, $BackupFileList[$i])
If @error = 6 Then FileCopy($SourcePath & "" & $BackupFileList[$i], $Path)
Next
EndIf
Else
If $Path <> $SourcePath Then
For $i = 1 To $BackupFileList[0]
FileCopy($SourcePath & "" & $BackupFileList[$i], $Path)
Next
EndIf
EndIf
EndFunc ;==>DelCopyFile