Ejemplo n.º 1
0
 private void backButton_Click(object sender, RoutedEventArgs e)
 {
     if (_currentItem.Parent != null)
     {
         _currentItem = _currentItem.Parent;
         MyFileItemViewSource.Source = _currentItem.SubFiles;
         SearchText.Clear();
     }
 }
Ejemplo n.º 2
0
        /* Personal Feature: Carver
            The MyFileItems class represents a directory and all of it's children (which are in turn MyFileItems)
            The constructor recurses through the diretories ensure that each item is cached in ram and the size
            of each folder in calculated only a single time.

            I eventually figured out how to create this object without blocking the UI thread, but if I continue to
            work on this in the future I would like to have the size calculated after the constructor so that folders
            can be displayed to the user before size is avialable.

            This class also handles the UnathorizeAccessException. When this excpetion occurs the class is marked as
            Unathorized and can then be properly displayed throughout the application.
        */
        public MyFileInfo(string path, MyFileInfo parent)
        {
            try
            {
                FileCount = 0;
                FullPath = path;
                Name = path.Substring(path.LastIndexOf("\\") + 1);
                SubFiles = new List<MyFileInfo>();
                FileAttributes attr = File.GetAttributes(path);
                LastEdit = Directory.GetLastWriteTime(path);
                Parent = parent;

                if (attr.HasFlag(FileAttributes.Directory))
                {
                    Type = FileType.Directory;
                    foreach (string dir in Directory.GetDirectories(path))
                    {
                        MyFileInfo subDir = new MyFileInfo(dir, this);
                        SubFiles.Add(subDir);
                        FileCount += subDir.FileCount;
                    }

                    foreach (string file in Directory.GetFiles(path))
                    {
                        MyFileInfo subDir = new MyFileInfo(file, this);
                        SubFiles.Add(subDir);
                        FileCount += 1;
                    }

                    foreach (MyFileInfo f in SubFiles)
                    {
                        Size += f.Size;
                    }
                }
                else
                {
                    Type = FileType.File;
                    Size = new FileInfo(path).Length;
                    FileCount = 1;

                }
                Name = path.Substring(path.LastIndexOf("\\") + 1);
                if (Name.Trim().Equals(""))
                {
                    Name = path;
                    Type = FileType.RootDrive;
                }
            }
            catch (UnauthorizedAccessException)
            {
                Type = FileType.Unauthorized;
                Size = -1;
                FileCount = -1;
            }
        }
Ejemplo n.º 3
0
        /* Personal Feature: Carver
         *  The MyFileItems class represents a directory and all of it's children (which are in turn MyFileItems)
         *  The constructor recurses through the diretories ensure that each item is cached in ram and the size
         *  of each folder in calculated only a single time.
         *
         *  I eventually figured out how to create this object without blocking the UI thread, but if I continue to
         *  work on this in the future I would like to have the size calculated after the constructor so that folders
         *  can be displayed to the user before size is avialable.
         *
         *  This class also handles the UnathorizeAccessException. When this excpetion occurs the class is marked as
         *  Unathorized and can then be properly displayed throughout the application.
         */
        public MyFileInfo(string path, MyFileInfo parent)
        {
            try
            {
                FileCount = 0;
                FullPath  = path;
                Name      = path.Substring(path.LastIndexOf("\\") + 1);
                SubFiles  = new List <MyFileInfo>();
                FileAttributes attr = File.GetAttributes(path);
                LastEdit = Directory.GetLastWriteTime(path);
                Parent   = parent;

                if (attr.HasFlag(FileAttributes.Directory))
                {
                    Type = FileType.Directory;
                    foreach (string dir in Directory.GetDirectories(path))
                    {
                        MyFileInfo subDir = new MyFileInfo(dir, this);
                        SubFiles.Add(subDir);
                        FileCount += subDir.FileCount;
                    }

                    foreach (string file in Directory.GetFiles(path))
                    {
                        MyFileInfo subDir = new MyFileInfo(file, this);
                        SubFiles.Add(subDir);
                        FileCount += 1;
                    }

                    foreach (MyFileInfo f in SubFiles)
                    {
                        Size += f.Size;
                    }
                }
                else
                {
                    Type      = FileType.File;
                    Size      = new FileInfo(path).Length;
                    FileCount = 1;
                }
                Name = path.Substring(path.LastIndexOf("\\") + 1);
                if (Name.Trim().Equals(""))
                {
                    Name = path;
                    Type = FileType.RootDrive;
                }
            }
            catch (UnauthorizedAccessException)
            {
                Type      = FileType.Unauthorized;
                Size      = -1;
                FileCount = -1;
            }
        }
Ejemplo n.º 4
0
        private async void searchButton_click(object sender, RoutedEventArgs e)
        {
            string path = TextDirectory.Text;

            if (Directory.Exists(path))
            {
                IsBusy       = true;
                _currentItem = await Task.Run(() =>
                {
                    return(new MyFileInfo(path, null));
                });

                MyFileItemViewSource.Source = _currentItem.SubFiles;
                IsBusy = false;
            }
        }
Ejemplo n.º 5
0
 public MainWindow()
 {
     InitializeComponent();
     _currentItem            = new MyFileInfo(null);
     SortStrategy            = SortStrategy.Name;
     SearchText.TextChanged += (sender, e) => FilterResults(SearchText.Text);
     NameHeader.Click       += (sender, e) => SortStrategy = (SortStrategy == SortStrategy.Name) ? SortStrategy.RName : SortStrategy.Name;
     PercentHeader.Click    += (sender, e) => SortStrategy = (SortStrategy == SortStrategy.Size) ? SortStrategy.RSize : SortStrategy.Size;
     SizeHeader.Click       += (sender, e) => SortStrategy = (SortStrategy == SortStrategy.Size) ? SortStrategy.RSize : SortStrategy.Size;
     LastEditHeader.Click   += (sender, e) => SortStrategy = (SortStrategy == SortStrategy.LastEdit) ? SortStrategy.RLastEdit : SortStrategy.LastEdit;
     FileCountHeader.Click  += (sender, e) => SortStrategy = (SortStrategy == SortStrategy.FileCount) ? SortStrategy.RFileCount : SortStrategy.FileCount;
     TypeHeader.Click       += (sender, e) => SortStrategy = (SortStrategy == SortStrategy.Type) ? SortStrategy.RType : SortStrategy.Type;
     ((INotifyCollectionChanged)MyFileItemListView.Items).CollectionChanged += (s, args) => {
         UpdateColumns();
         CanBack = _currentItem.Parent != null;
     };
 }
Ejemplo n.º 6
0
        private void myFileItemListView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var item = MyFileItemListView.SelectedItem as MyFileInfo;

            if (item != null)
            {
                if (item.Type == FileType.Directory)
                {
                    _currentItem = item;
                    MyFileItemViewSource.Source = _currentItem.SubFiles;
                    SearchText.Clear();
                }
                else
                {
                    Process.Start(item.FullPath);
                }
            }
        }
Ejemplo n.º 7
0
 public MyFileInfo(MyFileInfo parent)
 {
     Parent = parent;
 }
Ejemplo n.º 8
0
 public MainWindow()
 {
     InitializeComponent();
     _currentItem = new MyFileInfo(null);
     SortStrategy = SortStrategy.Name;
     SearchText.TextChanged += (sender, e) => FilterResults(SearchText.Text);
     NameHeader.Click += (sender, e) => SortStrategy = (SortStrategy == SortStrategy.Name) ? SortStrategy.RName : SortStrategy.Name;
     PercentHeader.Click += (sender, e) => SortStrategy = (SortStrategy == SortStrategy.Size) ? SortStrategy.RSize : SortStrategy.Size;
     SizeHeader.Click += (sender, e) => SortStrategy = (SortStrategy == SortStrategy.Size) ? SortStrategy.RSize : SortStrategy.Size;
     LastEditHeader.Click += (sender, e) => SortStrategy = (SortStrategy == SortStrategy.LastEdit) ? SortStrategy.RLastEdit : SortStrategy.LastEdit;
     FileCountHeader.Click += (sender, e) => SortStrategy = (SortStrategy == SortStrategy.FileCount) ? SortStrategy.RFileCount : SortStrategy.FileCount;
     TypeHeader.Click += (sender, e) => SortStrategy = (SortStrategy == SortStrategy.Type) ? SortStrategy.RType : SortStrategy.Type;
     ((INotifyCollectionChanged)MyFileItemListView.Items).CollectionChanged += (s, args) => {
         UpdateColumns();
         CanBack = _currentItem.Parent != null;
     };
 }
Ejemplo n.º 9
0
 private async void searchButton_click(object sender, RoutedEventArgs e)
 {
     string path = TextDirectory.Text;
     if (Directory.Exists(path))
     {
         IsBusy = true;
         _currentItem = await Task.Run(() =>
         {
             return new MyFileInfo(path, null);
         });
         MyFileItemViewSource.Source = _currentItem.SubFiles;
         IsBusy = false;
     }
 }
Ejemplo n.º 10
0
        private void backButton_Click(object sender, RoutedEventArgs e)
        {
            if (_currentItem.Parent != null)
            {
                _currentItem = _currentItem.Parent;
                MyFileItemViewSource.Source = _currentItem.SubFiles;
                SearchText.Clear();
            }

        }
Ejemplo n.º 11
0
 private void myFileItemListView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
 {
     var item = MyFileItemListView.SelectedItem as MyFileInfo;
     if (item != null)
     {
         if (item.Type == FileType.Directory)
         {
             _currentItem = item;
             MyFileItemViewSource.Source = _currentItem.SubFiles;
             SearchText.Clear();
         }
         else
         {
             Process.Start(item.FullPath);
         }
     }
     
 }
Ejemplo n.º 12
0
 public MyFileInfo(MyFileInfo parent)
 {
     Parent = parent;
 }