#include #include #include "RDC.au3" ; To use v1.1 (with corrections), you must dl and put in your local development folder Opt('MustDeclareVars', 1) Opt('GUICloseOnESC', 1) Opt('GUIOnEventMode', 1) ; Enable Event Mode Opt('TrayAutoPause', 0) Global $G_iRDCid, $G_hWnd, $G_bActionsOccurred, $G_sPath_Monitor, $G_sEventDesc[50], $G_iEventDescIndex=0, $G_iTotalRDCmsgCount=0 Global Const $CsAppTitle = "RDC v1.1 Test Script with GUI for faustf" Local $iStat, $sPart1, $sPart2, $sOutMsg $G_bActionsOccurred = False $sPart1 = StringReplace(@ScriptDir, "\INCLUDE", "") $sPart2 = IniRead(@ScriptDir & "\presync_conf.ini", "Path_to_sync", "key1", "Error") If $sPart2 = "Error" Then MsgBox($MB_ICONERROR, $CsAppTitle, "File 'presync_conf.ini' contains invalid data - Exiting") Exit EndIf $G_sPath_Monitor = $sPart1 & $sPart2 If Not FileExists($G_sPath_Monitor) Then MsgBox($MB_ICONERROR, $CsAppTitle, "Folder to be monitored does NOT exist! - Exiting") Exit EndIf _RDC_OpenDll() If @error <> 0 Then MsgBox($MB_ICONERROR, $CsAppTitle, 'Error: _RDC_OpenDll() - ' & @error & ' - Exiting' & @CRLF) Exit EndIf HotKeySet("{ESC}", "_ExitApp") $G_hWnd = GUICreate($CsAppTitle) If $G_hWnd = 0 Then MsgBox($MB_ICONERROR, $CsAppTitle, 'Error: GUICreate() Failed! - Exiting') Exit EndIf $iStat = GUIRegisterMsg($WM_RDC, 'WM_RDC') If $iStat <> 1 Then MsgBox($MB_ICONERROR, $CsAppTitle, "Error: GUIRegisterMsg() failed - Exiting") Exit EndIf $G_iRDCid = _RDC_Create($G_sPath_Monitor, True, _ BitOR($FILE_NOTIFY_CHANGE_FILE_NAME, $FILE_NOTIFY_CHANGE_DIR_NAME, $FILE_NOTIFY_CHANGE_SIZE), False, $G_hWnd, 47) If $G_iRDCid = -1 Then MsgBox($MB_ICONERROR, $CsAppTitle, 'Error: _RDC_Create() - @error = ' & @error & ' @extended = ' & @extended & ' -- Exiting' & @CRLF) Exit EndIf While True If $G_bActionsOccurred Then $iStat = GUIRegisterMsg($WM_RDC, "") ; Unregister this event handler to avoid being interrupted until done If $iStat <> 1 Then MsgBox($MB_ICONERROR, $CsAppTitle, "Error from GUIRegisterMsg() call to disable WM_RDC failed - Exiting") Exit EndIf $sOutMsg = "" For $i = 1 To $G_iEventDescIndex -1 $sOutMsg &= "Event # " & $i & " : " & $G_sEventDesc[$i] & @CRLF Next MsgBox($MB_OK, $CsAppTitle, "Total number of WM_RDC invocations thus far = " & $G_iTotalRDCmsgCount & @CRLF & @CRLF _ & "The changes occurred in directory : '" & $G_sEventDesc[0] & "'" & @CRLF & @CRLF _ & "Number of Action Events this pass = " & $G_iEventDescIndex -1 & " -- Here's the list..." & @CRLF & $sOutMsg) $G_bActionsOccurred = False ; Reset this flag so we won't be triggered until there are more events $iStat = GUIRegisterMsg($WM_RDC, "WM_RDC") ; Re-register this event handler If $iStat <> 1 Then MsgBox($MB_ICONERROR, $CsAppTitle, "Error from GUIRegisterMsg() call to re-enable WM_RDC failed - Exiting") Exit EndIf Else Sleep(500) EndIf WEnd Func WM_RDC($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam ; ; Upon entry, the RDC dll will provide the RDC ID/Thread ID for the relevant directory being watched in $lParam. ; This fact is not documented anywhere else. ; Local $sName, $iActionCount, $iEventType $G_iTotalRDCmsgCount += 1 Local $aData = _RDC_GetData($lParam) If @error = 0 Then $sName = _RDC_GetDirectory($lParam) If @error <> 0 Then MsgBox($MB_ICONERROR, $CsAppTitle, 'Error: _RDC_GetDirectory() failed. @error = ' & @error & ' @extended = ' _ & @extended & ' -- Exiting') Exit EndIf Else MsgBox($MB_ICONERROR, $CsAppTitle, 'Error: _RDC_GetData() - @error = ' & @error & ' @extended = ' & @extended _ & @CRLF & " Directory = '" & $sName & "... Exiting") _RDC_Delete($lParam) Exit EndIf $iActionCount = $aData[0][0] If $iActionCount < 1 Then Return 0 $G_sEventDesc[0] = $sName ; Record the root of the directory tree that saw the changes. $G_iEventDescIndex = 1 For $i = 1 To $iActionCount $iEventType = $aData[$i][0] $sName = $aData[$i][1] Switch $iEventType Case $FILE_ACTION_ADDED $G_sEventDesc[$G_iEventDescIndex] = "Item Added = " & $sName Case $FILE_ACTION_REMOVED $G_sEventDesc[$G_iEventDescIndex] = "Item Removed = " & $sName Case $FILE_ACTION_MODIFIED $G_sEventDesc[$G_iEventDescIndex] = "Item Modified = " & $sName Case $FILE_ACTION_RENAMED_OLD_NAME $G_sEventDesc[$G_iEventDescIndex] = "Old item named " & $sName & " will be renamed" Case $FILE_ACTION_RENAMED_NEW_NAME $G_sEventDesc[$G_iEventDescIndex] = "Item renamed to " & $sName Case Else $G_sEventDesc[$G_iEventDescIndex] = "INVALID ACTION!" EndSwitch $G_iEventDescIndex += 1 If $G_iEventDescIndex >= 50 Then MsgBox($MB_ICONERROR, $CsAppTitle, 'Error in WM_RDC: Too many events! - Exiting') Exit EndIf Next $G_bActionsOccurred = True Return 0 EndFunc ;==>WM_RDC Func _ExitApp() Exit EndFunc