I'm creating a dump from an external drive. I have the code for reading from the drive written, but I need to work out the best and fastest way to read from the drive. The code I have at the moment is:
public void beginBackup()
{
Reader r = _fatxDrive.Reader();
if (System.IO.File.Exists(_fileName))
System.IO.File.Delete(_fileName);
Writer w = new Writer(new System.IO.FileStream(_fileName, System.IO.FileMode.Create));
long ReadLength = 0x100000;
Dispatcher.Invoke(new Action(delegate { pbBackup.Maximum = r.BaseStream.Length; }));
while(r.BaseStream.Position != r.BaseStream.Length)
{
if (_cancelOp)
break;
if (r.BaseStream.Position + ReadLength > r.BaseStream.Length)
ReadLength = r.BaseStream.Length - r.BaseStream.Position;
w.Write(r.ReadBytes(Convert.ToInt32(ReadLength)));
}
w.Close();
Dispatcher.Invoke(new Action(delegate
{
FormFadeOut.Begin();
Backend.SettingsVault.Home.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.None;
}));
But this tells me I'm exceeding the length of the drive.
Question
Xerax
I'm creating a dump from an external drive. I have the code for reading from the drive written, but I need to work out the best and fastest way to read from the drive. The code I have at the moment is:
public void beginBackup() { Reader r = _fatxDrive.Reader(); if (System.IO.File.Exists(_fileName)) System.IO.File.Delete(_fileName); Writer w = new Writer(new System.IO.FileStream(_fileName, System.IO.FileMode.Create)); long ReadLength = 0x100000; Dispatcher.Invoke(new Action(delegate { pbBackup.Maximum = r.BaseStream.Length; })); while(r.BaseStream.Position != r.BaseStream.Length) { if (_cancelOp) break; if (r.BaseStream.Position + ReadLength > r.BaseStream.Length) ReadLength = r.BaseStream.Length - r.BaseStream.Position; w.Write(r.ReadBytes(Convert.ToInt32(ReadLength))); } w.Close(); Dispatcher.Invoke(new Action(delegate { FormFadeOut.Begin(); Backend.SettingsVault.Home.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.None; }));But this tells me I'm exceeding the length of the drive.
Link to comment
https://www.neowin.net/forum/topic/1066796-c-nubby-math-question/Share on other sites
3 answers to this question
Recommended Posts