// I dont' know why I'VariousFunctions even going to bother with this function.
        // I don't think I'VariousFunctions going to ever use it.
        public override int ReadByte()
        {
            // Check if we're at the edge of a cluster...
            if (RealOffset == VariousFunctions.UpToNearestClusterForce(RealSectorOffset, xFile.PartitionInfo.ClusterSize))
            {
                Underlying.Position = VariousFunctions.GetBlockOffset(xFile.BlocksOccupied[DetermineBlockIndex(VariousFunctions.UpToNearestClusterForce(RealSectorOffset, xFile.PartitionInfo.ClusterSize))], xFile);
                xPositionInFile++;
                return(Underlying.ReadByte());
            }
            // Check if we're at the beginning of a sector...
            if (RealOffset == VariousFunctions.DownToNearest200(RealOffset))
            {
                xPositionInFile++;
                return(Underlying.ReadByte());
            }
            // We aren't at the beginning of a sector, and we're not at the end of a cluster
            // We must be somewhere in-between, so we've got to do some hax.
            byte[] b = new byte[1];
            Read(b, 0, 1);
            return((int)b[0]);

            // I think I made it return that first byte for some reason, but idk
            // oh yeeeuh, I wanted it to read from the nearest 0x200 byte boundary
            // so if we keep calling .ReadByte() it would have that shit cached
            // idk why i didn't do that
            int index = (int)(RealOffset - RealSectorOffset);

            if (Position.DownToNearest200() == PreviouslyReadOffset && index < PreviouslyRead.Length)
            {
                xPositionInFile++;
                return((int)PreviouslyRead[index]);
            }
            else
            {
                byte[] buffer = new byte[0];
                // Read the buffer
                if (Length - Position >= 0x200)
                {
                    buffer = new byte[0x200];
                }
                else
                {
                    buffer = new byte[(Length - Position)];
                }
                index = (int)(RealOffset - RealSectorOffset);
                Read(buffer, 0, buffer.Length);
                try
                {
                    Position -= buffer.Length - 1;
                }
                catch { }
                // Set the previously read to thissssssssss
                PreviouslyRead       = buffer;
                PreviouslyReadOffset = Position.DownToNearest200();
                // Return the value at the index we should be at
                return((int)buffer[index]);
            }
        }
Beispiel #2
0
        public FATXFileStream(System.IO.Stream Stream, File file)
        {
            xFile = file;
            // Set our position
            long off = VariousFunctions.GetBlockOffset(xFile.BlocksOccupied[0], xFile);

            Underlying = Stream;
            //Underlying.Position = off;
            Position = 0;
        }
Beispiel #3
0
        public FATXFileStream(string Path, System.IO.FileMode fmode, File file)
        {
            xFile = file;
            // Set our position
            long off = VariousFunctions.GetBlockOffset(xFile.BlocksOccupied[0], xFile);

            Underlying = new FileStream(Path, fmode);
            //Underlying.Position = off;
            Position = 0;
        }
Beispiel #4
0
        public FATXFileStream(int DeviceIndex, System.IO.FileAccess fa, File file)
        {
            xFile = file;
            // Set our position to the beginning of the file
            long off = VariousFunctions.GetBlockOffset(xFile.BlocksOccupied[0], xFile);

            Underlying = new FileStream(VariousFunctions.CreateHandle(DeviceIndex), fa);
            //Underlying.Position = off;
            Position = 0;
        }
Beispiel #5
0
        public FATXFileStream(string[] InPaths, File file)
        {
            xFile = file;
            // Set our position to the beginning of the file
            long off = VariousFunctions.GetBlockOffset(xFile.BlocksOccupied[0], xFile);

            Underlying = new USBStream(InPaths, FileMode.Open);
            //Underlying.Position = off;
            Position = 0;
        }
        public FATXFileStream(System.IO.Stream Stream, File file)
        {
            if (file.Size == 0)
            {
                throw new Exception("Null files not supported");
            }
            xFile = file;
            // Set our position
            long off = VariousFunctions.GetBlockOffset(xFile.BlocksOccupied[0], xFile);

            Underlying = Stream;
            //Underlying.Position = off;
            Position = 0;
        }
        public FATXFileStream(string[] InPaths, File file)
        {
            if (file.Size == 0)
            {
                throw new Exception("Null files not supported");
            }
            xFile = file;
            // Set our position to the beginning of the file
            long off = VariousFunctions.GetBlockOffset(xFile.BlocksOccupied[0], xFile);

            Underlying = new USBStream(InPaths, FileMode.Open);
            //Underlying.Position = off;
            Position = 0;
        }
        public FATXFileStream(string Path, System.IO.FileMode fmode, File file)
        {
            //Underlying.Close();
            if (file.Size == 0)
            {
                throw new Exception("Null files not supported");
            }
            xFile = file;
            // Set our position
            long off = VariousFunctions.GetBlockOffset(xFile.BlocksOccupied[0], xFile);

            Underlying = new FileStream(Path, fmode);
            //Underlying.Position = off;
            Position = 0;
        }
        public FATXFileStream(int DeviceIndex, System.IO.FileAccess fa, File file)
        {
            //Underlying.Close();
            if (file.Size == 0)
            {
                throw new Exception("Null files not supported");
            }
            xFile = file;
            // Set our position to the beginning of the file
            long off = VariousFunctions.GetBlockOffset(xFile.BlocksOccupied[0], xFile);

            Underlying = new FileStream(VariousFunctions.CreateHandle(DeviceIndex), fa);
            //Underlying.Position = off;
            Position = 0;
        }
Beispiel #10
0
        long GetRealSectorOffset(long off)
        {
            // Get the size up to the nearest cluster
            // Divide by cluster size
            // That is the block index.
            long SizeInCluster = VariousFunctions.DownToNearest200(off - VariousFunctions.DownToNearestCluster(off, xFile.PartitionInfo.ClusterSize));//VariousFunctions.GetBlockOffset(xFile.StartingCluster) + 0x4000;            long SizeInCluster = VariousFunctions.DownToNearestCluster(off, xFile.PartitionInfo.ClusterSize) / xFile.PartitionInfo.ClusterSize)
            uint Cluster       = (uint)(VariousFunctions.DownToNearestCluster(off, xFile.PartitionInfo.ClusterSize) / xFile.PartitionInfo.ClusterSize);

            //Cluster = (Cluster == 0) ? 0 : Cluster - 1;
            try
            {
                long Underlying = VariousFunctions.GetBlockOffset(xFile.BlocksOccupied[Cluster], xFile);
                return(Underlying + SizeInCluster);
            }
            catch { return(VariousFunctions.GetBlockOffset(xFile.BlocksOccupied[Cluster - 1], xFile)); }
        }
Beispiel #11
0
        uint DetermineBlockIndex(long Off)
        {
            // Pre-planning... I need to figure ref the rounded offset in order
            // to determine the cluster that this bitch is in
            // So now that we have the rounded number, we can
            long rounded = VariousFunctions.DownToNearestCluster(Off, xFile.PartitionInfo.ClusterSize);

            // Loop for each cluster, determining if the sizes match
            for (uint i = 0; i < xFile.BlocksOccupied.Length; i++)
            {
                long off = VariousFunctions.GetBlockOffset(xFile.BlocksOccupied[i], xFile);
                if (off == rounded)
                {
                    return(i);
                }
            }
            throw new Exception("Block not allocated to this file!");
        }