コード例 #1
0
        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);
            }
        }
コード例 #2
0
        /// <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();
                }
            }
        }
コード例 #3
0
        private void Run(string[] args)
        {
            try
            {
                var files = ParseOptions(args);
                if (files.Count == 0)
                {
                    ShowUsage();
                    return;
                }

                var diskFileName = files[0] + ".vdk";
                if (Verbose)
                {
                    Console.WriteLine("Writing output VDK disk image \"{0}\".", diskFileName);
                }

                using (var dos = DragonDos.Initialize(DiskFactory.CreateDisk(diskFileName, DiskHeads, DiskTracks, DiskSectors, DiskSectorSize)))
                {
                    foreach (var file in files)
                    {
                        if (Verbose)
                        {
                            Console.WriteLine("Writing file \"{0}\" to disk image.", file);
                        }
                        dos.WriteFile(Path.GetFileName(file).ToUpper(), DragonDosFile.CreateDataFile(IOUtils.ReadStreamFully(new FileStream(file, FileMode.Open))));
                    }
                }
            }
            catch (DirectoryFullException e)
            {
                Console.Error.WriteLine("ERROR: Cannot write file to filesystem.  The directory is full.");
                if (Debug)
                {
                    Console.Error.WriteLine(e);
                }
                return;
            }
            catch (FileExistsException e)
            {
                Console.Error.WriteLine("ERROR: Cannot write the file as a file with the same name already exists.");
                if (Debug)
                {
                    Console.Error.WriteLine(e);
                }
                return;
            }
            catch (FilesystemFullException e)
            {
                Console.Error.WriteLine("ERROR: Cannot write file as the filesystem is full.");
                if (Debug)
                {
                    Console.Error.WriteLine(e);
                }
                return;
            }
            catch (InvalidFilenameException e)
            {
                Console.Error.WriteLine("ERROR: The filename {0} is invalid.", e.Filename);
                if (Debug)
                {
                    Console.Error.WriteLine(e);
                }
                return;
            }
            catch (System.IO.IOException e)
            {
                Console.Error.WriteLine("ERROR: Local filesystem I/O error.");
                if (Debug)
                {
                    Console.Error.WriteLine(e);
                }
                return;
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("ERROR: Unexpected error.");
                if (Debug)
                {
                    Console.Error.WriteLine(e);
                }
                return;
            }
        }