wi.nikolaev
Новичок
- Сообщения
- 32
- Репутация
- 1
Версия AutoIt: 3.3.8.1
Описание:
Программа должна иметь GUI.
В программе необходимо реализовать копирование файлов по сети в две и более директории, по возможности директории можно будет добавлять. Также необходимо сделать лог выполненных операций и реализовать файл с сохранением параметров.
Примечания:
Наброски программы - Помогите разобраться с работой кнопок "Обзор" и "Удаление"
Описание:
Программа должна иметь GUI.
В программе необходимо реализовать копирование файлов по сети в две и более директории, по возможности директории можно будет добавлять. Также необходимо сделать лог выполненных операций и реализовать файл с сохранением параметров.
Примечания:
Наброски программы - Помогите разобраться с работой кнопок "Обзор" и "Удаление"
Код:
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_Fileversion=1.0
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#region Include
#NoTrayIcon
#Include <Constants.au3>
#include <EditConstants.au3>
#Include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#Include <String.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#endregion
#region Opt
Opt('GUIOnEventMode', 1)
Opt('MustDeclareVars', 1)
#endregion
#region Pro
Global $sProName, $iProVer, $sProNameVer, $sProInstancID, $fProInstanc, $iProSleep, $hAutoItWin, $sCfgName, $sCfgFile
$sProName = 'FilesCopy'
$iProVer = '1.0'
$sProNameVer = $sProName &' v'& $iProVer
$sProInstancID = ' Instanc ID: '& $sProNameVer &' Instanc ID: '& $sProNameVer
$fProInstanc = 1
$iProSleep = 20
If Not _Singleton($sProInstancID, 1) Then
Msgbox(48, 'Warning', 'Program is already running')
Exit
EndIf
AutoItWinSetTitle($sProNameVer &' '& @AutoItPID)
$hAutoItWin = WinGetHandle(AutoItWinGetTitle())
OnAutoItExitRegister('_ProExit_Action')
;~ HotKeySet('{ESC}', '_ProExit')
$sCfgName = StringRegExpReplace(@ScriptName, '(.*)\..*', '\1') & '.ini'
$sCfgFile = FileGetShortName(@ScriptDir &'\'& $sCfgName)
#endregion
#region Global
Local $y
; Params
Global $sLastCopyFile, $sLastCopyPath, $sDefCopyPath, $fShowAtStart, $fTrayState, $fMinToTray, $fCloseToTray, $iTrayLeftClick, $iTrayRightClick
; GUI: Main win
Global $hMainWin, $iMainWin_Width, $iMainWin_Height, $iMainWin_X, $iMainWin_Y, $hMainWinMin, $aGUIs1[15], $aGUIs2[6]
Global $hCopyFile, $hCopyPath, $hBtCopy, $hCopyFileInfo, $hCopyPathInfo, $hCopyStatus
$hMainWinMin = 0
$iMainWin_Width = 600
$iMainWin_Height = 300
$aGUIs1[0] = 14
$aGUIs2[0] = 5
; GUI: Settings win
Global $hSettingsWin, $iSettingsWin_Width, $iSettingsWin_Height, $iSettingsWin_X, $iSettingsWin_Y
Global $hCopyDefPath
$iSettingsWin_Width = 500
$iSettingsWin_Height = 270
; GUI: Tray
Global $fTrayShow, $iTraiTipTime
Global $hMinToTray, $hCloseToTray, $hShowAtStart, $hTrayState, $hTrayLeftClick, $hTrayRightClick
$iTraiTipTime = 4000; msec
; Copy
Global $iCopyPID, $iCopyCheck, $sCopyParam, $iCopyFileSize, $sCopyFileTo
$iCopyCheck = 50
; Read/Write INI
If Not FileExists($sCfgFile) Then _IniCreate()
$sLastCopyFile = _IniRead('', 'Params', 'LastCopyFile', '', 1, 3)
$sLastCopyPath = _IniRead('', 'Params', 'LastCopyPath', '', 1, 3)
$sDefCopyPath = _IniRead('', 'Params', 'DefCopyPath', '', 1, 3)
$fShowAtStart = _IniRead('', 'Params', 'ShowAtStart', 1, 1, 8, '^[01]$')
#endregion
#region GUI: Main win
$hMainWin = GUICreate($sProNameVer, $iMainWin_Width, $iMainWin_Height, $iMainWin_X, $iMainWin_Y)
GUISetOnEvent($GUI_EVENT_CLOSE, '_MainWinClose')
; Copy file 1
$aGUIs1[1] = GUICtrlCreateGroup(' Копируемый файл 1: ', 10, 10, $iMainWin_Width-20, 65)
GUICtrlSetFont(-1, 10)
$aGUIs1[2] = GUICtrlCreateInput($sLastCopyFile, 25, 35, $iMainWin_Width-138-24, 25)
GUICtrlSetFont(-1, 12)
$hCopyFile = $aGUIs1[2]
$aGUIs1[3] = GUICtrlCreateButton('X', $iMainWin_Width-110-25, 35, 25)
GUICtrlSetOnEvent(-1, '_CopyFileNullInput')
$aGUIs1[4] = GUICtrlCreateButton('Обзор', $iMainWin_Width-85, 35, 60)
GUICtrlSetOnEvent(-1, '_CopyFileFind')
; Copy file 2
$aGUIs1[1] = GUICtrlCreateGroup(' Копируемый файл 2: ', 10, 85, $iMainWin_Width-20, 65)
GUICtrlSetFont(-1, 10)
$aGUIs1[2] = GUICtrlCreateInput($sLastCopyFile, 25, 105, $iMainWin_Width-138-24, 25)
GUICtrlSetFont(-1, 12)
$hCopyFile = $aGUIs1[2]
$aGUIs1[3] = GUICtrlCreateButton('X', $iMainWin_Width-110-25, 105, 25)
GUICtrlSetOnEvent(-1, '_CopyFileNullInput')
$aGUIs1[4] = GUICtrlCreateButton('Обзор', $iMainWin_Width-85, 105, 60)
GUICtrlSetOnEvent(-1, '_CopyFileFind')
; Copy path
;$y = 70
;$aGUIs1[5] = GUICtrlCreateGroup(' Папка копирования: ', 10, 10+$y, $iMainWin_Width-20, 65)
; GUICtrlSetFont(-1, 10)
;$aGUIs1[6] = GUICtrlCreateInput($sLastCopyPath, 25, 35+$y, $iMainWin_Width-138-24, 25)
; GUICtrlSetFont(-1, 11)
; $hCopyPath = $aGUIs1[6]
;$aGUIs1[7] = GUICtrlCreateButton('X', $iMainWin_Width-110-25, 35+$y, 25)
; GUICtrlSetOnEvent(-1, '_CopyPathNullInput')
;$aGUIs1[8] = GUICtrlCreateButton('O', $iMainWin_Width-110, 35+$y, 25)
; GUICtrlSetOnEvent(-1, '_CopyPathOpenDir')
;$aGUIs1[9] = GUICtrlCreateButton('Обзор', $iMainWin_Width-85, 35+$y, 60)
; GUICtrlSetOnEvent(-1, '_CopyPathFind')
; Buttons
$aGUIs1[10] = GUICtrlCreateButton('Закрыть', 10, 155, 70)
GUICtrlSetOnEvent(-1, '_ProExit')
$hBtCopy = GUICtrlCreateButton('Копировать', $iMainWin_Width-125, 155, 115)
GUICtrlSetFont(-1, 9, 600)
GUICtrlSetOnEvent(-1, '_Copy')
#region Start
GUIRegisterMsg($WM_MOVE, 'WM_MOVE')
GUIRegisterMsg($WM_NCHITTEST, 'WM_NCHITTEST')
_TrayState()
_TraySetClick()
If $fShowAtStart Then
_MainWinShow()
Else
_TrayShow()
EndIf
_MainWinHotKey()
#endregion
#region Sleep...
While 1
Sleep($iProSleep)
_MainWinMin()
WEnd
Func _ProExit()
Exit
EndFunc
Func _ProExit_Action()
EndFunc
#endregion
#region Ini
Func _IniCreate()
FileWrite($sCfgFile, '')
EndFunc
Func _IniRead($sFile, $sSection, $sKey, $sDef='', $fReWriteIfEr=0, $iStringStripWS=3, $sTestPattern='', $fTestOk=1)
If $sFile == '' Then $sFile = StringRegExpReplace(@ScriptFullPath, '(.*)\..*', '\1') & '.ini'
If Not FileExists($sFile) Then
SetError(1)
Return $sDef
EndIf
If $sSection == '' Then
SetError(2)
Return $sDef
EndIf
If $sKey == '' Then
SetError(3)
Return $sDef
EndIf
Local $sResult = IniRead($sFile, $sSection, $sKey, '<^!!$@#error#@$!!^>')
If $sResult <> '<^!!$@#error#@$!!^>' Then
$sResult = StringStripWS($sResult, $iStringStripWS)
If StringRegExp($sResult, '^-?\d+\.?\d*$') Then $sResult = Number($sResult)
Else
$sResult = $sDef
If $fReWriteIfEr Then _IniWrite($sFile, $sSection, $sKey, $sResult)
EndIf
If $sTestPattern <> '' Then
If $fTestOk <> 1 AND $fTestOk <> 0 Then $fTestOk = 1
If StringRegExp($sResult, $sTestPattern) <> $fTestOk Then $sResult = $sDef
EndIf
SetError(0)
Return $sResult
EndFunc
Func _IniWrite($sFile, $sSection, $sKey, $sValue='', $iStringStripWS=0)
If $sFile == '' Then $sFile = StringRegExpReplace(@ScriptFullPath, '(.*)\..*', '\1') & '.ini'
If $sSection == '' Then
SetError(1)
Return 0
EndIf
If $sKey == '' Then
SetError(2)
Return 0
EndIf
If $iStringStripWS Then $sValue = StringStripWS($sValue, $iStringStripWS)
If Not StringRegExp($sValue, '^-?\d+\.?\d*$') Then
$sValue = '"'& $sValue &'"'
Else
$sValue = Number($sValue)
EndIf
If Not IniWrite($sFile, $sSection, $sKey, $sValue) Then
SetError(3)
Return 0
EndIf
SetError(0)
Return 1
EndFunc
#endregion
#region Functions: Tray
Func _TrayState()
If $fTrayState Then
_TrayShow()
Else
_TrayHide()
EndIf
EndFunc
Func _TrayShow()
If $fTrayShow Then Return
TraySetState(1)
$fTrayShow = 1
EndFunc
Func _TrayHide()
If Not $fTrayShow Then Return
TraySetState(2)
$fTrayShow = 0
EndFunc
Func _TraySetClick()
Local $iMouseButton = 0
If $iTrayLeftClick == 1 Then
$iMouseButton += 1
Else
_TraySetClick_Action($TRAY_EVENT_PRIMARYDOWN, $iTrayLeftClick)
EndIf
If $iTrayRightClick == 1 Then
$iMouseButton += 8
Else
_TraySetClick_Action($TRAY_EVENT_SECONDARYDOWN, $iTrayRightClick)
EndIf
TraySetClick($iMouseButton)
EndFunc
Func _TraySetClick_Action($vEvent, $iType)
Switch $iType
Case 0
TraySetOnEvent($vEvent, '')
Case 2
TraySetOnEvent($vEvent, '_CopyQuick')
Case 3
TraySetOnEvent($vEvent, '_MainWinShow')
Case 4
TraySetOnEvent($vEvent, '_SettingsWinShow')
Case 5
TraySetOnEvent($vEvent, '_ProExit')
EndSwitch
EndFunc
#endregion
#region Functions: Main win
; Win
Func WM_NCHITTEST($hWnd, $Msg, $wParam, $lParam)
Local $iProc = DllCall('user32.dll', 'int', 'DefWindowProc', 'hwnd', $hWnd, 'int', $Msg, 'wparam', $wParam, 'lparam', $lParam)
If $iProc[0] = $HTCLIENT Then Return $HTCAPTION
Return $GUI_RUNDEFMSG
EndFunc
Func WM_MOVE($hWnd, $Msg, $wParam, $lParam)
If $hWnd <> $hMainWin OR BitAnd(WinGetState($hMainWin), 16) Then Return
Local $aWinPos = WinGetPos($hWnd)
_IniWrite('', 'Params', 'WinX', $aWinPos[0])
_IniWrite('', 'Params', 'WinY', $aWinPos[1])
EndFunc
Func _MainWinHotKey()
Local $sEvent = '_ProExit'
If $fCloseToTray Then $sEvent = '_MainWinHide'
If BitAnd(WinGetState($hMainWin), 16) OR Not BitAnd(WinGetState($hMainWin), 2) Then
HotKeySet('{ESC}')
Else
HotKeySet('{ESC}', $sEvent)
EndIf
EndFunc
Func _MainWinClose()
If $fCloseToTray Then
_MainWinHide()
Else
_ProExit()
EndIf
EndFunc
Func _MainWinMin()
If BitAnd(WinGetState($hMainWin), 16) OR Not BitAnd(WinGetState($hMainWin), 2) Then
If $hMainWinMin Then Return
$hMainWinMin = 1
If $fMinToTray Then
_MainWinHide()
_TrayShow()
EndIf
Else
If Not $hMainWinMin Then Return
$hMainWinMin = 0
EndIf
EndFunc
Func _MainWinShow()
GUISetState(@SW_SHOW, $hMainWin)
GUISetState(@SW_RESTORE, $hMainWin)
_TrayState()
_MainWinHotKey()
If Not WinActive($hMainWin) Then WinActivate($hMainWin)
EndFunc
Func _MainWinHide()
GUISetState(@SW_HIDE, $hMainWin)
_TrayShow()
_MainWinHotKey()
EndFunc
; Copy file
Func _CopyFileNullInput()
GUICtrlSetData($hCopyFile, '')
EndFunc
Func _CopyFileOpenDir()
Local $sFile = StringRegExpReplace(GUICtrlRead($hCopyFile), '^(.+\\).+\..*$', '\1')
If $sFile == '' OR Not FileExists($sFile) Then
MsgBox(16, 'Ошибка', 'Папка назначения не найдена')
Return
EndIf
Run('explorer.exe "' & $sFile & '"')
EndFunc
Func _CopyFileFind()
Local $sFile = GUICtrlRead($hCopyFile)
If $sFile == '' OR StringInStr(FileGetAttrib($sFile), 'D') OR Not FileExists($sFile) Then $sFile = $sLastCopyFile
$sFile = FileOpenDialog('Выберите копируемый файл', StringRegExpReplace($sFile, '^(.+\\).+\..*$', '\1'), 'All (*.*)', 1, StringRegExpReplace($sFile, '^.+\\(.+\..*)$', '\1'), $hMainWin)
If $sFile <> '' AND $sFile <> $sLastCopyFile Then
$sLastCopyFile = $sFile
GUICtrlSetData($hCopyFile, $sLastCopyFile)
_IniWrite('', 'Params', 'LastCopyFile', $sLastCopyFile)
EndIf
EndFunc
; Copy path
Func _CopyPathNullInput()
GUICtrlSetData($hCopyPath, '')
EndFunc
Func _CopyPathOpenDir()
_OpenDir(GUICtrlRead($hCopyPath))
EndFunc
Func _CopyPathFind()
Local $sDir = GUICtrlRead($hCopyPath)
If $sDir == '' OR Not StringInStr(FileGetAttrib($sDir), 'D') OR Not FileExists($sDir) Then $sDir = $sLastCopyPath
If Not StringInStr(FileGetAttrib($sDir), 'D') Then $sDir = ''
$sDir = FileSelectFolder('Выберите папку копирования', '', 1, $sDir, $hMainWin)
If $sDir <> '' AND $sDir <> $sLastCopyPath Then
$sLastCopyPath = $sDir
GUICtrlSetData($hCopyPath, $sLastCopyPath)
_IniWrite('', 'Params', 'LastCopyPath', $sLastCopyPath)
EndIf
EndFunc
Func _OpenDir($sDir)
If $sDir == '' OR Not StringInStr(FileGetAttrib($sDir), 'D') OR Not FileExists($sDir) Then
MsgBox(16, 'Ошибка', 'Папка назначения не найдена')
Return
EndIf
Run('explorer.exe "' & $sDir & '"')
EndFunc
#endregion
; Copy def path
Func _CopyDefPathNullInput()
GUICtrlSetData($hCopyPath, '')
EndFunc
Func _CopyDefPathOpenDir()
_OpenDir(GUICtrlRead($hCopyDefPath))
EndFunc
Func _CopyDefPathFind()
Local $sDir = GUICtrlRead($hCopyDefPath)
If $sDir == '' OR Not StringInStr(FileGetAttrib($sDir), 'D') OR Not FileExists($sDir) Then $sDir = $sDefCopyPath
If Not StringInStr(FileGetAttrib($sDir), 'D') Then $sDir = ''
$sDir = FileSelectFolder('Выберите папку копирования', '', 1, $sDir, $hSettingsWin)
If $sDir AND $sDir <> $sDefCopyPath Then
$sDefCopyPath = $sDir
GUICtrlSetData($hCopyDefPath, $sDefCopyPath)
_IniWrite('', 'Params', 'DefCopyPath', $sDefCopyPath)
EndIf
EndFunc
Func _CopyDone($sType)
AdlibUnRegister('_CopyCheck')
If $sType == 'done' AND (BitAnd(WinGetState($hMainWin), 16) OR Not BitAnd(WinGetState($hMainWin), 2)) Then TrayTip('Копирование файла', 'Выполненно', $iTraiTipTime)
For $i=1 To $aGUIs1[0]
GUICtrlSetState($aGUIs1[$i], $GUI_SHOW)
Next
For $i=1 To $aGUIs2[0]
GUICtrlSetState($aGUIs2[$i], $GUI_HIDE)
Next
GUICtrlSetData($hBtCopy, 'Копировать')
GUICtrlSetPos($hBtCopy, $iMainWin_Width-125, 155, 115)
GUICtrlSetOnEvent($hBtCopy, '_Copy')
If $sCopyParam == 'close' Then _ProExit()
EndFunc
Func _CopyStop()
_CopyDone('stop')
ProcessClose($iCopyPID)
If BitAnd(WinGetState($hMainWin), 16) OR Not BitAnd(WinGetState($hMainWin), 2) Then TrayTip('Копирование файла', 'Остановлено', $iTraiTipTime)
If FileExists($sCopyFileTo) Then Run(@ComSpec & ' /c ' & 'del /f /q "' & $sCopyFileTo & '"', '', @SW_HIDE)
If FileExists($sCopyFileTo) Then FileDelete($sCopyFileTo)
EndFunc
Func _CopyCheck()
If Not ProcessExists($iCopyPID) Then _CopyDone('done')
EndFunc
#endregion