diff options
author | sr55 <[email protected]> | 2013-05-26 16:11:55 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2013-05-26 16:11:55 +0000 |
commit | bb402730363d0a2192015f5062f9fda409bf743e (patch) | |
tree | 9b1b2ba85af0659c3d1410fa0cc3bd4dc30c9388 /win/CS/HandBrakeWPF/Services/DriveDetectService.cs | |
parent | ab11d3012d39eaa0991edbd069c602241d63905c (diff) |
WinGui: Add an attached property to the source menu to handle drive detection rather than relying on callbacks from the OS.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5517 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrakeWPF/Services/DriveDetectService.cs')
-rw-r--r-- | win/CS/HandBrakeWPF/Services/DriveDetectService.cs | 97 |
1 files changed, 0 insertions, 97 deletions
diff --git a/win/CS/HandBrakeWPF/Services/DriveDetectService.cs b/win/CS/HandBrakeWPF/Services/DriveDetectService.cs deleted file mode 100644 index 3a4ef5113..000000000 --- a/win/CS/HandBrakeWPF/Services/DriveDetectService.cs +++ /dev/null @@ -1,97 +0,0 @@ -// --------------------------------------------------------------------------------------------------------------------
-// <copyright file="DriveDetectService.cs" company="HandBrake Project (http://handbrake.fr)">
-// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
-// </copyright>
-// <summary>
-// Drive Detection Helper.
-// </summary>
-// --------------------------------------------------------------------------------------------------------------------
-
-namespace HandBrakeWPF.Services
-{
- using System;
- using System.Management;
- using System.Threading;
-
- using HandBrakeWPF.Services.Interfaces;
-
- /// <summary>
- /// Drive Detection Helper.
- /// </summary>
- public class DriveDetectService : IDriveDetectService
- {
- /// <summary>
- /// The watcher.
- /// </summary>
- private ManagementEventWatcher watcher;
-
- /// <summary>
- /// The detection action.
- /// </summary>
- private Action detectionAction;
-
- /// <summary>
- /// The start detection.
- /// </summary>
- /// <param name="action">
- /// The detection Action.
- /// </param>
- public void StartDetection(Action action)
- {
- ThreadPool.QueueUserWorkItem(
- delegate
- {
- this.detectionAction = action;
-
- var options = new ConnectionOptions { EnablePrivileges = true };
- var scope = new ManagementScope(@"root\CIMV2", options);
-
- try
- {
- var query = new WqlEventQuery
- {
- EventClassName = "__InstanceModificationEvent",
- WithinInterval = TimeSpan.FromSeconds(1),
- Condition = @"TargetInstance ISA 'Win32_LogicalDisk' and TargetInstance.DriveType = 5" // DriveType - 5: CDROM
- };
-
- this.watcher = new ManagementEventWatcher(scope, query);
- this.watcher.EventArrived += this.WatcherEventArrived;
- this.watcher.Start();
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- }
- });
- }
-
- /// <summary>
- /// The close.
- /// </summary>
- public void Close()
- {
- if (watcher != null)
- {
- this.watcher.Stop();
- }
- }
-
- /// <summary>
- /// The watcher_ event arrived.
- /// </summary>
- /// <param name="sender">
- /// The sender.
- /// </param>
- /// <param name="e">
- /// The EventArrivedEventArgs.
- /// </param>
- private void WatcherEventArrived(object sender, EventArrivedEventArgs e)
- {
- if (this.detectionAction != null)
- {
- this.detectionAction();
- }
- }
- }
-}
|