private async Task GenerateCleanedESM(CleanedESM directive) { var filename = directive.To.FileName; var gameFile = GameFolder !.Value.Combine((RelativePath)"Data", filename); Info($"Generating cleaned ESM for {filename}"); if (!gameFile.Exists) { throw new InvalidDataException($"Missing {filename} at {gameFile}"); } Status($"Hashing game version of {filename}"); var sha = await gameFile.FileHashAsync(); if (sha != directive.SourceESMHash) { throw new InvalidDataException( $"Cannot patch {filename} from the game folder because the hashes do not match. Have you already cleaned the file?"); } var patchData = await LoadBytesFromPath(directive.SourceDataID); var toFile = OutputFolder.Combine(directive.To); Status($"Patching {filename}"); using var output = toFile.Create(); using var input = gameFile.OpenRead(); Utils.ApplyPatch(input, () => new MemoryStream(patchData), output); }
private void GenerateCleanedESM(CleanedESM directive) { var filename = Path.GetFileName(directive.To); var gameFile = Path.Combine(GameFolder, "Data", filename); Info($"Generating cleaned ESM for {filename}"); if (!File.Exists(gameFile)) { throw new InvalidDataException($"Missing {filename} at {gameFile}"); } Status($"Hashing game version of {filename}"); var sha = gameFile.FileHash(); if (sha != directive.SourceESMHash) { throw new InvalidDataException( $"Cannot patch {filename} from the game folder because the hashes do not match. Have you already cleaned the file?"); } var patchData = LoadBytesFromPath(directive.SourceDataID); var toFile = Path.Combine(OutputFolder, directive.To); Status($"Patching {filename}"); using (var output = File.Open(toFile, FileMode.Create)) using (var input = File.OpenRead(gameFile)) { BSDiff.Apply(input, () => new MemoryStream(patchData), output); } }