#include ; @SW_SHOW #include ; DriveGetDrive Constants #include ; Searching other drives for files #include ; _ArrayDisplay #include ; For Msgbox $MB_OK and $MB_YESNO #include ; For the $TRAY_ICONSTATE_SHOW / HIDE constants #include ; For return value of $GUI_RUNDEFMSG Opt("TrayMenuMode", 3) ; File paths Global $sBackupPath = "Z:\My Network Path\" & @MON & "-" & @MDAY & "-" & @YEAR & " Backup\" Global $sLocalPath = "C:\My Local Path\" & @MON & "-" & @MDAY & "-" & @YEAR & " Backup\" Global $sEyeFiPath = "\SD Card Path\" ; Log file Global $sLog = "log.txt" ; Global file count that triggers TrayTip if not 0 Global $iFileCount = 0 $hGUI = GUICreate("",0,0,0,0) GUISetState(@SW_SHOW, $hGUI) ; Watch for foreign devices GUIRegisterMsg($WM_DEVICECHANGE, "WM_DEVICECHANGE") GUISetState(@SW_HIDE, $hGUI) ; Setup tray's OnClick menu Global $idDebug = TrayCreateItem("Debug") TrayCreateItem("") Global $idAbout = TrayCreateItem("About") TrayCreateItem("") Global $idExit = TrayCreateItem("Exit") Global $saFileList ; Set hover text TraySetToolTip("Eye-Fi Watcher") TraySetState($TRAY_ICONSTATE_SHOW) Main() Func Main() While 1=1 Switch TrayGetMsg() Case $idDebug copyFiles() Msgbox($MB_OK, "", "Copied Count: " & $iFileCount & @CRLF & "File Found Count: " & $saFileList[0]) Case $idAbout Msgbox($MB_OK, "Eye-Fi Watcher", "This program watches for your Eye-Fi SD card, and transfers the files and backs them up.") Case $idExit TraySetState($TRAY_ICONSTATE_HIDE) Exit EndSwitch ; If there are files if $iFileCount <> 0 then ; Tell the user logging( $iFileCount & " files were found and backed up.") ; Reset file count $iFileCount = 0 endif Wend EndFunc Func WM_DEVICECHANGE($hWnd, $msg, $wParam, $lParam) #forceref $hWnd, $msg, $wParam, $lParam ;need to check with device api as there is no data to retrieve here for usb devices that are not drives. ;for an iPod insertion/removal there is no struct in lParam and wParam is always DBT_DEVNODES_CHANGED Local $DBT_DEVNODES_CHANGED = 0x00000007 Switch $wParam Case $DBT_DEVNODES_CHANGED copyFiles() EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_DEVICECHANGE func copyFiles() logging("Copy Files Started") ; Get the list of removable drives $aDriveLetters = DriveGetDrive($DT_REMOVABLE) if not @error then ; Create the directory in C: DirCreate($sLocalPath) ; Create the directory in Z: DirCreate($sBackupPath) ; For each drive for $drive in $aDriveLetters ; If the status is ready (can be written/read to/from) if DriveStatus($drive) = $DS_READY then ; Get the list of files from the directory $saFileList = _FileListToArrayRec($drive & $sEyeFiPath, "*", $FLTAR_FILES) ; Initialize files copied count $iFileCopied = 0 ; For each file for $i = 1 to $saFileList[0] ; Reset copy failure flag $bFail = FALSE ; Copy to C:\ if not FileCopy($drive & $sEyeFiPath & $saFileList[$i], $sLocalPath, 0) then $bFail = TRUE ; Copy to Z:\ if not FileCopy($drive & $sEyeFiPath & $saFileList[$i], $sBackupPath, 0) then $bFail = TRUE ; If we didn't fail then add to copy count if not $bFail then $iFileCopied = $iFileCopied + 1 next ; Set the file count to tell the main loop that the files were copied $iFileCount = $iFileCopied ; If no files were copied then log it if $iFileCopied = 0 then logging("No files found :(") else logging("Your drive isn't ready.") endif next else logging("Error fetching all drives.") endif EndFunc Func logging($sMsg) FileWrite($sLog, @MON & "/" & @MDAY & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & "--> " & $sMsg & @CRLF) EndFunc