Esempio n. 1
0
 public static bool CanOpen(PartitionInfo volumeInfo)
 {
     using (var content = volumeInfo.Open())
     {
         return(SearchLabel(content, out _));
     }
 }
Esempio n. 2
0
        private static DiscFileSystem DetectFileSystem(PartitionInfo Partition)
        {
            using (var stream = Partition.Open())
            {
                if (NtfsFileSystem.Detect(stream))
                {
                    return(new NtfsFileSystem(Partition.Open()));
                }
                stream.Seek(0, SeekOrigin.Begin);
                if (FatFileSystem.Detect(stream))
                {
                    return(new FatFileSystem(Partition.Open()));
                }

                /* Ext2/3/4 file system - when Ext becomes fully writable
                 *
                 * stream.Seek(0, SeekOrigin.Begin);
                 * if (ExtFileSystem.Detect(stream))
                 *  return new ExtFileSystem(Partition.Open());
                 */

                return(null);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a temporary vhd of the given size in GB.
        /// The created VHD is dynamically allocated and is of type VHD (legacy)
        /// </summary>
        /// <param name="sizeInGB">The size of the VHD in GB</param>
        /// <returns>The path to the created vhd</returns>
        internal static string CreateVirtualDisk(long sizeInGB = 10)
        {
            long   diskSize = sizeInGB * 1024 * 1024 * 1024;
            string tempVhd  = Path.GetTempFileName();

            using Stream vhdStream = File.Create(tempVhd);
            using Disk disk        = Disk.InitializeDynamic(vhdStream, DiscUtils.Streams.Ownership.Dispose, diskSize);

            BiosPartitionTable table         = BiosPartitionTable.Initialize(disk, WellKnownPartitionType.WindowsNtfs);
            PartitionInfo      ntfsPartition = table.Partitions[0];

            NtfsFileSystem.Format(ntfsPartition.Open(), "Windows UUP Medium", Geometry.FromCapacity(diskSize), ntfsPartition.FirstSector, ntfsPartition.SectorCount);

            return(tempVhd);
        }
Esempio n. 4
0
        private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Console.WriteLine("Opening new project");
            fileLoaded = true;
            string fname = Interaction.InputBox("Enter project name.", "Dreamcaster", "project.bin");

            disk = new Disk(fname);
            PartitionTable partitions = disk.Partitions;
            PartitionInfo  fs_pi      = partitions[0];

            fs = new FatFileSystem(fs_pi.Open());
            PartitionInfo mfs_pi = partitions[1];

            mfs = new FatFileSystem(mfs_pi.Open());
            UpdateListbox();
            Text = "Dreamcaster -- " + fname;
            Console.WriteLine("Done");
        }
Esempio n. 5
0
        public static void Generate()
        {
            string rootPath = Path.Combine(Bootstrap.Root, @"Root");
            string vhdxPath = Path.Combine(Bootstrap.Root, @"Hyper-V\Virtual Hard Disks\Disk.vhdx");

            using (VirtualDisk virtualDisk = VirtualDisk.OpenDisk(vhdxPath, FileAccess.ReadWrite))
            {
                // Get system partition
                PartitionInfo partition = virtualDisk.Partitions.Partitions.FirstOrDefault();

                // Open FAT partition
                using (SparseStream partitionStream = partition.Open())
                    using (FatFileSystem fatFileSystem = new FatFileSystem(partitionStream))
                    {
                        // Clean partition
                        string[] fileSystemEntries = fatFileSystem.GetFileSystemEntries("");
                    }
            }
        }
Esempio n. 6
0
        public VHDXInstallProviderInterface(Stream vhdstream)
        {
            _vhdstream = vhdstream;
            _vhd       = new Disk(_vhdstream, DiscUtils.Streams.Ownership.Dispose);

            PartitionInfo part = null;

            foreach (var partition in _vhd.Partitions.Partitions)
            {
                if (part == null)
                {
                    part = partition;
                }
                else
                {
                    if (partition.SectorCount > part.SectorCount)
                    {
                        part = partition;
                    }
                }
            }

            _ntfs = new NtfsFileSystem(part.Open());
        }
Esempio n. 7
0
        public VMDKInstallProviderInterface(string vhdpath)
        {
            _vhdpath = vhdpath;
            _vhd     = new Disk(vhdpath, FileAccess.Read);

            PartitionInfo part = null;

            foreach (var partition in _vhd.Partitions.Partitions)
            {
                if (part == null)
                {
                    part = partition;
                }
                else
                {
                    if (partition.SectorCount > part.SectorCount)
                    {
                        part = partition;
                    }
                }
            }

            _ntfs = new NtfsFileSystem(part.Open());
        }
Esempio n. 8
0
        public static bool TryOpen(PartitionInfo volumeInfo, out PhysicalVolume pv)
        {
            var content = volumeInfo.Open();

            return(TryOpen(content, out pv));
        }
Esempio n. 9
0
        void MainC(string[] args)
        {
            Disk           disk       = new Disk("server.bin");
            PartitionTable partitions = disk.Partitions;
            PartitionInfo  fs_pi      = partitions[0];
            FatFileSystem  fs         = new FatFileSystem(fs_pi.Open());
            PartitionInfo  mfs_pi     = partitions[1];
            FatFileSystem  mfs        = new FatFileSystem(mfs_pi.Open());

            svtime = DateTime.Now.Ticks;
            Console.WriteLine("Starting...");
            netListener  = new EventBasedNetListener();
            client       = new NetManager(netListener, new XorEncryptLayer("dreamscape"));
            inetListener = new EventBasedNetListener();
            iclient      = new NetManager(inetListener);
            lua          = new Lua();
            gameInstance = new Instance("DataModel");
            Factory factoryContainer = new Factory("Factories");

            factoryContainer.Parent = gameInstance;
            CharacterFactory characterFactory = new CharacterFactory("CharacterFactory");

            characterFactory.Parent = factoryContainer;
            GameLibrary gameLibrary = new GameLibrary("GameLibrary");

            gameLibrary.Parent = factoryContainer;

            lua.LoadCLRPackage();
            lua.DebugHook += Lua_DebugHook;
            SparseStream stream = fs.OpenFile("lua\\main.lua", FileMode.Open, FileAccess.Read);

            byte[] data = new byte[stream.Length];
            stream.Read(data, 0, data.Length);
            string code = Encoding.ASCII.GetString(data);

            stream.Close();
            lua["netwriter"] = new NetDataWriter();
            lua["netserver"] = client;
            lua["DataModel"] = gameInstance;
            lua.DoString("import('dreamhost','dreamscape','System','NLua','LiteNetLib','LiteNetLib.Utils','dreamhost.lua')\n" + code, svtime.ToString());

            this.characterFactory = characterFactory;
            client.Start(6698);
            Console.WriteLine("Server ready! Hosting on UDP port 6698.");
            client.AutoRecycle = true;
            netListener.ConnectionRequestEvent += (request) =>
            {
                Console.WriteLine("Connection");
                LuaFunction func = lua["peerhandle"] as LuaFunction;
                try
                {
                    func.Call(request);
                } catch (Exception e)
                {
                    request.Accept();
                    Console.WriteLine(e);
                }
            };
            netListener.PeerDisconnectedEvent += (peer, info) =>
            {
                Player plr = null;
                foreach (Player i in characterFactory.Children)
                {
                    if (i.peer == peer)
                    {
                        plr = i;
                    }
                }
                Console.WriteLine("Disconnect");
                LuaFunction func = lua["peerdisconnect"] as LuaFunction;
                try
                {
                    func.Call(peer, info, plr);
                } catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            };
            netListener.PeerConnectedEvent += (peer) =>
            {
                Player player = new Player(gameLibrary.FindEntropy().ToString(), peer);
                player.Parent = characterFactory;
                Console.WriteLine("Successful Connect");
                LuaFunction func = lua["peerconnect"] as LuaFunction;
                try
                {
                    func.Call(peer, player);
                } catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            };
            netListener.NetworkReceiveEvent += NetworkReceive;
            Console.WriteLine("Starting info server...");
            inetListener.PeerConnectedEvent += (peer) =>
            {
                Console.WriteLine("Sending peer info");
                NetDataWriter writer = new NetDataWriter();
                LuaFunction   func   = lua["getinfo"] as LuaFunction;
                try
                {
                    writer.Put(func.Call(peer).First() as string);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    writer.Put("Please contact the <b>SYSOP</b> for this server.\n" + e);
                }
                peer.Send(writer, DeliveryMethod.ReliableSequenced);
            };
            inetListener.ConnectionRequestEvent += (request) =>
            {
                Console.WriteLine("Connected to info");
                request.Accept();
            };
            iclient.Start(6699);
            iclient.AutoRecycle = true;
            Console.WriteLine("Info server ready! Hosting on UDP port 6699.");
            while (true)
            {
                client.PollEvents();
                Thread.Sleep(15);
            }
        }