private void button1_Click(object sender, EventArgs e) { try { System.Threading.ThreadStart ts = delegate { CLKsFATXLib.Streams.Reader OR = Original.Reader(); CLKsFATXLib.Streams.Writer D = Destination.Writer(); OR.BaseStream.Position = 0; D.BaseStream.Position = 0; for (long i = 0; i < Original.Length; i += 0x6000) { D.Write(OR.ReadBytes(0x6000)); progressBar1.Invoke((MethodInvoker) delegate { try { progressBar1.Maximum = (int)(Original.Length >> 4); progressBar1.Value = (int)(((i >> 8) < 0) ? 0 : i >> 4); } catch { } }); } OR.Close(); D.Close(); }; System.Threading.Thread t = new System.Threading.Thread(ts); t.Start(); } catch (Exception x) { MessageBox.Show(x.Message); } }
public void ClearFATChain(uint[] Chain) { Streams.Reader r = Parent.Drive.Reader(); Streams.Writer w = new CLKsFATXLib.Streams.Writer(r.BaseStream); long buffersize = 0x1000; long lastoffset = 0;//VariousFunctions.BlockToFATOffset(Chain[0], Parent).DownToNearestCluster(buffersize); byte[] Buffer = new byte[buffersize]; for (int i = 0; i < Chain.Length; i++) { // Read the chain buffer if (lastoffset != VariousFunctions.BlockToFATOffset(Chain[i], Parent).DownToNearestCluster(0x1000)) { if (i != 0) { w.BaseStream.Position = lastoffset; w.Write(Buffer); } lastoffset = VariousFunctions.BlockToFATOffset(Chain[i], Parent).DownToNearestCluster(0x1000); r.BaseStream.Position = lastoffset; Buffer = r.ReadBytes((int)buffersize); } // Write the chain Streams.Writer mem = new CLKsFATXLib.Streams.Writer(new System.IO.MemoryStream(Buffer)); mem.BaseStream.Position = VariousFunctions.BlockToFATOffset(Chain[i], Parent) - VariousFunctions.BlockToFATOffset(Chain[i], Parent).DownToNearestCluster(0x1000); byte[] writing = new byte[0]; switch (Parent.PartitionInfo.EntrySize) { case 2: writing = BitConverter.GetBytes((ushort)0); break; case 4: writing = BitConverter.GetBytes(0); break; } mem.Write(writing); mem.Close(); if (i == Chain.Length - 1) { w.BaseStream.Position = lastoffset; w.Write(Buffer); } } }
void EntryAction_HandleCreated(object sender, EventArgs e) { if (Aero) { td = new TaskDialog(); } System.Threading.ThreadStart ts = delegate { #if TRACE try { #endif //while (true)//(!this.IsHandleCreated || !progressBar1.IsHandleCreated || !label1.IsHandleCreated || !lPercent.IsHandleCreated || !button1.IsHandleCreated) //{ // try // { // this.Invoke((MethodInvoker)delegate { }); // progressBar1.Invoke((MethodInvoker)delegate { }); // label1.Invoke((MethodInvoker)delegate { }); // lPercent.Invoke((MethodInvoker)delegate { }); // button1.Invoke((MethodInvoker)delegate { }); // break; // } // catch(Exception E) { Application.DoEvents(); } //} if (xDrive != null && m == Method.Backup || m == Method.ExtractJ || m == Method.ExtractSS || m == Method.Restore) { switch (m) { case Method.Backup: this.Invoke((MethodInvoker) delegate { this.Icon = Properties.Resources.Add; }); CLKsFATXLib.Streams.Reader r = xDrive.Reader(); CLKsFATXLib.Streams.Writer w = new CLKsFATXLib.Streams.Writer(new System.IO.FileStream(OutPath, System.IO.FileMode.Create)); int ReadLength = 0x200; if (xDrive.Length % 0x100000 == 0) { ReadLength = 0x100000; } else if (xDrive.Length % 0x40000 == 0) { ReadLength = 0x40000; } else if (xDrive.Length % 0x10000 == 0) { ReadLength = 0x10000; } else if (xDrive.Length % 0x5000 == 0) { ReadLength = 0x5000; } for (int i = 0; i < xDrive.Length / ReadLength; i++) { if (Cancel) { break; } w.Write(r.ReadBytes(ReadLength)); progressBar1.Invoke((MethodInvoker) delegate { try { progressBar1.Maximum = (int)(xDrive.Length / ReadLength); progressBar1.Value = (i + 1); if (Windows7) { tm.SetProgressValue(progressBar1.Value, progressBar1.Maximum); } } catch { } }); this.Invoke((MethodInvoker) delegate { this.Text = "Backing Up Drive"; }); label1.Invoke((MethodInvoker) delegate { label1.Text = (((decimal)(i + 1) / (decimal)(xDrive.Length / ReadLength)) * 100).ToString("#") + "%"; }); } w.Close(); break; case Method.ExtractSS: this.Invoke((MethodInvoker) delegate { this.Icon = Properties.Resources.Add; }); //Create our io for the drive CLKsFATXLib.Streams.Reader io = xDrive.Reader(); //Go to the location of the security sector io.BaseStream.Position = 0x2000; //Create our ref io for the file CLKsFATXLib.Streams.Writer bw = new CLKsFATXLib.Streams.Writer(new System.IO.FileStream(OutPath, System.IO.FileMode.Create)); //Read the sector. The size is an estimation, since I have no idea how big it really is bw.Write(io.ReadBytes(0xE00)); //Close our io bw.Close(); break; case Method.ExtractJ: this.Invoke((MethodInvoker) delegate { this.Icon = Properties.Resources.Add; }); //Create our io for the drive CLKsFATXLib.Streams.Reader io2 = xDrive.Reader(); //Go to the location of the security sector io2.BaseStream.Position = 0x800; //Create our ref io for the file CLKsFATXLib.Streams.Writer bw2 = new CLKsFATXLib.Streams.Writer(new System.IO.FileStream(OutPath, System.IO.FileMode.Create)); //Read the sector. The size is an estimation, since I have no idea how big it really is bw2.Write(io2.ReadBytes(0x400)); //Close our io bw2.Close(); break; case Method.Restore: this.Invoke((MethodInvoker) delegate { this.Icon = Properties.Resources.Remove; }); if (MessageBox.Show("WARNING: Restoring a drive that does not match your current one can cause for data to not be read correctly by the Xbox 360, or for other unforseen problems! Please make sure you know what you're doing before continuing. Are you sure you want to continue?", "WARNING AND STUFF", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { if (MessageBox.Show("This is your last chance to stop! Are you POSITIVE you want to continue?", "Last Chance!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { CLKsFATXLib.Streams.Reader r2 = new CLKsFATXLib.Streams.Reader(new System.IO.FileStream(OutPath, System.IO.FileMode.Open)); CLKsFATXLib.Streams.Writer w2 = xDrive.Writer(); int ReadLength2 = 0x200; if (xDrive.Length % 0x4000 != 0) { ReadLength2 = 0x4000; } else { for (int i = 0x300000; i > 0x200; i -= 0x1000) { if (xDrive.Length % i == 0) { ReadLength2 = i; break; } } } for (int i = 0; i < xDrive.Length / ReadLength2; i++) { if (Cancel) { break; } w2.Write(r2.ReadBytes(ReadLength2)); progressBar1.Invoke((MethodInvoker) delegate { try { progressBar1.Maximum = (int)(xDrive.Length / ReadLength2); progressBar1.Value = (i + 1); if (Windows7) { tm.SetProgressValue(progressBar1.Value, progressBar1.Maximum); } } catch { } }); this.Invoke((MethodInvoker) delegate { this.Text = "Restoring Drive"; }); label1.Invoke((MethodInvoker) delegate { label1.Text = (((decimal)(i + 1) / (decimal)(xDrive.Length / ReadLength2)) * 100).ToString("#") + "%"; }); } r2.Close(); } } break; } } else { Folder ParentFolder = null; this.Invoke((MethodInvoker) delegate { ParentFolder = Parent; }); switch (m) { case Method.Extract: #if DEBUG System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); if (Timer) { sw.Start(); } #endif this.Invoke((MethodInvoker) delegate { this.Icon = Properties.Resources.Add; }); foreach (Entry entry in Entries) { if (!entry.IsFolder) { ((File)entry).FileAction += new CLKsFATXLib.Structs.FileActionChanged(EntryAction_FileAction); this.Invoke((MethodInvoker) delegate { this.Text = entry.FullPath; }); label1.Invoke((MethodInvoker) delegate { label1.Text = entry.Name; }); // Check to see if we're batch-extracting... if (Entries.Length == 1) { ((File)entry).Extract(OutPath); } else { ((File)entry).Extract(OutPath + "\\" + entry.Name); } } else { ((Folder)entry).FolderAction += new CLKsFATXLib.Structs.FolderActionChanged(EntryAction_FolderAction); ((Folder)entry).Extract(OutPath, EntriesToSkip); } if (Cancel) { break; } } #if DEBUG if (Timer) { sw.Stop(); MessageBox.Show(string.Format("{0}:{1}:{2}", sw.Elapsed.Minutes, sw.Elapsed.Seconds, sw.Elapsed.Milliseconds)); } #endif break; case Method.Delete: this.Invoke((MethodInvoker) delegate { this.Icon = Properties.Resources.Remove; }); foreach (Entry entry in Entries) { if (Cancel) { break; } if (entry.IsFolder) { Folder current = ((Folder)entry); current.ResetFolderAction(); current.FolderAction += new CLKsFATXLib.Structs.FolderActionChanged(EntryAction_FolderAction); current.Delete(); } else { this.Invoke((MethodInvoker) delegate { this.Text = entry.FullPath; }); label1.Invoke((MethodInvoker) delegate { label1.Text = entry.Name; }); File current = ((File)entry); current.FileAction += new CLKsFATXLib.Structs.FileActionChanged(EntryAction_FileAction); current.Delete(); } } break; case Method.Inject: #if DEBUG System.Diagnostics.Stopwatch sw2 = new System.Diagnostics.Stopwatch(); if (Timer) { sw2.Start(); } #endif this.Invoke((MethodInvoker) delegate { this.Icon = Properties.Resources.Add; }); if (ParentFolder != null) { ParentFolder.ResetFolderAction(); ParentFolder.FolderAction += new CLKsFATXLib.Structs.FolderActionChanged(EntryAction_FolderAction); List <CLKsFATXLib.Structs.ExistingEntry> Existing = new List <CLKsFATXLib.Structs.ExistingEntry>(); foreach (string s in Paths) { if (Cancel) { break; } if (VariousFunctions.IsFolder(s)) { Existing.AddRange(ParentFolder.InjectFolder(s, false, false)); } else { ParentFolder.FolderAction += new CLKsFATXLib.Structs.FolderActionChanged(EntryAction_FolderAction); CLKsFATXLib.Structs.WriteResult wr = ParentFolder.CreateNewFile(s); if (wr.CouldNotWrite) { CLKsFATXLib.Structs.ExistingEntry ex = new CLKsFATXLib.Structs.ExistingEntry(); ex.Existing = wr.Entry; ex.NewPath = s; Existing.Add(ex); } } } DoExisting(Existing); } else { List <CLKsFATXLib.Structs.ExistingEntry> Existing = new List <CLKsFATXLib.Structs.ExistingEntry>(); foreach (string s in Paths) { string Path = ""; try { Path = VariousFunctions.GetFATXPath(s); } catch (Exception x) { ExceptionHandler(x); continue; } Folder thisFolder = xDrive.CreateDirectory("Data\\" + Path); thisFolder.ResetFolderAction(); thisFolder.FolderAction += new CLKsFATXLib.Structs.FolderActionChanged(EntryAction_FolderAction); if (Cancel) { break; } if (VariousFunctions.IsFolder(s)) { ExceptionHandler(new Exception("Can not write folder as STFS package (silly error wording)")); continue; } else { thisFolder.FolderAction += new CLKsFATXLib.Structs.FolderActionChanged(EntryAction_FolderAction); CLKsFATXLib.Structs.WriteResult wr = thisFolder.CreateNewFile(s); if (wr.CouldNotWrite) { CLKsFATXLib.Structs.ExistingEntry ex = new CLKsFATXLib.Structs.ExistingEntry(); ex.Existing = wr.Entry; ex.NewPath = s; Existing.Add(ex); } } } DoExisting(Existing); } #if DEBUG if (Timer) { sw2.Stop(); MessageBox.Show(string.Format("{0}:{1}:{2}", sw2.Elapsed.Minutes, sw2.Elapsed.Seconds, sw2.Elapsed.Milliseconds)); } #endif break; case Method.Move: List <CLKsFATXLib.Structs.WriteResult> Results = new List <CLKsFATXLib.Structs.WriteResult>(); foreach (Entry Entry in Entries) { CLKsFATXLib.Structs.WriteResult wr = Entry.Move(OutPath); if (wr.CouldNotWrite) { Results.Add(wr); } } break; } } this.Invoke((MethodInvoker) delegate { this.Close(); }); #if TRACE } catch (Exception x) { ExceptionHandler(x); this.Invoke((MethodInvoker) delegate { this.Close(); }); } #endif }; t = new System.Threading.Thread(ts); t.Start(); }
void EntryAction_HandleCreated(object sender, EventArgs e) { if (Aero) { td = new TaskDialog(); } System.Threading.ThreadStart ts = delegate { #if TRACE try { #endif //while (true)//(!this.IsHandleCreated || !progressBar1.IsHandleCreated || !label1.IsHandleCreated || !lPercent.IsHandleCreated || !button1.IsHandleCreated) //{ // try // { // this.Invoke((MethodInvoker)delegate { }); // progressBar1.Invoke((MethodInvoker)delegate { }); // label1.Invoke((MethodInvoker)delegate { }); // lPercent.Invoke((MethodInvoker)delegate { }); // button1.Invoke((MethodInvoker)delegate { }); // break; // } // catch(Exception E) { Application.DoEvents(); } //} if (xDrive != null && m == Method.Backup || m == Method.ExtractJ || m == Method.ExtractSS || m == Method.Restore) { switch (m) { case Method.Backup: this.Invoke((MethodInvoker)delegate { this.Icon = Properties.Resources.Add; }); CLKsFATXLib.Streams.Reader r = xDrive.Reader(); CLKsFATXLib.Streams.Writer w = new CLKsFATXLib.Streams.Writer(new System.IO.FileStream(OutPath, System.IO.FileMode.Create)); int ReadLength = 0x200; if (xDrive.Length % 0x100000 == 0) { ReadLength = 0x100000; } else if (xDrive.Length % 0x40000 == 0) { ReadLength = 0x40000; } else if (xDrive.Length % 0x10000 == 0) { ReadLength = 0x10000; } else if (xDrive.Length % 0x5000 == 0) { ReadLength = 0x5000; } for (int i = 0; i < xDrive.Length / ReadLength; i++) { if (Cancel) { break; } w.Write(r.ReadBytes(ReadLength)); progressBar1.Invoke((MethodInvoker)delegate { try { progressBar1.Maximum = (int)(xDrive.Length / ReadLength); progressBar1.Value = (i + 1); if (Windows7) { tm.SetProgressValue(progressBar1.Value, progressBar1.Maximum); } } catch { } }); this.Invoke((MethodInvoker)delegate { this.Text = "Backing Up Drive"; }); label1.Invoke((MethodInvoker)delegate { label1.Text = (((decimal)(i + 1) / (decimal)(xDrive.Length / ReadLength)) * 100).ToString("#") + "%"; }); } w.Close(); break; case Method.ExtractSS: this.Invoke((MethodInvoker)delegate { this.Icon = Properties.Resources.Add; }); //Create our io for the drive CLKsFATXLib.Streams.Reader io = xDrive.Reader(); //Go to the location of the security sector io.BaseStream.Position = 0x2000; //Create our ref io for the file CLKsFATXLib.Streams.Writer bw = new CLKsFATXLib.Streams.Writer(new System.IO.FileStream(OutPath, System.IO.FileMode.Create)); //Read the sector. The size is an estimation, since I have no idea how big it really is bw.Write(io.ReadBytes(0xE00)); //Close our io bw.Close(); break; case Method.ExtractJ: this.Invoke((MethodInvoker)delegate { this.Icon = Properties.Resources.Add; }); //Create our io for the drive CLKsFATXLib.Streams.Reader io2 = xDrive.Reader(); //Go to the location of the security sector io2.BaseStream.Position = 0x800; //Create our ref io for the file CLKsFATXLib.Streams.Writer bw2 = new CLKsFATXLib.Streams.Writer(new System.IO.FileStream(OutPath, System.IO.FileMode.Create)); //Read the sector. The size is an estimation, since I have no idea how big it really is bw2.Write(io2.ReadBytes(0x400)); //Close our io bw2.Close(); break; case Method.Restore: this.Invoke((MethodInvoker)delegate { this.Icon = Properties.Resources.Remove; }); if (MessageBox.Show("WARNING: Restoring a drive that does not match your current one can cause for data to not be read correctly by the Xbox 360, or for other unforseen problems! Please make sure you know what you're doing before continuing. Are you sure you want to continue?", "WARNING AND STUFF", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { if (MessageBox.Show("This is your last chance to stop! Are you POSITIVE you want to continue?", "Last Chance!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { CLKsFATXLib.Streams.Reader r2 = new CLKsFATXLib.Streams.Reader(new System.IO.FileStream(OutPath, System.IO.FileMode.Open)); CLKsFATXLib.Streams.Writer w2 = xDrive.Writer(); int ReadLength2 = 0x200; if (xDrive.Length % 0x4000 != 0) { ReadLength2 = 0x4000; } else { for (int i = 0x300000; i > 0x200; i -= 0x1000) { if (xDrive.Length % i == 0) { ReadLength2 = i; break; } } } for (int i = 0; i < xDrive.Length / ReadLength2; i++) { if (Cancel) { break; } w2.Write(r2.ReadBytes(ReadLength2)); progressBar1.Invoke((MethodInvoker)delegate { try { progressBar1.Maximum = (int)(xDrive.Length / ReadLength2); progressBar1.Value = (i + 1); if (Windows7) { tm.SetProgressValue(progressBar1.Value, progressBar1.Maximum); } } catch { } }); this.Invoke((MethodInvoker)delegate { this.Text = "Restoring Drive"; }); label1.Invoke((MethodInvoker)delegate { label1.Text = (((decimal)(i + 1) / (decimal)(xDrive.Length / ReadLength2)) * 100).ToString("#") + "%"; }); } r2.Close(); } } break; } } else { Folder ParentFolder = null; this.Invoke((MethodInvoker)delegate { ParentFolder = Parent; }); switch (m) { case Method.Extract: #if DEBUG System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); if (Timer) { sw.Start(); } #endif this.Invoke((MethodInvoker)delegate { this.Icon = Properties.Resources.Add; }); foreach (Entry entry in Entries) { if (!entry.IsFolder) { ((File)entry).FileAction += new CLKsFATXLib.Structs.FileActionChanged(EntryAction_FileAction); this.Invoke((MethodInvoker)delegate { this.Text = entry.FullPath; }); label1.Invoke((MethodInvoker)delegate { label1.Text = entry.Name; }); // Check to see if we're batch-extracting... if (Entries.Length == 1) { ((File)entry).Extract(OutPath); } else { ((File)entry).Extract(OutPath + "\\" + entry.Name); } } else { ((Folder)entry).FolderAction += new CLKsFATXLib.Structs.FolderActionChanged(EntryAction_FolderAction); ((Folder)entry).Extract(OutPath, EntriesToSkip); } if (Cancel) { break; } } #if DEBUG if (Timer) { sw.Stop(); MessageBox.Show(string.Format("{0}:{1}:{2}", sw.Elapsed.Minutes, sw.Elapsed.Seconds, sw.Elapsed.Milliseconds)); } #endif break; case Method.Delete: this.Invoke((MethodInvoker)delegate { this.Icon = Properties.Resources.Remove; }); foreach (Entry entry in Entries) { if (Cancel) { break; } if (entry.IsFolder) { Folder current = ((Folder)entry); current.ResetFolderAction(); current.FolderAction += new CLKsFATXLib.Structs.FolderActionChanged(EntryAction_FolderAction); current.Delete(); } else { this.Invoke((MethodInvoker)delegate { this.Text = entry.FullPath; }); label1.Invoke((MethodInvoker)delegate { label1.Text = entry.Name; }); File current = ((File)entry); current.FileAction += new CLKsFATXLib.Structs.FileActionChanged(EntryAction_FileAction); current.Delete(); } } break; case Method.Inject: #if DEBUG System.Diagnostics.Stopwatch sw2 = new System.Diagnostics.Stopwatch(); if (Timer) { sw2.Start(); } #endif this.Invoke((MethodInvoker)delegate { this.Icon = Properties.Resources.Add; }); if (ParentFolder != null) { ParentFolder.ResetFolderAction(); ParentFolder.FolderAction += new CLKsFATXLib.Structs.FolderActionChanged(EntryAction_FolderAction); List<CLKsFATXLib.Structs.ExistingEntry> Existing = new List<CLKsFATXLib.Structs.ExistingEntry>(); foreach (string s in Paths) { if (Cancel) { break; } if (VariousFunctions.IsFolder(s)) { Existing.AddRange(ParentFolder.InjectFolder(s, false, false)); } else { ParentFolder.FolderAction += new CLKsFATXLib.Structs.FolderActionChanged(EntryAction_FolderAction); CLKsFATXLib.Structs.WriteResult wr = ParentFolder.CreateNewFile(s); if (wr.CouldNotWrite) { CLKsFATXLib.Structs.ExistingEntry ex = new CLKsFATXLib.Structs.ExistingEntry(); ex.Existing = wr.Entry; ex.NewPath = s; Existing.Add(ex); } } } DoExisting(Existing); } else { List<CLKsFATXLib.Structs.ExistingEntry> Existing = new List<CLKsFATXLib.Structs.ExistingEntry>(); foreach (string s in Paths) { string Path = ""; try { Path = VariousFunctions.GetFATXPath(s); } catch (Exception x) { ExceptionHandler(x); continue; } Folder thisFolder = xDrive.CreateDirectory("Data\\" + Path); thisFolder.ResetFolderAction(); thisFolder.FolderAction += new CLKsFATXLib.Structs.FolderActionChanged(EntryAction_FolderAction); if (Cancel) { break; } if (VariousFunctions.IsFolder(s)) { ExceptionHandler(new Exception("Can not write folder as STFS package (silly error wording)")); continue; } else { thisFolder.FolderAction += new CLKsFATXLib.Structs.FolderActionChanged(EntryAction_FolderAction); CLKsFATXLib.Structs.WriteResult wr = thisFolder.CreateNewFile(s); if (wr.CouldNotWrite) { CLKsFATXLib.Structs.ExistingEntry ex = new CLKsFATXLib.Structs.ExistingEntry(); ex.Existing = wr.Entry; ex.NewPath = s; Existing.Add(ex); } } } DoExisting(Existing); } #if DEBUG if (Timer) { sw2.Stop(); MessageBox.Show(string.Format("{0}:{1}:{2}", sw2.Elapsed.Minutes, sw2.Elapsed.Seconds, sw2.Elapsed.Milliseconds)); } #endif break; case Method.Move: List<CLKsFATXLib.Structs.WriteResult> Results = new List<CLKsFATXLib.Structs.WriteResult>(); foreach (Entry Entry in Entries) { CLKsFATXLib.Structs.WriteResult wr = Entry.Move(OutPath); if (wr.CouldNotWrite) { Results.Add(wr); } } break; } } this.Invoke((MethodInvoker)delegate { this.Close(); }); #if TRACE } catch (Exception x) { ExceptionHandler(x); this.Invoke((MethodInvoker)delegate { this.Close(); }); } #endif }; t = new System.Threading.Thread(ts); t.Start(); }
/// <summary> /// Writes the file to a given directory /// </summary> public void Extract(string Destination) { // Check to see if this file is null... if (this.Size == 0) { System.IO.File.Create(Destination); return; } // Before doing anything else, check to see if hte user has // enough space on their current drive for the file try { if (new System.IO.DriveInfo(System.IO.Path.GetPathRoot(Destination)).AvailableFreeSpace < Size) { throw new Exception("Not enough free space on destination device to extract file \"" + Name + "\" to"); } } catch { } // Create a new instance of the blocks occupied uint[] Blocks = BlocksOccupied; // FileAction to be used Structs.FileAction Fa = new FileAction(); Fa.MaxValue = Blocks.Length; Fa.FullPath = this.FullPath; // The IO to read the file Streams.Reader FileReader = Drive.Reader(); // The IO to write to the destination file Streams.Writer FileWriter = new CLKsFATXLib.Streams.Writer(new System.IO.FileStream(Destination, System.IO.FileMode.Create)); // Loop for each block... for (int i = 0; i < Blocks.Length - 1; i++) { if (Fa.Cancel) { Fa.Cancel = false; FileWriter.Close(); return; } // Set the position to the beginning of the block FileReader.BaseStream.Position = VariousFunctions.GetBlockOffset(Blocks[i], this); for (int j = 1, k=0; j <= 0x100; j++, k++) { if (i + k == Blocks.Length - 1) { FileWriter.Write(FileReader.ReadBytes((int)PartitionInfo.ClusterSize * k)); i += k; Fa.Progress += k; break; } else if (Blocks[i + k] == Blocks.Length - 2 || Blocks[i + k] + 1 != Blocks[i + j] || j == 10) { FileWriter.Write(FileReader.ReadBytes((int)PartitionInfo.ClusterSize * j)); i += k; Fa.Progress += j; break; } } OnFileAction(ref Fa); } // For the last cluster, we don't know how long it is... so we use // this nifty function I made to do that for us FileReader.BaseStream.Position = VariousFunctions.GetBlockOffset(Blocks[Blocks.Length - 1], this); // Read/write data FileWriter.Write(VariousFunctions.ReadBytes(ref FileReader, VariousFunctions.RemainingData(this))); Fa.Progress++; OnFileAction(ref Fa); FileWriter.Close(); }