示例#1
0
文件: Program.cs 项目: pedrokj/0x10c
        static void MainTest(string[] args)
        {
            {
                var disk = new Disk();
                "Hello, World!".PackInto(disk.Words, 0);
                disk.WriteTo("hello.disk.txt");
                disk.WriteTo("hello.disk.bin", raw: true);
            }

            int __break = 1;

            {
                var disk = new Disk("hello.disk.txt");
                var msg  = disk.Words.UnpackString(0);
                Console.WriteLine("Message: \"{0}\"", msg);
            }

            {
                var disk = new Disk();
                disk.ReadFrom("hello.disk.bin", raw: true);
                var msg = disk.Words.UnpackString(0);
                Console.WriteLine("Message: \"{0}\"", msg);
            }

            {
                var fs = new Ssfs();

                fs.Format(BinaryImage.ReadImage("boot/bootload.bin"));
                fs.AddFile("kernel.sys", BinaryImage.ReadImage("boot/kernel.sys"));
                fs.AddFile("hmd2043.drv", BinaryImage.ReadImage("boot/hmd2043.drv"));
                fs.AddFile("ssfs.drv", BinaryImage.ReadImage("boot/ssfs.drv"));
                fs.AddFile("shell.sys", BinaryImage.ReadImage("boot/shell.sys"));
                fs.AddFile("shell.ro", BinaryImage.ReadImage("boot/shell.ro"));

                fs.WriteTo("boot.disk.txt");
                fs.WriteTo("boot.disk.bin", raw: true);
            }

            {
                var fs = new Ssfs("boot.disk.txt");
                Console.WriteLine("List of files in boot.disk.txt:");
                foreach (var file in fs.IterFiles())
                {
                    Console.WriteLine(" {0}", file.Path);
                }
            }
        }
示例#2
0
        private void readFromStream(Stream s)
        {
            var headers = new Dictionary <string, string>();

            ushort[] disk;

            disk = BinaryImage.ReadImage(s, headers);

            if (disk.Length != 1440 * 512)
            {
                throw new InvalidDataException("disk image not expected size");
            }

            _words    = disk;
            _readOnly = false;

            foreach (var kv in headers)
            {
                switch (kv.Key)
                {
                case "type":
                    if (kv.Value.ToLower() != "floppy")
                    {
                        throw new InvalidDataException("disk is not a floppy");
                    }
                    break;

                case "access":
                    switch (kv.Value.ToLower())
                    {
                    case "read-write":
                        _readOnly = false;
                        break;

                    case "read-only":
                        _readOnly = true;
                        break;
                    }
                    break;
                }
            }
        }
示例#3
0
文件: Program.cs 项目: pedrokj/0x10c
        static void CreateCmd(IEnumerable <string> args)
        {
            Access access     = Access.ReadWrite;
            string bootloader = "";
            //ByteOrder byteOrder = ByteOrder.BigEndian;
            //Compression compression = Compression.Zlib;
            //var encoding = Dk.x10c.Encoding.Base64;
            List <string> priorityList = new List <string>();
            bool          raw          = false;
            bool          help         = false;

            string disk = null,
                   root = null;

            var opt = new OptionSet()
            {
                { "a|access=", "the {ACCESS} permissions on the disk.",
                  (Access a) => access = a },
                { "b|bootloader=", "the {FILE} to use as a boot loader.",
                  a => bootloader = a },

                /*{"byte-order=", "{ENDIANNESS} of raw output.",
                 *  (ByteOrder a) => byteOrder = a},*/
                /*{"c|compression=", "{COMPRESSION} type to use.",
                 *  (Compression a) => compression = a},*/
                /*{"e|encoding=", "{ENCODING} type to use.",
                 *  (Dk.x10c.Encoding a) => encoding = a},*/
                { "p|priority-list=", "{FILE} containing list of files to add to filesystem first.",
                  a => UpdatePriorityList(priorityList, a) },
                { "r|raw", "Output disk in raw big-endian.",
                  a => raw = (a != null) },
                { "help", "This message.",
                  a => help = (a != null) },
            };

            List <string> pargs = null;

            try
            {
                pargs = opt.Parse(args);
            }
            catch (OptionException e)
            {
                ShowCommandError("create", e.Message);
                return;
            }

            if (!help)
            {
                switch (pargs.Count)
                {
                case 1:
                    // ssfs create [OPTIONS] ROOT
                    root = pargs[0];
                    disk = Path.ChangeExtension(root, "disk");
                    break;

                case 2:
                    // ssfs create [OPTIONS] ROOT DISK
                    root = pargs[0];
                    disk = pargs[1];
                    break;

                default:
                    ShowCommandError("create", "invalid number of arguments");
                    return;
                }
            }

            if (help)
            {
                ShowCommandHelp("create [OPTIONS] ROOT [DISK]",
                                "Creates a new SSFS disk image using the files in directory ROOT.",
                                opt);
                return;
            }

            ushort[] blData = null;
            if (bootloader != "")
            {
                blData = BinaryImage.ReadImage(bootloader);
            }

            var fs = new Ssfs();

            fs.Format(blData);

            var prioritySet = new HashSet <string>(priorityList);

            foreach (var name in priorityList)
            {
                var path = Path.Combine(root, name);

                ushort[] data = null;
                //*
                try
                {
                    data = BinaryImage.ReadImage(path);
                }
                catch (BiefException e)
                {
                    Console.Error.Write("Error occured while reading file {0}: ", name);
                    Console.Error.WriteLine(e.Message);
                    Environment.Exit(1);
                }

                /*/
                 * data = BinaryImage.ReadImage(path);
                 * //*/

                try
                {
                    fs.AddFile(name, data);
                }
                catch (SsfsException e)
                {
                    Console.Error.Write("Error occurred while adding file {0}: ", name);
                    Console.Error.WriteLine(e.Message);
                    Environment.Exit(1);
                }
            }

            foreach (var name in from f in Directory.EnumerateFiles(root)
                     where !prioritySet.Contains(Path.GetFileName(f))
                     select Path.GetFileName(f))
            {
                var path = Path.Combine(root, name);

                ushort[] data = null;
                //*
                try
                {
                    data = BinaryImage.ReadImage(path);
                }
                catch (BiefException e)
                {
                    Console.Error.Write("Error occured while reading file {0}: ", name);
                    Console.Error.WriteLine(e.Message);
                    Environment.Exit(1);
                }

                /*/
                 * data = BinaryImage.ReadImage(path);
                 * //*/

                try
                {
                    fs.AddFile(name, data);
                }
                catch (SsfsException e)
                {
                    Console.Error.Write("Error occurred while adding file {0}: ", name);
                    Console.Error.WriteLine(e.Message);
                    Environment.Exit(1);
                }
            }

            fs.Disk.WriteTo(disk, raw);
        }