Exemplo n.º 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); }
        }
Exemplo n.º 2
0
        internal bool xInject(DJsIO xIOIn)
        {
            List <uint> blocks = new List <uint>(Partition.xTable.GetBlocks(xStartBlock));

            if (blocks.Count == 0)
            {
                throw new Exception();
            }
            uint xct = xIOIn.BlockCountFATX(Partition);

            if (blocks.Count < xct)
            {
                uint[] blocks2 = Partition.xTable.GetNewBlockChain((uint)(xct - blocks.Count), 1);
                if (blocks2.Length == 0)
                {
                    throw new Exception();
                }
                blocks.AddRange(blocks2);
                uint[] x = blocks.ToArray();
                if (!Partition.xTable.WriteChain(ref x))
                {
                    throw new Exception();
                }
            }
            else if (blocks.Count > xct)
            {
                uint[] xUnneeded = new uint[blocks.Count - xct];
                for (uint i = xct; i < blocks.Count; i++)
                {
                    xUnneeded[(int)i] = i;
                    blocks.RemoveAt((int)i--);
                }
                if (!Partition.xTable.DC(ref xUnneeded))
                {
                    throw new Exception();
                }
            }
            xIOIn.Position = 0;
            xDrive.GetIO();
            foreach (uint i in blocks)
            {
                xDrive.xIO.Position = Partition.BlockToOffset(i);
                xDrive.xIO.Write(xIOIn.ReadBytes(Partition.xBlockSize));
            }
            if ((xSize == 0 || (uint)(((xSize - 1) / Partition.xBlockSize) + 1) != xct) &&
                !Partition.WriteAllocTable())
            {
                throw new Exception();
            }
            xSize = (int)xIOIn.Length;
            xIOIn.Close();
            return(xWriteEntry());
        }
Exemplo n.º 3
0
        internal bool xReplace(DJsIO xIOIn)
        {
            uint bu   = xStartBlock;
            int  size = xSize;

            try
            {
                uint[] curblocks = Partition.xTable.GetBlocks(xStartBlock);
                uint[] blocks    = Partition.xTable.GetNewBlockChain(xIOIn.BlockCountFATX(Partition), 1);
                if (blocks.Length == 0)
                {
                    throw new Exception();
                }
                if (!Partition.xTable.WriteChain(ref blocks))
                {
                    throw new Exception();
                }
                if (!Partition.xTable.DC(ref curblocks))
                {
                    throw new Exception();
                }
                xIOIn.Position = 0;
                xDrive.GetIO();
                if (!Partition.WriteFile(blocks, ref xIOIn))
                {
                    throw new Exception();
                }
                if (!Partition.WriteAllocTable())
                {
                    throw new Exception();
                }
                base.xStartBlock = blocks[0];
                base.xSize       = (int)xIOIn.Length;
                xIOIn.Close();
                return(xWriteEntry());
            }
            catch { xIOIn.Close(); base.xStartBlock = bu; base.xSize = size; return(false); }
        }
Exemplo n.º 4
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); }
        }