static void AddFiles(FilesBag bag, string subFolder, string rootFolder) { string[] files = Directory.GetFiles(subFolder); string relDir = subFolder.Remove(0, rootFolder.Length + 1); foreach (string file in files) { bag.Add(file, relDir); } string[] folders = Directory.GetDirectories(subFolder); foreach (string folder in folders) { AddFiles(bag, folder, rootFolder); } }
FilesBag CreateBag(string srcFolder) { Initializing?.Invoke(); var bag = new FilesBag(); string[] files = Directory.GetFiles(srcFolder); foreach (string file in files) { bag.Add(file); } string[] folders = Directory.GetDirectories(srcFolder); foreach (string folder in folders) { AddFiles(bag, folder, srcFolder); } return(bag); }
private void AddPackage_Click(object sender, EventArgs e) { using (var dlg = new AppUpdateDialog()) if (dlg.ShowDialog(this) == DialogResult.OK) { IDatumProvider dp = null; var waitDlg = new Jobs.ProcessingDialog(); Action buildUpdate = () => { var bag = new FilesBag(); foreach (string file in dlg.Files) { waitDlg.Message = $"Préparation de {file}"; string relDir = Path.GetDirectoryName(file.Remove(0, dlg.RootFolder.Length + 1)); if (relDir.Length > 0) { bag.Add(file, relDir); } else { bag.Add(file); } } waitDlg.Message = "Compression en cours..."; dp = AppContext.TableManager.AppUpdates.DataProvider; dp.Connect(); var update = new AppUpdate(AppContext.TableManager.AppUpdates.CreateUniqID(), dlg.Version, dlg.AppArchitecture); bag.Compress(Path.Combine(AppPaths.AppUpdateFolder, update.ID.ToString("X"))); NormalizeAppUpdates(update); dp.Insert(update); }; Action <Task> onErr = t => { TextLogger.Error(t.Exception.InnerException.Message); this.ShowError(t.Exception.InnerException.Message); dp?.Dispose(); waitDlg.Dispose(); }; Action onSuccess = () => { dp?.Dispose(); waitDlg.Dispose(); }; var task = new Task(buildUpdate, TaskCreationOptions.LongRunning); task.OnSuccess(onSuccess); task.OnError(onErr); task.Start(); waitDlg.ShowDialog(this); } }