private static void PatchBinarc(Context context, AssetFile assetFile, Stream stream) { var binarc = Bar.IsValid(stream) ? Bar.Read(stream) : new Bar() { Motionset = assetFile.MotionsetType }; foreach (var file in assetFile.Source) { if (!Enum.TryParse <Bar.EntryType>(file.Type, true, out var barEntryType)) { throw new Exception($"BinArc type {file.Type} not recognized"); } var entry = binarc.FirstOrDefault(x => x.Name == file.Name && x.Type == barEntryType); if (entry == null) { entry = new Bar.Entry { Name = file.Name, Type = barEntryType, Stream = new MemoryStream() }; binarc.Add(entry); } PatchFile(context, file, entry.Stream); } Bar.Write(stream.SetPosition(0), binarc); foreach (var entry in binarc) { entry.Stream?.Dispose(); } }
private static void CopyFile(Context context, AssetFile assetFile, Stream stream) { if (assetFile.Source == null || assetFile.Source.Count == 0) { throw new Exception($"File '{assetFile.Name}' does not contain any source"); } string srcFile; if (assetFile.Source[0].Type == "internal") { srcFile = context.GetOriginalAssetPath(assetFile.Source[0].Name); } else { srcFile = context.GetSourceModAssetPath(assetFile.Source[0].Name); if (!File.Exists(srcFile)) { throw new FileNotFoundException($"The mod does not contain the file {assetFile.Source[0].Name}", srcFile); } } using var srcStream = File.OpenRead(srcFile); srcStream.CopyTo(stream); }