Exemplo n.º 1
0
        /// <summary>
        /// Create empty DragonDos filesystem.
        /// </summary>
        /// <param name="args">Command arguments: &lt;disk image name&gt; [&lt;tracks&gt; [&lt;sectors&gt;]].</param>
        private void CreateFilesystem(IEnumerable <string> args)
        {
            int tracks  = DefaultTracks;
            int sectors = DefaultSectors;

            var ai = args.GetEnumerator();

            if (!ai.MoveNext())
            {
                Console.Error.WriteLine("ERROR: Disk image name missing.");
                return;
            }
            var diskname = ai.Current;

            if (ai.MoveNext())
            {
                tracks = Convert.ToInt32(ai.Current);
                if (tracks != 40 && tracks != 80)
                {
                    Console.Error.WriteLine("ERROR: DragonDos only supports 40 and 80 track diskettes.");
                    return;
                }
            }

            if (ai.MoveNext())
            {
                sectors = Convert.ToInt32(ai.Current);
                if (sectors != 18 && sectors != 36)
                {
                    Console.Error.WriteLine("ERROR: DragonDos only supports 18 or 36 sectors per track.");
                    return;
                }
            }

            int heads = sectors / 18;

            sectors -= (heads - 1) * 18;

            if (File.Exists(diskname))
            {
                Console.Error.WriteLine("ERROR: Target file {0} already exists.", diskname);
                return;
            }

            using (var disk = DiskFactory.CreateDisk(diskname, heads, tracks, sectors, DefaultSectorSize))
            {
                using (var dos = DragonDos.Initialize(disk))
                {
                    Console.WriteLine("Created empty filesystem in {0}. Capacity {1} bytes.", diskname, dos.Free());
                }
            }
        }
Exemplo n.º 2
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;
            }
        }