Exemple #1
0
        public void Build(ref PollResults results)
        {
            //get list of new items
            List <FsItem> items = GetNewItems();

            //comapre items with our tree
            CheckForNewOrChangedFiles(ref results, items);
            CheckRemoved(ref results, items);

            //Recursive through directory tree.
            foreach (FsItem item in Folders)
            {
                if (item.FsItemState == FsItemState.None ||
                    item.FsItemState == FsItemState.Changed ||
                    item.FsItemState == FsItemState.Added)
                {
                    item.Build(ref results);
                }
            }

            //Update the scan progress.
            results.ScannedFileCountLastScan += items.Count;

            int cur = results.ScannedFileCountLastScan;
            int tot = results.TotalFileCount;

            Globals.MainForm.BeginInvoke(new Action(() =>
            {
                Globals.MainForm.StatsForm.CurrentScanPct = (double)cur / (double)tot;
                Globals.MainForm.StatsForm.Update();
            }));

            results.NewFileCountLastScan += Children.Where(x => x.FsItemState == FsItemState.Added).ToList().Count;
        }
Exemple #2
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());
            }
        }
Exemple #3
0
 private void CheckRemoved(ref PollResults results, List <FsItem> items)
 {
     //Check Removed Items
     foreach (FsItem c in Children)
     {
         FsItem found = items.Where(x => x.Hash == c.Hash).FirstOrDefault();
         if (found == null)
         {
             //Item was removed
             c.FsItemState = FsItemState.Removed;
             results.NumDeleted++;
         }
     }
 }
Exemple #4
0
        private void CheckHotFile(FsItem child, ref PollResults results)
        {
            //Cache the top changed files
            if (child.WriteCount > 0)
            {
                if (results.TopFileChanges.Count == 0 || child.WriteCount > results.TopFileChanges[results.TopFileChanges.Count - 1].WriteCount)
                {
                    results.TopFileChanges.Add(child);

                    if (results.TopFileChanges.Count > Globals.Settings.NumTopFiles)
                    {
                        results.TopFileChanges.RemoveRange(Globals.Settings.NumTopFiles,
                                                           results.TopFileChanges.Count - Globals.Settings.NumTopFiles);
                    }
                }
            }
        }
Exemple #5
0
        private void CheckForNewOrChangedFiles(ref PollResults results, List <FsItem> items)
        {
            //Compare our tree with the FS items.
            foreach (FsItem item in items)
            {
                if ((!item.IsFolder() && Globals.Settings.PollFiles) || (item.IsFolder() && Globals.Settings.PollDirectories))
                {
                    if (FsItemState == FsItemState.Added)
                    {
                        //We are a new Dir
                        //Simply add everything to the new parent.
                        AddChildNode(item);
                        item.FsItemState = FsItemState.Added;
                        results.NumAdded++;
                    }
                    else
                    {
                        FsItem child = FindChild(item, false);
                        if (child != null)
                        {
                            //item is there.
                            //*We will ignore changes to folders (whcih in windows, shows only parent folder changed if contents changed).
                            //Instead we show the whole parent branch as modified if a file gets changed
                            if (child.IsFolder() == false)
                            {
                                if (item.LastModifyTime > child.LastModifyTime)
                                {
                                    child.FsItemState   = FsItemState.Changed;
                                    child.NewModifyTime = item.LastModifyTime;
                                    results.NumChanged++;
                                    child.WriteCount++;
                                }

                                CheckHotFile(child, ref results);
                            }
                        }
                        else
                        {
                            AddChildNode(item);
                            item.FsItemState = FsItemState.Added;
                            results.NumAdded++;
                        }
                    }
                }
            }
        }