private async void EventBackup(object sender, EventArgs e) { isDeleteEnabled = false; MenuItemClick(); var outputFolder = txtOutput.Text; if (!FS.FolderExists(outputFolder)) { if (MessageBox.Show($"{outputFolder} does not exist\r\n\r\nDo you want to create it?", "EmuELEC Output Folder verification", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } else { FS.CreateFolder(outputFolder); } } this.Cursor = Cursors.WaitCursor; isProcessing = true; tsProgressBar.Value = 0; string[] listPath = { outputFolder }; var myTasks = (from path in listPath select(Task.Run(() => Business.BackupFiles(UI.selectedNode, path, txtInput.Text)))).ToArray(); var t = Task.WhenAll(myTasks); await t.ContinueWith(x => EndTaskBackup()); }
public static void BackupFiles(string selectedNode, string path, string baseInputPath) { DateTime dt = DateTime.Now; StatusStripControl.InitStatusStrip(string.Empty, fileList.Count); //todo: criar caminhos relativos? var i = 1; var newLIst = fileList.ToList(); if (!string.IsNullOrEmpty(selectedNode)) { newLIst.RemoveAll(u => !u.Contains(selectedNode)); } newLIst.Sort(); foreach (var file in newLIst) { StatusStripControl.UpdateProgressBar(); StatusStripControl.UpdateLabel($"{i++}/{found} - {file}"); var fileFolder = FS.GetFolderName(file).Replace(baseInputPath + "\\", ""); fileFolder = FS.PathCombine(path, fileFolder); if (!FS.FolderExists(fileFolder)) { FS.CreateFolder(fileFolder); } FS.CopyFileIfNewer(file, FS.PathCombine(path, fileFolder)); } StatusStripControl.UpdateLabel($"{found} {UI.GetExtensionName()} files backup completed in {DateTime.Now.Subtract(dt).TotalSeconds.ToString("#.#")} seconds"); found = 0; if (string.IsNullOrEmpty(selectedNode)) { fileList.Clear(); } }