/// <summary>
 /// Write a DragonDos file to a plain data file in the local file system.
 /// </summary>
 /// <param name="file">DragonDos file.</param>
 /// <param name="localFilename">Local filename.</param>
 private void SaveToPlainFile(DragonDosFile file, string localFilename)
 {
     if (file.FileType == DragonDosFileType.Basic && ascii)
     {
         var basicTokenizer = new DragonBasicTokenizer(DragonBasicDialect.DragonDos);
         var basicText = basicTokenizer.Decode(file.GetData());
         var output = new StreamWriter(new FileStream(localFilename, FileMode.Create), Encoding.ASCII);
         output.Write(basicText);
         output.Close();
     }
     else
     {
         File.WriteAllBytes(localFilename, file.GetData());
     }
 }
        /// <summary>
        /// Write a DragonDos file to a Dragon virtual tape in the CAS format.  If the CAS file already exists, write the
        /// file to the end of the virtual tape.
        /// </summary>
        /// <param name="file">DragonDos file.</param>
        /// <param name="tapeFilename">Name of the CAS file.</param>
        /// <param name="ai">Additional arguments: Optional name of file within virtual tape container.</param>
        private void SaveToCasFile(DragonDosFile file, string tapeFilename, IEnumerator<string> ai)
        {
            var localFilename = ai.MoveNext() ? ai.Current : file.FileInfo.Name;

            IFile dragonFile;
            switch (file.FileType)
            {
                case DragonDosFileType.MachineCode:
                    dragonFile = DragonFile.CreateMachineCodeFile(localFilename, file.GetData(), file.LoadAddress, file.StartAddress, false, false);
                    break;
                case DragonDosFileType.Basic:
                    if (ascii)
                    {
                        var basicTokenizer = new DragonBasicTokenizer(DragonBasicDialect.DragonDos);
                        var basicText = basicTokenizer.DecodeToBytes(file.GetData());
                        dragonFile = DragonFile.CreateBasicFile(localFilename, basicText, true, true);
                    }
                    else
                        dragonFile = DragonFile.CreateBasicFile(localFilename, file.GetData(), false, false);
                    break;
                default:
                    dragonFile = DragonFile.CreateDataFile(localFilename, file.GetData(), false, false);
                    break;
            }

            using (var tape = new DragonTape(new CasTape(new FileStream(tapeFilename, FileMode.Append))))
            {
                tape.WriteFile(dragonFile);
            }
        }