/// <summary> /// Save data blocks /// </summary> /// <param name="vm">Export parameters</param> /// <param name="blocksToSave">Collection of data blocks to save</param> private static void SaveDataBlocks(ExportZ80ProgramViewModel vm, IEnumerable <byte[]> blocksToSave) { try { // --- Create directory var dirName = Path.GetDirectoryName(vm.Filename); if (dirName != null && !Directory.Exists(dirName)) { Directory.CreateDirectory(dirName); } // --- Save data blocks if (vm.Format == ExportFormat.Tzx) { using (var writer = new BinaryWriter(File.Create(vm.Filename))) { var header = new TzxHeader(); header.WriteTo(writer); foreach (var block in blocksToSave) { var tzxBlock = new TzxStandardSpeedDataBlock { Data = block, DataLength = (ushort)block.Length }; tzxBlock.WriteTo(writer); } } } else { using (var writer = new BinaryWriter(File.Create(vm.Filename))) { foreach (var block in blocksToSave) { writer.Write((ushort)block.Length); writer.Write(block); } } } } catch (Exception ex) { VsxDialogs.Show($"An error has been raised while exporting a program: {ex.Message}", "Errorr when exporting file"); } }
/// <summary> /// Save data blocks /// </summary> /// <param name="vm">Export parameters</param> /// <param name="blocksToSave">Collection of data blocks to save</param> private static void SaveDataBlocks(ExportZ80ProgramViewModel vm, IEnumerable <byte[]> blocksToSave) { // --- Create directory var dirName = Path.GetDirectoryName(vm.Filename); if (dirName != null && !Directory.Exists(dirName)) { Directory.CreateDirectory(dirName); } // --- Save data blocks if (vm.Format == ExportFormat.Tzx) { using (var writer = new BinaryWriter(File.Create(vm.Filename))) { var header = new TzxHeader(); header.WriteTo(writer); foreach (var block in blocksToSave) { var tzxBlock = new TzxStandardSpeedDataBlock { Data = block, DataLength = (ushort)block.Length }; tzxBlock.WriteTo(writer); } } } else { using (var writer = new BinaryWriter(File.Create(vm.Filename))) { foreach (var block in blocksToSave) { writer.Write((ushort)block.Length); writer.Write(block); } } } }