public static void Do() { var filePatcher = new FilePatcher(@"g:\temp\coda\resources.assets", @"g:\temp\coda\18_diff\Client_Data\resources.assets", @"g:\temp\coda\resources.assets.18"); filePatcher.Patch(); }
public WingmanPatchServiceBuilder(ISourceFileService sourceFileService, FilePatcher filePatcher, AssetPatcher assetPatcher, DirectoryBuildContextFactory contextFactory, IModBuilder modBuilder, ILogger <ModPatchService <WingmanMod> > logger) { _fileService = sourceFileService; _filePatcher = filePatcher; _assetPatcher = assetPatcher; _ctxFactory = contextFactory; _modBuilder = modBuilder; _tgtLogger = logger; }
private FilePatcher Patch(string patchPath) { var patcher = FilePatcher.FromPatchFile(patchPath); patcher.Patch(mode); results.Add(patcher); CreateParentDirectory(patcher.PatchedPath); patcher.Save(); int exact = 0, offset = 0; foreach (var result in patcher.results) { if (!result.success) { failures++; continue; } if (result.mode == Patcher.Mode.FUZZY || result.offsetWarning) { warnings++; } if (result.mode == Patcher.Mode.EXACT) { exact++; } else if (result.mode == Patcher.Mode.OFFSET) { offset++; } else if (result.mode == Patcher.Mode.FUZZY) { fuzzy++; } } var log = new StringBuilder(); log.AppendLine($"{patcher.patchFile.basePath},\texact: {exact},\toffset: {offset},\tfuzzy: {fuzzy},\tfailed: {failures}"); foreach (var res in patcher.results) { log.AppendLine(res.Summary()); } Log(log.ToString()); return(patcher); }
public FilePatcherViewModel(FilePatcher filePatcher, string commonBasePath) { fp = filePatcher; var label = fp.patchFile.basePath; if (commonBasePath != null && label.StartsWith(commonBasePath)) { label = label.Substring(commonBasePath.Length); } Label = label; Children = (ListCollectionView)CollectionViewSource.GetDefaultView(_results); Children.SortDescriptions.Add(new SortDescription { PropertyName = nameof(ResultViewModel.Start1), Direction = ListSortDirection.Ascending }); Children.IsLiveSorting = true; ((INotifyCollectionChanged)Children).CollectionChanged += ResultsMoved; UpdateResults(); }
private void PatchFile(string fileName, string packageDirPath) { string filePath = _localData.Path.PathCombine(fileName); if (!File.Exists(filePath)) { throw new InstallerException(string.Format("Couldn't patch file <{0}> - file doesn't exists.", fileName)); } if (!_localMetaData.IsEntryRegistered(fileName)) { throw new InstallerException(string.Format("Couldn't patch file <{0}> - file is not registered in meta data.", fileName)); } int fileVersion = _localMetaData.GetEntryVersionId(fileName); if (fileVersion != _versionId - 1) { throw new InstallerException(string.Format( "Couldn't patch file <{0}> - expected file with previous version ({1}) but the file version is {2}.", fileName, _versionId - 1, fileVersion)); } string newFilePath = _temporaryData.GetUniquePath(); try { var filePatcher = new FilePatcher(filePath, Path.Combine(packageDirPath, fileName), newFilePath); filePatcher.Patch(); FileOperations.Copy(newFilePath, filePath, true); } finally { if (File.Exists(newFilePath)) { FileOperations.Delete(newFilePath); } } }
public FilePatcherViewModel(FilePatcher filePatcher, string commonBasePath) { fp = filePatcher; rejectsFilePath = Path.ChangeExtension(fp.patchFilePath, "rej"); rejectsFile = File.Exists(rejectsFilePath) ? PatchFile.FromText(File.ReadAllText(rejectsFilePath), verifyHeaders: false) : new PatchFile(); var label = fp.patchFile.basePath; if (commonBasePath != null && label.StartsWith(commonBasePath)) { label = label.Substring(commonBasePath.Length); } Label = label; Children = (ListCollectionView)CollectionViewSource.GetDefaultView(_results); Children.SortDescriptions.Add(new SortDescription { PropertyName = nameof(ResultViewModel.Start1), Direction = ListSortDirection.Ascending }); Children.IsLiveSorting = true; ((INotifyCollectionChanged)Children).CollectionChanged += ResultsMoved; UpdateResults(); }
private void PatchFile( string fileName, string packageDirPath, string suffix, TemporaryDirectory tempDiffDir, CancellationToken cancellationToken) { _logger.LogDebug(string.Format("Processing patch file entry {0}", fileName)); var filePath = _localData.Path.PathCombine(fileName); _logger.LogTrace("filePath = " + filePath); if (!File.Exists(filePath)) { throw new MissingLocalDataFileException( string.Format("Couldn't patch file {0} because it doesn't exists in local data.", fileName)); } var fileVersion = _localMetaData.GetEntryVersionId(fileName); _logger.LogTrace("fileVersion = " + fileVersion); if (fileVersion != _versionId - 1) { throw new InvalidLocalDataFileVersionException(string.Format( "Couldn't patch file {0} because expected file version to be ({1}) but it's {2}.", fileName, _versionId - 1, fileVersion)); } _logger.LogDebug("Checking whether patching file content is necessary..."); if (IsPatchingFileContentNecessary(fileName)) { _logger.LogDebug("Patching is necessary. Generating new file with patched content..."); var sourceDeltaFilePath = Path.Combine(packageDirPath, fileName + suffix); _logger.LogTrace("sourceDeltaFilePath = " + sourceDeltaFilePath); if (!File.Exists(sourceDeltaFilePath)) { throw new MissingFileFromPackageException(string.Format("Cannot find delta file {0} in diff package.", fileName)); } var newFilePath = tempDiffDir.GetUniquePath(); _logger.LogTrace("newFilePath = " + newFilePath); var filePatcher = new FilePatcher(filePath, sourceDeltaFilePath, newFilePath); filePatcher.Patch(); _logger.LogDebug("New file generated. Deleting old file in local data..."); FileOperations.Delete(filePath, cancellationToken); _logger.LogDebug("Old file deleted. Moving new file to local data..."); FileOperations.Move(newFilePath, filePath, cancellationToken); _logger.LogDebug("New file moved."); } else { _logger.LogDebug("Patching is not necessary. File content is the same as in previous version."); } _localMetaData.RegisterEntry(fileName, _versionId); _logger.LogDebug("Patch file entry processed."); }
public void SetUp() { lines = ResourceHelper.TestUST(); patcher = new FilePatcher(); }