コード例 #1
0
        public void ImageFileDisposeFlushes()
        {
            string filename = System.IO.Path.GetTempFileName();

            DiskImage disk = new DiskImage();

            Assert.AreEqual(true, disk.CreateImage(filename));
            disk.Format("Name", "1");
            IImageFile file = disk.Open("TEST", C64FileType.PRG, "wb");

            Assert.IsNotNull(file);

            byte[] data = Encoding.ASCII.GetBytes("This is some sample data!");
            Assert.AreEqual(data.Length, file.Write(data, data.Length));
            file.Dispose();
            disk.Dispose();

            DiskImage disk1 = new DiskImage();

            Assert.AreEqual(true, disk1.LoadImage(filename));
            IImageFile file1 = disk1.Open("TEST", C64FileType.PRG, "rb");

            Assert.IsNotNull(file1);
            byte[] data1 = new byte[100];
            Assert.AreEqual(25, file1.Read(data1, 100));
            byte[] trucatedData = new byte[25];
            Array.Copy(data1, trucatedData, 25);
            Assert.AreEqual("This is some sample data!", Encoding.ASCII.GetString(trucatedData));
            file1.Close();
            disk1.Dispose();

            System.IO.File.Delete(filename);
        }
コード例 #2
0
        public void CreateWriteLoadReadMultiTrackFile()
        {
            string filename = System.IO.Path.GetTempFileName();

            DiskImage disk = new DiskImage();

            Assert.AreEqual(true, disk.CreateImage(filename));
            disk.Format("Name", "1");
            IImageFile file = disk.Open("TEST", C64FileType.PRG, "wb");

            Assert.IsNotNull(file);

            byte[] data = new byte[2000];
            for (int i = 0; i < 2000; ++i)
            {
                data[i] = (byte)(i % 256);
            }
            Assert.AreEqual(data.Length, file.Write(data, data.Length));
            file.Close();
            disk.Dispose();

            DiskImage disk1 = new DiskImage();

            Assert.AreEqual(true, disk1.LoadImage(filename));
            IImageFile file1 = disk1.Open("TEST", C64FileType.PRG, "rb");

            Assert.IsNotNull(file1);
            byte[] data1 = new byte[3000];
            Assert.AreEqual(2000, file1.Read(data1, 3000));
            byte[] trucatedData = new byte[2000];
            Array.Copy(data1, trucatedData, 2000);
            for (int i = 0; i < 2000; ++i)
            {
                Assert.AreEqual(i % 256, trucatedData[i]);
            }
            file1.Close();
            disk1.Dispose();

            System.IO.File.Delete(filename);
        }
コード例 #3
0
        public void Save(IDiskImage di)
        {
            if (RawData == null)
            {
                throw new InvalidOperationException("Cannot save a file without loading one first.");
            }

            RawData[SexOffset]            = (byte)Sex;
            RawData[ClassOffset]          = (byte)Class;
            RawData[RaceOffset]           = (byte)Race;
            RawData[HitPointsOffset]      = (byte)(HitPoints & 0x00ff);
            RawData[HitPointsOffset + 1]  = (byte)(HitPoints >> 8);
            RawData[ExperienceOffset]     = (byte)(Experience & 0x00ff);
            RawData[ExperienceOffset + 1] = (byte)(Experience >> 8);

            RawData[StrengthOffset]     = (byte)Strength;
            RawData[AgilityOffset]      = (byte)Agility;
            RawData[StaminaOffset]      = (byte)Stamina;
            RawData[CharismaOffset]     = (byte)Charisma;
            RawData[WisdomOffset]       = (byte)Wisdom;
            RawData[IntelligenceOffset] = (byte)Intelligence;

            for (int i = 0; i < 10; ++i)
            {
                RawData[SpellsOffset + i] = (byte)Spells[i];
            }

            for (int i = 0; i < 5; ++i)
            {
                RawData[ArmorOffset + i] = (byte)Armor[i];
            }

            for (int i = 0; i < 15; ++i)
            {
                RawData[WeaponsOffset + i] = (byte)Weapons[i];
            }

            RawData[FoodOffset]     = (byte)(Food & 0x00ff);
            RawData[FoodOffset + 1] = (byte)(Food >> 8);

            RawData[CoinsOffset]     = (byte)(Coins & 0x00ff);
            RawData[CoinsOffset + 1] = (byte)(Coins >> 8);

            for (int i = 0; i < 4; ++i)
            {
                RawData[GemsOffset + i] = (byte)Gems[i];
            }

            RawData[EnemyShipsOffset] = (byte)EnemyShips;

            RawData[LocationOffset]     = (byte)Location.X;
            RawData[LocationOffset + 1] = (byte)Location.Y;


            IImageFile image = di.Open("P" + RosterId, C64FileType.PRG, "wb");

            if (image == null)
            {
                throw new System.IO.FileLoadException("Cannot open save file 'P" + RosterId + ".PRG' for write.");
            }

            int len = image.Write(RawData, RawData.Length);

            if (len != RawData.Length)
            {
                throw new System.IO.IOException("There was an error writing file 'P" + RosterId + ".PRG'.");
            }

            image.Close();
        }