/// <summary> /// Appends the TZX block to the tape file /// </summary> /// <param name="block"></param> public void SaveTapeBlock(ITapeDataSerialization block) { if (_dataBlockCount == 0) { if (!Directory.Exists(SaveFileFolder)) { Directory.CreateDirectory(SaveFileFolder); } var baseFileName = $"{_suggestedName ?? DEFAULT_NAME}_{DateTime.Now:yyyyMMdd_HHmmss}{DEFAULT_EXT}"; _fullFileName = Path.Combine(SaveFileFolder, baseFileName); using (var writer = new BinaryWriter(File.Create(_fullFileName))) { var header = new TzxHeader(); header.WriteTo(writer); } } _dataBlockCount++; var stream = File.Open(_fullFileName, FileMode.Append); using (var writer = new BinaryWriter(stream)) { block.WriteTo(writer); } }
/// <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); } } } }