private void correctSourceCreationDateButton_Click(object sender, EventArgs e) { correctSourceCreationDateButton.Enabled = false; var sourcePath = sourcePathTxt.Text; var sourcePathThread = MyThread.DoInThread(false, () => GetHashes(sourcePath)); MyThread.DoInThread(false, () => { var res = sourcePathThread.Await(); foreach (var hash in res) { foreach (var path in hash.Value) { var pInfo = new FileInfo(path); if (pInfo.CreationTimeUtc > pInfo.LastWriteTimeUtc) { File.SetCreationTimeUtc(path, pInfo.LastWriteTimeUtc); } } } correctSourceCreationDateButton.ThreadSafe(x => x.Enabled = true); return(0); }); }
private void checkButton_Click(object sender, EventArgs e) { string sourceFolder = sourceTextBox.Text; string destinationFolder = destinationTextBox.Text; if (IsNotEmpty(sourceFolder) && IsNotEmpty(destinationFolder)) { if (!Directory.Exists(sourceFolder)) { MessageBox.Show("Source folder doesn't exist"); } else if (!Directory.Exists(destinationFolder)) { MessageBox.Show("Destination folder doesn't exist"); } else { checkButton.Enabled = false; AppSetting setting = Settings.Get(); setting.SourceFolder = sourceFolder; setting.DestinationFolder = destinationFolder; Settings.Set(setting); IntPtr windowHandle = this.Handle; MyThread <int> actionthread = MyThread.DoInThread(true, () => { CheckResult checkResult = CheckDifferences(sourceFolder, destinationFolder); checkButton.ThreadSafe(x => x.Enabled = true); string dialogtext = string.Format("{0} files and {1} will be copied, {2} files and {3} will be deleted, continue?", checkResult.FileCountToCopy, ByteSize.SizeSuffix(checkResult.BytesToCopy), checkResult.FileCountToDelete, ByteSize.SizeSuffix(checkResult.BytesToDelete)); DialogResult dialogResult = MessageBox.Show(dialogtext, "Copy Files", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { thread = new FileCopyingThread(checkResult.FilesToCopy, windowHandle, checkResult.BytesToCopy, fileCopyLabel, checkResult.FilesToDelete, destinationFolder); } return(0); }); } } else { MessageBox.Show("Choose both folders"); } }
public MainForm() { InitializeComponent(); this.consoleOutput.Size = this.Size; this.Resize += MainForm_Resize; this.FormClosing += MainForm_FormClosing; this.notifyIcon.MouseDoubleClick += NotifyIcon_MouseDoubleClick; Func <int> threadAction = () => { MainProgram(); return(0); }; this.consoleOutput.Text = "Checking database availability..." + "\n"; MyThread.DoInThread(true, threadAction); }
private CheckResult CheckDifferences(string sourceFolder, string destinationFolder) { string[] subfolders = new string[] { "Pictures", "Videos", "Desktop", "Documents", "Downloads", "Music", "workspace" }; // Copying files to hard drive int fileCountToCopy = 0; long bytesToCopy = 0; var threadToCopy = MyThread.DoInThread(true, () => { List <FileCopyInfo> result = GetFilesToCopy(sourceFolder, destinationFolder, subfolders, ref fileCountToCopy, ref bytesToCopy); return(result); }); // Deleting files from hard drive int fileCountToDelete = 0; long bytesToDelete = 0; var threadToDelete = MyThread.DoInThread(true, () => { List <string> result = GetFilesToDelete(sourceFolder, destinationFolder, subfolders, ref fileCountToDelete, ref bytesToDelete); return(result); }); List <FileCopyInfo> filesToCopy = threadToCopy.Await(); List <string> filesToDelete = threadToDelete.Await(); return(new CheckResult { FilesToCopy = filesToCopy, FileCountToCopy = fileCountToCopy, BytesToCopy = bytesToCopy, FilesToDelete = filesToDelete, FileCountToDelete = fileCountToDelete, BytesToDelete = bytesToDelete }); }
private void deleteButton_Click(object sender, EventArgs e) { deleteButton.Enabled = false; var ss = new List <string>(); var sourcePath = sourcePathTxt.Text; var destinationPath = destinationPathTxt.Text; var sourcePathThread = MyThread.DoInThread(false, () => GetHashes(sourcePath)); var destinationPathThread = MyThread.DoInThread(false, () => GetHashes(destinationPath)); MyThread.DoInThread(false, () => { var sourceHashes = sourcePathThread.Await(); var destinationHashes = destinationPathThread.Await(); foreach (var key in destinationHashes.Keys) { if (sourceHashes.TryGetValue(key, out var sourceFoundFiles)) { var destinationFoundFiles = destinationHashes[key]; ss.Add("FoundSource:\n"); foreach (var item in sourceFoundFiles) { ss.Add(item); } foreach (var item in destinationFoundFiles) { ss.Add(item); } ss.Add("\n"); foreach (var filePath in destinationFoundFiles) { File.Delete(filePath); } } } foreach (var pair in sourceHashes) { var list = pair.Value; if (list.Count > 1) { for (int i = 1; i < list.Count; i++) { File.Delete(list[i]); } } } File.WriteAllLines("output.txt", ss.ToArray()); deleteButton.ThreadSafe(x => x.Enabled = true); return(0); }); }