private void ProcessFile(PatchDefinition definition, PatchDefinitionEntry entry) { switch (entry.Operation) { case PatchOperation.Added: _context.LogProgress(string.Format(_context.LocalizedMessages.UpdateProcessingNewFile, entry.RelativePath)); HandleAddedFile(definition, entry); _context.ReportProgress(string.Format(_context.LocalizedMessages.UpdateProcessedNewFile, entry.RelativePath)); break; case PatchOperation.Deleted: _context.LogProgress(string.Format(_context.LocalizedMessages.UpdateProcessingDeletedFile, entry.RelativePath)); HandleDeletedFile(definition, entry); _context.ReportProgress(string.Format(_context.LocalizedMessages.UpdateProcessedDeletedFile, entry.RelativePath)); break; case PatchOperation.Updated: _context.LogProgress(string.Format(_context.LocalizedMessages.UpdateProcessingUpdatedFile, entry.RelativePath)); HandleUpdatedFile(definition, entry); _context.ReportProgress(string.Format(_context.LocalizedMessages.UpdateProcessedUpdatedFile, entry.RelativePath)); break; case PatchOperation.ChangedAttributes: _context.LogProgress(string.Format(_context.LocalizedMessages.UpdateProcessingChangedAttributesFile, entry.RelativePath)); HandleChangedAttributesFile(definition, entry); _context.ReportProgress(string.Format(_context.LocalizedMessages.UpdateProcessedChangedAttributesFile, entry.RelativePath)); break; } }
private void HandleChangedAttributesFile(PatchDefinitionEntry entry) { var path = PathsManager.Combine(_context.Settings.GetGameFolderPath(_context.VersionTo), entry.RelativePath); var info = FilesManager.GetFileInfo(path); entry.Attributes = info.Attributes; entry.LastWriting = info.LastWriting; }
private void HandleAddedFile(PatchDefinition definition, PatchDefinitionEntry entry) { var sourcePath = PathsManager.Combine(_context.Settings.GetUncompressedPatchArchivePath(definition.From, definition.To), entry.RelativePath); var destinationPath = PathsManager.Combine(_context.Settings.GetGamePath(), entry.RelativePath); FilesManager.Delete(destinationPath); FilesManager.Move(sourcePath, destinationPath); EnsureDefinition(destinationPath, entry); }
private void HandleUpdatedFile(PatchDefinitionEntry entry) { var fromFile = PathsManager.Combine(_context.Settings.GetGameFolderPath(_context.VersionFrom), entry.RelativePath); var toFile = PathsManager.Combine(_context.Settings.GetGameFolderPath(_context.VersionTo), entry.RelativePath); var patchFile = PathsManager.Combine(_context.Settings.GetPatchesTempFolderPath(), entry.RelativePath + ".patch"); var signatureFile = PathsManager.Combine(_context.Settings.GetPatchesTempFolderPath(), entry.RelativePath + ".signature"); DirectoriesManager.Create(PathsManager.GetDirectoryPath(patchFile)); DeltaFileBuilder.Build(fromFile, toFile, patchFile, signatureFile); var path = PathsManager.Combine(_context.Settings.GetGameFolderPath(_context.VersionTo), entry.RelativePath); var info = FilesManager.GetFileInfo(path); entry.Attributes = info.Attributes; entry.LastWriting = info.LastWriting; }
private void HandleUpdatedFile(PatchDefinition definition, PatchDefinitionEntry entry) { var filePath = PathsManager.Combine(_context.Settings.GetGamePath(), entry.RelativePath); var fileBackupPath = filePath + ".bak"; var patchPath = PathsManager.Combine(_context.Settings.GetUncompressedPatchArchivePath(definition.From, definition.To), entry.RelativePath + ".patch"); try { FilesManager.Rename(filePath, fileBackupPath); DeltaFileApplier.Apply(fileBackupPath, patchPath, filePath); EnsureDefinition(filePath, entry); } catch { } finally { FilesManager.Delete(fileBackupPath); } }
private void EnsureDefinition(string filePath, PatchDefinitionEntry entry) { File.SetAttributes(filePath, entry.Attributes); File.SetLastWriteTimeUtc(filePath, entry.LastWriting); }
private void HandleChangedAttributesFile(PatchDefinition definition, PatchDefinitionEntry entry) { var path = PathsManager.Combine(_context.Settings.GetGamePath(), entry.RelativePath); EnsureDefinition(path, entry); }
private void HandleDeletedFile(PatchDefinition definition, PatchDefinitionEntry entry) { var path = PathsManager.Combine(_context.Settings.GetGamePath(), entry.RelativePath); FilesManager.Delete(path); }