internal bool xReplace(DJsIO xIOin)
 {
     if (!Opened)
         ReadBlocks();
     if (!xIOin.Accessed || xIOin.Length > 0xFFFFFFFF)
         return false;
     try
     {
         // Allocates new blocks for new data
         xPackage.AddToLog("Allocating blocks");
         BlockRecord[] xEntAlloc = xPackage.xAllocateBlocks(xPackage.xCurEntBlckCnt, 0);
         BlockRecord[] xFileAlloc = xPackage.xAllocateBlocks(xIOin.BlockCountSTFS(), xEntAlloc[xEntAlloc.Length - 1].ThisBlock + 1);
         // Updates entry
         xPackage.AddToLog("Updating entry");
         xStartBlock = xFileAlloc[0].ThisBlock;
         xSize = (int)xIOin.Length;
         xBlockCount = xIOin.BlockCountSTFS();
         if (xPackage.xDoAdd(ref xIOin, ref xEntAlloc, ref xFileAlloc))
         {
             xPackage.xDeleteChain(xBlocks);
             ClearBlocks();
             return true;
         }
         return false;
     }
     catch { ClearBlocks(); return false; }
 }
 /// <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; }
 }
 internal bool xInject(DJsIO xIOin)
 {
     if (!Opened && !ReadBlocks())
         return false;
     try
     {
         if (xIOin.Length > 0xFFFFFFFF)
             return false;
         uint y = xIOin.BlockCountSTFS();
         List<BlockRecord> x = xBlocks.ToList();
         List<BlockRecord> xdel = null;
         if (y > xBlocks.Length)// Allocates data for blocks needed
             x.AddRange(xPackage.xAllocateBlocks((uint)(y - xBlocks.Length), 0));
         else
         {
             xdel = new List<BlockRecord>();
             for (int i = (int)y; i < x.Count; i++)
             {
                 xdel.Add(x[i]);
                 x.RemoveAt(i--);
             }
         }
         bool success = xPackage.xWriteTo(ref xIOin, x.ToArray());
         if (success)
         {
             xBlocks = x.ToArray();
             if (xdel != null && xdel.Count != 0)
                 xPackage.xDeleteChain(xdel.ToArray());
         }
         return (success & ClearBlocks());
     }
     catch { ClearBlocks(); return false; }
 }
 /// <summary>
 /// Writes a file via blocks
 /// </summary>
 /// <param name="xIOIn"></param>
 /// <param name="xBlocks"></param>
 /// <returns></returns>
 internal bool xWriteTo(ref DJsIO xIOIn, BlockRecord[] xBlocks)
 {
     if (!xIOIn.Accessed || (xIOIn.BlockCountSTFS() != xBlocks.Length))
         return false;
     try
     {
         xIOIn.Position = 0;
         for (int i = 0; i < xBlocks.Length - 1; i++)
         {
             // Finds spot and writes block of data
             xIO.Position = GenerateDataOffset(xBlocks[i].ThisBlock);
             xIO.Write(xIOIn.ReadBytes(0x1000));
         }
         xIO.Position = GenerateDataOffset(xBlocks[xBlocks.Length - 1].ThisBlock);
         xIO.Write(xIOIn.ReadBytes(xIOIn.BlockRemainderSTFS()));
         xIO.Flush();
         return true;
     }
     catch { return false; }
 }