diff --git a/Saviour Backup System/addBackupWizard.cs b/Saviour Backup System/addBackupWizard.cs
index 981085a..479b0e6 100644
--- a/Saviour Backup System/addBackupWizard.cs
+++ b/Saviour Backup System/addBackupWizard.cs
@@ -153,29 +153,33 @@ namespace Saviour_Backup_System
/// Create record for drive
///
private void createRecord() {
- SqlCeConnection conn = databaseTools.conn;
- SqlCeCommand cmd = conn.CreateCommand();
- DriveInfo drive = USBTools.getDriveObject(drivesDropdown.Text.Substring(0, 1));
- conn.Open();
+ SqlCeConnection conn = databaseTools.conn; //Get connection object
+ SqlCeCommand cmd = conn.CreateCommand(); //Generate command object to run SQL
+ DriveInfo drive = USBTools.getDriveObject(drivesDropdown.Text.Substring(0, 1)); //Get drive object from
+ string driveID = USBTools.calculateDriveID(drive); //Calculate ID for drive
+ conn.Open(); //Open connection to database
statusProgress.Text = "Connection established...";
- cmd.CommandText = "INSERT INTO Drive (ID, Name, Capacity, File_System, Type) VALUES (?,?,?,?,?)";
+ cmd.CommandText = "INSERT INTO Drive (ID, Name, Capacity, File_System, Type) VALUES (?,?,?,?,?)"; //Defined SQL statement for insertion
+ /*Generate SQL parameters, stops injection */
cmd.Parameters.Add(new SqlCeParameter("Drive ID", SqlDbType.NText));
cmd.Parameters.Add(new SqlCeParameter("Drive Name", SqlDbType.NText));
cmd.Parameters.Add(new SqlCeParameter("Capacity", SqlDbType.BigInt));
cmd.Parameters.Add(new SqlCeParameter("File System", SqlDbType.NText));
cmd.Parameters.Add(new SqlCeParameter("Type", SqlDbType.NText));
- cmd.Prepare();
- cmd.Parameters["Drive ID"].Value = USBTools.calculateDriveID(drive);
+ cmd.Prepare(); //Prepare the parameters for use
+ /*Assign values to parameters */
+ cmd.Parameters["Drive ID"].Value = driveID;
cmd.Parameters["Drive Name"].Value = drive.VolumeLabel;
cmd.Parameters["Capacity"].Value = Convert.ToInt64(drive.TotalSize);
cmd.Parameters["File System"].Value = drive.DriveFormat;
cmd.Parameters["Type"].Value = USBTools.getDriveType(drive);
- cmd.ExecuteNonQuery();
- cmd.Parameters.Clear();
- statusProgress.Text = "Drive Record Created...";
+ cmd.ExecuteNonQuery(); //Execute code
+ cmd.Parameters.Clear(); //Clear teh parameters for reuse
+ statusProgress.Text = "Drive Record Created..."; //Display message
- cmd.CommandText = "INSERT INTO Recordset VALUES (?, ?, ?, ?, ?, ?, ?)";
+ cmd.CommandText = "INSERT INTO Recordset VALUES (?, ?, ?, ?, ?, ?, ?)"; //Redefine SQL statement for different insertion
+ /* Generate SQL Paramters for use */
cmd.Parameters.Add(new SqlCeParameter("Name", SqlDbType.NText));
cmd.Parameters.Add(new SqlCeParameter("Drive ID", SqlDbType.NText));
cmd.Parameters.Add(new SqlCeParameter("Creation Date", SqlDbType.BigInt));
@@ -183,19 +187,18 @@ namespace Saviour_Backup_System
cmd.Parameters.Add(new SqlCeParameter("Automatic", SqlDbType.Bit));
cmd.Parameters.Add(new SqlCeParameter("Compression", SqlDbType.Bit));
cmd.Parameters.Add(new SqlCeParameter("Previous Backups", SqlDbType.Int));
- cmd.Prepare();
+ cmd.Prepare(); //Prepare parameters
cmd.Parameters["Name"].Value = backupNameInput.Text;
- cmd.Parameters["Drive ID"].Value = USBTools.calculateDriveID(drive);
- cmd.Parameters["Creation Date"].Value = tools.getUnixTimeStamp();
+ cmd.Parameters["Drive ID"].Value = driveID;
+ cmd.Parameters["Creation Date"].Value = tools.getUnixTimeStamp(); //Calulate current time
cmd.Parameters["Backup Location"].Value = folderPath.Text;
cmd.Parameters["Automatic"].Value = insertionSwitch.Value;
cmd.Parameters["Compression"].Value = compressionSwitch.Value;
cmd.Parameters["Previous Backups"].Value = previousBackupInput.Value;
- cmd.ExecuteNonQuery();
- cmd.Parameters.Clear();
- statusProgress.Text = "Recordset created...";
- conn.Close();
-
+ cmd.ExecuteNonQuery(); //Execute SQL
+ cmd.Parameters.Clear(); //Clear parameter list
+ statusProgress.Text = "Recordset created..."; //Display message
+ conn.Close(); //Close database connection
}
private void insertionSwitch_Click(object sender, EventArgs e) { insertionSwitch.Value = !insertionSwitch.Value; }
diff --git a/Saviour Backup System/currentTransfers.cs b/Saviour Backup System/currentTransfers.cs
index 69eb52e..01645aa 100644
--- a/Saviour Backup System/currentTransfers.cs
+++ b/Saviour Backup System/currentTransfers.cs
@@ -28,29 +28,28 @@ namespace Saviour_Backup_System
/// Directory to store files
/// Will the progress window be displayed?
public void startCopy(DriveInfo drive, string endDirectory, bool visible) { //used for validation to make sure the copy wont fail.
- if (!Directory.Exists(drive.Name)) { MessageBox.Show("The drive directory does not exist."); }
+ if (!Directory.Exists(drive.Name)) { MessageBox.Show("The drive directory does not exist."); } //Check if the drive is still attached
- else if (!Directory.Exists(endDirectory)) { MessageBox.Show("The end directory does not exist."); }
+ else if (!Directory.Exists(endDirectory)) { MessageBox.Show("The end directory does not exist."); } //Check if the directory exists
else { //error checking is done (just in case something slips through.
- string hash = tools.hashDirectory(drive.Name);
+ string hash = tools.hashDirectory(drive.Name); //Generate a hash of the drive in current state
string DBHash = databaseTools.getHashofRecentBackup(USBTools.calculateDriveID(drive)); //get the hash from the database
- MessageBox.Show("hash:" + hash + "\nDBHash:" + DBHash);
if (DBHash != "NONE") {//if the hash is found in the database
if (DBHash == hash) { //if the hash in the database matches the drive, don't backup because nothing will have changed.
MessageBox.Show("No changes have been made to files on drive " + drive.VolumeLabel + ", Will not backup.", "No Changes", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
} else { //The actual backup case
string addition; //stores any extra directory needed, mainly for adding temp.
- if (databaseTools.isCompression(USBTools.calculateDriveID(drive)))
+ if (databaseTools.isCompression(USBTools.calculateDriveID(drive))) //is the drive using compression
{
- addition = "\\Temp";
+ addition = "\\Temp"; //Append temp to directory for backup
}
- else {addition = "\\" + drive.VolumeLabel + "-" + DateTime.Now.ToString(); }
- copyFiles(drive.Name.Substring(0, 1), endDirectory + addition, visible, drive, hash);
+ else {addition = "\\" + drive.VolumeLabel + "-" + DateTime.Now.ToString(); } //Generate directory with date / Time
+ copyFiles(drive.Name.Substring(0, 1), endDirectory + addition, visible, drive, hash); //Initiate the copy
}
} else {
- MessageBox.Show("An error occured when getting the drive hash. Please try again.", "Hash Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ MessageBox.Show("An error occured when getting the drive hash. Please try again.", "Hash Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //Hashes dont match
return;
}
}
@@ -67,16 +66,16 @@ namespace Saviour_Backup_System
private void copyFiles(string driveLetter, string endDirectory, bool display, DriveInfo drive, string hash)
{
backups++; //appends to the number of backups running
- progressBars.Add(new copyProgressBar());
- layoutPanel.Controls.Add(new copyProgressLabel());
- layoutPanel.Controls.Add(progressBars[backups]);
+ progressBars.Add(new copyProgressBar()); //Create the display progressbar and store it for reference
+ layoutPanel.Controls.Add(new copyProgressLabel()); //Create the display label and add it to display
+ layoutPanel.Controls.Add(progressBars[backups]); //Display the progress bar and add it to display
- copyFilesList.Add(new CopyFiles.CopyFiles(driveLetter + ":\\", endDirectory));
+ copyFilesList.Add(new CopyFiles.CopyFiles(driveLetter + ":\\", endDirectory)); //Generate copying oject, and pass it details of copy
- transfersList.Add(new transferWindow(backups, drive, hash, endDirectory));
+ transfersList.Add(new transferWindow(backups, drive, hash, endDirectory)); //Generate progress window, and pass it details
transfersList[backups].SynchronizationObject = this;
- copyFilesList[backups].CopyAsync(transfersList[backups]);
+ copyFilesList[backups].CopyAsync(transfersList[backups]); //Initiate the backup (in a new thread) from reference to copying object
if (!display) { transfersList[backups].Hide(); } //if it is a startup backup process, quickly hide the dialog.
}