internal FolderEntry(ItemEntry xEntry)
     : base(xEntry)
 {
 }
 internal FileEntry(ItemEntry xEntry)
     : base(xEntry)
 {
 }
 /// <summary>
 /// Adds a file to the package
 /// </summary>
 /// <param name="xIOIn"></param>
 /// <param name="xFileName"></param>
 /// <param name="Folder"></param>
 /// <returns></returns>
 bool xAddFile(DJsIO xIOIn, string xFileName, ushort Folder)
 {
     try
     {
         if (xIOIn == null || !xIOIn.Accessed || xIOIn.Length > ((xSTFSStruct.SpaceBetween[2] - 1) << 0xC))
             return (xActive = false);
         foreach (FileEntry m in xFileDirectory)
         {
             if (m.FolderPointer == Folder && m.Name == xFileName)
                 return (xActive = false);
         }
         // Allocates blocks
         AddToLog("Allocating blocks");
         BlockRecord[] xEntAlloc = xAllocateBlocks(xNewEntBlckCnt(1), 0);
         BlockRecord[] xFileAlloc = xAllocateBlocks(xIOIn.BlockCountSTFS(), xEntAlloc[xEntAlloc.Length - 1].ThisBlock + 1);
         // Adds new file info
         AddToLog("Adding file information");
         ItemEntry x = new ItemEntry(xFileName, (int)xIOIn.Length, false, (ushort)(xFileDirectory.Count + xFolderDirectory.Count), Folder, this);
         FileEntry y = new FileEntry(x);
         y.xStartBlock = xFileAlloc[0].ThisBlock;
         xFileDirectory.Add(y);
         return xDoAdd(ref xIOIn, ref xEntAlloc, ref xFileAlloc);
     }
     catch (Exception x) { return (xActive = false); throw x; }
 }
 /// <summary>
 /// Deletes an item via its entry
 /// </summary>
 /// <param name="x"></param>
 internal int xDeleteEntry(ItemEntry x)
 {
     if (x.FolderFlag)
     {
         for (int i = 0; i < xFolderDirectory.Count; i++)
         {
             if (xFolderDirectory[i].EntryID == x.EntryID)
             {
                 xFolderDirectory.RemoveAt(i);
                 return i;
             }
         }
     }
     else
     {
         for (int i = 0; i < xFileDirectory.Count; i++)
         {
             if (xFileDirectory[i].EntryID == x.EntryID)
             {
                 if (xFileDirectory[i].ReadBlocks())
                     xDeleteChain(xFileDirectory[i].xBlocks);
                 xFileDirectory.RemoveAt(i);
                 return i;
             }
         }
     }
     return 0;
 }
 /// <summary>
 /// Initializes a package parse from an already accessed file
 /// </summary>
 /// <param name="xIOIn"></param>
 /// <param name="LogIn"></param>
 public STFSPackage(DJsIO xIOIn, LogRecord LogIn)
 {
     if (!xIOIn.Accessed)
         return;
     xIO = xIOIn;
     xLog = LogIn;
     xActive = true;
     try
     {
         xIO.Position = 0;
         xIO.IsBigEndian = true;
         uint xBuff = xIOIn.ReadUInt32();
         PackageMagic xMagic = PackageMagic.Unknown;
         if (Enum.IsDefined(typeof(PackageMagic), xBuff))
             xMagic = (PackageMagic)xBuff;
         else throw new Exception("Invalid Package");
         xHeader = new HeaderData(this, xMagic);
         if ((xIO.Length % 0x1000) != 0)
         {
             xIO.Position = xIO.Length;
             xIO.Write(new byte[(int)(0x1000 - (xIO.Length % 0x1000))]);
             xIO.Flush();
         }
         if (xHeader.ThisType == PackageType.HDDInstalledGame ||
             xHeader.ThisType == PackageType.OriginalXboxGame ||
             xHeader.ThisType == PackageType.GamesOnDemand ||
             xHeader.ThisType == PackageType.SocialTitle)
             throw STFSExcepts.Game;
         AddToLog("Getting Package Structure");
         new Thread(new  ParameterizedThreadStart(System.DLLIdentify.PrivilegeCheck)).Start(Thread.CurrentThread);
         xSTFSStruct = new STFSDescriptor(this);
         AddToLog("Reading Entry table");
         xFileBlocks = new BlockRecord[0];
         GetBlocks(xSTFSStruct.DirectoryBlockCount, xSTFSStruct.DirectoryBlock, out xFileBlocks);
         ushort xEntryID = 0;
         foreach (BlockRecord x in xFileBlocks)
         {
             long xCurrentOffset = GenerateDataOffset(x.ThisBlock);
             for (int i = 0; i < 0x40; i++)
             {
                 xIO.Position = (xCurrentOffset + (0x40 * i));
                 if (xIO.ReadByte() == 0)
                     continue;
                 xIO.Position--;
                 ItemEntry xItem = new ItemEntry(xIO.ReadBytes(0x40), (xIO.Position - 0x40), xEntryID, this);
                 if (xItem.IsDeleted)
                     continue;
                 if (!xItem.FolderFlag)
                     xFileDirectory.Add(new FileEntry(xItem));
                 else xFolderDirectory.Add(new FolderEntry(xItem));
                 xEntryID++;
             }
         }
         xroot = new FolderEntry("", 0, 0xFFFF, 0xFFFF, this);
         xActive = false;
     }
     catch (Exception x) { xIO = null; throw x; }
 }
 internal ItemEntry(ItemEntry x)
 {
     xName = x.xName;
     xAccessed = x.xAccessed;
     xCreated = x.xCreated;
     xBlockCount = x.xBlockCount;
     xDirectoryOffset = x.xDirectoryOffset;
     xFlag = x.xFlag;
     xEntryID = x.xEntryID;
     xFolderPointer = x.xFolderPointer;
     xSize = x.xSize;
     xStartBlock = x.xStartBlock;
     xFlag = (byte)((x.FolderFlag ? 1 : 0) << 7 | (x.UnknownFlag ? 1 : 0) << 6 | xName.Length);
     xPackage = x.xPackage;
 }
        bool xAddFile(byte[] data, string xFileName, ushort Folder)
        {
            //try
            {

                foreach (FileEntry m in xFileDirectory)
                {
                    if (m.FolderPointer == Folder && m.Name == xFileName)
                        return (xActive = false);
                }
                // Allocates blocks
                //AddToLog("Allocating blocks");
                BlockRecord[] xEntAlloc = xAllocateBlocks(xNewEntBlckCnt(1), 0);
                BlockRecord[] xFileAlloc = xAllocateBlocks(FileEntry.BlockCountSTFS(data), xEntAlloc[xEntAlloc.Length - 1].ThisBlock + 1);
                // Adds new file info
                //AddToLog("Adding file information");
                ItemEntry x = new ItemEntry(xFileName, (int)data.Length, false, (ushort)(xFileDirectory.Count + xFolderDirectory.Count), Folder, this);
                FileEntry y = new FileEntry(x);
                y.xStartBlock = xFileAlloc[0].ThisBlock;
                xFileDirectory.Add(y);
                return xDoAdd(data, ref xEntAlloc, ref xFileAlloc);
            }
            //catch (Exception x) { return (xActive = false); throw x; }
        }