/// <summary> /// Takes the scanned files and adds them to the <see cref="Duplicates"/> collection. /// The ScannedFiles will be sorted by Hash before being added to the ViewModel. /// Internally exposed for unit testing. /// It is assumed that <paramref name="scannedFiles"/> is sorted by Hash before calling. /// </summary> /// <param name="scannedFiles">The scanned files to add</param> internal void AddScannedFiles(List <ScannedFile> scannedFiles) { byte[] previousHash = null; BackgroundColor color = BackgroundColor.Transparent; ScannedFileHashComparer comparer = new ScannedFileHashComparer(); foreach (ScannedFile scannedFile in scannedFiles) { // If the hash is not same as the previous hash flip the same color if (previousHash != null && !comparer.Equals(previousHash, scannedFile.Hash)) { // If there are ever more than two BackgroundColor types, this flipping logic // will need to be revisited. color = 1 - color; } ScanResult scanResult = new ScanResult() { FilePath = scannedFile.Path, Hash = scannedFile.Hash, Background = color.ToString(), IsSelected = false }; Duplicates.Add(scanResult); previousHash = scannedFile.Hash; } }
public Duplicates FindDuplicatesMetod() { Duplicates globalDuplicates = new Duplicates(); if (MetodsClass.DirExists(PathFromUser)) { string[] AllFiles = MetodsClass.GetAllFiles(PathFromUser); List <FileClass> ListAllFilesAsClass = MetodsClass.ParseStringToClass(AllFiles.ToList()); List <List <FileClass> > ListGlobalDuplicates = MetodsClass.FindDuplicates(ListAllFilesAsClass); foreach (List <FileClass> y in ListGlobalDuplicates) { globalDuplicates.Add(ConvertToObservable(y)); } } else { MessageBox.Show("Can't find such path"); } return(globalDuplicates); }
public void Add(Item item) { // Dupe-check list bool stacked = item.StackCount > 1 || _cache.StackableRecords.Contains(item.BaseRecord) || _cache.SpecialRecords.Contains(item.BaseRecord); // Special "single seed" items. if (stacked) { Stacked.Add(item); All.Add(item); return; } // TODO: Detect slith rings etc // We don't have this record at all, unknown to IA. Probably need to parse DB. bool unknownItem = !_cache.AllRecords.Contains(item.BaseRecord); if (unknownItem) { if (item.BaseRecord.StartsWith("records/storyelements/rewards/")) { Quest.Add(item); } else { Unknown.Add(item); } All.Add(item); return; } // We already have this item.. if (All.Any(m => m.Equals(item))) { Duplicates.Add(item); All.Add(item); return; } // We already have this item.. if (_playerItemDao.Exists(TransferStashService.Map(item, null, false))) { Duplicates.Add(item); All.Add(item); return; } Remaining.Add(item); All.Add(item); }
public void AddDuplicate(Duplicate dup) { if (dup.Location == PhysicalPath) { Duplicates.Add(dup); } else { Journal.Info($"{dup.Location} does not match instance {Name}"); } }
/// <summary> /// look for xstr in each file /// </summary> private void FetchXstr() { List <string> compatibleFiles = FilesList.Where(x => !x.Contains("-lcl.tbm") && !x.Contains("-tlc.tbm") && !x.Contains("strings.tbl")).ToList(); foreach (string file in compatibleFiles) { FileInfo fileInfo = new(file); string fileContent = File.ReadAllText(file); IEnumerable <Match> combinedResults = Utils.GetAllXstrFromFile(fileInfo, fileContent); foreach (Match match in combinedResults) { //match.Groups[0] => entire line //match.Groups[1] => text //match.Groups[2] => id if (int.TryParse(match.Groups[2].Value, out int id)) { string text = match.Groups[1].Value; // if id not existing, add a new line if (id >= 0 && !Lines.Any(x => x.Id == id)) { Lines.Add(new Xstr(id, text, fileInfo)); } // if id already existing but value is different, then put it in another list that will be treated separately else if (ManageDuplicates && (id < 0 || Lines.First(x => x.Id == id).Text != text)) { Duplicates.Add(new Xstr(id, text, fileInfo, match.Value)); } } else { throw new Exception(); } } } int maxProgress = Lines.Count + (ManageDuplicates ? FilesList.Count + Duplicates.Count : 0); Parent.SetMaxProgress(maxProgress); }
public bool CheckForDuplicates() { if (m_state != Upload506MasterState.ReadyForCheckDuplicates) { return(false); } Duplicates.Clear(); using (var manager = DbManagerFactory.Factory.Create(EidssUserContext.Instance)) { foreach (var upload506Item in Items) { var updateItem = Upload506Duplicate.Accessor.Instance(null).SelectByItem(manager, upload506Item); if (updateItem != null) { Duplicates.Add(updateItem); } else { upload506Item.Resolution = (int)Upload506Resolution.Created; } } } if (Duplicates.Count > 0) { SetState(Upload506MasterState.HasDuplicates); return(false); } SetState(Upload506MasterState.ReadyForSave); return(true); }
private void HandleImport() { OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "Import duplicates from file"; var res = dlg.ShowDialog(); if (res == DialogResult.OK) { using (var c = new CursorHelper(this)) { using (Stream reader = new FileStream(dlg.FileName, FileMode.Open)) { XmlSerializer mySerializer = new XmlSerializer(typeof(ObservableCollection <SingleFileEntry>)); var items = (ObservableCollection <SingleFileEntry>)mySerializer.Deserialize(reader); Duplicates.Clear(); foreach (var i in items) { Duplicates.Add(i); } } } } }
private void DoWorkEvent(object sender, DoWorkEventArgs e) { CanExecuteCancel = true; IsIdle = false; using (var c = new CursorHelper(this)) { var res = queryService.QueryDuplicates(bgw, e, startPath, string.IsNullOrEmpty(filter) ? "*.*" : filter); System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { res.ForEach(x => Duplicates.Add(x)); })); } ProgressPercent = 0; CanExecuteCancel = false; IsIdle = true; }