Ejemplo n.º 1
0
        public void HonoursReadOnly()
        {
            SparseMemoryStream diskStream = new SparseMemoryStream();
            FatFileSystem      fs         = FatFileSystem.FormatFloppy(diskStream, FloppyDiskType.HighDensity, "FLOPPY_IMG ");

            fs.CreateDirectory(@"AAA");
            fs.CreateDirectory(@"BAR");
            using (Stream t = fs.OpenFile(@"BAR\AAA.TXT", FileMode.Create, FileAccess.ReadWrite)) { }
            using (Stream s = fs.OpenFile(@"BAR\FOO.TXT", FileMode.Create, FileAccess.ReadWrite))
            {
                StreamWriter w = new StreamWriter(s);
                w.WriteLine("FOO - some sample text");
                w.Flush();
            }
            fs.SetLastAccessTimeUtc(@"BAR", new DateTime(1980, 1, 1));
            fs.SetLastAccessTimeUtc(@"BAR\FOO.TXT", new DateTime(1980, 1, 1));

            // Check we can access a file without any errors
            SparseStream  roDiskStream = SparseStream.ReadOnly(diskStream, Ownership.None);
            FatFileSystem fatFs        = new FatFileSystem(roDiskStream);

            using (Stream fileStream = fatFs.OpenFile(@"BAR\FOO.TXT", FileMode.Open))
            {
                fileStream.ReadByte();
            }
        }
Ejemplo n.º 2
0
        public void Create_A_Directory_Entry()
        {
            string xNewDirectoryEntryName = "NEW";

            var xRootDirectory = mFS.GetRootDirectory();

            Assert.NotNull(xRootDirectory);

            var xRootDirectoryListing = mFS.GetDirectoryListing(xRootDirectory);

            Assert.AreEqual(xRootDirectoryListing.Count, 0);

            mFS.CreateDirectory(xRootDirectory, xNewDirectoryEntryName);

            xRootDirectoryListing = mFS.GetDirectoryListing(xRootDirectory);
            Assert.AreEqual(xRootDirectoryListing.Count, 1);

            var xNewDirectoryEntry = xRootDirectoryListing[0];

            Assert.AreEqual(xNewDirectoryEntry.mName, xNewDirectoryEntryName);

            var dirDirectoryListing = mFS.GetDirectoryListing(xNewDirectoryEntry);

            Assert.AreEqual(0, dirDirectoryListing.Count); //the . and .. directories should not be included
        }
Ejemplo n.º 3
0
        public void CreateDirectory()
        {
            FatFileSystem fs = FatFileSystem.FormatFloppy(new MemoryStream(), FloppyDiskType.HighDensity, "FLOPPY_IMG ");

            fs.CreateDirectory(@"UnItTeSt");
            Assert.AreEqual("UNITTEST", fs.Root.GetDirectories("UNITTEST")[0].Name);

            fs.CreateDirectory(@"folder\subflder");
            Assert.AreEqual("FOLDER", fs.Root.GetDirectories("FOLDER")[0].Name);

            fs.CreateDirectory(@"folder\subflder");
            Assert.AreEqual("SUBFLDER", fs.Root.GetDirectories("FOLDER")[0].GetDirectories("SUBFLDER")[0].Name);
        }
Ejemplo n.º 4
0
        public void Cyrillic()
        {
#if NET40
            SetupHelper.RegisterAssembly(typeof(FatFileSystem).Assembly);
#else
            SetupHelper.RegisterAssembly(typeof(FatFileSystem).GetTypeInfo().Assembly);
#endif

            string lowerDE = "\x0434";
            string upperDE = "\x0414";

            MemoryStream ms = new MemoryStream();
            using (FatFileSystem fs = FatFileSystem.FormatFloppy(ms, FloppyDiskType.HighDensity, "KBFLOPPY   "))
            {
                fs.FatOptions.FileNameEncoding = Encoding.GetEncoding(855);

                string name = lowerDE;
                fs.CreateDirectory(name);

                string[] dirs = fs.GetDirectories("");
                Assert.Equal(1, dirs.Length);
                Assert.Equal(upperDE, dirs[0]); // Uppercase

                Assert.True(fs.DirectoryExists(lowerDE));
                Assert.True(fs.DirectoryExists(upperDE));

                fs.CreateDirectory(lowerDE + lowerDE + lowerDE);
                Assert.Equal(2, fs.GetDirectories("").Length);

                fs.DeleteDirectory(lowerDE + lowerDE + lowerDE);
                Assert.Equal(1, fs.GetDirectories("").Length);
            }

            FileSystemInfo[] detectDefaultFileSystems = FileSystemManager.DetectFileSystems(ms);

            DiscFileSystem fs2 = detectDefaultFileSystems[0].Open(
                ms,
                new FileSystemParameters {
                FileNameEncoding = Encoding.GetEncoding(855)
            });

            Assert.True(fs2.DirectoryExists(lowerDE));
            Assert.True(fs2.DirectoryExists(upperDE));
            Assert.Equal(1, fs2.GetDirectories("").Length);
        }
Ejemplo n.º 5
0
        private void MakeDirectory(string fileName, FatFileSystem dstFat)
        {
            var dirname = Path.GetDirectoryName(fileName);

            if (dirname != @"\" && dirname != "" && !dstFat.DirectoryExists(dirname))
            {
                dstFat.CreateDirectory(dirname);
            }
        }
Ejemplo n.º 6
0
 public void SimpleVhdFat()
 {
     using (Disk disk = Disk.InitializeDynamic(new MemoryStream(), Ownership.Dispose, 16 * 1024 * 1024))
     {
         BiosPartitionTable.Initialize(disk, WellKnownPartitionType.WindowsFat);
         using (FatFileSystem fs = FatFileSystem.FormatPartition(disk, 0, null))
         {
             fs.CreateDirectory("Foo");
         }
     }
 }
Ejemplo n.º 7
0
        public void FormatPartition()
        {
            MemoryStream ms = new MemoryStream();

            Geometry      g  = Geometry.FromCapacity(1024 * 1024 * 32);
            FatFileSystem fs = FatFileSystem.FormatPartition(ms, "KBPARTITION", g, 0, (int)g.TotalSectors, 13);

            fs.CreateDirectory(@"DIRB\DIRC");

            FatFileSystem fs2 = new FatFileSystem(ms);

            Assert.AreEqual(1, fs2.Root.GetDirectories().Length);
        }
Ejemplo n.º 8
0
        public void Cyrillic()
        {
            string lowerDE = "\x0434";
            string upperDE = "\x0414";

            MemoryStream ms = new MemoryStream();

            using (FatFileSystem fs = FatFileSystem.FormatFloppy(ms, FloppyDiskType.HighDensity, "KBFLOPPY   "))
            {
                fs.FatOptions.FileNameEncoding = Encoding.GetEncoding(855);

                string name = lowerDE;
                fs.CreateDirectory(name);

                string[] dirs = fs.GetDirectories("");
                Assert.AreEqual(1, dirs.Length);
                Assert.AreEqual(upperDE, dirs[0]); // Uppercase

                Assert.IsTrue(fs.DirectoryExists(lowerDE));
                Assert.IsTrue(fs.DirectoryExists(upperDE));

                fs.CreateDirectory(lowerDE + lowerDE + lowerDE);
                Assert.AreEqual(2, fs.GetDirectories("").Length);

                fs.DeleteDirectory(lowerDE + lowerDE + lowerDE);
                Assert.AreEqual(1, fs.GetDirectories("").Length);
            }

            DiscFileSystem fs2 = FileSystemManager.DetectDefaultFileSystems(ms)[0].Open(
                ms,
                new FileSystemParameters {
                FileNameEncoding = Encoding.GetEncoding(855)
            });

            Assert.IsTrue(fs2.DirectoryExists(lowerDE));
            Assert.IsTrue(fs2.DirectoryExists(upperDE));
            Assert.AreEqual(1, fs2.GetDirectories("").Length);
        }
Ejemplo n.º 9
0
        public void Create()
        {
            var size = 1024 * 1024 * 1024; // 1gb


            var sectorSize       = 512;
            var headsPerCylinder = 16;
            var sectorsPerTrack  = 63;
            var cylinders        = size / (headsPerCylinder * sectorsPerTrack * sectorSize);

            var path = @"d:\temp\mbr.img";

            using var imgStream = File.Create(path);
            //var disk = Disk.Initialize(imgStream, Ownership.None, size, new Geometry(cylinders, headsPerCylinder, sectorsPerTrack, sectorSize));
            var disk = Disk.Initialize(imgStream, Ownership.None, size);

            BiosPartitionTable.Initialize(disk, WellKnownPartitionType.WindowsFat);

            // var bootSector = new byte[512];
            // imgStream.Position = 0;
            // imgStream.Read(bootSector, 0, bootSector.Length);
            // EndianUtilities.WriteBytesLittleEndian((ushort)sectorSize, bootSector, 11);
            // //EndianUtilities.ToUInt16LittleEndian(bpb, 11);
            // imgStream.Position = 0;
            // imgStream.Write(bootSector, 0, bootSector.Length);

            var partitionSize      = 1024 * 1024 * 512;
            var partitionCylinders = partitionSize / (headsPerCylinder * sectorsPerTrack * sectorSize);
            var partitionSectors   = partitionSize / sectorSize;

            // using FatFileSystem fs = FatFileSystem.FormatPartition(imgStream, "AmigaTest",
            //     new Geometry(partitionCylinders, headsPerCylinder, sectorsPerTrack, sectorSize), 1024 * 512,
            //     partitionSectors, 0);
            // fs.CreateDirectory(@"TestDir\CHILD");
            using FatFileSystem fs = FatFileSystem.FormatPartition(disk, 0, "AmigaMBRTest");

            var bootSector = new byte[512];

            imgStream.Position = 0;
            imgStream.Read(bootSector, 0, bootSector.Length);

            fs.CreateDirectory(@"TestDir\CHILD");

            using var s      = fs.OpenFile("foo.txt", FileMode.Create);
            using var writer = new StreamWriter(s, Encoding.UTF8);
            writer.WriteLine("hello");

            fs.Dispose();
            disk.Dispose();
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            ICarrierStreamFactory factory = new CarrierStreamFactory(CARRIER_STREAM_PROVIDER_DIRECTORY);

            using (Stream carrierClusterStream = factory.BuildClusterStream("Basic",
                                                                            new OneKeySequence(), GetClusterFiles()))
            {
                DiscUtils.FileSystemInfo[] fsInfos = FileSystemManager.DetectDefaultFileSystems(carrierClusterStream);
                if (fsInfos != null && fsInfos.Count() > 0)
                {
                    using (FatFileSystem fs = (FatFileSystem)fsInfos[0].Open(carrierClusterStream))
                    {
                        foreach (DiscDirectoryInfo info in fs.Root.GetDirectories())
                        {
                            Console.WriteLine(info.FullName);
                        }

                        DisplayDiskSize(fs);
                    }
                }
                else
                {
                    carrierClusterStream.Position = 0;

                    Geometry geometry = Geometry.FromCapacity(carrierClusterStream.Length - 512);
                    using (FatFileSystem fs = FatFileSystem.FormatPartition(carrierClusterStream,
                                                                            string.Empty, geometry, 0, geometry.TotalSectors, 13))
                    {
                        DateTime start = DateTime.Now;
                        for (int i = 0; i < 511; ++i)
                        {
                            fs.CreateDirectory(@"D" + i);
                        }

                        Console.WriteLine("511 Directories created in {0}", DateTime.Now - start);
                        foreach (DiscDirectoryInfo info in fs.Root.GetDirectories())
                        {
                            Console.WriteLine(info.FullName);
                        }

                        DisplayDiskSize(fs);
                    }
                }
            }

            Console.ReadLine();
        }
Ejemplo n.º 11
0
 private void CompileToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (fileLoaded)
     {
         UpdateListbox();
         fs.DeleteDirectory("lua", true);
         fs.CreateDirectory("lua");
         foreach (LuaFile file in lfiles)
         {
             Console.WriteLine("Writing " + file.name);
             SparseStream stream = fs.OpenFile(file.name, FileMode.Create);
             stream.Write(Encoding.ASCII.GetBytes(file.data), 0, file.data.Length);
             stream.Close();
             Console.WriteLine("Wrote");
         }
         MessageBox.Show("Finished saving.", "Dreamcaster");
     }
 }
Ejemplo n.º 12
0
        public void DefaultCodepage()
        {
            string graphicChar = "\x255D";

            MemoryStream  ms = new MemoryStream();
            FatFileSystem fs = FatFileSystem.FormatFloppy(ms, FloppyDiskType.HighDensity, "KBFLOPPY   ");

            fs.FatOptions.FileNameEncoding = Encoding.GetEncoding(855);

            string name = graphicChar;

            fs.CreateDirectory(name);

            string[] dirs = fs.GetDirectories("");
            Assert.AreEqual(1, dirs.Length);
            Assert.AreEqual(graphicChar, dirs[0]); // Uppercase

            Assert.IsTrue(fs.DirectoryExists(graphicChar));
        }
Ejemplo n.º 13
0
 private void CopyDirectoriesAndFiles(FatFileSystem ffs, string parentDirectory)
 {
     foreach (var file in Directory.GetFiles(parentDirectory))
     {
         SparseStream ss    = ffs.OpenFile(file.Replace(InputRootDirectory, ""), FileMode.CreateNew);
         FileStream   fs    = new FileStream(file, FileMode.Open);
         byte[]       bytes = new byte[fs.Length];
         fs.Read(bytes, 0, (int)fs.Length);
         ss.Write(bytes, 0, (int)fs.Length);
         ss.Flush();
         ss.Close();
         ffs.SetAttributes(file.Replace(InputRootDirectory, ""), FileAttributes.Normal);
     }
     foreach (var directory in Directory.GetDirectories(parentDirectory))
     {
         ffs.CreateDirectory(directory.Replace(InputRootDirectory, ""));
         CopyDirectoriesAndFiles(ffs, directory);
     }
 }
Ejemplo n.º 14
0
        public void Create_A_Directory_Entry()
        {
            string xNewDirectoryEntryName = "NEW";

            var xRootDirectory = mFS.GetRootDirectory();

            Assert.NotNull(xRootDirectory);

            var xRootDirectoryListing = mFS.GetDirectoryListing(xRootDirectory);

            Assert.AreEqual(xRootDirectoryListing.Count, 0);

            mFS.CreateDirectory(xRootDirectory, xNewDirectoryEntryName);

            xRootDirectoryListing = mFS.GetDirectoryListing(xRootDirectory);
            Assert.AreEqual(xRootDirectoryListing.Count, 1);

            var xNewDirectoryEntry = xRootDirectoryListing[0];

            Assert.AreEqual(xNewDirectoryEntry.mName, xNewDirectoryEntryName);
        }
Ejemplo n.º 15
0
        private void NewToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Console.WriteLine("Creating new project");
            fileLoaded = true;
            string     flasize = Interaction.InputBox("Enter lua & asset size in megabytes.", "Dreamcaster", "30");
            long       asSize  = int.Parse(flasize) * 1024 * 1024;
            string     fmdsize = Interaction.InputBox("Enter meta size in megabytes.", "Dreamcaster", "5");
            long       mdSize  = int.Parse(fmdsize) * 1024 * 1024;
            string     fname   = Interaction.InputBox("Enter project name.", "Dreamcaster", "project.bin");
            FileStream fst     = File.Create(fname);

            Console.WriteLine("Asset Dat Size: " + asSize);
            Console.WriteLine("Media Dat Size: " + mdSize);
            Console.WriteLine("Total Dat Size: " + (asSize + mdSize));
            disk = Disk.Initialize(fst, Ownership.None, asSize + mdSize);
            BiosPartitionTable table = BiosPartitionTable.Initialize(disk);

            table.Create(asSize, WellKnownPartitionType.WindowsFat, false); // main assets
            table.Create(mdSize, WellKnownPartitionType.WindowsFat, false); // meta
            fs  = FatFileSystem.FormatPartition(disk, 0, "DHP1-LA");        // lua and assets
            mfs = FatFileSystem.FormatPartition(disk, 1, "DHP1-MD");        // metadata
            fs.CreateDirectory("lua");
            mfs.CreateDirectory("mdlg");
            mfs.CreateDirectory("gpst");
            mfs.CreateDirectory(@"gpst\readonly");
            SparseStream mstream    = mfs.OpenFile(@"mdlg\licn.mdt", FileMode.OpenOrCreate);
            SparseStream stream     = fs.OpenFile(@"lua\main.lua", FileMode.Create);
            string       defaultstr = @"local key = '' -- this is the key that people will use to enter your Server
-- if the key specified here is not the same as the key people use to join(e.g.the key is bivkoi and the user is joining with a key of "")
-- then the connection will be denied, and if the key is blank and someone joins with a key the connection will be denied aswell.
-- you can manually change how it accepts requests by changing the function peerhandle
local game = DataModel:C('Factories'):C('GameLibrary')
local characterfactory = DataModel:C('Factories'):C('CharacterFactory')
local math = game.math
local random = game:GenerateRandom(game:FindEntropy())
resolution = { 433, 426}

function peerhandle(request)
    request:AcceptIfKey(key)
end

function peerdisconnect(peer, info, player)
    player:Destroy()
end

function peerconnect(peer, player)
    game:Debug('New Connection')
    player = characterfactory:NewPlayer('newpeer', peer)
    char = player:GetChar()
    char:Fill(0, 0, 0)
    player:SetGameTitle('Dreamscape')
    char:AddBrush(0, 0, 0)-- brush 0 black
    char:AddBrush(255, 0, 0)-- brush 1 red
    char:AddBrush(0, 255, 0)-- brush 2 green
    char:AddBrush(0, 0, 255)-- brush 3 blue
    char:AddBrush(255, 0, 255)-- brush 4 red + blue
    char:AddBrush(255, 255, 0)-- brush 5 red + green
    char:AddBrush(0, 255, 255)-- brush 6 green + blue
    char:AddBrush(255, 255, 255)-- brush 7 white
    char:AddBrush(127, 127, 127)-- brush 8 gray
end

function act(action, peer, player)

end

function getinfo()
    return '<head><style>body { font-family: arial; }</style></head><body><h1>Generic Dreamscape Server</h1></body>'
end";

            byte[] defautlbyt = Encoding.ASCII.GetBytes(defaultstr);
            stream.Write(defautlbyt, 0, defautlbyt.Length);
            defaultstr = m_file.Text;
            defautlbyt = Encoding.ASCII.GetBytes(defaultstr);
            mstream.Write(defautlbyt, 0, defautlbyt.Length);
            stream.Close();
            mstream.Close();
            UpdateListbox();
            Text = "Dreamcaster -- " + fname;
            Console.WriteLine("Done");
        }