diff --git a/Saviour Backup System/transferWindow.cs b/Saviour Backup System/transferWindow.cs index 863b737..08188fe 100644 --- a/Saviour Backup System/transferWindow.cs +++ b/Saviour Backup System/transferWindow.cs @@ -8,6 +8,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; +using System.Diagnostics; using CopyFiles; @@ -16,15 +17,29 @@ namespace Saviour_Backup_System public partial class transferWindow : Form, CopyFiles.ICopyFilesDiag, IDisposable { public System.ComponentModel.ISynchronizeInvoke SynchronizationObject { get; set; } - int arrayIndex; - DriveInfo copyingDrive; - - public transferWindow(int backups, DriveInfo drive) { + private int arrayIndex; + public Int64 startTime = tools.getUnixTimeStamp(); //snapshots it. + private DriveInfo copyingDrive; + private Stopwatch SW = new Stopwatch(); + string driveHash; + bool finalised = false; + public transferWindow(int backups, DriveInfo drive, string hash) { + driveHash = hash; copyingDrive = drive; InitializeComponent(); arrayIndex = backups; currentFileProgress.Maximum = 1000; + SW.Start(); //starts the stopwatch to count how long the copy takes + } + private void finaliseCopy() { + SW.Stop(); //stops the stopwatch. Is done a little too early, but it's good enough! + databaseTools.createBackupRecord(copyingDrive, startTime, SW.Elapsed.Seconds, driveHash); + setup.CT.progressBars[arrayIndex].ColorTable = DevComponents.DotNetBar.eProgressBarItemColor.Normal; + setup.CT.progressBars[arrayIndex].Value = 100; + setup.CT.progressBars[arrayIndex].Maximum = 100; + setup.CT.progressBars[arrayIndex].Text = "Complete!"; + finalised = true; } public void update(Int32 totalFiles, Int32 copiedFiles, Int64 totalBytes, Int64 copiedBytes, string currentFilename) @@ -40,12 +55,11 @@ namespace Saviour_Backup_System setup.CT.progressBars[arrayIndex].Value = totalFilesProgress.Value; setup.CT.progressBars[arrayIndex].Maximum = totalFiles; setup.CT.progressBars[arrayIndex].Text = "Copying " + (copiedBytes / 1024f).ToString() + " of " + (totalBytes / 1024f).ToString(); - - if (setup.MW.selectedDrive.Name.Substring(0, 1) == currentFilename.Substring(0, 1)) { - setup.MW.backupProgress.Value = totalFilesProgress.Value; - setup.MW.backupProgress.Maximum = totalFiles; + int percentage = ((totalFiles + 1) / (copiedFiles + 1)) * 10000; + if (percentage >= 9999 && !finalised) + { + finaliseCopy(); } - } public void cancelCopy() {