/* 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); } }
/* 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; } }
/// <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); } }
/* 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; } }
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); } }
/// <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); } }