private DragonDosFile ReadLocalFile(string localFilename, IEnumerator <string> ai)
        {
            if (localFilename.EndsWith(".CAS", StringComparison.InvariantCultureIgnoreCase))
            {
                return(ReadLocalCasFile(localFilename, ai));
            }
            else
            {
                var           data = File.ReadAllBytes(localFilename);
                DragonDosFile file = null;
                switch (filetype)
                {
                case FileType.Data:
                    file = DragonDosFile.CreateDataFile(data);
                    break;

                case FileType.Basic:
                    file = DragonDosFile.CreateBasicFile(data);
                    break;

                case FileType.Native:
                    file = DragonDosFile.CreateMachineCodeFile(data, LoadAddress, StartAddress);
                    break;

                default:
                    throw new Exception("Invalid file type specified");
                }
                return(file);
            }
        }
        /// <summary>
        /// Read a file from a virtual Dragon cassette and return the corresponding DragonDosFile
        /// object.
        /// </summary>
        /// <param name="tapeFilename">Name of the virtual Dragon tape.</param>
        /// <param name="ai">Additional parameters: Filename</param>
        /// <returns></returns>
        private DragonDosFile ReadLocalCasFile(string tapeFilename, IEnumerator <string> ai)
        {
            var filename = ai.MoveNext() ? ai.Current : null;

            using (var tape = new DragonTape(new CasTape(new FileStream(tapeFilename, FileMode.Open))))
            {
                var file = (DragonFile)tape.ReadFile(filename);
                switch (file.FileType)
                {
                case DragonFileType.Basic:
                    return(DragonDosFile.CreateBasicFile(file.GetData()));

                case DragonFileType.MachineCode:
                    return(DragonDosFile.CreateMachineCodeFile(file.GetData(), file.LoadAddress, file.StartAddress));

                case DragonFileType.Data:
                    return(DragonDosFile.CreateDataFile(file.GetData()));

                default:
                    throw new InvalidFileTypeException();
                }
            }
        }