Example #1
0
        private async void DeviceAdded(DeviceWatcher sender, DeviceInformation args)
        {
            var deviceId = args.Id;

            var root = StorageDevice.FromId(deviceId);

            // If drive already in list, skip.
            if (Drives.Any(x => x.tag == root.Name))
            {
                return;
            }

            DriveType type = DriveType.Removable;

            var driveItem = new DriveItem(
                root,
                Visibility.Visible,
                type);

            // Update the collection on the ui-thread.
            try
            {
                CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Drives.Add(driveItem); });
            }
            catch (Exception e)
            {
                // Ui-Thread not yet created.
                Drives.Add(driveItem);
            }
        }
Example #2
0
        /// <summary>
        /// Constructor for <see cref="ChooseFolderDialog"/>.
        /// </summary>
        public ChooseFolderDialogViewModel(string sourcePath)
        {
            UpperFolderCommand = new DelegateCommand(UpperFolderHandler);
            SelectedFolderDoubleClickCommand = new DelegateCommand(SelectedFolderDoubleClickHandler);
            SelectFolderCommand  = new DelegateCommand(SelectFolderHandler, CanSelectFolder);
            RefreshFolderCommand = new DelegateCommand(RefreshFolderHandler);

            Initialize();

            if (!string.IsNullOrEmpty(sourcePath))
            {
                if (Path.IsPathRooted(sourcePath))
                {
                    var rootDrive = Drives.FirstOrDefault(sourcePath.StartsWith);
                    _selectedDrive = rootDrive;
                }

                var parent = Directory.GetParent(sourcePath);
                if (parent != null)
                {
                    sourcePath = parent.FullName;
                }

                SourcePath = sourcePath;
            }
            else
            {
                if (Drives.Any())
                {
                    SourcePath = Drives.FirstOrDefault();
                }
            }
        }
Example #3
0
        private void OnUsbDeviceChanged(UsbDeviceChangedEventArgs e)
        {
            var drives = FileManager.GetDrives();

            for (var i = 0; i < drives.Count; i++)
            {
                var current = drives[i];
                if (i < Drives.Count && current.Name == Drives[i].Name)
                {
                    continue;
                }
                if (i < Drives.Count && Drives.Any(d => d.Name == current.Name))
                {
                    var existing = Drives[i];
                    if (Drive.Name == existing.Name)
                    {
                        Drive = GetDefaultDrive();
                    }
                    Drives.Remove(existing);
                }
                else
                {
                    Drives.Insert(i, new FileSystemItemViewModel(current));
                }
            }
        }
Example #4
0
        private async void DeviceAdded(DeviceWatcher sender, DeviceInformation args)
        {
            var           deviceId = args.Id;
            StorageFolder root     = null;

            try
            {
                root = StorageDevice.FromId(deviceId);
            }
            catch (UnauthorizedAccessException)
            {
                Logger.Warn($"UnauthorizedAccessException: Attemting to add the device, {args.Name}, failed at the StorageFolder initialization step. This device will be ignored. Device ID: {args.Id}");
                return;
            }

            // If drive already in list, skip.
            if (Drives.Any(x => x.tag == root.Name))
            {
                return;
            }

            DriveType type = DriveType.Removable;

            var driveItem = new DriveItem(
                root,
                Visibility.Visible,
                type);

            Logger.Info($"Drive added: {driveItem.tag}, {driveItem.Type}");

            // Update the collection on the ui-thread.
            try
            {
                CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                {
                    Drives.Add(driveItem);
                    DeviceWatcher_EnumerationCompleted(null, null);
                });
            }
            catch (Exception e)
            {
                // Ui-Thread not yet created.
                Drives.Add(driveItem);
            }
        }
Example #5
0
        /// <summary>
        /// Get a complete list of active disc drives and fill the combo box
        /// </summary>
        /// <remarks>TODO: Find a way for this to periodically run, or have it hook to a "drive change" event</remarks>
        private void PopulateDrives()
        {
            ViewModels.LoggerViewModel.VerboseLogLn("Scanning for drives..");

            // Always enable the disk scan
            this.Find <Button>("MediaScanButton").IsEnabled = true;

            // Populate the list of drives and add it to the combo box
            Drives = Validators.CreateListOfDrives(UIOptions.Options.IgnoreFixedDrives);
            this.Find <ComboBox>("DriveLetterComboBox").Items = Drives;

            if (Drives.Any())
            {
                // Check for active optical drives first
                int index = Drives.FindIndex(d => d.MarkedActive && d.InternalDriveType == InternalDriveType.Optical);

                // Then we check for floppy drives
                if (index == -1)
                {
                    index = Drives.FindIndex(d => d.MarkedActive && d.InternalDriveType == InternalDriveType.Floppy);
                }

                // Then we try all other drive types
                if (index == -1)
                {
                    index = Drives.FindIndex(d => d.MarkedActive);
                }

                // Set the selected index
                this.Find <ComboBox>("DriveLetterComboBox").SelectedIndex = (index != -1 ? index : 0);
                this.Find <TextBlock>("StatusLabel").Text             = "Valid drive found! Choose your Media Type";
                this.Find <Button>("CopyProtectScanButton").IsEnabled = true;

                // Get the current media type
                if (!UIOptions.Options.SkipSystemDetection && index != -1)
                {
                    ViewModels.LoggerViewModel.VerboseLog("Trying to detect system for drive {0}.. ", Drives[index].Letter);
                    var currentSystem = Validators.GetKnownSystem(Drives[index]);
                    ViewModels.LoggerViewModel.VerboseLogLn(currentSystem == null || currentSystem == KnownSystem.NONE ? "unable to detect." : ("detected " + currentSystem.LongName() + "."));

                    if (currentSystem != null && currentSystem != KnownSystem.NONE)
                    {
                        int sysIndex = Systems.FindIndex(s => s == currentSystem);
                        this.Find <ComboBox>("SystemTypeComboBox").SelectedIndex = sysIndex;
                    }
                }

                // Only enable the start/stop if we don't have the default selected
                this.Find <Button>("StartStopButton").IsEnabled = (this.Find <ComboBox>("SystemTypeComboBox").SelectedItem as KnownSystemComboBoxItem) != KnownSystem.NONE;

                ViewModels.LoggerViewModel.VerboseLogLn("Found {0} drives: {1}", Drives.Count, string.Join(", ", Drives.Select(d => d.Letter)));
            }
            else
            {
                this.Find <ComboBox>("DriveLetterComboBox").SelectedIndex = -1;
                this.Find <TextBlock>("StatusLabel").Text             = "No valid drive found!";
                this.Find <Button>("StartStopButton").IsEnabled       = false;
                this.Find <Button>("CopyProtectScanButton").IsEnabled = false;

                ViewModels.LoggerViewModel.VerboseLogLn("Found no drives");
            }
        }