Пример #1
0
        public DirectoryEntry TryResolveDirectory([NotNull] AbsolutePath path, [CanBeNull] string incomingPath = null)
        {
            Guard.NotNull(path, nameof(path));

            string completePath = incomingPath ?? path.GetText();

            AssertNetworkShareExists(path, completePath);

            if (!container.ContainsVolume(path.VolumeName))
            {
                return(null);
            }

            DirectoryEntry directory = container.GetVolume(path.VolumeName);

            foreach (AbsolutePathComponent component in path.EnumerateComponents().Skip(1))
            {
                AssertIsNotFile(component, directory, completePath);

                if (!directory.ContainsDirectory(component.Name))
                {
                    return(null);
                }

                directory = directory.GetDirectory(component.Name);
            }

            return(directory);
        }
Пример #2
0
        private CardItemViewModel CreateCardItem(CardInfo card)
        {
            try
            {
                if (card.Capacity == null)
                {
                    var volume = VolumeContainer.GetVolume(card.DriveLetter);
                    card.Capacity = volume.Disk.DiskSize;
                }
            }
            catch (FileNotFoundException)
            {
                return(null);
            }

            var partTypes = PartitionService.GetPartitionTypes(card.DriveLetter);

            return(new CardItemViewModel
            {
                Info = card,
                DisplayName = GetDisplayName(card),
                PartitionTypes = partTypes,
                Switched = PartitionService.TestSwitchedPartitions(partTypes),
                Bootable = BootService.TestBootable(card, card.FileSystem),
                Scriptable = ScriptService.TestScriptable(card, card.FileSystem),
            });
        }
Пример #3
0
        public bool Eject(string driveLetter)
        {
            Logger.LogInformation("Ejecting {0}", driveLetter);

            var volume = VolumeContainer.GetVolume(driveLetter);

            Thread.Sleep(Settings.Default.VolumeEjectDelay);

            using (var hDevice = Device.OpenRead(volume.Disk.DeviceName))
            {
                if (!Lock(hDevice) || !Dismount(hDevice))
                {
                    return(false);
                }
            }

            Thread.Sleep(Settings.Default.VolumeEjectDelay);

            try
            {
                return(DoEject(driveLetter));
            }
            catch (Exception ex)
            {
                Logger.LogError(0, ex, "Eject failed");
                return(false);
            }
        }
Пример #4
0
 private void UpdateEject()
 {
     if (ViewModel.SelectedItem != null)
     {
         var volume    = VolumeContainer.GetVolume(ViewModel.SelectedItem.Info.DriveLetter);
         var isHotplug = volume.IsHotplugDevice();
         EjectViewModel.IsEject     = !isHotplug;
         EjectViewModel.IsCompleted = isHotplug;
     }
 }