예제 #1
0
        /* Note: Have plans for safer and better manipulation to prevent
         * minimal block loss to human error */

        /// <summary>
        /// Adds a folder
        /// </summary>
        /// <param name="FolderName"></param>
        /// <returns></returns>
        public bool AddFolder(string FolderName)
        {
            FolderName.IsValidXboxName();
            if (xDrive.ActiveCheck())
            {
                return(false);
            }
            try
            {
                FATXReadContents xconts = xRead();
                foreach (FATXFolderEntry x in xconts.xfolds)
                {
                    if (x.Name == FolderName)
                    {
                        return(xDrive.xActive = false);
                    }
                }
                DJsIO xIOIn = new DJsIO(new byte[Partition.xBlockSize], true);
                uint  xnew  = 0;
                long  xpos  = GetNewEntryPos(out xnew);
                if (xpos == -1)
                {
                    return(xDrive.xActive = false);
                }
                uint[] blocks = Partition.xTable.GetNewBlockChain(xIOIn.BlockCountFATX(Partition), xnew + 1);
                if (blocks.Length == 0)
                {
                    return(xDrive.xActive = false);
                }
                if (!Partition.WriteFile(blocks, ref xIOIn))
                {
                    return(xDrive.xActive = false);
                }
                FATXEntry y = new FATXEntry(FolderName, blocks[0], (int)xIOIn.Length, xpos, true, ref xDrive);
                if (!y.xWriteEntry())
                {
                    return(xDrive.xActive = false);
                }
                if (xnew > 0)
                {
                    List <uint> fileblocks = new List <uint>(Partition.xTable.GetBlocks(xStartBlock));
                    fileblocks.Add(xnew);
                    uint[] xtemp = fileblocks.ToArray();
                    if (!Partition.xTable.WriteChain(ref xtemp))
                    {
                        return(xDrive.xActive = false);
                    }
                }
                if (!Partition.xTable.WriteChain(ref blocks))
                {
                    return(xDrive.xActive = false);
                }
                if (Partition.WriteAllocTable())
                {
                    return(!(xDrive.xActive = false));
                }
                return(xDrive.xActive = false);
            }
            catch { return(xDrive.xActive = false); }
        }
예제 #2
0
        public FATXEntry GetSubEntry(string fileName, FATXReadContents parent)
        {
            FATXEntry ret = GetSubFolder(fileName, parent);

            if (ret == null)
            {
                ret = GetSubFile(fileName, parent);
            }
            return(ret);
        }
예제 #3
0
 internal FATXEntry(ref FATXEntry xEntry, ref FATXDrive xdrive)
 {
     xOffset     = xEntry.xOffset;
     xNLen       = xEntry.xNLen;
     xName       = xEntry.xName;
     xStartBlock = xEntry.xStartBlock;
     xSize       = xEntry.xSize;
     xT1         = xEntry.xT1;
     xT2         = xEntry.xT2;
     xT3         = xEntry.xT3;
     xIsValid    = xEntry.xIsValid;
     xIsFolder   = xEntry.IsFolder;
     xPart       = xEntry.xPart;
     xDrive      = xEntry.xDrive;
 }
예제 #4
0
        public FATXEntry GetSubFile(string fileName, FATXReadContents parent)
        {
            FATXEntry ret = null;

            for (int x = 0; x < parent.Files.Length; x++)
            {
                var subFile = parent.Files[x];
                if (string.Compare(subFile.Name, fileName, true) == 0)
                {
                    ret = subFile;
                    break;
                }
            }
            return(ret);
        }
예제 #5
0
파일: Entries.cs 프로젝트: VictorOverX/X360
 internal FATXEntry(ref FATXEntry xEntry, ref FATXDrive xdrive)
 {
     xOffset = xEntry.xOffset;
     xNLen = xEntry.xNLen;
     xName = xEntry.xName;
     xStartBlock = xEntry.xStartBlock;
     xSize = xEntry.xSize;
     xT1 = xEntry.xT1;
     xT2 = xEntry.xT2;
     xT3 = xEntry.xT3;
     xIsValid = xEntry.xIsValid;
     xIsFolder = xEntry.IsFolder;
     xPart = xEntry.xPart;
     xDrive = xEntry.xDrive;
 }
예제 #6
0
        internal FATXReadContents xRead()
        {
            FATXReadContents xreturn = new FATXReadContents();

            try
            {
                xDrive.GetIO();
                List <FATXEntry> xEntries = new List <FATXEntry>();
                uint[]           xBlocks  = Partition.xTable.GetBlocks(xStartBlock);
                for (int i = 0; i < xBlocks.Length; i++)
                {
                    long xCurrent = Partition.BlockToOffset(xBlocks[i]);
                    if (xCurrent == -1)
                    {
                        break;
                    }
                    for (int x = 0; x < Partition.xEntryCount; x++)
                    {
                        xDrive.xIO.Position = xCurrent + (0x40 * x);
                        FATXEntry z = new FATXEntry((xCurrent + (0x40 * x)), xDrive.xIO.ReadBytes(0x40), ref xDrive);
                        z.SetAtts(Partition);
                        if (z.xIsValid)
                        {
                            xEntries.Add(z);
                        }
                        else if (z.xNLen != 0xE5)
                        {
                            break;
                        }
                    }
                }
                xreturn.xfolds = new List <FATXFolderEntry>();
                xreturn.xfiles = new List <FATXFileEntry>();
                for (int i = 0; i < xEntries.Count; i++)
                {
                    if (xEntries[i].IsFolder)
                    {
                        xreturn.xfolds.Add(new FATXFolderEntry(xEntries[i], ref xDrive));
                    }
                    else
                    {
                        xreturn.xfiles.Add(new FATXFileEntry(xEntries[i], ref xDrive));
                    }
                }
                return(xreturn);
            }
            catch { return(xreturn = null); }
        }
예제 #7
0
        public FATXEntry GetSubFolder(string folderName, FATXReadContents parent)
        {
            FATXEntry ret = null;

            for (int x = 0; x < parent.Folders.Length; x++)
            {
                var subFolder = parent.Folders[x];
                if (string.Compare(subFolder.Name, folderName, true) == 0)
                {
                    ret = subFolder;

                    break;
                }
            }
            return(ret);
        }
        public bool AddFile(string FileName, byte[] fileData, AddType xType)
        {
            if (!VariousFunctions.IsValidXboxName(FileName))
                return false;

            if (xDrive.ActiveCheck())
                return false;

            DJsIO xIOIn = null;
            byte[] b = fileData;
            xIOIn = new DJsIO(b, true);

            try
            {
                FATXReadContents xconts = xRead();
                foreach (FATXFileEntry x in xconts.xfiles)
                {
                    if (string.Compare(x.Name, FileName, true) == 0)
                    {
                        bool xreturn = false;
                        if (xType == AddType.NoOverWrite)
                        {
                            xIOIn.Close();
                            return (xDrive.xActive = false);
                        }
                        else if (xType == AddType.Inject)
                        {
                            xreturn = x.xInject(xIOIn);
                        }
                        else
                        {
                            xreturn = x.xReplace(xIOIn);
                        }
                        xIOIn.Close();
                        return (xreturn & !(xDrive.xActive = false));
                    }
                }
                uint xnew = 0;
                long xpos = GetNewEntryPos(out xnew);
                if (xpos == -1)
                    return (xDrive.xActive = false);

                var count = xIOIn.BlockCountFATX(Partition);

                uint[] blocks = Partition.xTable.GetNewBlockChain(count, xnew + 1);

                if (blocks.Length == 0)
                    return (xDrive.xActive = false);

                if (!Partition.WriteFile(blocks, ref xIOIn))
                    return (xDrive.xActive = false);

                FATXEntry y = new FATXEntry(this,
                    FileName,
                    blocks[0], (int)xIOIn.Length,
                    xpos, false, ref xDrive);

                if (!y.xWriteEntry())
                    return (xDrive.xActive = false);

                if (xnew > 0)
                {
                    var filebx = Partition.xTable.GetBlocks(xStartBlock);
                    List<uint> fileblocks = new List<uint>(filebx);

                    fileblocks.Add(xnew);

                    uint[] xtemp = fileblocks.ToArray();

                    if (!Partition.xTable.WriteChain(ref xtemp))
                        return (xDrive.xActive = false);
                }

                if (!Partition.xTable.WriteChain(ref blocks))
                    return (xDrive.xActive = false);

                if (Partition.WriteAllocTable())
                    return !(xDrive.xActive = false);

                return (xDrive.xActive = false);
            }
            catch { xIOIn.Close(); return (xDrive.xActive = false); }
        }
예제 #9
0
파일: Entries.cs 프로젝트: VictorOverX/X360
 /// <summary>
 /// Adds a file
 /// </summary>
 /// <param name="FileName"></param>
 /// <param name="FileLocation"></param>
 /// <param name="xType"></param>
 /// <returns></returns>
 public bool AddFile(string FileName, string FileLocation, AddType xType)
 {
     FileName.IsValidXboxName();
     if (xDrive.ActiveCheck())
         return false;
     DJsIO xIOIn = null;
     try { xIOIn = new DJsIO(FileLocation, DJFileMode.Open, true); }
     catch { return (xDrive.xActive = false); }
     try
     {
         FATXReadContents xconts = xRead();
         foreach (FATXFileEntry x in xconts.xfiles)
         {
             if (x.Name == FileName)
             {
                 bool xreturn = false;
                 if (xType == AddType.NoOverWrite)
                      return (xDrive.xActive = false);
                 else if (xType == AddType.Inject)
                     xreturn = x.xInject(xIOIn);
                 else xreturn = x.xReplace(xIOIn);
                 return (xreturn & !(xDrive.xActive = false));
             }
         }
         uint xnew = 0;
         long xpos = GetNewEntryPos(out xnew);
         if (xpos == -1)
             return (xDrive.xActive = false);
         uint[] blocks = Partition.xTable.GetNewBlockChain(xIOIn.BlockCountFATX(Partition), xnew + 1);
         if (blocks.Length == 0)
             return (xDrive.xActive = false);
         if (!Partition.WriteFile(blocks, ref xIOIn))
             return (xDrive.xActive = false);
         FATXEntry y = new FATXEntry(FileName, blocks[0], (int)xIOIn.Length, xpos, false, ref xDrive);
         if (!y.xWriteEntry())
             return (xDrive.xActive = false);
         if (xnew > 0)
         {
             List<uint> fileblocks = new List<uint>(Partition.xTable.GetBlocks(xStartBlock));
             fileblocks.Add(xnew);
             uint[] xtemp = fileblocks.ToArray();
             if (!Partition.xTable.WriteChain(ref xtemp))
                 return (xDrive.xActive = false);
         }
         if (!Partition.xTable.WriteChain(ref blocks))
             return (xDrive.xActive = false);
         if (Partition.WriteAllocTable())
             return !(xDrive.xActive = false);
         return (xDrive.xActive = false);
     }
     catch { xIOIn.Close(); return (xDrive.xActive = false); }
 }
예제 #10
0
파일: Entries.cs 프로젝트: VictorOverX/X360
 /* Note: Have plans for safer and better manipulation to prevent
  * minimal block loss to human error */
 /// <summary>
 /// Adds a folder
 /// </summary>
 /// <param name="FolderName"></param>
 /// <returns></returns>
 public bool AddFolder(string FolderName)
 {
     FolderName.IsValidXboxName();
     if (xDrive.ActiveCheck())
         return false;
     try
     {
         FATXReadContents xconts = xRead();
         foreach (FATXFolderEntry x in xconts.xfolds)
         {
             if (x.Name == FolderName)
                 return (xDrive.xActive = false);
         }
         DJsIO xIOIn = new DJsIO(new byte[Partition.xBlockSize], true);
         uint xnew = 0;
         long xpos = GetNewEntryPos(out xnew);
         if (xpos == -1)
             return (xDrive.xActive = false);
         uint[] blocks = Partition.xTable.GetNewBlockChain(xIOIn.BlockCountFATX(Partition), xnew + 1);
         if (blocks.Length == 0)
             return (xDrive.xActive = false);
         if (!Partition.WriteFile(blocks, ref xIOIn))
             return (xDrive.xActive = false);
         FATXEntry y = new FATXEntry(FolderName, blocks[0], (int)xIOIn.Length, xpos, true, ref xDrive);
         if (!y.xWriteEntry())
             return (xDrive.xActive = false);
         if (xnew > 0)
         {
             List<uint> fileblocks = new List<uint>(Partition.xTable.GetBlocks(xStartBlock));
             fileblocks.Add(xnew);
             uint[] xtemp = fileblocks.ToArray();
             if (!Partition.xTable.WriteChain(ref xtemp))
                 return (xDrive.xActive = false);
         }
         if (!Partition.xTable.WriteChain(ref blocks))
             return (xDrive.xActive = false);
         if (Partition.WriteAllocTable())
             return !(xDrive.xActive = false);
         return (xDrive.xActive = false);
     }
     catch { return xDrive.xActive = false; }
 }
예제 #11
0
파일: Entries.cs 프로젝트: VictorOverX/X360
 internal FATXFileEntry(FATXEntry x, ref FATXDrive xdrive)
     : base(ref x, ref xdrive)
 {
 }
예제 #12
0
파일: Entries.cs 프로젝트: VictorOverX/X360
 internal FATXFolderEntry(FATXEntry xEntry, ref FATXDrive xdrive)
     : base(ref xEntry, ref xdrive)
 {
 }
예제 #13
0
 public FATXEntry(FATXEntry parent, string xNameIn, uint xStart, int xSizeIn, long xPosition, bool xFolder, ref FATXDrive xdrive)
 {
     Debug.WriteLine("fatx string " + xNameIn);
     int DT = TimeStamps.FatTimeInt(DateTime.Now);
     xT1 = DT;
     xT2 = DT;
     xT3 = DT;
     Name = xNameIn;
     xStartBlock = xStart;
     xSize = (xIsFolder = xFolder) ? 0 : xSizeIn;
     xOffset = xPosition;
     xIsValid = true;
     xDrive = xdrive;
 }
예제 #14
0
 public FATXFileEntry(FATXFolderEntry folder, FATXEntry x)
     : base(folder, ref x)
 {
 }
예제 #15
0
        public FATXPartition(long xOffset, long xPartitionSize,
            FATXDrive xDrive,
            string xLocaleName)
        {
            xdrive = xDrive;
            xName = xLocaleName;
            xBase = xOffset;
            xDrive.GetIO();
            xDrive.xIO.IsBigEndian = true;
            xDrive.xIO.Position = xOffset;

            string fatX = Encoding.ASCII.GetString(xdrive.xIO.ReadBytes(4).Reverse().ToArray());
            if (fatX != "FATX")
                return;

            //if (xDrive.xIO.ReadUInt32() != 0x58544146)
            //  return;
            var VolumeID = xDrive.xIO.ReadUInt32(); // Partition ID (884418784)

            SectorsPerBlock = xDrive.xIO.ReadUInt32();//Cluster size in (512 byte) sectors

            uint blockct = (uint)(xPartitionSize / xBlockSize);

            if (blockct < 0xFFF5 && xLocaleName != "Content")
                FatType = FATXType.FATX16;
            else
                FatType = FATXType.FATX32;

            uint dirblock = (uint)xdrive.xIO.ReadUInt32(); //Number of FAT copies

            xFATSize = (int)(blockct * (byte)FatType);
            xFATSize += (0x1000 - (xFATSize % 0x1000));

            xTable = new AllocationTable(new DJsIO(true),
                (uint)((xPartitionSize - 0x1000 - xFATSize) / xBlockSize), FatType);

            xTable.xAllocTable.Position = 0;
            xDrive.xIO.Position = xFATLocale;
            for (int i = 0; i < xFATSize; i += 0x1000)
            {
                var blockBytes = xdrive.xIO.ReadBytes(0x1000);
                xTable.xAllocTable.Write(blockBytes);
            }

            xTable.xAllocTable.Flush();

            long DirOffset = BlockToOffset(dirblock);

            xFolders = new List<FATXFolderEntry>();
            xFiles = new List<FATXFileEntry>();
            var xEntries = new List<FATXEntry>();

            for (byte x = 0; x < xEntryCount; x++)
            {
                var offset = (DirOffset + (0x40 * x));
                xDrive.xIO.Position = offset;

                var entry64 = xdrive.xIO.ReadBytes(0x40);

                FATXEntry z = new FATXEntry(FatType, offset, entry64, ref xdrive);
                z.SetAtts(this);

                if (z.xIsValid)
                {
                    xEntries.Add(z);
                }
                else if (z.xNLen == 0xE5)
                {
                }
                else if (z.xNLen != 0xE5)
                {
                    break;
                }
            }

            foreach (FATXEntry x in xEntries)
            {
                if (x.IsFolder)
                {
                    xFolders.Add(new FATXFolderEntry(null, x, this.PartitionName + "/" + x.Name));
                }
                else
                {
                    xFiles.Add(new FATXFileEntry(null, x));
                }
            }

            xExtParts = new List<FATXPartition>();
            for (int i = 0; i < xFiles.Count; i++)
            {
                if (xFiles[i].Name.ToLower() != "extendedsystem.partition")
                    continue;

                var x = new FATXPartition(
                    BlockToOffset(xFiles[i].StartBlock),
                    xFiles[i].Size, xdrive, xFiles[i].Name);

                if (!x.IsValid)
                    continue;

                xExtParts.Add(x);
                xFiles.RemoveAt(i--);
            }
        }
예제 #16
0
 public FATXEntry(FATXEntry parent, ref FATXEntry xEntry)
 {
     this.Parent = parent;
     //Debug.WriteLine("fatx entry ref");
     xOffset = xEntry.xOffset;
     xNLen = xEntry.xNLen;
     xName = xEntry.xName;
     xStartBlock = xEntry.xStartBlock;
     xSize = xEntry.xSize;
     xT1 = xEntry.xT1;
     xT2 = xEntry.xT2;
     xT3 = xEntry.xT3;
     xIsValid = xEntry.xIsValid;
     xIsFolder = xEntry.IsFolder;
     xPart = xEntry.xPart;
     xDrive = xEntry.xDrive;
     fatType = xEntry.fatType;
     this.xPart = xEntry.xPart;
     this.FatEntry = xEntry.FatEntry;
 }
예제 #17
0
        internal FATXPartition(long xOffset, long xPartitionSize, FATXDrive xDrive, string xLocaleName)
        {
            xdrive = xDrive;
            xName  = xLocaleName;
            xBase  = xOffset;
            xDrive.GetIO();
            xDrive.xIO.IsBigEndian = true;
            xDrive.xIO.Position    = xOffset;
            if (xDrive.xIO.ReadUInt32() != 0x58544146)
            {
                return;
            }
            xDrive.xIO.ReadBytes(4); // Partition ID
            SectorsPerBlock = xDrive.xIO.ReadUInt32();
            uint blockct = (uint)(xPartitionSize / xBlockSize);

            if (blockct < 0xFFF5)
            {
                FatType = FATXType.FATX16;
            }
            else
            {
                FatType = FATXType.FATX32;
            }
            uint dirblock = xdrive.xIO.ReadUInt32();

            xFATSize  = (int)(blockct * (byte)FatType);
            xFATSize += (0x1000 - (xFATSize % 0x1000));
            xTable    = new AllocationTable(new DJsIO(true), (uint)((xPartitionSize - 0x1000 - xFATSize) / xBlockSize), FatType);
            xTable.xAllocTable.Position = 0;
            xDrive.xIO.Position         = xFATLocale;
            for (int i = 0; i < xFATSize; i += 0x1000)
            {
                xTable.xAllocTable.Write(xdrive.xIO.ReadBytes(0x1000));
            }
            xTable.xAllocTable.Flush();
            long DirOffset = BlockToOffset(dirblock);

            xFolders = new List <FATXFolderEntry>();
            xFiles   = new List <FATXFileEntry>();
            List <FATXEntry> xEntries = new List <FATXEntry>();

            for (byte x = 0; x < xEntryCount; x++)
            {
                xDrive.xIO.Position = DirOffset + (0x40 * x);
                FATXEntry z = new FATXEntry((DirOffset + (0x40 * x)), xdrive.xIO.ReadBytes(0x40), ref xdrive);
                z.SetAtts(this);
                if (z.xIsValid)
                {
                    xEntries.Add(z);
                }
                else if (z.xNLen != 0xE5)
                {
                    break;
                }
            }
            foreach (FATXEntry x in xEntries)
            {
                if (x.IsFolder)
                {
                    xFolders.Add(new FATXFolderEntry(x, ref xdrive));
                }
                else
                {
                    xFiles.Add(new FATXFileEntry(x, ref xdrive));
                }
            }
            xExtParts = new List <FATXPartition>();
            for (int i = 0; i < xFiles.Count; i++)
            {
                if (xFiles[i].Name.ToLower() != "extendedsystem.partition")
                {
                    continue;
                }
                FATXPartition x = new FATXPartition(BlockToOffset(xFiles[i].StartBlock), xFiles[i].Size, xdrive, xFiles[i].Name);
                if (!x.IsValid)
                {
                    continue;
                }
                xExtParts.Add(x);
                xFiles.RemoveAt(i--);
            }
        }
예제 #18
0
        public FATXReadContents xRead()
        {
            FATXReadContents xreturn = new FATXReadContents();
            try
            {
                xDrive.GetIO();

                if (!Partition.xTable.xAllocTable.Accessed)
                {
                    return null;
                }
                List<FATXEntry> xEntries = new List<FATXEntry>();
                uint[] xBlocks = Partition.xTable.GetBlocks(xStartBlock);

                for (int i = 0; i < xBlocks.Length; i++)
                {
                    long xCurrent = Partition.BlockToOffset(xBlocks[i]);
                    if (xCurrent == -1)
                        break;

                    for (int x = 0; x < Partition.xEntryCount; x++)
                    {
                        xDrive.xIO.Position = xCurrent + (0x40 * x);
                        FATXEntry z = new FATXEntry(Partition.FatType,
                            (xCurrent + (0x40 * x)),
                            xDrive.xIO.ReadBytes(0x40),
                            ref xDrive);

                        z.SetAtts(Partition);

                        if (z.xIsValid)
                        {
                            xEntries.Add(z);
                        }
                        else
                        {
                            if (z.xNLen != 0xE5)
                                break;
                        }
                    }
                }
                xreturn.xfolds = new List<FATXFolderEntry>();
                xreturn.xfiles = new List<FATXFileEntry>();
                for (int i = 0; i < xEntries.Count; i++)
                {
                    if (xEntries[i].IsFolder)
                    {
                        if (string.Compare(xEntries[i].Name, this.Name, true) != 0)
                        {
                            var f = new FATXFolderEntry(this, xEntries[i], Path + "/" + xEntries[i].Name);

                            xreturn.xfolds.Add(f);
                        }
                    }
                    else
                    {
                        var f = new FATXFileEntry(this, xEntries[i]);

                        xreturn.xfiles.Add(f);
                    }
                }
                return xreturn;
            }
            catch { return (xreturn = null); }
        }
예제 #19
0
파일: Entries.cs 프로젝트: VictorOverX/X360
 internal FATXReadContents xRead()
 {
     FATXReadContents xreturn = new FATXReadContents();
     try
     {
         xDrive.GetIO();
         List<FATXEntry> xEntries = new List<FATXEntry>();
         uint[] xBlocks = Partition.xTable.GetBlocks(xStartBlock);
         for (int i = 0; i < xBlocks.Length; i++)
         {
             long xCurrent = Partition.BlockToOffset(xBlocks[i]);
             if (xCurrent == -1)
                 break;
             for (int x = 0; x < Partition.xEntryCount; x++)
             {
                 xDrive.xIO.Position = xCurrent + (0x40 * x);
                 FATXEntry z = new FATXEntry((xCurrent + (0x40 * x)), xDrive.xIO.ReadBytes(0x40), ref xDrive);
                 z.SetAtts(Partition);
                 if (z.xIsValid)
                     xEntries.Add(z);
                 else if (z.xNLen != 0xE5)
                         break;
             }
         }
         xreturn.xfolds = new List<FATXFolderEntry>();
         xreturn.xfiles = new List<FATXFileEntry>();
         for (int i = 0; i < xEntries.Count; i++)
         {
             if (xEntries[i].IsFolder)
                 xreturn.xfolds.Add(new FATXFolderEntry(xEntries[i], ref xDrive));
             else xreturn.xfiles.Add(new FATXFileEntry(xEntries[i], ref xDrive));
         }
         return xreturn;
     }
     catch { return (xreturn = null); }
 }
예제 #20
0
 public FATXFolderEntry(FATXEntry parent, FATXEntry xEntry, string path)
     : base(parent, ref xEntry)
 {
     this.Path = path;
 }
예제 #21
0
        /// <summary>
        /// Adds a file
        /// </summary>
        /// <param name="FileName"></param>
        /// <param name="FileLocation"></param>
        /// <param name="xType"></param>
        /// <returns></returns>
        public bool AddFile(string FileName, string FileLocation, AddType xType)
        {
            FileName.IsValidXboxName();
            if (xDrive.ActiveCheck())
            {
                return(false);
            }
            DJsIO xIOIn = null;

            try { xIOIn = new DJsIO(FileLocation, DJFileMode.Open, true); }
            catch { return(xDrive.xActive = false); }
            try
            {
                FATXReadContents xconts = xRead();
                foreach (FATXFileEntry x in xconts.xfiles)
                {
                    if (x.Name == FileName)
                    {
                        bool xreturn = false;
                        if (xType == AddType.NoOverWrite)
                        {
                            return(xDrive.xActive = false);
                        }
                        else if (xType == AddType.Inject)
                        {
                            xreturn = x.xInject(xIOIn);
                        }
                        else
                        {
                            xreturn = x.xReplace(xIOIn);
                        }
                        return(xreturn & !(xDrive.xActive = false));
                    }
                }
                uint xnew = 0;
                long xpos = GetNewEntryPos(out xnew);
                if (xpos == -1)
                {
                    return(xDrive.xActive = false);
                }
                uint[] blocks = Partition.xTable.GetNewBlockChain(xIOIn.BlockCountFATX(Partition), xnew + 1);
                if (blocks.Length == 0)
                {
                    return(xDrive.xActive = false);
                }
                if (!Partition.WriteFile(blocks, ref xIOIn))
                {
                    return(xDrive.xActive = false);
                }
                FATXEntry y = new FATXEntry(FileName, blocks[0], (int)xIOIn.Length, xpos, false, ref xDrive);
                if (!y.xWriteEntry())
                {
                    return(xDrive.xActive = false);
                }
                if (xnew > 0)
                {
                    List <uint> fileblocks = new List <uint>(Partition.xTable.GetBlocks(xStartBlock));
                    fileblocks.Add(xnew);
                    uint[] xtemp = fileblocks.ToArray();
                    if (!Partition.xTable.WriteChain(ref xtemp))
                    {
                        return(xDrive.xActive = false);
                    }
                }
                if (!Partition.xTable.WriteChain(ref blocks))
                {
                    return(xDrive.xActive = false);
                }
                if (Partition.WriteAllocTable())
                {
                    return(!(xDrive.xActive = false));
                }
                return(xDrive.xActive = false);
            }
            catch { xIOIn.Close(); return(xDrive.xActive = false); }
        }
예제 #22
0
 internal FATXFileEntry(FATXEntry x, ref FATXDrive xdrive)
     : base(ref x, ref xdrive)
 {
 }
예제 #23
0
 internal FATXFolderEntry(FATXEntry xEntry, ref FATXDrive xdrive) : base(ref xEntry, ref xdrive)
 {
 }
예제 #24
0
파일: Entries.cs 프로젝트: VictorOverX/X360
 internal FATXPartition(long xOffset, long xPartitionSize, FATXDrive xDrive, string xLocaleName)
 {
     xdrive = xDrive;
     xName = xLocaleName;
     xBase = xOffset;
     xDrive.GetIO();
     xDrive.xIO.IsBigEndian = true;
     xDrive.xIO.Position = xOffset;
     if (xDrive.xIO.ReadUInt32() != 0x58544146)
         return;
     xDrive.xIO.ReadBytes(4); // Partition ID
     SectorsPerBlock = xDrive.xIO.ReadUInt32();
     uint blockct = (uint)(xPartitionSize / xBlockSize);
     if (blockct < 0xFFF5)
         FatType = FATXType.FATX16;
     else FatType = FATXType.FATX32;
     uint dirblock = xdrive.xIO.ReadUInt32();
     xFATSize = (int)(blockct * (byte)FatType);
     xFATSize += (0x1000 - (xFATSize % 0x1000));
     xTable = new AllocationTable(new DJsIO(true), (uint)((xPartitionSize - 0x1000 - xFATSize) / xBlockSize), FatType);
     xTable.xAllocTable.Position = 0;
     xDrive.xIO.Position = xFATLocale;
     for (int i = 0; i < xFATSize; i += 0x1000)
         xTable.xAllocTable.Write(xdrive.xIO.ReadBytes(0x1000));
     xTable.xAllocTable.Flush();
     long DirOffset = BlockToOffset(dirblock);
     xFolders = new List<FATXFolderEntry>();
     xFiles = new List<FATXFileEntry>();
     List<FATXEntry> xEntries = new List<FATXEntry>();
     for (byte x = 0; x < xEntryCount; x++)
     {
         xDrive.xIO.Position = DirOffset + (0x40 * x);
         FATXEntry z = new FATXEntry((DirOffset + (0x40 * x)), xdrive.xIO.ReadBytes(0x40), ref xdrive);
         z.SetAtts(this);
         if (z.xIsValid)
             xEntries.Add(z);
         else if (z.xNLen != 0xE5)
             break;
     }
     foreach (FATXEntry x in xEntries)
     {
         if (x.IsFolder)
             xFolders.Add(new FATXFolderEntry(x, ref xdrive));
         else xFiles.Add(new FATXFileEntry(x, ref xdrive));
     }
     xExtParts = new List<FATXPartition>();
     for (int i = 0; i < xFiles.Count; i++)
     {
         if (xFiles[i].Name.ToLower() != "extendedsystem.partition")
             continue;
         FATXPartition x = new FATXPartition(BlockToOffset(xFiles[i].StartBlock), xFiles[i].Size, xdrive, xFiles[i].Name);
         if (!x.IsValid)
             continue;
         xExtParts.Add(x);
         xFiles.RemoveAt(i--);
     }
 }
예제 #25
0
        /* Note: Have plans for safer and better manipulation to prevent
         * minimal block loss to human error */
        /// <summary>
        /// Adds a folder
        /// </summary>
        /// <param name="FolderName"></param>
        /// <returns></returns>
        public bool AddFolder(string FolderName)
        {
            if (!VariousFunctions.IsValidXboxName(FolderName))
                return false;

            if (xDrive.ActiveCheck())
                return false;
            try
            {
                FATXReadContents xconts = xRead();
                if (xconts == null)
                    return false;
                foreach (FATXFolderEntry x in xconts.xfolds)
                {
                    if (string.Compare(x.Name , FolderName,true)==0)
                        return (xDrive.xActive = false);
                }

                var b = new byte[Partition.xBlockSize];
                for (int x = 0; x < 4; x++)
                    b[x] = 0x00;

                for (int x = 4; x < b.Length; x++)
                {
                    b[x] = 0xFF;
                }
                DJsIO xIOIn = new DJsIO(b, true);
                uint xnew = 0;
                long xpos = GetNewEntryPos(out xnew);
                if (xpos == -1)
                    return (xDrive.xActive = false);

                var blockCount = xIOIn.BlockCountFATX(Partition);
                var xnewIndex = xnew + 1;

                uint[] blocks = Partition.xTable.GetNewBlockChain(blockCount, xnewIndex);
                if (blocks.Length == 0)
                    return (xDrive.xActive = false);

                if (!Partition.WriteFile(blocks, ref xIOIn))
                    return (xDrive.xActive = false);

                FATXEntry y = new FATXEntry(this, FolderName, blocks[0],
                    (int)xIOIn.Length, xpos, true, ref xDrive);

                //y.FatEntry = new FATXEntry64(xData);

                y.SetAtts(this.Partition);
                if (!y.xWriteEntry())
                    return (xDrive.xActive = false);

                if (xnew > 0)
                {
                    var fileblocks = Partition.xTable.GetBlocks(xStartBlock).ToList();
                    fileblocks.Add(xnew);

                    uint[] xtemp = fileblocks.ToArray();

                    if (!Partition.xTable.WriteChain(ref xtemp))
                        return (xDrive.xActive = false);
                }

                if (!Partition.xTable.WriteChain(ref blocks))
                    return (xDrive.xActive = false);

                if (Partition.WriteAllocTable())
                    return !(xDrive.xActive = false);

                return (xDrive.xActive = false);
            }
            catch { return xDrive.xActive = false; }
        }