Esempio n. 1
0
        /// <summary>
        /// Refreshes the selected folder in the UI on a background thread. Has special case code.
        /// Uses the value stored in the sidebarFolder to choose the folder to resize.
        /// </summary>
        /// <param name="sender">Object that raised the event</param>
        /// <param name="e">Arguments about the event</param>
        private void resizeFolder(object sender, RoutedEventArgs e)
        {
            if (sidebarFolder == null)
            {
                return;
            }
            //reinitialize background worker
            bgWorker = new System.Threading.Thread(() =>
            {
                bool onProgressUpdate(FolderData fd, double prog)
                {
                    System.Windows.Application.Current.Dispatcher.Invoke((Action) delegate
                    {
                        if (prog == 1 && sidebarPath.Equals(fd.path.FullName))
                        {
                            updateSidebar();
                            StopBtn.IsEnabled = false;
                            //calculate the level
                            int lev = sidebarFolder.path.FullName.Split(System.IO.Path.DirectorySeparatorChar).Length - displayList[0].folderData.path.FullName.Split(System.IO.Path.DirectorySeparatorChar).Length - 1;
                            if (lev < 0)
                            {
                                lev = 0;
                            }
                            //if this is the root folder, don't add a second collumn when updating UI
                            if (fd.root)
                            {
                                lev = -1;
                            }
                            //call the grid clicked event to update the table views
                            OnGridClicked(new FolderDisplay(sidebarFolder, lev), new FolderDisplayEvent()
                            {
                                folderData = sidebarFolder
                            });
                            ResizeFolder.IsEnabled = true;
                        }
                        StatusL.Content = "Refreshing " + sidebarPath + " (" + Math.Round(prog * 100) + "%)";
                        MainProg.Value  = prog;

                        //update the UI in the table
                        foreach (FolderDisplay f in displayList)
                        {
                            if (f.folderData.path.FullName.Equals(fd.path.FullName))
                            {
                                f.folderData = fd;
                                f.updateTableListing();
                            }
                        }
                    });

                    return(true);
                }
                //resize the folder
                sidebarFolder.size(onProgressUpdate);
            });

            bgWorker.Start();
            StopBtn.IsEnabled      = true;
            ResizeFolder.IsEnabled = false;
        }
Esempio n. 2
0
        /// <summary>
        /// Sizes the folder tree with the given root folder on a background thread
        /// </summary>
        /// <param name="path">String representing the fully qualified path to the root folder</param>
        private void sizeFolder(string path)
        {
            FolderData fd = new FolderData(path, true);

            displayList             = new List <FolderDisplay>();
            bgWorker                = new System.Threading.Thread(() => fd.size(UpdateUIOnCallback));
            sidebarPath             = path;
            revealButton.IsEnabled  = true;
            RevealToolbar.IsEnabled = true;
            copyPath.IsEnabled      = true;
            bgWorker.Start();
            //hide instructions label
            ContentGrid.Children.Remove(LInstructions);
        }
Esempio n. 3
0
        /// <summary>
        /// Recursively determines the total size of the folder, including subfolders
        /// </summary>
        /// <param name="callback">Bool returning function that takes a double 0-1. Pass this if you want progress updates (i.e. doing the size asyncronously)</param>
        public void size(Func <FolderData, double, bool> callback = null)
        {
            sfDict     = new Dictionary <string, FolderData>();
            subFolders = new List <FolderData>();

            if (sfdi == null)
            {
                return;
            }
            total_size = 0;
            files_size = 0;
            num_items  = 0;
            size_files();

            //build the list of subfolders by sizing each one
            double prog = 0;

            foreach (DirectoryInfo d in sfdi)
            {
                FolderData t = new FolderData(d.FullName);
                t.size();
                total_size += t.total_size;
                num_items  += t.num_items;
                subFolders.Add(t);
                sfDict.Add(t.path.Name, t);

                //call the callback
                if (callback != null)
                {
                    prog++;
                    callback(this, prog / sfdi.Count());
                }
            }
            //if the target folder has no subfolders
            if (prog == 0 && callback != null)
            {
                callback(this, 1);
            }
        }