ZForge.Win32.RemovableDriveDetector.EnableQueryRemove C# (CSharp) Method

EnableQueryRemove() public method

Hooks specified drive to receive a message when it is being removed. This can be achieved also by setting e.HookQueryRemove to true in your DeviceArrived event handler. By default DriveDetector will open the root directory of the flash drive to obtain notification handle from Windows (to learn when the drive is about to be removed).
public EnableQueryRemove ( string fileOnDrive ) : bool
fileOnDrive string Drive letter or relative path to a file on the drive which should be /// used to get a handle - required for registering to receive query remove messages. /// If only drive letter is specified (e.g. "D:\\", root directory of the drive will be opened.
return bool
        public bool EnableQueryRemove(string fileOnDrive)
        {
            if (fileOnDrive == null || fileOnDrive.Length == 0)
                throw new ArgumentException("Drive path must be supplied to register for Query remove.");

            if (fileOnDrive.Length == 2 && fileOnDrive[1] == ':')
                fileOnDrive += '\\';        // append "\\" if only drive letter with ":" was passed in.

            if (mDeviceNotifyHandle != IntPtr.Zero)
            {
                // Unregister first...
                RegisterForDeviceChange(false, null);
            }

            if (Path.GetFileName(fileOnDrive).Length == 0 || !File.Exists(fileOnDrive))
                mFileToOpen = null;     // use root directory...
            else
                mFileToOpen = fileOnDrive;

            RegisterQuery(Path.GetPathRoot(fileOnDrive));
            if (mDeviceNotifyHandle == IntPtr.Zero)
                return false;   // failed to register

            return true;
        }