예제 #1
0
        //uint dicks(ref uint r3, ref uint r4, ref uint r6, ref uint r7, ref uint r8, ref uint r9, ref uint r10)
        //{

        //}

        public long GetFreeSpace()
        {
            // Our return
            long Return      = 0;
            long ClusterSize = this.ClusterSize();

            // Get our position
            long positionya = FATOffset;

            // Get our end point
            long toBeLessThan = FATOffset + RealFATSize();

            // Get our IO
            Streams.Reader io = FATXDrive.Reader();
            // Set the position
            io.BaseStream.Position = positionya;

            // Start reading!
            for (long dick = io.BaseStream.Position; dick < toBeLessThan; dick += 0x200)
            {
                bool BreakAndShit = false;
                // Set the position
                io.BaseStream.Position = dick;
                // Read our buffer
                byte[] Buffer = null;
                if ((dick - FATOffset).DownToNearest200() == (toBeLessThan - FATOffset).DownToNearest200())
                {
                    byte[] Temp = io.ReadBytes(0x200);
                    Buffer = new byte[(toBeLessThan - FATOffset) - (dick - FATOffset).DownToNearest200()];
                    Array.Copy(Temp, 0, Buffer, 0, Buffer.Length);
                }
                else
                {
                    Buffer = io.ReadBytes(0x200);
                }
                // Length to loop for (used for the end so we can read ONLY usable partitions)
                long Length = Buffer.Length;
                if (dick == VariousFunctions.DownToNearest200(toBeLessThan))
                {
                    Length       = toBeLessThan - VariousFunctions.DownToNearest200(toBeLessThan);
                    BreakAndShit = true;
                }
                // Check the values
                Streams.Reader ioya = new Streams.Reader(new System.IO.MemoryStream(Buffer));
                for (int i = 0; i < Length; i += EntrySize)
                {
                    // This size will be off by a few megabytes, no big deal in my opinion
                    if (EntrySize == 2)
                    {
                        ushort Value = ioya.ReadUInt16();
                        if (Value == 0)
                        {
                            Return += ClusterSize;
                        }
                    }
                    else
                    {
                        if (ioya.ReadUInt32() == 0)
                        {
                            Return += ClusterSize;
                        }
                    }
                }
                ioya.Close();
                if (BreakAndShit)
                {
                    break;
                }
            }

            return(Return);
        }