Skip to content

Commit

Permalink
Adding a progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
agross committed May 2, 2012
1 parent f750b0f commit bb6555c
Show file tree
Hide file tree
Showing 12 changed files with 320 additions and 214 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions rakefile.rb
Expand Up @@ -270,6 +270,7 @@ def configure_env_for(env_key)
task :ilmerge => ['compile:app'] do
assemblies = FileList.new("#{configatron.dir.build}/Application/DuplicateFinder*.exe") \
.include("#{configatron.dir.build}/Application/DuplicateFinder*.dll") \
.include("#{configatron.dir.build}/Application/Microsoft.WindowsAPI*.dll") \
.exclude("#{configatron.dir.build}/Application/*.vshost.exe")

ILMerge.merge \
Expand Down
Expand Up @@ -21,7 +21,8 @@ public class When_all_files_are_removed_before_they_are_hashed
Finder = new DuplicateFinder(new[] { new NonExistingFilesFinder() },
new[] { new ThrowingHashCodeProvider() },
Output,
new NullHistory());
new NullHistory(),
new TaskbarProgress());
};

Because of = () => Finder.FindDuplicates().Duplicates.ToArray();
Expand Down
Expand Up @@ -11,71 +11,72 @@

namespace DuplicateFinder.Core.CommandLine.Factories
{
class FindDuplicatesCommandFactory : ICommandFactory
{
readonly IFileSystem _fileSystem;
readonly ModifyableOptionSet _options;
readonly IOutput _output;
class FindDuplicatesCommandFactory : ICommandFactory
{
readonly IFileSystem _fileSystem;
readonly ModifyableOptionSet _options;
readonly IOutput _output;

public FindDuplicatesCommandFactory(IOutput output, IFileSystem fileSystem, ModifyableOptionSet options)
{
_output = output;
_fileSystem = fileSystem;
_options = options;
}
public FindDuplicatesCommandFactory(IOutput output, IFileSystem fileSystem, ModifyableOptionSet options)
{
_output = output;
_fileSystem = fileSystem;
_options = options;
}

public bool CanHandle(string[] args)
{
return !_options.With(args).Has(Args.PruneHistory);
}
public bool CanHandle(string[] args)
{
return !_options.With(args).Has(Args.PruneHistory);
}

public ICommand CreateCommand(string[] args)
{
var hashes = new List<Func<IHashCodeProvider>>();
var decorators = new List<IStreamDecorator>();
var deletionSelector = (ISelectFilesToDelete) new AllButFirstDuplicateSelector();
var deleter = (IFileDeleter) new FileDeleter(_fileSystem, _output);
var history = (IRememberHashCodes) new NullHistory();
public ICommand CreateCommand(string[] args)
{
var hashes = new List<Func<IHashCodeProvider>>();
var decorators = new List<IStreamDecorator>();
var deletionSelector = (ISelectFilesToDelete) new AllButFirstDuplicateSelector();
var deleter = (IFileDeleter) new FileDeleter(_fileSystem, _output);
var history = (IRememberHashCodes) new NullHistory();

_options.Update<string>(Args.Name, v => hashes.Add(() => new FileNameHashCodeProvider()));
_options.Update<string>(Args.Size, v => hashes.Add(() => new FileSizeHashCodeProvider(_fileSystem)));
_options.Update<string>(Args.Content,
v => hashes.Add(() => new FileContentHashCodeProvider(_fileSystem, decorators.ToArray())));
_options.Update(Args.Head, (long v) => decorators.Add(new HeadStreamDecorator(v)));
_options.Update(Args.Tail, (long v) => decorators.Add(new TailStreamDecorator(v)));
_options.Update<string>(Args.Keep, v => deletionSelector = new KeepOneCopyInDirectorySelector(v));
_options.Update<string>(Args.History, v => history = new DatabaseHistory(v, _fileSystem));
_options.Update<string>(Args.WhatIf, v => deleter = new WhatIfFileDeleter(_output));
_options.Update<string>(Args.Name, v => hashes.Add(() => new FileNameHashCodeProvider()));
_options.Update<string>(Args.Size, v => hashes.Add(() => new FileSizeHashCodeProvider(_fileSystem)));
_options.Update<string>(Args.Content,
v => hashes.Add(() => new FileContentHashCodeProvider(_fileSystem, decorators.ToArray())));
_options.Update(Args.Head, (long v) => decorators.Add(new HeadStreamDecorator(v)));
_options.Update(Args.Tail, (long v) => decorators.Add(new TailStreamDecorator(v)));
_options.Update<string>(Args.Keep, v => deletionSelector = new KeepOneCopyInDirectorySelector(v));
_options.Update<string>(Args.History, v => history = new DatabaseHistory(v, _fileSystem));
_options.Update<string>(Args.WhatIf, v => deleter = new WhatIfFileDeleter(_output));

var directories = _options.Parse(args);
var directories = _options.Parse(args);

var messages = Missing(hashes, "The comparison type is missing")
.Union(Missing(directories, "No directories to compare"));
var messages = Missing(hashes, "The comparison type is missing")
.Union(Missing(directories, "No directories to compare"));

if (messages.Any())
{
throw new CommandLineParserException(messages);
}
if (messages.Any())
{
throw new CommandLineParserException(messages);
}

var finder = new DuplicateFinder(directories.Select(x => (IFileFinder) new RecursiveFileFinder(_fileSystem, x)),
hashes.Select(x => x()),
_output,
history);
var finder = new DuplicateFinder(directories.Select(x => (IFileFinder) new RecursiveFileFinder(_fileSystem, x)),
hashes.Select(x => x()),
_output,
history,
new TaskbarProgress());

return new FindDuplicatesCommand(_output,
finder,
deletionSelector,
deleter);
}
return new FindDuplicatesCommand(_output,
finder,
deletionSelector,
deleter);
}

static IEnumerable<string> Missing(IEnumerable hashes, string message)
{
if (hashes.Cast<object>().Any())
{
yield break;
}
static IEnumerable<string> Missing(IEnumerable hashes, string message)
{
if (hashes.Cast<object>().Any())
{
yield break;
}

yield return message;
}
}
}
yield return message;
}
}
}
Expand Up @@ -10,72 +10,73 @@

namespace DuplicateFinder.Core.CommandLine.Factories
{
class PruneHistoryCommandFactory : ICommandFactory
{
readonly IFileSystem _fileSystem;
readonly ModifyableOptionSet _options;
readonly IOutput _output;
class PruneHistoryCommandFactory : ICommandFactory
{
readonly IFileSystem _fileSystem;
readonly ModifyableOptionSet _options;
readonly IOutput _output;

public PruneHistoryCommandFactory(IOutput output, IFileSystem fileSystem, ModifyableOptionSet options)
{
_output = output;
_fileSystem = fileSystem;
_options = options;
}
public PruneHistoryCommandFactory(IOutput output, IFileSystem fileSystem, ModifyableOptionSet options)
{
_output = output;
_fileSystem = fileSystem;
_options = options;
}

public bool CanHandle(string[] args)
{
return _options.With(args).Has(Args.PruneHistory);
}
public bool CanHandle(string[] args)
{
return _options.With(args).Has(Args.PruneHistory);
}

public ICommand CreateCommand(string[] args)
{
var hashes = new List<Func<IHashCodeProvider>>();
var decorators = new List<IStreamDecorator>();
IRememberHashCodes history = null;
public ICommand CreateCommand(string[] args)
{
var hashes = new List<Func<IHashCodeProvider>>();
var decorators = new List<IStreamDecorator>();
IRememberHashCodes history = null;

_options.Update<string>(Args.Name, v => hashes.Add(() => new FileNameHashCodeProvider()));
_options.Update<string>(Args.Size, v => hashes.Add(() => new FileSizeHashCodeProvider(_fileSystem)));
_options.Update<string>(Args.Content,
v => hashes.Add(() => new FileContentHashCodeProvider(_fileSystem, decorators.ToArray())));
_options.Update(Args.Head, (long v) => decorators.Add(new HeadStreamDecorator(v)));
_options.Update(Args.Tail, (long v) => decorators.Add(new TailStreamDecorator(v)));
_options.Update<string>(Args.History, v => history = new DatabaseHistory(v, _fileSystem));
_options.Update<string>(Args.Name, v => hashes.Add(() => new FileNameHashCodeProvider()));
_options.Update<string>(Args.Size, v => hashes.Add(() => new FileSizeHashCodeProvider(_fileSystem)));
_options.Update<string>(Args.Content,
v => hashes.Add(() => new FileContentHashCodeProvider(_fileSystem, decorators.ToArray())));
_options.Update(Args.Head, (long v) => decorators.Add(new HeadStreamDecorator(v)));
_options.Update(Args.Tail, (long v) => decorators.Add(new TailStreamDecorator(v)));
_options.Update<string>(Args.History, v => history = new DatabaseHistory(v, _fileSystem));

var directories = _options.Parse(args);
var directories = _options.Parse(args);

var messages = Missing(hashes, "The comparison type is missing")
.Union(Missing(directories, "No directories to compare"))
.Union(Missing(history, "No history file was specified"));
var messages = Missing(hashes, "The comparison type is missing")
.Union(Missing(directories, "No directories to compare"))
.Union(Missing(history, "No history file was specified"));

if (messages.Any())
{
throw new CommandLineParserException(messages);
}
if (messages.Any())
{
throw new CommandLineParserException(messages);
}

var finder = new DuplicateFinder(directories.Select(x => (IFileFinder) new RecursiveFileFinder(_fileSystem, x)),
hashes.Select(x => x()),
_output,
new NullHistory());
var finder = new DuplicateFinder(directories.Select(x => (IFileFinder) new RecursiveFileFinder(_fileSystem, x)),
hashes.Select(x => x()),
_output,
new NullHistory(),
new TaskbarProgress());

return new PruneHistoryCommand(_output,
finder,
history);
}
return new PruneHistoryCommand(_output,
finder,
history);
}

static IEnumerable<string> Missing(object instance, string nullReference)
{
return Missing(new[] {instance}, nullReference);
}
static IEnumerable<string> Missing(object instance, string nullReference)
{
return Missing(new[] { instance }, nullReference);
}

static IEnumerable<string> Missing(IEnumerable hashes, string message)
{
if (hashes.Cast<object>().Any(x => x != null))
{
yield break;
}
static IEnumerable<string> Missing(IEnumerable hashes, string message)
{
if (hashes.Cast<object>().Any(x => x != null))
{
yield break;
}

yield return message;
}
}
}
yield return message;
}
}
}
8 changes: 8 additions & 0 deletions source/DuplicateFinder.Core/DuplicateFinder.Core.csproj
Expand Up @@ -43,8 +43,15 @@
<Reference Include="Machine.Specifications">
<HintPath>..\..\packages\Machine.Specifications.0.5.2.0\lib\Machine.Specifications.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAPICodePack.Shell">
<HintPath>..\..\lib\WindowsAPICodePack.1.1\Microsoft.WindowsAPICodePack.Shell.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\SolutionInfo.cs">
Expand Down Expand Up @@ -110,6 +117,7 @@
<DependentUpon>DatabaseHistory.cs</DependentUpon>
</Compile>
<Compile Include="HashCodeHistory\IRememberHashCodes.cs" />
<Compile Include="IDisplayProgress.cs" />
<Compile Include="ISelectFilesToDelete.cs" />
<Compile Include="Deletion\WhatIfFileDeleter.cs" />
<Compile Include="HashCodeProviders\FileContentHashCodeProvider.cs" />
Expand Down

0 comments on commit bb6555c

Please sign in to comment.