private void DoAfter(ModFileToMerge modFileToMerge) { var modFile = modFileToMerge.Source; var match = ModNameParse.Parse(modFile); if (match?.Filename == null) { throw new InvalidDataException($"provided file path \"{modFile.Path}\" was not in en expected format - please contact the developer."); } var surroundings = GetMatchingFiles(match); var hasPrefix = match.HasPrefix; if (hasPrefix) { var prefix = match.Prefix; if (surroundings.Any(s => s.HasPrefix && s.Prefix == prefix + 1)) { var toModify = surroundings.Where(s => s.HasPrefix && s.Prefix <= prefix).OrderByDescending(s => s.Prefix); var modPrefix = prefix; foreach (var item in toModify) { if (modPrefix != item.Prefix) { break; } modPrefix--; item.Prefix = modPrefix; item.File.Path = item.Path; } } else { match.Prefix = prefix + 1; modFile.Path = match.Path; } } else { var dir = Path.GetDirectoryName(modFile.Path); var filename = Path.GetFileName(modFile.Path); var extension = Path.GetExtension(modFile.Path); var postfix = 0; string newPath; do { newPath = Path.Combine(dir, $"{filename}_{postfix++}{extension}"); } while (modFiles.Any(mf => string.CompareOrdinal(mf.Path, newPath) == 0)); modFile.Path = newPath; } Result.Files.Add(modFile); CurrentProcess.Remove(modFile); }
private void DoBefore(ModFileToMerge modFileToMerge) { var modFile = modFileToMerge.Source; var match = ModNameParse.Parse(modFile); if (match?.Filename == null) { throw new InvalidDataException($"provided file path \"{modFile.Path}\" was not in en expected format - please contact the developer."); } var surroundings = GetMatchingFiles(match); var hasPrefix = match.HasPrefix; if (hasPrefix) { var prefix = match.Prefix; if (prefix == 0 || surroundings.Any(s => s.HasPrefix && s.Prefix == prefix - 1)) { var toModify = surroundings.Where(s => s.HasPrefix && s.Prefix >= prefix).OrderBy(s => s.Prefix); var modPrefix = prefix; foreach (var item in toModify) { if (modPrefix != item.Prefix) { break; } modPrefix++; item.Prefix = modPrefix; item.File.Path = item.Path; } } else { match.Prefix = prefix - 1; modFile.Path = match.Path; } } else { int prefix = 0; if (surroundings.Any(s => s.HasPrefix)) { prefix = surroundings.Where(s => s.HasPrefix).Max(s => s.Prefix) + 1; } match.Prefix = prefix; modFile.Path = match.Path; } Result.Files.Add(modFile); CurrentProcess.Remove(modFile); }
public MergeProcess(MergedModFile fileToMerge) { file = fileToMerge; _result = new ModFileToMerge(file); _sourceFiles = new ObservableCollection <ModFileToMerge>(file.SourceFiles.Select(f => new ModFileToMerge(f))); _sourceFiles.Add(_result); _sourceFiles.CollectionChanged += SourceFilesCollectionChanged; LeftSelection = _sourceFiles.CreateDerivedCollection(f => f, f => f?.RawContents != null && f != Right); RightSelection = _sourceFiles.CreateDerivedCollection(f => f, f => f?.RawContents != null && f != Left); Left = LeftSelection.First(); Right = RightSelection.First(); PickLeft = ReactiveCommand.Create(DoPickLeft); PickRight = ReactiveCommand.Create(DoPickRight); SaveMerge = ReactiveCommand.Create(DoSaveMerge, _canSaveMerge); Reset = ReactiveCommand.Create(DoReset); }