// Reset Buttons private void button1_Click_1(object sender, EventArgs e) { Source.Clear(); Obstacle.Clear(); Destination.Clear(); panel1.Controls.Clear(); panel1.Refresh(); checkBox1.Refresh(); checkBox2.Refresh(); checkBox1.Checked = false; checkBox2.Checked = false; radioButton1.Checked = false; radioButton2.Checked = false; radioButton3.Checked = false; textBox2.Clear(); }
//On clicking the 'Enter' button this function will be called private void GetTheResult_Click(object sender, EventArgs e) { try { cancelOperation = 0; string str1 = Source.Text; Total = 0; //a and b string is to get files and directories and check whether only file is selected or directory is selected string[] a; //getting files string[] b; //getting Directories try { a = Directory.GetFiles(str1, "*.*", SearchOption.TopDirectoryOnly); } catch { a = new string[0]; } try { b = Directory.GetDirectories(str1); } catch { b = null; } fileTransfer.Text = "Please Wait..."; try { FileInfo f_Source = new FileInfo(Source.Text); string driveSource = Path.GetPathRoot(f_Source.FullName); try { FileInfo f_Dest = new FileInfo(Destination.Text); string driveDest = Path.GetPathRoot(f_Dest.FullName); long totalDriveSize = GetTotalDriveSize(driveDest); string str2 = ""; if (str1.Split('\\').Last() == "") { str2 = Destination.Text + "\\" + str1.Replace(":\\", " Drive"); } else { str2 = Destination.Text + "\\" + str1.Split('\\').Last(); } DirectoryInfo src = new DirectoryInfo(@str1); FileInfo src1 = new FileInfo(str1); DirectoryInfo dest = new DirectoryInfo(@str2); listBox.Items.Clear(); final = 0; totalBytes = 0; totalCount = 0; valueDeleated = 0; showPercent.Text = final + "%"; no = 1; Font font = new System.Drawing.Font("Times New Roman", 12.0f); listBox.Font = font; ProgressBar.Value = 0; //Checking for calling 'CopySingleFile' function or 'CopyDirectory' function if (a.Length == 0 && b == null) { i = 3; long countTheSourceSize = src1.Length; if (totalDriveSize - countTheSourceSize > 100 * 1024 * 1024) { if (Source.Text != "" && Destination.Text != "") { browseSource.Enabled = false; browseDest.Enabled = false; Source.Enabled = false; Destination.Enabled = false; GetTheResult.Enabled = false; cancelTheOperation.Enabled = true; CopySingleFile(src1, dest); } else { MessageBox.Show("Destination Text is Empty...Please Check", "Please Review"); fileTransfer.Text = "Please Select a File/Folder To Copy To Destination..."; } } else { MessageBox.Show("Sorry Not Enough Space"); fileTransfer.Text = "Please Select a File/Folder To Copy To Destination..."; } } else { i = 3; long countTheSourceSize; if (Source.Text == driveSource) { countTheSourceSize = GetTotalDriveSize(str1.Split('\\').First() + "\\"); } else //if (src.Exists) { countTheSourceSize = GetDirectorySize(src.FullName); } if (totalDriveSize - countTheSourceSize > 100 * 1024 * 1024) { if (Source.Text != "" && Destination.Text != "") { countDi = 0; browseSource.Enabled = false; browseDest.Enabled = false; Source.Enabled = false; Destination.Enabled = false; GetTheResult.Enabled = false; cancelTheOperation.Enabled = true; CopyDirectory(src, dest); } else { MessageBox.Show("Destination Text is Empty...Please Check", "Please Review"); fileTransfer.Text = "Please Select a File/Folder To Copy To Destination..."; } } else { MessageBox.Show("Sorry Not Enough Space"); fileTransfer.Text = "Please Select a File/Folder To Copy To Destination..."; } } if (i == 2 & cancelOperation != 1) { ProgressBar.Value = ProgressBar.Maximum; fileTransfer.Text = "Copied......... "; showPercent.Text = "100%"; MessageBox.Show("Copied Successfully...", "Status"); showPercent.Text = final + "%"; ProgressBar.Value = 0; browseSource.Enabled = true; browseDest.Enabled = true; Source.Enabled = true; Destination.Enabled = true; GetTheResult.Enabled = true; cancelTheOperation.Enabled = false; } else if (cancelOperation == 1) { FilesCountingFromDestination(dest); browseSource.Enabled = true; browseDest.Enabled = true; Source.Enabled = true; Destination.Enabled = true; GetTheResult.Enabled = true; cancelTheOperation.Enabled = false; fileTransfer.Text = "Please Select a File/Folder To Copy To Destination..."; } else { i = 2; fileTransfer.Text = "Please Select a File/Folder to Copy To Destination..."; browseSource.Enabled = true; browseDest.Enabled = true; Source.Enabled = true; Destination.Enabled = true; GetTheResult.Enabled = true; cancelTheOperation.Enabled = false; } Source.Clear(); Destination.Clear(); } catch { MessageBox.Show("Destination Text is Empty...Please Check", "Please Review"); fileTransfer.Text = "Please Select a File/Folder To Copy To Destination..."; } } catch { MessageBox.Show("Source Text is Empty...Please Check", "Please Review"); fileTransfer.Text = "Please Select a File/Folder To Copy To Destination..."; } } catch { MessageBox.Show("Check the entry Please"); } }