Esempio n. 1
0
        public List <MatchingEntity> MatchBasic(Dictionary <string, FileEntryBase> source, Dictionary <string, FileEntryBase> target, MatchOptions options)
        {
            List <MatchingEntity> retValue = new List <MatchingEntity>();

            Parallel.ForEach(source, item =>
            {
                MatchingEntity entity = MatchBasic(item, target, options);
                if (entity != null)
                {
                    retValue.Add(entity);
                }
            });
            return(retValue);
        }
Esempio n. 2
0
 public MatchingEntity MatchBasic(KeyValuePair <string, FileEntryBase> source, Dictionary <string, FileEntryBase> target, MatchOptions options)
 {
     foreach (var targetItem in target)
     {
         MatchingEntity matched = new MatchingEntity()
         {
             SourceFilesCount = 1, TargetFilesCount = 1
         };
         if (targetItem.Value.Crc32.ToUpper() == source.Value.Crc32.ToUpper())
         {
             KeyValuePair <FileEntryBase, MatchLevel> entry = MatchFileEntry(source.Value, targetItem.Value, options);
             matched.PercentageMatch = 100;
             matched.SourceTarget    = new Tuple <string, string>(source.Key, targetItem.Key);
             //matched.MatchedFiles.Add(entry.Key, entry.Value);
             matched.MatchedFiles.Add(entry.Key);
             return(matched);
         }
     }
     return(null);
 }
Esempio n. 3
0
        public MatchingEntity MatchBasicZip(KeyValuePair <string, List <FileEntryBase> > source, Dictionary <string, List <FileEntryBase> > target, MatchOptions options, int minimumSize = 10)
        {
            Dictionary <MatchingEntity, decimal> MatchedGames = new Dictionary <MatchingEntity, decimal>();

            bool fileFound = false;

            //foreach (var targetItem in target)
            Parallel.ForEach(target, targetItem =>
            {
                MatchingEntity matched = new MatchingEntity()
                {
                    SourceTarget = new Tuple <string, string>(source.Key, targetItem.Key), SourceFilesCount = source.Value.Count, TargetFilesCount = targetItem.Value.Count
                };

                fileFound = false;
                foreach (var targetFile in targetItem.Value)//.Where(a => minimumSize == -1 || a.Size > minimumSize))
                //Parallel.ForEach(targetItem.Value, targetFile =>
                {
                    if (targetFile.Crc32 != "00000000")
                    {
                        foreach (var sourceFile in source.Value)//.Where(a => minimumSize == -1 || a.Size > minimumSize))
                        {
                            //if (sourceFile.IsIgnored)
                            //{
                            //    matched.IgnoredFiles.Add(sourceFile);
                            //    fileFound = true;
                            //    break;
                            //}
                            //else if ((targetFile.GetHashCode_CRC == sourceFile.GetHashCode_CRC && targetFile.GetHashCode_NameExtension == sourceFile.GetHashCode_NameExtension)
                            //    || targetFile.GetHashCode_NameExtension == sourceFile.GetHashCode_NameExtension)
                            //{
                            //    matched.MatchedFiles.Add(sourceFile);
                            //    fileFound = true;
                            //    break;
                            //}
                        }
                    }
                    if (!fileFound)
                    {
                        matched.ExpectedFiles.Add(targetFile);
                    }
                }
                //);
                if (matched.MatchedFiles.Count > 0)
                {
                    //matched.NonMatchedFiles = source.Value.Where(a => !matched.MatchedFiles.ContainsKey(a)).ToList();
                    matched.NonMatchedFiles = source.Value.Where(a => !matched.MatchedFiles.Contains(a)).ToList();
                    //This is the best way of matching the to the correct file that I could find. If there's a better way, change it :P
                    //I wanted to go with the Not Matched files counting to more than 100 but then it starts throwing off perfect matches so I would rather stick with not being 100% even though the zip has a lot of superfluous data e.g. nfo's etc.
                    //If it's got crap files in, remove it from the zip to get it to 100 :P
                    matched.PercentageMatch = (matched.MatchedFiles.Count == 0) ? 0 : Convert.ToDecimal(matched.MatchedFiles.Count) / Math.Max(matched.TargetFilesCount, matched.SourceFilesCount) * 100;
                    //if (matched.PercentageMatch > 30)
                    //{
                    lock (MatchedGames)
                    {
                        MatchedGames.Add(matched, matched.PercentageMatch);
                    }
                    //}
                }
            }
                             );
            return(MatchedGames.OrderByDescending(a => a.Value).FirstOrDefault().Key);
        }