private void btnRebuildFile_ItemClick(object sender, ItemClickEventArgs e)
{
// show the transactionlog again and ask the user upto what datetime he wants to rebuild the file
// first ask a datetime
frmRebuildFileParameters filepar = new frmRebuildFileParameters();
if (filepar.ShowDialog() == DialogResult.OK)
{
// get the last backup that is older than the selected datetime
string file2Process = GetBackupOlderThanDateTime(Tools.Instance.m_CurrentWorkingProject, filepar.SelectedDateTime);
// now rebuild the file
// first create a copy of this file
string tempRebuildFile = m_appSettings.ProjectFolder + "\\" + Tools.Instance.m_CurrentWorkingProject + "rebuild.bin";
if (File.Exists(tempRebuildFile))
{
File.Delete(tempRebuildFile);
}
// CREATE A BACKUP FILE HERE
CreateProjectBackupFile();
File.Copy(file2Process, tempRebuildFile);
// now do all the transactions newer than this file and older than the selected date time
FileInfo fi = new FileInfo(file2Process);
foreach (TransactionEntry te in Tools.Instance.m_ProjectTransactionLog.TransCollection)
{
if (te.EntryDateTime >= fi.LastAccessTime && te.EntryDateTime <= filepar.SelectedDateTime)
{
// apply this change
RollForwardOnFile(tempRebuildFile, te);
}
}
// rename/copy file
if (filepar.UseAsNewProjectFile)
{
// just delete the current file
File.Delete(Tools.Instance.m_currentfile);
File.Copy(tempRebuildFile, Tools.Instance.m_currentfile);
File.Delete(tempRebuildFile);
// done
}
else
{
// ask for destination file
SaveFileDialog sfd = new SaveFileDialog();
sfd.Title = "Save rebuild file as...";
sfd.Filter = "Binary files|*.bin";
if (sfd.ShowDialog() == DialogResult.OK)
{
if (File.Exists(sfd.FileName)) File.Delete(sfd.FileName);
File.Copy(tempRebuildFile, sfd.FileName);
File.Delete(tempRebuildFile);
}
}
if (Tools.Instance.m_CurrentWorkingProject != string.Empty)
{
Tools.Instance.m_ProjectLog.WriteLogbookEntry(LogbookEntryType.ProjectFileRecreated, "Reconstruct upto " + filepar.SelectedDateTime.ToString("dd/MM/yyyy") + " selected file " + file2Process);
}
UpdateRollbackForwardControls();
}
}