diff --git a/DropboxForRemovable.ahk b/DropboxForRemovable.ahk index 42e14db..93b1b69 100644 --- a/DropboxForRemovable.ahk +++ b/DropboxForRemovable.ahk @@ -1,15 +1,15 @@ ; ---------------------------------------------------------------------------------------------------------------------- ; Name .........: DropboxForRemovable -; Description ..: Dropbox helper that checks for a volume presence during Dropbox running. +; Description ..: Dropbox helper that controls the process according to the presence of a specific removable drive. ; AHK Version ..: AHK_L 1.1.13.01 x32/64 Unicode ; Author .......: Cyruz - http://ciroprincipe.info -; ..............: Tray icons from Kayamoon IcoMoon set: https://www.iconfinder.com/iconsets/Keyamoon-IcoMoon--limited -; ..............: The hex icons code is released under CC terms: http://creativecommons.org/licenses/by-sa/3.0/ +; ..............: Tray icons from Hawcons icon set: http://hawcons.com/. Thanks to Yannick Lung: http://www.yanlu.de/. ; Changelog ....: Dic. 27, 2013 - v0.1 - First revision. ; ..............: Jan. 02, 2014 - v0.2 - Changed behaviour, keep monitoring Dropbox in the long run. ; ..............: Jul. 21, 2014 - v0.3 - Removed monitoring and management of the Dropbox process. Now using polling -; ..............: to get the handle. Autostart through task scheduler. Uninstallation feature. +; ..............: to get the handle. Autostart through Task Scheduler. Uninstallation feature. ; ..............: Jul. 22, 2014 - v0.3.1 - Tracking of the Dropbox process to limit polling only when it's not running. +; ..............: Aug. 01, 2015 - v0.4 - New icons. Rewrite of the icons and task scheduler code. ; License ......: GNU Lesser General Public License ; ..............: This program is free software: you can redistribute it and/or modify it under the terms of the GNU ; ..............: Lesser General Public License as published by the Free Software Foundation, either version 3 of the @@ -22,66 +22,100 @@ ; ---------------------------------------------------------------------------------------------------------------------- #SingleInstance force -#Include +#Include +#Include +#Include +#Include #Include ; ===[ VARIABLES ]====================================================================================================== - DROPBOX_INI_CONF := "DropboxForRemovable.ini" - DROPBOX_VOL_FLAG := "DropboxForRemovable" - DROPBOX_SEC_WAIT := 3000 + DROPBOX_EXE := "Dropbox.exe" + SCRIPT_NAME := "DropboxForRemovable" + SCRIPT_VERSION := "0.4.0" + SCRIPT_ICON := "RES\ICON.ICO" ; Main icon. + SCRIPT_ICON_WHI := "RES\ICON_WHITE.ICO" ; Dropbox running tray icon. + SCRIPT_ICON_RED := "RES\ICON_RED.ICO" ; Dropbox suspended tray icon. + SCRIPT_ICON_YEL := "RES\ICON_YELLOW.ICO" ; Dropbox not running tray icon. + SCRIPT_VOL_FLAG := SCRIPT_NAME + SCRIPT_SEC_WAIT := 2000 + SCRIPT_ABOUT := SCRIPT_NAME " - Removable drives Dropbox helper - v." SCRIPT_VERSION "`n" + . "Created by Ciro Principe: http://ciroprincipe.info`n" + . "License under the terms of the GNU LGPL" ; ====================================================================================================================== -; Configure Tray menu. +; Get icon handles. +If ( A_IsCompiled ) +{ + pDataIcon := UpdRes_LockResource( 0, SCRIPT_ICON, 10, szDataIcon:="" ) + pDataIconWhi := UpdRes_LockResource( 0, SCRIPT_ICON_WHI, 10, szDataIconWhi:="" ) + pDataIconRed := UpdRes_LockResource( 0, SCRIPT_ICON_RED, 10, szDataIconRed:="" ) + pDataIconYel := UpdRes_LockResource( 0, SCRIPT_ICON_YEL, 10, szDataIconYel:="" ) +} +Else +{ ; We make the tray icon work also when running this script with the interpreter. + FileRead, cDataIcon, % "*c " A_ScriptDir "\" SCRIPT_ICON + FileRead, cDataIconWhi, % "*c " A_ScriptDir "\" SCRIPT_ICON_WHI + FileRead, cDataIconRed, % "*c " A_ScriptDir "\" SCRIPT_ICON_RED + FileRead, cDataIconYel, % "*c " A_ScriptDir "\" SCRIPT_ICON_YEL + pDataIcon := &cDataIcon, pDataIconWhi := &cDataIconWhi + , pDataIconRed := &cDataIconRed, pDataIconYel := &cDataIconYel +} +SCRIPT_HICO := BinGet_Icon( pDataIcon, 48 ) +SCRIPT_HICO_WHI := BinGet_Icon( pDataIconWhi, 16 ) +SCRIPT_HICO_RED := BinGet_Icon( pDataIconRed, 16 ) +SCRIPT_HICO_YEL := BinGet_Icon( pDataIconYel, 16 ) +cDataIconWht := cDataIconRed := cDataIconYel := "" ; Free buffers. + +; Remove tray menu, set traytip and script icon on startup. +; * Notice that the traytip setting must precede the icon +; * changing because it will restore the original one. Menu, Tray, NoStandard +Menu, Tray, Tip, %SCRIPT_NAME% +TrayIcon_Set( A_ScriptHwnd, 1028, SCRIPT_HICO_WHI, SCRIPT_HICO_WHI, SCRIPT_HICO ) + +; Connect to the Task Scheduler and get the root folder. +objServ := ComObjCreate( "Schedule.Service" ) +objServ.Connect(), objFold := objServ.GetFolder( "\" ) + +try ; * Check if the task exists, otherwise configure the software. + ; * The following method throws an exception in case of errors. + objFold.GetTask( "\" SCRIPT_NAME ) +catch +{ + If ( !A_IsAdmin ) + Auth_RunAsAdmin() + GoSub, SHOWCONFIG + Return +} + +; Exit if it is not started from the Task Scheduler. +nParIfn := Process_GetImageFileName( Process_GetParentPid( DllCall( "GetCurrentProcessId" ) ) ) +If ( !InStr( nParIfn, "taskeng.exe" ) ) +{ + MsgBox, 0x10, %SCRIPT_NAME%, DropboxForRemovable must be started from the appropriate scheduled task! + ExitApp +} + +; Configure Tray menu. Menu, Tray, Add, About, ABOUT Menu, Tray, Add, Uninstall, UNINSTALL Menu, Tray, Add Menu, Tray, Add, Quit, EXIT -Menu, Tray, Tip, DropboxForRemovable -; Set script icon for the first time. -UpdateScriptIcon(0) +; The volume to be monitored is passed as parameter by the Task Scheduler. +VOL_TO_MONITOR = %1% -; Configuration starting if the .ini file is not present. -If ( !FileExist(A_ScriptDir "\" DROPBOX_INI_CONF) ) { - ShellExecute := (A_IsUnicode) ? "Shell32.dll\ShellExecute" : "Shell32.dll\ShellExecuteA" - If ( !A_IsAdmin ) { - A_IsCompiled - ? DllCall( ShellExecute, UInt,0, Str,"RunAs", Str,"""" A_ScriptFullPath """", Ptr,0 , Str,A_WorkingDir, Int,1 ) - : DllCall( ShellExecute, UInt,0, Str,"RunAs", Str,"""" A_AhkPath """", Str,"""" A_ScriptFullPath """" - , Str,A_WorkingDir, Int,1 ) - ExitApp - } - GoSub, SHOWCONFIG -} -Else { - ; Exit if it is not started from the Task Scheduler. - sParam = %1% - If ( sParam != "/task" ) { - MsgBox, 0x10, DropboxForRemovable, DropboxForRemovable must be started from the appropriate scheduled task! - ExitApp - } - - ; Read and check settings. - IniRead, S_VOL, %A_ScriptDir%\%DROPBOX_INI_CONF%, SETTINGS, VOLUME_TO_MONITOR - IniRead, DROPBOX_SEC_WAIT, %A_ScriptDir%\%DROPBOX_INI_CONF%, SETTINGS, DROPBOX_WAIT_TIMER - If ( StrLen(S_VOL) != 1 ) { - MsgBox, 0x10, DropboxForRemovable, Volume not configured correctly! - ExitApp - } +; Check volume presence. +IS_VOL_READY := ( FileExist( VOL_TO_MONITOR ":\" SCRIPT_VOL_FLAG ) ) ? 1 : 0 - ; Check volume presence. - B_VOL_READY := (FileExist(S_VOL ":\" DROPBOX_VOL_FLAG)) ? 1 : 0 - - ; Monitor WM_DEVICECHANGE to catch device plug and unplug. - OnMessage(0x0219, "VolumeHandler") ; WM_DEVICECHANGE = 0x0219 - - ; Register callback to wait for Dropbox. - A_CALLBACK := RegisterCallback("TermNotifier") - - ; Set timer to check for the Dropbox process. - SetTimer, CHECKDROPBOX, %DROPBOX_SEC_WAIT% -} +; Monitor WM_DEVICECHANGE (0x0219) to catch device plugging and unplugging. +OnMessage( 0x0219, "VolumeHandler" ) + +; Register callback to wait for Dropbox. +aCallback := RegisterCallback( "TermNotifier", "Fast" ) + +; Set timer to check for the Dropbox process. +SetTimer, WAITDROPBOX, %SCRIPT_SEC_WAIT% Return @@ -89,246 +123,222 @@ Return ; ===[ LABELS ]========================================================================================================= ; ====================================================================================================================== - CHECKDROPBOX: +ABOUT: + MsgBox, 0x40, %SCRIPT_NAME%, %SCRIPT_ABOUT% + Return +;ABOUT + +WAITDROPBOX: + ; * If the Dropbox process is found running, a thread will be started to wait for its termination. + ; * This label is called only as a timer, so it will be shut off. If the monitored drive has been + ; * unplugged during the time that Dropbox was not running, Dropbox will be suspended when it will + ; * be catched. This strictly depends from the frequency of the polling. Critical - Process, Exist, Dropbox.exe - If ( ErrorLevel ) { - ; * If the Dropbox process is found running, a thread will be started to wait for - ; * its termination. This label is called only as a timer, so it will be shut off. - H_DROPBOX := DllCall( "OpenProcess", UInt,0x0001F0FFF, Int,0, UInt,ErrorLevel ) - If ( !B_VOL_READY ) { - ; * If the monitored drive has been unplugged during the time that Dropbox - ; * was not running, Dropbox will be suspended only when it will be catched. - ; * This strictly depends from the frequency of the polling. - DllCall( "ntdll.dll\NtSuspendProcess", Ptr,H_DROPBOX ) ; Suspend Dropbox process. - OBJ_TRAY := TrayIcon_GetInfo("Dropbox.exe") - TrayIcon_Hide(OBJ_TRAY[1].idcmd, OBJ_TRAY[1].place, True) ; Hide Dropbox icon. - TrayTip, DropboxForRemovable, Dropbox found and suspended..., 10, 1 - } Else - TrayTip, DropboxForRemovable, Dropbox found..., 10, 1 - DllCall( "RegisterWaitForSingleObject", PtrP,hWait, Ptr,H_DROPBOX, Ptr,A_CALLBACK, Ptr,0, UInt,0xFFFFFFFF - , UInt,0x00000004|0x00000008 ) - B_DROPBOX_RUNNING := 1 + Process, Exist, %DROPBOX_EXE% + If ( ErrorLevel ) + { + ; Get a handle to the Dropbox process and wait for its termination. + ; PROCESS_ALL_ACCESS = 0x0001F0FFF. + hDropbox := DllCall( "OpenProcess", UInt,0x0001F0FFF, Int,0, Ptr,ErrorLevel ) + ; INFINITE = 0xFFFFFFFF, WT_EXECUTEONLYONCE = 0x00000008. + DllCall( "RegisterWaitForSingleObject", PtrP,hWait, Ptr,hDropbox, Ptr,aCallback + , Ptr,0, UInt,0xFFFFFFFF, UInt,0x00000008 ) + DllCall( "CloseHandle", Ptr,hDropbox ) + + ; Update Dropbox tray info object. + While ( !IsObject( DROPBOX_TRAY_OBJ := TrayIcon_GetInfo( DROPBOX_EXE ) ) ) + Sleep, 1000 ; This while/sleep is required because Dropbox tray isn't updated quickly. + + If ( !IS_VOL_READY ) + DropboxToggle( 0, "Dropbox found and suspended..." ) + Else + { + TrayIcon_Set( A_ScriptHwnd, 1028, SCRIPT_HICO_WHI ) + TrayTip, %SCRIPT_NAME%, Dropbox found..., 10, 1 + } + + IS_DROPBOX_RUNNING := 1 SetTimer, %A_ThisLabel%, Off } Return -;CHECKDROPBOX - - WAITDROPBOX: - TrayTip, DropboxForRemovable, Dropbox terminated. Waiting for it..., 10, 1 - B_DROPBOX_RUNNING := 0 - SetTimer, CHECKDROPBOX, %DROPBOX_SEC_WAIT% - Return ;WAITDROPBOX - SHOWCONFIG: - DriveGet, S_DRIVE, List, REMOVABLE - S_DRIVE_LIST := RegExReplace(S_DRIVE, "([\w])(?=[\w])", "$1|") - Gui, Margin, 20, 20 - Gui, Add, Text, w120, Volume to monitor: - Gui, Add, DropDownList, vDDLIST_1 w250 y+10, %S_DRIVE_LIST% - Gui, Add, Button, vBUTTON_1 gREFRESH w80 x+5, Refresh - Gui, Add, Button, vBUTTON_3 gCONFIGURE w80 x+-165 y+20, Configure - Gui, Add, Button, vBUTTON_4 gGUICLOSE w80 x+5, Exit - Gui, Show, AutoSize, DropboxForRemovable - Return -;SHOWCONFIG - - REFRESH: - DriveGet, S_DRIVE, List, REMOVABLE - S_DRIVE_LIST := RegExReplace(S_DRIVE, "([\w])(?=[\w])", "$1|") - GuiControl,, DDLIST_1, |%S_DRIVE_LIST% - Return -;REFRESH - - CONFIGURE: +CONFIGURE: + Gui, +OwnDialogs Gui, Submit, NoHide - If ( !DDLIST_1 ) { - MsgBox, 0x10, DropboxForRemovable, No volume to monitor selected. + If ( !DDLIST_1 ) + { + MsgBox, 0x10, %SCRIPT_NAME%, No volume selected. Return } - IniWrite, %DDLIST_1%, %A_ScriptDir%\%DROPBOX_INI_CONF%, SETTINGS, VOLUME_TO_MONITOR - IniWrite, %DROPBOX_SEC_WAIT%, %A_ScriptDir%\%DROPBOX_INI_CONF%, SETTINGS, DROPBOX_WAIT_TIMER - FileAppend,, %DDLIST_1%:\%DROPBOX_VOL_FLAG% - FileSetAttrib, +RSH, %DDLIST_1%:\%DROPBOX_VOL_FLAG% - ; Create a task scheduler item to automatically start the program on boot. - S_COMMAND := ( A_IsCompiled ) ? A_ScriptFullPath : A_AhkPath - S_ARGUMENT := ( A_IsCompiled ) ? "/task" : """" A_ScriptFullPath """ /task" - FileAppend, - ( - - - - %A_YYYY%-%A_MM%-%A_DD%T%A_Hour%:%A_Min%:%A_Sec%.%A_MSec% - %A_ComputerName%\%A_UserName% - - - - true - %A_ComputerName%\%A_UserName% - - - - - %A_ComputerName%\%A_UserName% - InteractiveToken - HighestAvailable - - - - IgnoreNew - false - false - false - true - false - - false - false - - true - true - false - false - false - PT0S - 7 - - PT1M - 3 - - - - - %S_COMMAND% - %S_ARGUMENT% - - - - ), temp.xml - S_CMD := "schtasks /Create /XML """ A_ScriptDir "\temp.xml"" /TN ""DropboxForRemovable""" - RunWait, % COMSPEC " /c """ S_CMD """",, Hide - FileDelete, temp.xml - MsgBox, 0x40, DropboxForRemovable, Task configured. Starting it... - S_CMD := "schtasks /Run /TN ""DropboxForRemovable""" - RunWait, % COMSPEC " /c """ S_CMD """",, Hide + + ; Get the volume label and create the flag file inside it. + VOL_TO_MONITOR := DDLIST_1 + FileAppend,, %VOL_TO_MONITOR%:\%SCRIPT_VOL_FLAG% + FileSetAttrib, +RSH, %VOL_TO_MONITOR%:\%SCRIPT_VOL_FLAG% + + ; Create a new task definition object. + objTask := objServ.NewTask( 0 ) + ; Get the RegistrationInfo object to change task information. + objInfo := objTask.RegistrationInfo + objInfo.Description := "DropboxForRemovable starter task" + objInfo.Author := A_UserName + + ; Get the Principal object to change credential related information. + objPrin := objTask.Principal + objPrin.LogonType := 3 ; TASK_LOGON_INTERACTIVE_TOKEN + objPrin.RunLevel := 1 ; TASK_RUNLEVEL_HIGHEST + + ; Get the TaskSettings object to change all task settings. + objSett := objTask.Settings + objSett.Enabled := 1 ; Enable the task. + objSett.DisallowStartIfOnBatteries := 0 ; Unflag "Start the task only if the computer is on AC power". + objSett.StopIfGoingOnBatteries := 0 ; Unflag "Stop if the computer switches to battery power". + objSett.AllowDemandStart := 1 ; Allow task to be run on demand. + objSett.StartWhenAvailable := 1 ; Run the task as soon as possible after a scheduled start is missed. + objSett.RestartInterval := "PT1M" ; If the task fails, restart every 1 minutes. + objSett.RestartCount := 3 ; Attempt to restart up to 3 times. + objSett.ExecutionTimeLimit := "PT0S" ; Stop the task if it runs longer than 1 hour. + + ; Get the Trigger object to add a trigger to the task. + colTrig := objTask.Triggers + objTrig := colTrig.Create(9) ; Logon type trigger = 2 + objTrig.Enabled := 1 ; Enable the trigger. + + ; Get the Action object to add an action to the task. + colActi := objTask.Actions + objActi := colActi.Create(0) ; TASK_ACTION_EXEC + objActi.Path := ( A_IsCompiled ) ? """" A_ScriptFullPath """" : """" A_AhkPath """" + objActi.Arguments := ( A_IsCompiled ) ? VOL_TO_MONITOR : """" A_ScriptFullPath """ " VOL_TO_MONITOR + + ; Register the task. TASK_CREATE_OR_UPDATE = 6, TASK_LOGON_INTERACTIVE_TOKEN = 3 + objFold.RegisterTaskDefinition( SCRIPT_NAME, objTask, 6, "", "", 3 ) + + MsgBox, 0x40, %SCRIPT_NAME%, Task configured. Starting it... + objTask := objFold.GetTask( "\" SCRIPT_NAME ) + objTask.Run( 0 ) + ExitApp ;CONFIG - UNINSTALL: - MsgBox, 0x24, DropboxForRemovable, Are you sure you want to uninstall? +DUMMY: + FileInstall, RES\ICON.ICO, DUMMY + FileInstall, RES\ICON_WHITE.ICO, DUMMY + FileInstall, RES\ICON_RED.ICO, DUMMY + FileInstall, RES\ICON_YELLOW.ICO, DUMMY +;DUMMY + +EXIT: + Gui, +OwnDialogs ; Avoid showing the AutoHotkey icon on the taskbar. + MsgBox, 0x24, %SCRIPT_NAME%, Are you sure you want to quit? IfMsgBox, No Return - FileDelete, %A_ScriptDir%\%DROPBOX_INI_CONF% - S_CMD := "schtasks /Delete /TN ""DropboxForRemovable"" /F" - RunWait, % COMSPEC " /c """ S_CMD """",, Hide - MsgBox, 0x40, DropboxForRemovable, Uninstalled! + ; Unregister the waiting thread and stop the task. + DllCall( "UnregisterWait", Ptr,hWait ) + objTask.Stop( 0 ) +GUICLOSE: ExitApp -;UNINSTALL +;GUICLOSE +;EXIT - ABOUT: - MsgBox, 0x40, DropboxForRemovable, % "DropboxForRemovable - Removable drives Dropbox helper`n" - . "Created by Ciro Principe: http://ciroprincipe.info`n" - . "License under the terms of the GNU GPL" +NOTIFYDROPBOX: + TrayIcon_Set( A_ScriptHwnd, 1028, SCRIPT_HICO_YEL ) + TrayTip, %SCRIPT_NAME%, Dropbox terminated. Waiting for it..., 10, 1 + IS_DROPBOX_RUNNING := 0 + SetTimer, WAITDROPBOX, %SCRIPT_SEC_WAIT% Return -;ABOUT +;NOTIFYDROPBOX + +REFRESH: + DriveGet, sDrive, List, REMOVABLE + sDriveList := RegExReplace( sDrive, "([\w])(?=[\w])", "$1|" ) + GuiControl,, DDLIST_1, |%sDriveList% + Return +;REFRESH - EXIT: - MsgBox, 0x24, DropboxForRemovable, Are you sure you want to quit? - IfMsgBox, Yes - GUICLOSE: +SHOWCONFIG: + DriveGet, sDrive, List, REMOVABLE + sDriveList := RegExReplace( sDrive, "([\w])(?=[\w])", "$1|" ) + + Gui, +HwndhGui + Gui, Margin, 20, 20 + Gui, Add, Text, w120, Volume to monitor: + Gui, Add, DropDownList, vDDLIST_1 w250 y+10, %sDriveList% + Gui, Add, Button, vBUTTON_1 gREFRESH w80 x+5, Refresh + Gui, Add, Button, vBUTTON_3 gCONFIGURE w80 x+-165 y+20, Configure + Gui, Add, Button, vBUTTON_4 gGUICLOSE w80 x+5, Exit + Gui, Show, AutoSize, %SCRIPT_NAME% + + SendMessage, 0x80, 0, SCRIPT_HICO,, ahk_id %hGui% + SendMessage, 0x80, 1, SCRIPT_HICO,, ahk_id %hGui% + Return +;SHOWCONFIG + +UNINSTALL: + Gui, +OwnDialogs ; Avoid showing the AutoHotkey icon on the taskbar. + MsgBox, 0x24, %SCRIPT_NAME%, Are you sure you want to uninstall? + IfMsgBox, No + Return + + ; Unregister the waiting thread, stop the task and delete it. + DllCall( "UnregisterWait", Ptr,hWait ) + objTask.Stop( 0 ) + objFold.DeleteTask( "\" SCRIPT_NAME, 0 ) + + MsgBox, 0x40, %SCRIPT_NAME%, Uninstalled! ExitApp -;GUICLOSE -;EXIT +;UNINSTALL ; ====================================================================================================================== ; ===[ FUNCTIONS ]====================================================================================================== ; ====================================================================================================================== -VolumeHandler(wParam, lParam, uMsg, hWnd) { +DropboxToggle(bStatus, sMsg) +{ + Global SCRIPT_NAME, SCRIPT_HICO_WHI, SCRIPT_HICO_RED, DROPBOX_EXE, DROPBOX_TRAY_OBJ + + Process, Exist, %DROPBOX_EXE% + If ( !ErrorLevel ) + Return + + hDropbox := DllCall( "OpenProcess", UInt,0x0001F0FFF, Int,0, Ptr,ErrorLevel ) + DllCall( "ntdll.dll\Nt" ( bStatus ? "Resume" : "Suspend" ) "Process", Ptr,hDropbox ) + DllCall( "CloseHandle", Ptr,hDropbox ) + + TrayIcon_Hide( DROPBOX_TRAY_OBJ[1].idcmd, DROPBOX_TRAY_OBJ[1].place, !bStatus ) + TrayIcon_Set( A_ScriptHwnd, 1028, ( bStatus ? SCRIPT_HICO_WHI : SCRIPT_HICO_RED ) ) + TrayTip, %SCRIPT_NAME%, %sMsg%, 10, 1 +} + +TermNotifier() +{ + ; * Get notified of Dropbox termination and give back control + ; * to the primary thread to wait for the new Dropbox process. + SetTimer, NOTIFYDROPBOX, -1 + Return +} + +VolumeHandler(wParam, lParam, uMsg, hWnd) +{ Critical - Global B_VOL_READY, S_VOL, DROPBOX_VOL_FLAG, B_DROPBOX_RUNNING, H_DROPBOX + Global IS_DROPBOX_RUNNING, IS_VOL_READY, VOL_TO_MONITOR, SCRIPT_VOL_FLAG, DROPBOX_TRAY_OBJ ; * It's better to wait for DBT_DEVNODES_CHANGED (0x0007) events and check if ; * the volume is still present, because the DBT_DEVICEREMOVECOMPLETE will not ; * be sent when unplugging the device with the "remove device" feature. So we ; * will return quickly if the event is not DBT_DEVNODES_CHANGED. If ( wParam != 0x0007 ) Return - If ( B_VOL_READY && !FileExist(S_VOL ":\" DROPBOX_VOL_FLAG) ) { - If ( B_DROPBOX_RUNNING ) { - DllCall( "ntdll.dll\NtSuspendProcess", Ptr,H_DROPBOX ) ; Suspend Dropbox process. - , OBJ_TRAY := TrayIcon_GetInfo("Dropbox.exe") - , TrayIcon_Hide(OBJ_TRAY[1].idcmd, OBJ_TRAY[1].place, True) ; Hide Dropbox icon. - TrayTip, DropboxForRemovable, Dropbox suspended..., 10, 1 - } - B_VOL_READY := 0 - , UpdateScriptIcon(1) ; Set script suspended icon. + If ( IS_VOL_READY && !FileExist( VOL_TO_MONITOR ":\" SCRIPT_VOL_FLAG ) ) + { + If ( IS_DROPBOX_RUNNING ) + DropboxToggle( 0, "Dropbox suspended..." ) + IS_VOL_READY := 0 } - Else If ( !B_VOL_READY && FileExist(S_VOL ":\" DROPBOX_VOL_FLAG) ) { - If ( B_DROPBOX_RUNNING ) { - DllCall( "ntdll.dll\NtResumeProcess", Ptr,H_DROPBOX ) ; Resume Dropbox process. - , OBJ_TRAY := TrayIcon_GetInfo("Dropbox.exe") - , TrayIcon_Hide(OBJ_TRAY[1].idcmd, OBJ_TRAY[1].place, False) ; Unhide Dropbox icon. - TrayTip, DropboxForRemovable, Dropbox resumed..., 10, 1 - } - B_VOL_READY := 1 - , UpdateScriptIcon(0) ; Set script normal icon. + Else If ( !IS_VOL_READY && FileExist( VOL_TO_MONITOR ":\" SCRIPT_VOL_FLAG ) ) + { + If ( IS_DROPBOX_RUNNING ) + DropboxToggle( 1, "Dropbox resumed..." ) + IS_VOL_READY := 1 } - OBJ_TRAY := "" - Return -} - -TermNotifier() { - ; * Get notified of Dropbox termination and give back control - ; * to the primary thread to wait for the new Dropbox process. - SetTimer, WAITDROPBOX, -1 Return -} - -UpdateScriptIcon(bSuspended) { - Static hNormalIcon := IconData_Create("" - . "0000010001001010000001002000680400001600000028000000100000002000000001002000000000000000000000000000000000000000" - . "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" - . "0000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - . "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - . "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - . "ffffffffff9fffffff9fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - . "ffffffffffffffffff600000000000000000ffffff60ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - . "ffffffffffffffffffefffffff3000000000000000000000000000000000ffffff30ffffffefffffffffffffffffffffffffffffffffffff" - . "ffffffffffffffffffffffffffafffffff10000000000000000000000000000000000000000000000000ffffff10ffffffcfffffffffffff" - . "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000000000000000000ffffffffffffffffffff" - . "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000000000000000000ffff" - . "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000000" - . "000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - . "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - . "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9fffffffffffff" - . "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9f0000" - . "0000ffffff9fffffffefffffff300000000000000000000000000000000000000000000000000000000000000000ffffff30ffffffefffff" - . "ff9f000000000000000000000000ffffff9fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - . "ffffffffff9f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" - . "00000000000000000000000000000000000000000000ffffac410000ac410000ac410000ac410180ac4103c0ac4107e0ac4103c0ac4103c0" - . "ac4103c0ac410000ac410000ac410000ac418ff1ac41c003ac41ffffac4") - , hSuspendedIcon := IconData_Create("" - . "0000010001001010000001002000680400001600000028000000100000002000000001002000000000000000000000000000000000000000" - . "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" - . "00000000000000000000000000000000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000" - . "FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000" - . "FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000" - . "FFFF0000FF9F0000FF9F0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000" - . "FFFF0000FFFF0000FF6000000000000000000000FF600000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000" - . "FFFF0000FFFF0000FFEF0000FF30000000000000000000000000000000000000FF300000FFEF0000FFFF0000FFFF0000FFFF0000FFFF0000" - . "FFFF0000FFFF0000FFFF0000FFAF0000FF100000000000000000000000000000000000000000000000000000FF100000FFCF0000FFFF0000" - . "FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF000000000000000000000000000000000000FFFF0000FFFF0000" - . "FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF000000000000000000000000000000000000" - . "FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF00000000000000000000" - . "0000000000000000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000" - . "FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000" - . "FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FF9F0000FFFF0000" - . "FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FF9F0000" - . "00000000FF9F0000FFEF0000FF3000000000000000000000000000000000000000000000000000000000000000000000FF300000FFEF0000" - . "FF9F0000000000000000000000000000FF9F0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000" - . "FFFF0000FF9F0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" - . "00000000000000000000000000000000000000000000FFFFAC410000AC410000AC410000AC410180AC4103C0AC4107E0AC4103C0AC4103C0" - . "AC4103C0AC410000AC410000AC410000AC418FF1AC41C003AC41FFFFAC4") - (bSuspended) ? IconData_Set(hSuspendedIcon) : IconData_Set(hNormalIcon) } \ No newline at end of file diff --git a/DropboxForRemovable.ico b/DropboxForRemovable.ico deleted file mode 100644 index 913b196..0000000 Binary files a/DropboxForRemovable.ico and /dev/null differ diff --git a/res/icon.ico b/res/icon.ico new file mode 100644 index 0000000..28859c0 Binary files /dev/null and b/res/icon.ico differ diff --git a/res/icon_red.ico b/res/icon_red.ico new file mode 100644 index 0000000..e71d108 Binary files /dev/null and b/res/icon_red.ico differ diff --git a/res/icon_white.ico b/res/icon_white.ico new file mode 100644 index 0000000..c7bf5e1 Binary files /dev/null and b/res/icon_white.ico differ diff --git a/res/icon_yellow.ico b/res/icon_yellow.ico new file mode 100644 index 0000000..39c600c Binary files /dev/null and b/res/icon_yellow.ico differ