예제 #1
0
        private async Task <List <HashPair> > ComputeHashes(string source)
        {
            var hashes = new List <HashPair>();

            source = source.Replace("\"", "").Replace("\'", "");

            if (File.Exists(source))
            {
                hashes.Add(await _hashGenerator.FromFileAsync(source));
            }
            else if (Directory.Exists(source))
            {
                hashes.AddRange(await _hashGenerator.FromDirectoryAsync(source));
            }
            else if (source.Contains("*") || source.Contains("?"))
            {
                if (source.Contains(Path.DirectorySeparatorChar))
                {
                    var dir     = Path.GetDirectoryName(source);
                    var pattern = source
                                  .Replace(dir, string.Empty)
                                  .Replace(Path.DirectorySeparatorChar.ToString(), string.Empty);
                    hashes.AddRange(await _hashGenerator.FromDirectoryAsync(dir, pattern));
                }
                else
                {
                    hashes.AddRange(await _hashGenerator.FromDirectoryAsync(Directory.GetCurrentDirectory(), source));
                }
            }
            else
            {
                _console.WriteLine("Source not found");
                Environment.Exit(-1);
            }
            return(hashes);
        }