#include #include #include #include #include "RDC.au3" Opt('MustDeclareVars', 1) Opt('GUICloseOnESC', 1) Opt('GUIOnEventMode', 1) ; Enable Event Mode Opt('TrayAutoPause', 0) Global $GiRDCid, $GhWnd, $GbActionsOccurred, $GsPath_Monitor, $GsEventDesc[50], $GiEventDescIndex = 0, $GiTotalRDCmsgCount = 0 Global Const $CsAppTitle = "RDC Test Script" Local $iStat, $sPart1, $sPart2, $sOutMsg $GbActionsOccurred = 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 $GsPath_Monitor = $sPart1 & $sPart2 If Not FileExists($GsPath_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' & @CR) Exit EndIf HotKeySet("{ESC}", "_ExitApp") $GhWnd = GUICreate($CsAppTitle) If $GhWnd = 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 $GiRDCid = _RDC_Create($GsPath_Monitor, True, _ BitOR($FILE_NOTIFY_CHANGE_FILE_NAME, $FILE_NOTIFY_CHANGE_DIR_NAME, $FILE_NOTIFY_CHANGE_SIZE), False, $GhWnd, 47) If $GiRDCid = -1 Then MsgBox($MB_ICONERROR, $CsAppTitle, 'Error: _RDC_Create() - @error = ' & @error & ' @extended = ' & @extended & ' -- Exiting' & @CR) Exit EndIf While True If $GbActionsOccurred 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 = 0 To $GiEventDescIndex -1 $sOutMsg &= "Event # " & $i & " : " & $GsEventDesc[$i] & @CRLF Next MsgBox($MB_OK, $CsAppTitle, "Total number of WM_RDC invocations thus far = " & $GiTotalRDCmsgCount & @CRLF & @CRLF _ & "Number of Action Events this pass = " & $GiEventDescIndex & " -- Here's the list..." & @CRLF & $sOutMsg) $GbActionsOccurred = 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 Local $sName, $iActionCount, $iEventType $GiTotalRDCmsgCount += 1 Local $aData = _RDC_GetData($GiRDCid) If @error <> 0 Then $sName = _RDC_GetDirectory($GiRDCid) If @error <> 0 Then MsgBox($MB_ICONERROR, $CsAppTitle, 'Error: _RDC_GetDirectory() failed. @error = ' & @error & ' @extended = ' _ & @extended & ' -- Exiting' & @CR) Exit EndIf MsgBox($MB_ICONERROR, $CsAppTitle, 'Error: _RDC_GetData() - @error = ' & @error & ' @extended = ' & @extended _ & @CR & " Directory = '" & $sName & @CR & "... Exiting") _RDC_Delete($GiRDCid) Exit EndIf $iActionCount = $aData[0][0] If $iActionCount < 1 Then Return 0 $GiEventDescIndex = 0 For $i = 1 To $iActionCount $iEventType = $aData[$i][0] $sName = $aData[$i][1] Switch $iEventType Case $FILE_ACTION_ADDED $GsEventDesc[$GiEventDescIndex] = "Item Added = " & $sName Case $FILE_ACTION_REMOVED $GsEventDesc[$GiEventDescIndex] = "Item Removed = " & $sName Case $FILE_ACTION_MODIFIED $GsEventDesc[$GiEventDescIndex] = "Item Modified = " & $sName Case $FILE_ACTION_RENAMED_OLD_NAME $GsEventDesc[$GiEventDescIndex] = "Old item named " & $sName & " will be renamed" Case $FILE_ACTION_RENAMED_NEW_NAME $GsEventDesc[$GiEventDescIndex] = "Item renamed to " & $sName Case Else $GsEventDesc[$GiEventDescIndex] = "INVALID ACTION!" EndSwitch $GiEventDescIndex += 1 If $GiEventDescIndex >= 50 Then MsgBox($MB_ICONERROR, $CsAppTitle, 'Error in WM_RDC: Too many events! - Exiting') Exit EndIf Next $GbActionsOccurred = True Return 0 EndFunc ;==>WM_RDC Func _ExitApp() Exit EndFunc