/// <summary> /// Returns the remaining size of a file/folder /// </summary> public long RemainingData(File f) { long length = (long)(f.BlocksOccupied.Length - 1) * f.PartInfo.ClusterSize; return f.Size - length; }
public bool OverWriteFile(File FileToOverwrite, string FilePath, ref int Progress, ref int BlocksToWrite) { FATX_Browser.FATX.IOReader br = null; //Do a try... try { //Create our new fatstuff to get our free blocks FATStuff fs = new FATStuff(FileToOverwrite); //Get our blocks needed int BlocksNeeded = (int)(m.UpToNearestCluster(new System.IO.FileInfo(FilePath).Length, FileToOverwrite.PartInfo.ClusterSize) / FileToOverwrite.PartInfo.ClusterSize); //Create our block array for the blocks we do have uint[] BlocksWeHave = FileToOverwrite.BlocksOccupied; //If we have more blocks than we need already... if ((int)FileToOverwrite.BlocksOccupied.Length > BlocksNeeded) { //Get our blocks that we're going to clear... List<uint> BlocksList = FileToOverwrite.BlocksOccupied.ToList<uint>(); //Remove the blocks we need from the list of blocks to overwrite BlocksList.RemoveRange(0x0, (int)((int)FileToOverwrite.BlocksOccupied.Length - BlocksNeeded)); //Finalize uint[] BlocksToFree = BlocksList.ToArray(); //Clears the blocks. ClearFATChain(BlocksToFree, FileToOverwrite); //Make the final block in the series the ending block by writing 0xFFFF to it uint EndBlock = FileToOverwrite.BlocksOccupied[(FileToOverwrite.BlocksOccupied.Length - 1) - BlocksNeeded]; if (FileToOverwrite.PartInfo.EntrySize == Info.PartitionBit.FATX16) { WriteBlock(EndBlock, new byte[] { 0xFF, 0xFF }, FileToOverwrite); } else { WriteBlock(EndBlock, new byte[] { 0xFF, 0xFF, 0xFF, 0xFF }, FileToOverwrite); } BlocksList = FileToOverwrite.BlocksOccupied.ToList<uint>(); BlocksList.RemoveRange(0x0, (FileToOverwrite.BlocksOccupied.Length - 1) - BlocksNeeded); BlocksWeHave = BlocksList.ToArray(); } else if ((int)FileToOverwrite.BlocksOccupied.Length < BlocksNeeded) { //Get the number of blocks we REALLY need int RealBlocksNeeded = BlocksNeeded - FileToOverwrite.BlocksOccupied.Length; //Write out the FAT chain from that last block List<uint> bl = new List<uint>(); bl.Add(FileToOverwrite.BlocksOccupied[FileToOverwrite.BlocksOccupied.Length - 1]); uint[] newBlocks = new FATStuff(FileToOverwrite).GetFreeBlocks(RealBlocksNeeded, bl[0], 0, false); bl.AddRange(newBlocks); //Set the BlocksWeHave BlocksWeHave = bl.ToArray(); } //Create our binary reader to read our file br = new FATX_Browser.FATX.IOReader(new System.IO.FileStream(FilePath, System.IO.FileMode.Open)); for (int i = 0; i < BlocksWeHave.Length; i++) { WriteToCluster(m.GetBlockOffset(BlocksWeHave[i], FileToOverwrite), br.ReadBytes(0x200)); } br.Close(); return true; } catch (Exception e) { try { br.Close(); } catch { } throw e; } }
private bool DeleteInternal(File f, ref long progressUpdate, ref long progressMax, ref string CurrentFile) { return true; }
public bool Delete(File f, ref long ProgressUpdate, ref long ProgressMax, ref string CurrentFile) { return DeleteInternal(f, ref ProgressUpdate, ref ProgressMax, ref CurrentFile); }
public bool OverWriteFile(File FileToOverwrite, string FilePath) { int p = 0; int d = 0; return OverWriteFile(FileToOverwrite, FilePath, ref p, ref d); }
public bool Delete(File f) { long ProgressUpdate = 0; long ProgressMax = 0; string CurrentFile = ""; return DeleteInternal(f, ref ProgressUpdate, ref ProgressMax, ref CurrentFile); }
internal bool ExtractFileInternal(File f, FATX_Browser.FATX.IOWriter outIO, ref long sizeWritten, ref long maxVal) { //Create our binaryreader FATX_Browser.FATX.IOReader br; try { //Create our new misc class Misc m = new Misc(); //Create our blocks occupied list to speed some things up if the //blocks haven't been loaded yet System.Diagnostics.Stopwatch s = new System.Diagnostics.Stopwatch(); s.Start(); List<uint> BlocksOccupied = f.BlocksOccupied.ToList<uint>(); maxVal = BlocksOccupied.Count; if (BlocksOccupied.Count >= 1) { //Get our IO... br = xDrive.GetIO(); //For each loop increase our sizewritten, and keep looping //until we've reached the block BEFORE the final (size may not //be 0x4000 bytes) for (int i = 0; i < BlocksOccupied.Count - 1; i++, sizeWritten++) { //Get and set our reader position long position = m.GetBlockOffset(BlocksOccupied.ToArray()[i], f.PartInfo); br.BaseStream.Position = position; //Write to our output file what we just read outIO.Write(br.ReadBytes((int)f.PartInfo.ClusterSize)); br.BaseStream.Flush(); outIO.BaseStream.Flush(); } //KAY, now we've reached the final block in the series br.BaseStream.Position = m.GetBlockOffset(BlocksOccupied.ToArray()[BlocksOccupied.Count - 1], f); //Right here, we read the remaining data, and write it all //in one swoop outIO.Write(m.ReadBytes(ref br, m.RemainingData(f))); br.BaseStream.Flush(); outIO.BaseStream.Flush(); //Close our IO's br.Close(); outIO.Close(); sizeWritten++; return true; } return false; } catch (Exception e) { outIO.Close(); throw e; } }
/// <summary> /// Returns a folder when given a path /// </summary> /// <param name="path">The path to the folder</param> //public Folder GetFolder(string path) //{ // //Create our folder for the root // string[] FolderNames = path.Split('\\'); // Folder PartitionEntries = new Folder(DeviceID, Partition); // PartitionEntries.EData.StartingCluster = 1; // //Call to our function that will return our folder // return GetOurFolder(PartitionEntries, FolderNames, 0); //} //private Folder GetOurFolder(Folder f, string[] names, int startIndex) //{ // //Create our array of subfolders // Folder[] subs = f.SubFolders(); // //Loop for each folder in our subfolder // foreach (Folder g in subs) // { // //If the subfolder name matches the name for our desired index // if (g.Name == names[startIndex]) // { // //If we're not at the end of our name array... // if (!(startIndex == names.Length - 1)) // { // //Loop again for the next in the index // GetOurFolder(g, names, startIndex++); // } // //If we ARE in the end of our name array // else // { // //Return our folder // return g; // } // } // } // //The folder was not found, return null // return null; //} /// <summary> /// Returns an array of files and folders for a folder /// </summary> /// <param name="block">The block to read from</param> public object[] LoadEntries(Folder f, bool ShowDeletedEntries) { //Build our list of entry data List<EntryData> eList = new List<EntryData>(); //Build our list for files List<File> fileList = new List<File>(); //Build our list for folders List<Folder> folderList = new List<Folder>(); //For each block this shit occupies for (int i = 0; i < f.BlocksOccupied.Length; i++) { //Builds our list of entry data eList.AddRange(GetEntries(f.BlocksOccupied[i])); } //For each entry in our entry data EntryData[] eArray = eList.ToArray(); foreach (EntryData e in eArray) { //If the entry is a folder if (e.Size == 0) { Folder folder = new Folder(xDrive, Partition); folder.Drive = xDrive; folder.EData = e; folder.PartInfo = ((Folder)Holder).PartInfo; if (e.FileNameSize == 0xE5) { folder.IsDeleted = true; folder.EData.FileName = folder.EData.FileName.Remove(folder.EData.FileName.IndexOf('?')); } folderList.Add(folder); } //If the shit is a file else if (e.FileNameSize > 0x00) { //If the entry is a folder if (e.Flags == 0x10) { //Do nothing } else if (e.Size == 0 && e.StartingCluster == 0) { File file = new File(xDrive, Partition); file.Drive = xDrive; file.EData = e; file.PartInfo = ((Folder)Holder).PartInfo; if (e.FileNameSize == 0xE5) { file.IsDeleted = true; file.EData.FileName = file.EData.FileName.Remove(file.EData.FileName.IndexOf('?')); } fileList.Add(file); } else { File file = new File(xDrive, Partition); file.Drive = xDrive; file.EData = e; file.PartInfo = ((Folder)Holder).PartInfo; if (e.FileNameSize == 0xE5) { file.IsDeleted = true; file.EData.FileName = file.EData.FileName.Remove(file.EData.FileName.IndexOf('?')); } fileList.Add(file); } } } return new object[] { folderList.ToArray(), fileList.ToArray() }; }
/// <summary> /// Returns an array of files for the specified block /// </summary> /// <param name="block">The block to read from</param> public File[] Files(uint block) { List<File> fList = new List<File>(); foreach (EntryData data in GetEntries(block)) { if (data.FileNameSize != 0xE5 && data.FileNameSize > 0x00) { //If the entry is a folder if (data.Size == 0 && data.StartingCluster != 0) { //Do nothing } else { File file = new File(xDrive, Partition); file.Drive = xDrive; file.EData = data; file.PartInfo = ((Folder)Holder).PartInfo; fList.Add(file); } } } return fList.ToArray(); }
/// <summary> /// Extracts your file to the specified path /// </summary> /// <param name="f">File to extract</param> /// <param name="path">Path to extract the file to</param> /// <param name="sizeWritten">Used for updating progress on the file(not necessary)</param> /// <param name="maxVal">Used for updating the file size (not necessary)</param> public bool ExtractFile(File f, string path, ref long sizeWritten, ref long maxVal) { //try // { Misc m = new Misc(); //Create our binary writer FATX_Browser.FATX.IOWriter bw = new FATX_Browser.FATX.IOWriter(new System.IO.FileStream(path, System.IO.FileMode.Create)); //Set our maxVal maxVal = f.Block; sizeWritten = 0; return ExtractFileInternal(f, bw, ref sizeWritten, ref maxVal); // } //catch { return false; } }