public CollectionManager(IHashCheck hashChecker, IHashInfoHandler hashInfoHandler, ILogger logger)
 {
     _hashChecker     = hashChecker;
     _hashInfoHandler = hashInfoHandler;
     _logger          = logger;
 }
Example #2
0
        public static async Task <bool> ValidateAsync(this FolderItem folderItem, IHashCheck hashChecker, IHashInfoHandler hashInfoHandler, ILogger logger = null)
        {
            var sfvFiles      = folderItem.Search("*.sfv", true);
            var validityCheck = true;

            foreach (var sfvFile in sfvFiles)
            {
                var parentFolder = sfvFile.Parent;

                if (!hashInfoHandler.ValidateFile(sfvFile.FullPath))
                {
                    logger?.LogWarning($"SFV file in {sfvFile.FullPath} is invalid! Skipping....");
                    continue;
                }

                var sfvInfo = hashInfoHandler.Parse(sfvFile.FullPath);
                foreach (var sfvFileInfo in sfvInfo.Keys)
                {
                    var properpath = Path.Combine(sfvFile.Parent.FullPath, sfvFileInfo);

                    if (!await hashChecker.ValidateAsync(properpath, sfvInfo[sfvFileInfo]))
                    {
                        logger?.LogWarning($@"File {sfvFileInfo} has invalid CRC according to sfv file {sfvFile.FullPath}.
Expected CRC: {sfvInfo[sfvFileInfo]} | Calculated CRC: {await hashChecker.GetHashAsync(sfvFileInfo)}");
                        validityCheck = false;
                    }
                }
            }

            return(validityCheck);
        }