Пример #1
0
        private void BuildFileTree(bool buildOnly)
        {
            PollResults results = new PollResults();

            if (Root == null)
            {
                Root = new FsItem("*Root", null, true, true);
            }

            try
            {
                //Scan for changes and update tree
                SetStatus("Scanning..");
                Stopwatch s = new Stopwatch();
                s.Start();
                results.TotalFileCount = Globals.FileCountInAllRoots();
                Root.Build(ref results);
                Root.UpdateFolderContentsChanged();
                s.Stop();
                SetStatus("Scan complete.");

                //Do work to show what's changed.
                BeginInvoke(new Action(() =>
                {
                    StatsForm.LastScanTimeMs    = s.ElapsedMilliseconds;
                    StatsForm.AverageScanTimeMs = (StatsForm.AverageScanTimeMs + StatsForm.LastScanTimeMs) / 2;
                    StatsForm.NumberOfScans++;
                    StatsForm.FileCount = results.ScannedFileCountLastScan;
                    StatsForm.NewCount  = results.NewFileCountLastScan;

                    StatsForm.AvgAddedPerScan   = (StatsForm.AvgAddedPerScan + results.NumAdded) / 2;
                    StatsForm.AvgDeletedPerScan = (StatsForm.AvgDeletedPerScan + results.NumDeleted) / 2;
                    StatsForm.AvgChangedPerScan = (StatsForm.AvgChangedPerScan + results.NumChanged) / 2;

                    StatsForm.TopFileWriteList = results.TopFileChanges;

                    UpdateStats();
                }));
                if (buildOnly == false)
                {
                    if (Root.HasChanges())
                    {
                        PrintResults();
                        ExecShellCommand();
                    }
                }

                //MUST clean tree after building to remove changed files.
                Root.CleanAndSync(true);
            }
            catch (Exception ex)
            {
                Globals.LogError(ex.ToString());
            }
        }