mirror of
				https://github.com/wagesj45/mdfinder.git
				synced 2025-09-09 03:20:38 -05:00 
			
		
		
		
	Periodic Checkin
Got the application scanning and displaying results.
This commit is contained in:
		
					parent
					
						
							
								c0afde943e
							
						
					
				
			
			
				commit
				
					
						f81e4f13da
					
				
			
		
					 7 changed files with 130 additions and 10 deletions
				
			
		| 
						 | 
					@ -1,6 +1,7 @@
 | 
				
			||||||
using LiteDB;
 | 
					using LiteDB;
 | 
				
			||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using System.Collections.ObjectModel;
 | 
				
			||||||
using System.IO;
 | 
					using System.IO;
 | 
				
			||||||
using System.Linq;
 | 
					using System.Linq;
 | 
				
			||||||
using System.Text;
 | 
					using System.Text;
 | 
				
			||||||
| 
						 | 
					@ -9,7 +10,7 @@ using System.Threading.Tasks;
 | 
				
			||||||
namespace mdfinder
 | 
					namespace mdfinder
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    /// <summary> A database helper class. </summary>
 | 
					    /// <summary> A database helper class. </summary>
 | 
				
			||||||
    public class DBHelper
 | 
					    public class DBHelper : PropertyChangedAlerter
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        #region Members
 | 
					        #region Members
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,6 +35,15 @@ namespace mdfinder
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public IEnumerable<FileRecord> ASDF
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            get
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                return this.FileRecords.FindAll();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        #endregion
 | 
					        #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        #region Constructors
 | 
					        #region Constructors
 | 
				
			||||||
| 
						 | 
					@ -63,6 +73,7 @@ namespace mdfinder
 | 
				
			||||||
        public void InsertFileRecord(string path, long size, string hash, string hashProvider)
 | 
					        public void InsertFileRecord(string path, long size, string hash, string hashProvider)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            this.FileRecords.Insert(new FileRecord() { Path = path, Size = size, Hash = hash, HashProvider = hashProvider });
 | 
					            this.FileRecords.Insert(new FileRecord() { Path = path, Size = size, Hash = hash, HashProvider = hashProvider });
 | 
				
			||||||
 | 
					            OnPropertyChanged("ASDF");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        #endregion
 | 
					        #endregion
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,7 +12,7 @@ namespace mdfinder
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary> Gets or sets the identifier. </summary>
 | 
					        /// <summary> Gets or sets the identifier. </summary>
 | 
				
			||||||
        /// <value> The identifier. </value>
 | 
					        /// <value> The identifier. </value>
 | 
				
			||||||
        public uint Id { get; set; }
 | 
					        public Int64 Id { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary> Gets or sets the full pathname of the file. </summary>
 | 
					        /// <summary> Gets or sets the full pathname of the file. </summary>
 | 
				
			||||||
        /// <value> The full pathname of the file. </value>
 | 
					        /// <value> The full pathname of the file. </value>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -69,7 +69,7 @@
 | 
				
			||||||
                    </Button>
 | 
					                    </Button>
 | 
				
			||||||
                </Grid>
 | 
					                </Grid>
 | 
				
			||||||
            </GroupBox>
 | 
					            </GroupBox>
 | 
				
			||||||
            <DataGrid Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type mdfinder:MainWindow}} }" />
 | 
					            <DataGrid Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3" ItemsSource="{Binding Database.ASDF, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type mdfinder:MainWindow}}}" />
 | 
				
			||||||
            <ProgressBar Grid.Row="3" Grid.ColumnSpan="4" Name="progressBar" Minimum="0" Height="16"/>
 | 
					            <ProgressBar Grid.Row="3" Grid.ColumnSpan="4" Name="progressBar" Minimum="0" Height="16"/>
 | 
				
			||||||
        </Grid>
 | 
					        </Grid>
 | 
				
			||||||
    </DockPanel>
 | 
					    </DockPanel>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -39,7 +39,13 @@ namespace mdfinder
 | 
				
			||||||
            this.Scanner = new Scanner();
 | 
					            this.Scanner = new Scanner();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            this.Scanner.DirectoryFound += (sender, args) => Dispatcher.Invoke(() => txtScanLocation.Text = args.Directory.Name);
 | 
					            this.Scanner.DirectoryFound += (sender, args) => Dispatcher.Invoke(() => txtScanLocation.Text = args.Directory.Name);
 | 
				
			||||||
            //this.Scanner.FilesFound += (sender, args) => args.Files;
 | 
					            this.Scanner.FilesFound += (sender, args) => 
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                foreach(var file in args.Files)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    this.Database.InsertFileRecord(file.FullName, file.Length, Guid.NewGuid().ToString(), "test");
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
            this.Scanner.ReportProgress += (sender, args) => Dispatcher.Invoke(() => { if (args.Processed > 0) { this.progressBar.Value = args.Percentage * 100; } });
 | 
					            this.Scanner.ReportProgress += (sender, args) => Dispatcher.Invoke(() => { if (args.Processed > 0) { this.progressBar.Value = args.Percentage * 100; } });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            InitializeComponent();
 | 
					            InitializeComponent();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										89
									
								
								mdfinder/PropertyChangedAlerter.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										89
									
								
								mdfinder/PropertyChangedAlerter.cs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,89 @@
 | 
				
			||||||
 | 
					using System;
 | 
				
			||||||
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using System.ComponentModel;
 | 
				
			||||||
 | 
					using System.Linq;
 | 
				
			||||||
 | 
					using System.Runtime.CompilerServices;
 | 
				
			||||||
 | 
					using System.Text;
 | 
				
			||||||
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace mdfinder
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    /// <summary> A class responsible for implementing the <see cref="INotifyPropertyChanged"/> interface and helper functions. </summary>
 | 
				
			||||||
 | 
					    public abstract class PropertyChangedAlerter : INotifyPropertyChanged
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        #region Members
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary> Occurs when a property value changes. </summary>
 | 
				
			||||||
 | 
					        public event PropertyChangedEventHandler PropertyChanged;
 | 
				
			||||||
 | 
					        /// <summary> A list of properties to always call as updated. Generally used for composite properties. </summary>
 | 
				
			||||||
 | 
					        private List<string> alwaysCall = new List<string>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #region Properties
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #region Methods
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// Executes the property changed action. This alerts subscribers to its change in value.
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="name"> (Optional) The name of the property. </param>
 | 
				
			||||||
 | 
					        /// <example>
 | 
				
			||||||
 | 
					        /// This will automatically pass in "SomeProperty" as the property name, derived useing the
 | 
				
			||||||
 | 
					        /// <see cref="CallerMemberNameAttribute" /> attribute.
 | 
				
			||||||
 | 
					        /// <code lang="cs" title="Automatic Property Detection">
 | 
				
			||||||
 | 
					        /// public bool SomeProperty
 | 
				
			||||||
 | 
					        /// {
 | 
				
			||||||
 | 
					        ///     get
 | 
				
			||||||
 | 
					        ///     {
 | 
				
			||||||
 | 
					        ///         return this.someProperty;
 | 
				
			||||||
 | 
					        ///     }
 | 
				
			||||||
 | 
					        ///     set
 | 
				
			||||||
 | 
					        ///     {
 | 
				
			||||||
 | 
					        ///         this.someProperty = value;
 | 
				
			||||||
 | 
					        ///         OnPropertyChanged();
 | 
				
			||||||
 | 
					        ///     }
 | 
				
			||||||
 | 
					        /// }
 | 
				
			||||||
 | 
					        /// </code>
 | 
				
			||||||
 | 
					        /// </example>
 | 
				
			||||||
 | 
					        protected virtual void OnPropertyChanged([CallerMemberName]string name = null)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if (!string.IsNullOrWhiteSpace(name))
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
 | 
				
			||||||
 | 
					                foreach (var updatedProperty in this.alwaysCall)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(updatedProperty));
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary> Executes when all properties are changed and should be updated. </summary>
 | 
				
			||||||
 | 
					        protected virtual void OnAllPropertiesChanged()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(string.Empty));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary> Adds a property that will always be called when any property is updated.. </summary>
 | 
				
			||||||
 | 
					        /// <param name="name"> The name of the property. </param>
 | 
				
			||||||
 | 
					        public void AddConstantCallProperty(string name)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if (this.alwaysCall == null)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                // This item has been deserialized and the list needs to be reinitialized.
 | 
				
			||||||
 | 
					                this.alwaysCall = new List<string>();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (!this.alwaysCall.Any(c => c.Equals(name, StringComparison.OrdinalIgnoreCase)))
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                this.alwaysCall.Add(name);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #endregion
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -43,24 +43,37 @@ namespace mdfinder
 | 
				
			||||||
            var scanPath = new DirectoryInfo(path);
 | 
					            var scanPath = new DirectoryInfo(path);
 | 
				
			||||||
            if (scanPath.Exists)
 | 
					            if (scanPath.Exists)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
 | 
					                Discover(scanPath);
 | 
				
			||||||
                Scan(scanPath);
 | 
					                Scan(scanPath);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
 | 
					        private void Discover(DirectoryInfo directory)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            try
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                this.Total += (uint)directory.EnumerateFiles().Count();
 | 
				
			||||||
 | 
					                foreach (var subdirectory in directory.GetDirectories())
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    OnDirectoryFound(subdirectory);
 | 
				
			||||||
 | 
					                    Discover(subdirectory);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            catch (UnauthorizedAccessException unauthorizedAccessException)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                //Ignore and just continue.
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void Scan(DirectoryInfo directory)
 | 
					        private void Scan(DirectoryInfo directory)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            try
 | 
					            try
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                var files = directory.GetFiles();
 | 
					                var fileBatches = directory.EnumerateFiles().Bin(Properties.Settings.Default.FilesFoundAlert);
 | 
				
			||||||
                var fileBatches = files.Bin(Properties.Settings.Default.FilesFoundAlert);
 | 
					 | 
				
			||||||
                var subdirectories = directory.GetDirectories();
 | 
					                var subdirectories = directory.GetDirectories();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                this.Total += (uint)files.Count();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                foreach (var subdirectory in subdirectories)
 | 
					                foreach (var subdirectory in subdirectories)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    OnDirectoryFound(subdirectory);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    Scan(subdirectory);
 | 
					                    Scan(subdirectory);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -91,6 +91,7 @@
 | 
				
			||||||
    <Compile Include="FileRecord.cs" />
 | 
					    <Compile Include="FileRecord.cs" />
 | 
				
			||||||
    <Compile Include="InverseBoolConverter.cs" />
 | 
					    <Compile Include="InverseBoolConverter.cs" />
 | 
				
			||||||
    <Compile Include="InverseBoolVisibilityConverter.cs" />
 | 
					    <Compile Include="InverseBoolVisibilityConverter.cs" />
 | 
				
			||||||
 | 
					    <Compile Include="PropertyChangedAlerter.cs" />
 | 
				
			||||||
    <Compile Include="Scanner.cs" />
 | 
					    <Compile Include="Scanner.cs" />
 | 
				
			||||||
    <Compile Include="Localization\Localization.Designer.cs">
 | 
					    <Compile Include="Localization\Localization.Designer.cs">
 | 
				
			||||||
      <AutoGen>True</AutoGen>
 | 
					      <AutoGen>True</AutoGen>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue