コード例 #1
0
        public void Resetdrives()
        {
            var drives = new List <DriveInfo>();

            foreach (var drive in DriveInfo.GetDrives())
            {
                try
                {
                    if (drive.DriveType != DriveType.Removable)
                    {
                        continue;
                    }
                    if (drive.TotalSize <= ExpectedSize)
                    {
                        drives.Add(drive);
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }
            }

            SystemDrives.Clear();
            foreach (var driveInfo in (drives))
            {
                SystemDrives.Add(driveInfo);
            }
            Drives.MoveCurrentToFirst();
        }
コード例 #2
0
        private void LoadFileSystemItems(bool forCurrentDirectory = false)
        {
            try
            {
                var path = forCurrentDirectory
                    ? _explorerModel.CurrentDirectory
                    : SelectedPath;

                _explorerModel.CurrentDirectory = path;

                var items = _explorerModel.GetAllItemsUnderPath(path);

                if (items == null && SystemDrives.Contains(path))
                {
                    _fileSystemItemsCollection.Clear();
                    return;
                }

                if (items == null)
                {
                    return;
                }

                _fileSystemItemsCollection.Clear();
                _fileSystemItemsCollection.Add(
                    new FileSystemBackItemProxy(
                        new FileSystemItem(
                            new DirectoryInfo(_explorerModel.GetCurrentDirectoryParent ??
                                              _explorerModel.CurrentDirectory), TraversalDirection.Up)));

                foreach (var extendedFileSystemInfo in items)
                {
                    _fileSystemItemsCollection.Add(extendedFileSystemInfo);
                }

                SelectedPath   = path;
                _itemsReloaded = true;
            }
            catch (UnauthorizedAccessException exception)
            {
                DialogService.ShowError(Resources.UnauthorizedAccesMessage, Resources.Exception, MessageBoxButton.OK);
            }
            catch (FileSystemException exception)
            {
                _logger.Info($"Exception catched inside {MethodBase.GetCurrentMethod().Name}.", exception);
                DialogService.ShowError(exception.Message, Resources.Exception, MessageBoxButton.OK);
            }
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public FileSystemExplorerViewModel(FileSystemExplorerModel explorerModel)
        {
            _messanger = Messenger.Default;
            _messanger.Register <CancelAsyncOperationMessage>(this, CancellationRequestedHandler);
            _messanger.Register <ReloadFileSystemMessage>(this, ReloadFileSystem);

            _explorerModel = explorerModel;
            SelectedItems  = _explorerModel.SelectedItems;
            SelectedPath   = SystemDrives.First();

            LoadFileSystemItems();

            LoadFileSystemItemsCommand  = new RelayCommand <bool>(LoadFileSystemItems);
            RespondForUserActionCommand = new RelayCommand <ActionType>(ResponseForUserActionAsync);
            SelectionChangedCommand     = new RelayCommand <EventArgs>(HandleSelectionEvent);
        }