protected Schedule(SerializationInfo info, StreamingContext context) { base.resourceId = "Schedule"; name = info.GetString("Name"); driveList = info.GetValue("DriveList", typeof(DriveList)) as DriveList; deserialized = info.GetValue("Steps", typeof(object[])) as object[]; }
private void DriveLetter_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (e != null && e.RemovedItems.Count > 0) { char c = (char)(e.RemovedItems[0]); ((App)App.Current).Unmount(c, true); } var sI = (sender as ComboBox).SelectedItem; if (sI == null) { return; } var selectedLetter = (char)sI; if (!DriveToMount.ContainsKey(selectedLetter)) { var curItem = ((ListViewItem)DriveList.ContainerFromElement((sender as ComboBox))); var myContentPresenter = FindVisualChild <ContentPresenter>(curItem); var myDataTemplate = myContentPresenter.ContentTemplate; ((Button)myDataTemplate.FindName("UnmountBtn", myContentPresenter)).Visibility = Visibility.Visible; ((App)App.Current).Mount(selectedLetter, (sender as ComboBox).DataContext as Atonline.Rest.Drive, true); } }
/// <summary> /// 在U盘移除后清理可移动磁盘列表和控件 /// </summary> private void ClearDriveList() { DriveInfo[] drives = DriveInfo.GetDrives(); //清除在DriveList中但已被移除的设备,通常是直接拔出U盘 foreach (USBDevice usbDrive in DriveList) { if (!Array.Exists(drives, x => x.Name == usbDrive.Name)) { leftPanel.Children.Remove(usbDrive.Button); rightPanel.Children.Remove(usbDrive.ComState); DriveList.Remove(usbDrive); break; } } //清除已移除但仍在DriveList中并未清除控件的设备,通常是使用界面按钮移除的设备 foreach (DriveInfo drive in drives) { if (!drive.IsReady) { USBDevice usbDrive = DriveList.Find(x => x.Name == drive.Name); if (usbDrive != null) { leftPanel.Children.Remove(usbDrive.Button); rightPanel.Children.Remove(usbDrive.ComState); DriveList.Remove(usbDrive); } } } if (DriveList.Count == 0) { NoDriveState.Visibility = Visibility.Visible; } }
private async static void NetworkDriveCheckTimer_Tick(object sender, object e) { NetworkDriveCheckTimer.Stop(); DriveInfo[] NewNetworkDrive = DriveInfo.GetDrives().Where((Drives) => Drives.DriveType == DriveType.Network).ToArray(); DriveRelatedData[] ExistNetworkDrive = DriveList.Where((ExistDrive) => ExistDrive.DriveType == DriveType.Network).ToArray(); IEnumerable <DriveInfo> AddList = NewNetworkDrive.Where((NewDrive) => ExistNetworkDrive.All((ExistDrive) => ExistDrive.Folder.Path != NewDrive.RootDirectory.FullName)); IEnumerable <DriveRelatedData> RemoveList = ExistNetworkDrive.Where((ExistDrive) => NewNetworkDrive.All((NewDrive) => ExistDrive.Folder.Path != NewDrive.RootDirectory.FullName)); foreach (DriveRelatedData ExistDrive in RemoveList) { DriveList.Remove(ExistDrive); } foreach (DriveInfo Drive in AddList) { try { StorageFolder Device = await StorageFolder.GetFolderFromPathAsync(Drive.RootDirectory.FullName); DriveList.Add(await DriveRelatedData.CreateAsync(Device, Drive.DriveType)); } catch (Exception ex) { LogTracer.Log(ex, $"Hide the device \"{Drive.RootDirectory.FullName}\" for error"); } } NetworkDriveCheckTimer.Start(); }
/// <summary> /// 创建云 /// </summary> /// <param name="item"></param> /// <returns></returns> private static Cloudbase CreateCloud(DriveList item) { Cloudbase cloudclass = null; switch (item.Service) { case "microsoft": cloudclass = new OneDriveManager(); break; } if (cloudclass != null) { cloudclass.CloudId = Guid.NewGuid(); cloudclass.Cloud = new Cloud { CloudDriveId = item.Id, CloudEmail = item.Email, CloudService = item.Service, CloudToken = item.Token, CloudExpiresAt = item.ExpiresAt, CloudExpiresIn = item.ExpiresIn }; } return(cloudclass); }
private async Task Edit(Guid id) { try { IsBusy = true; var selectedDrive = DriveList.Single(x => x.DriveId == id); if (selectedDrive.State == Enums.Status.Created) { await _navigationService.NavigateAsync <EditDriveViewModel>(selectedDrive); } else { await _navigationService.NavigateAsync <DriveViewModel>(selectedDrive); } } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "OK"); } finally { IsBusy = false; } }
public static IList <File> ListFiles() { // Create Drive API service. var service = GetGDriveService(); // Define parameters of request. FilesResource.ListRequest listRequest = service.Files.List(); listRequest.PageSize = 50; listRequest.Fields = "nextPageToken, files(id, name)"; DriveList driveList = service.Drives.List().Execute(); driveList.Drives.Select(d => { Debug.WriteLine($"Drive: {d.Name}, Id: {d.Id}"); return(d); }).ToList(); // List files. IList <Google.Apis.Drive.v3.Data.File> files = listRequest.Execute().Files; Debug.WriteLine("Files:"); if (files != null && files.Count > 0) { foreach (var file in files) { Debug.WriteLine("{0} ({1})", file.Name, file.Id); } } else { Debug.WriteLine("No files found."); } //.Read(); return(files); }
private async static void NetworkDriveCheckTimer_Tick(object sender, object e) { NetworkDriveCheckTimer.Stop(); DriveInfo[] NewNetworkDrive = DriveInfo.GetDrives().Where((Drives) => Drives.DriveType == DriveType.Network).ToArray(); DriveDataBase[] ExistNetworkDrive = DriveList.OfType <NormalDriveData>().Where((ExistDrive) => ExistDrive.DriveType == DriveType.Network).ToArray(); IEnumerable <DriveInfo> AddList = NewNetworkDrive.Where((NewDrive) => ExistNetworkDrive.All((ExistDrive) => !ExistDrive.Path.Equals(NewDrive.RootDirectory.FullName, StringComparison.OrdinalIgnoreCase))); IEnumerable <DriveDataBase> RemoveList = ExistNetworkDrive.Where((ExistDrive) => NewNetworkDrive.All((NewDrive) => !ExistDrive.Path.Equals(NewDrive.RootDirectory.FullName, StringComparison.OrdinalIgnoreCase))); foreach (DriveDataBase ExistDrive in RemoveList) { DriveList.Remove(ExistDrive); } foreach (DriveInfo Drive in AddList) { try { StorageFolder Device = await StorageFolder.GetFolderFromPathAsync(Drive.RootDirectory.FullName); DriveList.Add(await DriveDataBase.CreateAsync(Device, Drive.DriveType)); } catch (Exception ex) { LogTracer.Log(ex, $"Hide the device \"{Drive.RootDirectory.FullName}\" for error"); } } NetworkDriveCheckTimer.Start(); }
public static async Task LoadDeviceAsync() { foreach (DriveInfo Drive in DriveInfo.GetDrives().Where((Drives) => Drives.DriveType == DriveType.Fixed || Drives.DriveType == DriveType.Removable || Drives.DriveType == DriveType.Network) .Where((NewItem) => DriveList.All((Item) => Item.Folder.Path != NewItem.RootDirectory.FullName))) { try { StorageFolder DriveFolder = await StorageFolder.GetFolderFromPathAsync(Drive.RootDirectory.FullName); DriveList.Add(await DriveRelatedData.CreateAsync(DriveFolder, Drive.DriveType).ConfigureAwait(true)); } catch (Exception ex) { LogTracer.Log(ex, $"Hide the device \"{Drive.RootDirectory.FullName}\" for error"); } } switch (PortalDeviceWatcher.Status) { case DeviceWatcherStatus.Created: case DeviceWatcherStatus.Aborted: case DeviceWatcherStatus.Stopped: { PortalDeviceWatcher.Start(); break; } } NetworkDriveCheckTimer.Start(); }
Schedule active; // mit dem wird simuliert public ShowPropertySchedules(Model model) { scheduleList = model.AllSchedules; driveList = model.AllDrives; base.resourceId = "Schedule.List"; if (scheduleList.Count > 0) { active = scheduleList[0]; } }
public DeviceSelector() { InitializeComponent(); DriveList.LargeImageList = LargeList; DriveList.SmallImageList = LargeList; DriveList.SetExplorerTheme(); this.Load += new EventHandler(DeviceSelector_Load); this.DriveList.DoubleClick += new EventHandler(DriveList_DoubleClick); this.FormClosing += new FormClosingEventHandler(DeviceSelector_FormClosing); }
public PositionProperty(Schedule schedule, DriveList driveList, IDrive drive, double time, double position) { this.driveList = driveList; this.schedule = schedule; this.drive = drive; this.position = position; this.time = time; orgDrive = drive; orgTime = time; orgPosition = position; }
private void CheckBox_Checked(object sender, RoutedEventArgs e) { var curItem = ((ListViewItem)DriveList.ContainerFromElement((CheckBox)sender)); var myContentPresenter = FindVisualChild <ContentPresenter>(curItem); var myDataTemplate = myContentPresenter.ContentTemplate; var cb = (ComboBox)myDataTemplate.FindName("DriveLetter", myContentPresenter); cb.Visibility = Visibility.Visible; cb.ItemsSource = getAvailableDriveLetters(); cb.SelectedIndex = cb.Items.Count - 1; }
private void UnmountBtn_Click(object sender, RoutedEventArgs e) { var btn = sender as Button; btn.Visibility = Visibility.Hidden; var curItem = ((ListViewItem)DriveList.ContainerFromElement(btn)); var myContentPresenter = FindVisualChild <ContentPresenter>(curItem); var myDataTemplate = myContentPresenter.ContentTemplate; var cb = (ComboBox)myDataTemplate.FindName("DriveLetter", myContentPresenter); cb.SelectedIndex = -1; }
private void FillDriveList(bool isRefreshing = false) { var list = DriveInfo.GetDrives().Where(x => x.IsReady && (showAllDrives || (x.DriveType == DriveType.Removable && x.DriveFormat.StartsWith("FAT")))).ToArray(); if (isRefreshing) { if (DriveList.Select(x => x.Name).SequenceEqual(list.Select(x => x.Name))) { return; } DriveList.Clear(); } //fill drive list and try to find drive with gdemu contents foreach (DriveInfo drive in list) { DriveList.Add(drive); //look for GDEMU.ini file if (SelectedDrive == null && File.Exists(Path.Combine(drive.RootDirectory.FullName, Constants.MenuConfigTextFile))) { SelectedDrive = drive; } } //look for 01 folder if (SelectedDrive == null) { foreach (DriveInfo drive in list) { if (Directory.Exists(Path.Combine(drive.RootDirectory.FullName, "01"))) { SelectedDrive = drive; break; } } } if (!DriveList.Any()) { return; } if (SelectedDrive == null) { SelectedDrive = DriveList.LastOrDefault(); } }
/// <summary> /// 弹出U盘 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DoUSBout(object sender, RoutedEventArgs e) { var sourceButton = sender as Button; string deviceName = DriveList.Find(x => x.Button.Equals(sourceButton)).Name; uint removeState = USBDevice.RemoveDevice(deviceName); if (removeState == 0) { //MessageBox.Show(string.Format("可移动设备{0}已移除", deviceName)); ClearDriveList(); } else { MessageBox.Show(string.Format("可移动设备{0}移除失败代码:{1}", deviceName, removeState.ToString())); } }
private void CheckBox_Unchecked(object sender, RoutedEventArgs e) { var curItem = ((ListViewItem)DriveList.ContainerFromElement((CheckBox)sender)); var myContentPresenter = FindVisualChild <ContentPresenter>(curItem); var myDataTemplate = myContentPresenter.ContentTemplate; var cb = (ComboBox)myDataTemplate.FindName("DriveLetter", myContentPresenter); cb.Visibility = Visibility.Hidden; var selectedItem = cb.SelectedItem as ComboBoxItem; cb.SelectedIndex = -1; if (selectedItem == null) { return; } DriveToMount.Remove((char)selectedItem.Content); }
public static async Task LoadDeviceAsync() { if (Interlocked.Exchange(ref LoadDriveLockResource, 1) == 0) { try { if (!IsDriveLoaded) { IsDriveLoaded = true; foreach (DriveInfo Drive in DriveInfo.GetDrives().Where((Drives) => Drives.DriveType == DriveType.Fixed || Drives.DriveType == DriveType.Removable || Drives.DriveType == DriveType.Network) .Where((NewItem) => DriveList.All((Item) => Item.Folder.Path != NewItem.RootDirectory.FullName))) { try { StorageFolder DriveFolder = await StorageFolder.GetFolderFromPathAsync(Drive.RootDirectory.FullName); DriveList.Add(await DriveRelatedData.CreateAsync(DriveFolder, Drive.DriveType)); } catch (Exception ex) { LogTracer.Log(ex, $"Hide the device \"{Drive.RootDirectory.FullName}\" for error"); } } switch (PortalDeviceWatcher.Status) { case DeviceWatcherStatus.Created: case DeviceWatcherStatus.Aborted: case DeviceWatcherStatus.Stopped: { PortalDeviceWatcher.Start(); break; } } NetworkDriveCheckTimer.Start(); } } finally { _ = Interlocked.Exchange(ref LoadDriveLockResource, 0); } } }
public void SetObjectData(IJsonReadData data) { name = data.GetProperty <string>("Name"); driveList = data.GetProperty <DriveList>("DriveList"); object[] l = data.GetProperty <object[]>("Steps"); steps = new Dictionary <IDrive, SortedList <double, double> >(); for (int i = 0; i < l.Length; i = i + 3) { if (l[i + 1] is string) { // why is this a string and not a double? AddPosition(l[i] as IDrive, double.Parse((string)l[i + 1]), double.Parse((string)l[i + 2])); } else { AddPosition(l[i] as IDrive, (double)l[i + 1], (double)l[i + 2]); } } }
private static async void PortalDeviceWatcher_Added(DeviceWatcher sender, DeviceInformation args) { try { StorageFolder DeviceFolder = StorageDevice.FromId(args.Id); if (DriveList.All((Device) => (string.IsNullOrEmpty(Device.Path) || string.IsNullOrEmpty(DeviceFolder.Path)) ? !Device.Name.Equals(DeviceFolder.Name, StringComparison.OrdinalIgnoreCase) : !Device.Path.Equals(DeviceFolder.Path, StringComparison.OrdinalIgnoreCase))) { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { DriveList.Add(await DriveDataBase.CreateAsync(DeviceFolder, DriveType.Removable)); }); } } catch (Exception ex) { LogTracer.Log(ex, $"Error happened when add device to HardDeviceList"); } }
private static async void PortalDeviceWatcher_Added(DeviceWatcher sender, DeviceInformation args) { try { StorageFolder DeviceFolder = StorageDevice.FromId(args.Id); if (DriveList.All((Device) => (string.IsNullOrEmpty(Device.Folder.Path) || string.IsNullOrEmpty(DeviceFolder.Path)) ? Device.Folder.Name != DeviceFolder.Name : Device.Folder.Path != DeviceFolder.Path)) { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { DriveList.Add(await DriveRelatedData.CreateAsync(DeviceFolder, DriveType.Removable).ConfigureAwait(true)); }); } } catch (Exception ex) { LogTracer.Log(ex, $"Error happened when add device to HardDeviceList"); } }
/// <summary> /// 增加设备,用于在设备插入后将其添加到列表和处理队列中 /// </summary> private void AddUSBDevices() { var drives = DriveInfo.GetDrives(); string deviceNum = ""; foreach (var drive in drives) { if (drive.IsReady && drive.DriveType == DriveType.Removable && !DriveList.Exists(x => x.Name == drive.Name) && Directory.Exists(drive.Name + MainWindow.devicePath)) { try { deviceNum = drive.Name; if (File.Exists(drive.Name + "Config.ini")) { string[] deviceInfo = File.ReadAllLines(drive.Name + "Config.ini", Encoding.Default); if (deviceInfo.Length > 1 && deviceInfo[0] == "调车") { deviceNum = deviceInfo[1] + "号"; } } string[] files = Directory.GetFiles(drive.Name + MainWindow.devicePath, "YC?????_*.MP4", SearchOption.TopDirectoryOnly); if (files.Length != 0) { deviceNum = System.IO.Path.GetFileName(files[files.GetUpperBound(0)]).Substring(6, 1) + "号"; } } catch { MessageBox.Show("部分U盘设备未连接好,请重新连接"); } AddControl(deviceNum, out ComState comState, out Button button); USBDevice usbDevice = new USBDevice(drive.Name, comState, button, drive.DriveType); DriveList.Add(usbDevice); CopyQueue.Enqueue(usbDevice); } } if (DriveList.Count == 0) { NoDriveState.Visibility = Visibility.Visible; } }
private static async void PortalDeviceWatcher_Removed(DeviceWatcher sender, DeviceInformationUpdate args) { try { List <string> AllBaseDevice = DriveInfo.GetDrives().Where((Drives) => Drives.DriveType == DriveType.Fixed || Drives.DriveType == DriveType.Network) .Select((Info) => Info.RootDirectory.FullName).ToList(); List <StorageFolder> PortableDevice = new List <StorageFolder>(); foreach (DeviceInformation Device in await DeviceInformation.FindAllAsync(StorageDevice.GetDeviceSelector())) { try { PortableDevice.Add(StorageDevice.FromId(Device.Id)); } catch (Exception ex) { LogTracer.Log(ex, $"Error happened when get storagefolder from {Device.Name}"); } } foreach (string PortDevice in AllBaseDevice.Where((Path) => PortableDevice.Any((Item) => Item.Path.Equals(Path, StringComparison.OrdinalIgnoreCase)))) { AllBaseDevice.Remove(PortDevice); } List <DriveDataBase> OneStepDeviceList = DriveList.Where((Item) => !AllBaseDevice.Contains(Item.Path)).ToList(); List <DriveDataBase> TwoStepDeviceList = OneStepDeviceList.Where((RemoveItem) => PortableDevice.All((Item) => !Item.Name.Equals(RemoveItem.Name, StringComparison.OrdinalIgnoreCase))).ToList(); await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { foreach (DriveDataBase Device in TwoStepDeviceList) { DriveList.Remove(Device); } }); } catch (Exception ex) { LogTracer.Log(ex, $"Error happened when remove device from HardDeviceList"); } }
private void UpOneLevel_Click(object sender, RoutedEventArgs e) { if (currentPath.EndsWith(":")) { FileFolderList.Items.Clear(); DriveList.Focus(); DriveList.SelectedIndex = -1; SelectedPath.Text = ""; parentPath = ""; } else { if (currentPath.Contains("\\")) { currentPath = currentPath.Substring(0, currentPath.LastIndexOf('\\')); } ListFilesAndFolders(); } SelectedPath.Text = parentPath; }
public void UpdateDrives() { using (var sdd = new StorageDeviceDescriptor()) { var drives = new DriveList(); foreach (var drive in Directory.GetLogicalDrives()) { var deviceName = GetDeviceName(drive); if (sdd.Load(deviceName)) { if (sdd.BusType == STORAGE_BUS_TYPE.BusTypeUsb && sdd.RemovableMedia == true) { drives.Add(drive); } } } Drives = drives; } }
private static void Main() { UserCredential credential; using (FileStream stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read)) { // The file token.json stores the user's access and refresh tokens, and is created // automatically when the authorization flow completes for the first time. string credPath = "token.json"; credential = GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, Scopes, "user", CancellationToken.None, new FileDataStore(credPath, true)).Result; Console.WriteLine("Credential file saved to: " + credPath); } // Create Drive API service. DriveService driveService = new DriveService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = ApplicationName, }); DrivesResource.ListRequest listRequest = driveService.Drives.List(); DriveList driveList = listRequest.Execute(); string sourceFolderId = GetFileId(driveService, "root", new string[] { "PC dalībniekiem" }); Drive targetDrive = driveList.Drives.Single(d => d.Name == "PC info dalībniekiem"); string targetFolderId = GetFileId(driveService, targetDrive.Id, new string[] { }); //string targetFolderId = GetFileId(driveService, "root", new string[] { "PC Google My Maps" }); CopyFiles(driveService, "/", sourceFolderId, targetFolderId, null); }
private void DriveForm_Load(object sender, EventArgs e) { driveListBindingSource.DataSource = DriveList.GetDriveList(); }
private void FillDriveList(bool isRefreshing = false) { DriveInfo[] list; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { list = DriveInfo.GetDrives().Where(x => x.IsReady && (showAllDrives || (x.DriveType == DriveType.Removable && x.DriveFormat.StartsWith("FAT")))).ToArray(); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { list = DriveInfo.GetDrives().Where(x => x.IsReady && (showAllDrives || x.DriveType == DriveType.Removable || x.DriveType == DriveType.Fixed)).ToArray();//todo need to test } else//linux { list = DriveInfo.GetDrives().Where(x => x.IsReady && (showAllDrives || ((x.DriveType == DriveType.Removable || x.DriveType == DriveType.Fixed) && x.DriveFormat.Equals("msdos", StringComparison.InvariantCultureIgnoreCase) && x.Name.StartsWith("/media/", StringComparison.InvariantCultureIgnoreCase)))).ToArray(); } if (isRefreshing) { if (DriveList.Select(x => x.Name).SequenceEqual(list.Select(x => x.Name))) { return; } DriveList.Clear(); } //fill drive list and try to find drive with gdemu contents //look for GDEMU.ini file foreach (DriveInfo drive in list) { try { DriveList.Add(drive); if (SelectedDrive == null && File.Exists(Path.Combine(drive.RootDirectory.FullName, Constants.MenuConfigTextFile))) { SelectedDrive = drive; } } catch { } } //look for 01 folder if (SelectedDrive == null) { foreach (DriveInfo drive in list) { try { if (Directory.Exists(Path.Combine(drive.RootDirectory.FullName, "01"))) { SelectedDrive = drive; break; } } catch { } } } //look for /media mount if (SelectedDrive == null) { foreach (DriveInfo drive in list) { try { if (drive.Name.StartsWith("/media/", StringComparison.InvariantCultureIgnoreCase)) { SelectedDrive = drive; break; } } catch { } } } if (!DriveList.Any()) { return; } if (SelectedDrive == null) { SelectedDrive = DriveList.LastOrDefault(); } }
void LoadDeivce() { this.mWorker = new System.Threading.Thread((System.Threading.ThreadStart) delegate { try { if (mDriveList != null) { for (int i = 0; i < mDriveList.Count; i++) { mDriveList[i].Close(); } } DriveList.Invoke((MethodInvoker) delegate { DriveList.Items.Clear(); }); l_Message.Invoke((MethodInvoker) delegate { l_Message.Text = "正在加载驱动器..."; }); b_RefreshDrive.Invoke((MethodInvoker) delegate { b_RefreshDrive.Enabled = false; }); mDriveList = ParrotLibs.StartHere.GetFATXDrives().ToList(); if (Properties.Settings.Default.RecentLoadFiles != null) { foreach (string sPathToFile in Properties.Settings.Default.RecentLoadFiles) { if (System.IO.File.Exists(sPathToFile)) { try { ParrotLibs.Drive sDrive = new ParrotLibs.Drive(sPathToFile); if (sDrive.IsFATXDrive()) { mDriveList.Add(sDrive); } } catch (Exception e) { if (!e.Message.Contains("being used")) { MessageBox.Show("An exception was thrown: " + e.Message + "\r\n\r\nStack Trace:\r\n" + e.StackTrace); } else { continue; } } } } } List <ListViewItem> sListView = new List <ListViewItem>(); for (int i = 0; i < mDriveList.Count; i++) { try { ListViewItem sDriveItem = new ListViewItem(mDriveList[i].Name); if (mDriveList[i].DriveType == ParrotLibs.DriveType.HardDisk) { sDriveItem.ImageIndex = 0; sDriveItem.SubItems.Add(mDriveList[i].DeviceIndex.ToString()); } else if (mDriveList[i].DriveType == ParrotLibs.DriveType.USB) { sDriveItem.ImageIndex = 1; sDriveItem.SubItems.Add(System.IO.Path.GetPathRoot(mDriveList[i].USBPaths[0])); } else { sDriveItem.ImageIndex = 2; sDriveItem.SubItems.Add(System.IO.Path.GetFileName(mDriveList[i].FilePath)); } sDriveItem.SubItems.Add(mDriveList[i].LengthFriendly); sDriveItem.Tag = mDriveList[i]; sListView.Add(sDriveItem); } catch (Exception e) { if (!e.Message.Contains("being used")) { MessageBox.Show("An exception was thrown: " + e.Message + "\r\n\r\nStack Trace:\r\n" + e.StackTrace); } else { continue; } } } DriveList.Invoke((MethodInvoker) delegate { DriveList.Items.AddRange(sListView.ToArray()); }); l_Message.Invoke((MethodInvoker) delegate { if (sListView.Count == 0) { l_Message.Text = "未发现驱动器..."; } else { l_Message.Text = sListView.Count.ToString() + "个驱动器被加载!"; } }); b_RefreshDrive.Invoke((MethodInvoker) delegate { b_RefreshDrive.Enabled = true; }); } catch (Exception e) { if (!e.Message.Contains("being used")) { MessageBox.Show("An exception was thrown: " + e.Message + "\r\n\r\nStack Trace:\r\n" + e.StackTrace); } } }); mWorker.Start(); }
public static async Task LoadDriveAsync(bool IsRefresh = false) { if (Interlocked.Exchange(ref LoadDriveLockResource, 1) == 0) { try { if (!IsDriveLoaded || IsRefresh) { IsDriveLoaded = true; foreach (DriveInfo Drive in DriveInfo.GetDrives().Where((Drives) => Drives.DriveType == DriveType.Fixed || Drives.DriveType == DriveType.Removable || Drives.DriveType == DriveType.Network) .Where((NewItem) => DriveList.All((Item) => !Item.Path.Equals(NewItem.RootDirectory.FullName, StringComparison.OrdinalIgnoreCase)))) { try { StorageFolder Folder = await StorageFolder.GetFolderFromPathAsync(Drive.RootDirectory.FullName); if (DriveList.All((Item) => (string.IsNullOrEmpty(Item.Path) || string.IsNullOrEmpty(Folder.Path)) ? !Item.Name.Equals(Folder.Name, StringComparison.OrdinalIgnoreCase) : !Item.Path.Equals(Folder.Path, StringComparison.OrdinalIgnoreCase))) { DriveList.Add(await DriveDataBase.CreateAsync(Folder, Drive.DriveType)); } } catch (Exception ex) { LogTracer.Log(ex, $"Hide the device \"{Drive.RootDirectory.FullName}\" for error"); } } foreach (DeviceInformation Drive in await DeviceInformation.FindAllAsync(StorageDevice.GetDeviceSelector())) { try { StorageFolder Folder = StorageDevice.FromId(Drive.Id); if (DriveList.All((Item) => (string.IsNullOrEmpty(Item.Path) || string.IsNullOrEmpty(Folder.Path)) ? !Item.Name.Equals(Folder.Name, StringComparison.OrdinalIgnoreCase) : !Item.Path.Equals(Folder.Path, StringComparison.OrdinalIgnoreCase))) { DriveList.Add(await DriveDataBase.CreateAsync(Folder, DriveType.Removable)); } } catch (Exception ex) { LogTracer.Log(ex, $"Hide the device for error"); } } foreach (StorageFolder Folder in await GetWslDriveAsync()) { try { if (DriveList.All((Item) => (string.IsNullOrEmpty(Item.Path) || string.IsNullOrEmpty(Folder.Path)) ? !Item.Name.Equals(Folder.Name, StringComparison.OrdinalIgnoreCase) : !Item.Path.Equals(Folder.Path, StringComparison.OrdinalIgnoreCase))) { DriveList.Add(await DriveDataBase.CreateAsync(Folder, DriveType.Network)); } } catch (Exception ex) { LogTracer.Log(ex, $"Hide the device \"{Folder.Name}\" for error"); } } switch (PortalDeviceWatcher.Status) { case DeviceWatcherStatus.Created: case DeviceWatcherStatus.Aborted: case DeviceWatcherStatus.Stopped: { PortalDeviceWatcher.Start(); break; } } if (!NetworkDriveCheckTimer.IsEnabled) { NetworkDriveCheckTimer.Start(); } } } catch (Exception ex) { LogTracer.Log(ex, $"An exception was threw in {nameof(LoadDriveAsync)}"); } finally { _ = Interlocked.Exchange(ref LoadDriveLockResource, 0); } } }