コード例 #1
0
        private void DriveComboBox_OnLoaded(object sender, RoutedEventArgs e)
        {
            if (this.IsDesignMode())
            {
                return;
            }

            Drives = DriveCache.Instance.AllDrives;

            if (!Items.Contains(_selectPath))
            {
                Items.Add(_selectPath);
            }

            if (ShowAllDrive)
            {
                TryAddDrive(_allDrive);
            }

            DriveCache.Instance.NewDriveCreated += OnNewDriveCreated;

            if (ShowAllDrive)
            {
                IsAllDrive = true;
            }
            else
            {
                SelectedDrive = _prevSelected ?? Drives.FirstOrDefault();
            }
        }
コード例 #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();
                }
            }
        }
コード例 #3
0
        public bool HaveSubFolder()
        {
            var drive = Drives.FirstOrDefault(info => info.Name == GetPath());

            if (drive != null && !drive.IsReady)
            {
                return(false);
            }
            // Get the IEnumIDList interface pointer.
            ShellAPI.IEnumIDList pEnum = null;
            try
            {
                uint hRes = ShellFolder.EnumObjects(IntPtr.Zero, ShellAPI.SHCONTF.SHCONTF_FOLDERS, out pEnum);
                if (hRes != 0)
                {
                    Marshal.ThrowExceptionForHR((int)hRes);
                }
            }

            catch (Exception ex)
            {
                // \todo
            }
            IntPtr pIDL = IntPtr.Zero;
            Int32  iGot = 0;

            // Grab the first enumeration.
            pEnum.Next(1, out pIDL, out iGot);
            return(!pIDL.Equals(IntPtr.Zero) && iGot == 1);
        }
コード例 #4
0
        public StorageManagerService()
        {
            var drives = GetPortableDrives();

            Drives.AddRange(drives);

            SelectedDrive = Drives.FirstOrDefault();
        }
コード例 #5
0
 private FileSystemItemViewModel GetDefaultDrive()
 {
     if (Drives.Count == 0)
     {
         return(null);
     }
     return(Drives.FirstOrDefault(d => d.Name == "C:") ?? Drives.First());
 }
コード例 #6
0
 public OpenFileViewModel(IFileSystemAccessor accessor)
 {
     _accessor        = new FilteredFileSystemAccessor(accessor);
     _parentDirectory = new ParentDirectoryInfo();
     _fileSystemInfos = new ObservableCollection <object>();
     Drives           = _accessor.GetLogicalDrives();
     SelectedDrive    = Drives.FirstOrDefault();
     InitialDirectory = Properties.Settings.Default.OpenFileViewLastUsedPath;
 }
コード例 #7
0
        private void OnScanDrivesCompleted(IEnumerable <InstalledMountedDriveInfo> drives)
        {
            Drives.Clear();

            Drives.AddRange(drives.Select(drive => new DriveViewModel(drive)));

            SelectedDrive = Drives.FirstOrDefault();

            IsScanning = false;
        }
コード例 #8
0
        public MainWindow()
        {
            InitializeComponent();
            DeleteCheckbox.IsChecked = Settings.Default.Delete;
            Drives = DriveInfo.GetDrives().Where(drive => drive.DriveType == DriveType.Removable).ToList();
            bw     = new BackgroundWorker();
            bw.WorkerReportsProgress = true;
            bw.DoWork             += Bw_DoWork;
            bw.ProgressChanged    += Bw_ProgressChanged;
            bw.RunWorkerCompleted += Bw_RunWorkerCompleted;

            //Set Default Settings If Not Set
            if (Settings.Default.LastFolders == null)
            {
                Settings.Default.LastFolders = new System.Collections.Specialized.StringCollection();
            }
            if (Settings.Default.Path == "UNSET")
            {
                Settings.Default.Path = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
                Settings.Default.Save();
            }

            //Get Drives Only works if exactly one drive
            if (Drives.Count == 1)
            {
                SourcePath.Content      = PathShortner(Strings.StartLabelText, Drives.FirstOrDefault().Name);
                DestinationPath.Content = PathShortner(Strings.FinishLabelText, Settings.Default.Path);
                RecursiveFileCount(Drives[0].RootDirectory.FullName);
                OverallProgressBar.Maximum = FileCount;
            }
            else
            {
                if (MessageBox.Show(Strings.NoDriveSettings, Strings.NoDrive, MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    SettingsWindow settings = new SettingsWindow();
                    settings.Show();
                    this.Close();
                }
                else
                {
                    this.Close();
                }
            }

            //For Textbox
            FolderNameTextBox.Focus();
            LastFoldersList.ItemsSource = Settings.Default.LastFolders;

            var desktopWorkingArea = System.Windows.SystemParameters.WorkArea;

            this.Left = desktopWorkingArea.Right - this.Width;
            this.Top  = desktopWorkingArea.Bottom - this.Height;
        }
コード例 #9
0
        private void DriveComboBox_OnLoaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }

            Drives = DriveCache.Instance.AllDrives;

            if (!Items.Contains(_selectPath))
            {
                Items.Add(_selectPath);
            }

            DriveCache.Instance.NewDriveCreated += OnNewDriveCreated;

            SelectedDrive = _prevSelected ?? Drives.FirstOrDefault();
        }
コード例 #10
0
        public static string FriendlyName(string path)
        {
            if (path == null)
            {
                return(string.Empty);
            }

            if (path == StoragePath.Root)
            {
                return(StoragePath.RootName);
            }

            if (path.EndsWith(@":\"))
            {
                var volumeLabel = Drives.FirstOrDefault(i => i.Name == path)?.VolumeLabel;
                return(volumeLabel != null ? $"{volumeLabel} ({path.TrimEnd('\\')})" : path);
            }

            var result = Path.GetFileName(path);

            return(result.NullOrEmpty() ? path : result);
        }
コード例 #11
0
        public bool IsReady()
        {
            var drive = Drives.FirstOrDefault(info => info.Name == Path);

            return((drive != null && !drive.IsReady));
        }
コード例 #12
0
        protected override FileSystemItemViewModel GetDriveFromPath(string path)
        {
            var storedDrive = Path.GetPathRoot(path);

            return(Drives.FirstOrDefault(d => d.Path == storedDrive));
        }