private void RunBackgroundWorker() { if (RTB_Instructions.Lines.Any(line => line.Length == 0)) { WinFormsUtil.Error("Invalid instruction detected."); return; } var sets = StringInstructionSet.GetBatchSets(RTB_Instructions.Lines).ToArray(); if (sets.Any(s => s.Filters.Any(z => string.IsNullOrWhiteSpace(z.PropertyValue)))) { WinFormsUtil.Error("Filter empty."); return; } if (sets.Any(z => z.Instructions.Count == 0)) { WinFormsUtil.Error("No instructions."); return; } var emptyVal = sets.SelectMany(s => s.Instructions.Where(z => string.IsNullOrWhiteSpace(z.PropertyValue))).ToArray(); if (emptyVal.Length > 0) { string props = string.Join(", ", emptyVal.Select(z => z.PropertyName)); string invalid = "Property empty." + Environment.NewLine + props; if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, invalid, "Continue?")) { return; } } RTB_Instructions.Enabled = B_Go.Enabled = false; RunBatchEdit(sets); }
private void RunBackgroundWorker() { if (RTB_Instructions.Lines.Any(line => line.Length == 0)) { WinFormsUtil.Error(MsgBEInstructionInvalid); return; } var sets = StringInstructionSet.GetBatchSets(RTB_Instructions.Lines).ToArray(); if (sets.Any(s => s.Filters.Any(z => string.IsNullOrWhiteSpace(z.PropertyValue)))) { WinFormsUtil.Error(MsgBEFilterEmpty); return; } if (sets.Any(z => z.Instructions.Count == 0)) { WinFormsUtil.Error(MsgBEInstructionNone); return; } var emptyVal = sets.SelectMany(s => s.Instructions.Where(z => string.IsNullOrWhiteSpace(z.PropertyValue))).ToArray(); if (emptyVal.Length > 0) { string props = string.Join(", ", emptyVal.Select(z => z.PropertyName)); string invalid = MsgBEPropertyEmpty + Environment.NewLine + props; if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, invalid, MsgContinue)) { return; } } string?destPath = null; if (RB_Path.Checked) { WinFormsUtil.Alert(MsgExportFolder, MsgExportFolderAdvice); using var fbd = new FolderBrowserDialog(); var dr = fbd.ShowDialog(); if (dr != DialogResult.OK) { return; } destPath = fbd.SelectedPath; } FLP_RB.Enabled = RTB_Instructions.Enabled = B_Go.Enabled = false; foreach (var set in sets) { BatchEditing.ScreenStrings(set.Filters); BatchEditing.ScreenStrings(set.Instructions); } RunBatchEdit(sets, TB_Folder.Text, destPath); }
private void RunBackgroundWorker() { if (RTB_Instructions.Lines.Any(line => line.Length == 0)) { WinFormsUtil.Error("Line length error in instruction list."); return; } var sets = StringInstructionSet.GetBatchSets(RTB_Instructions.Lines).ToArray(); if (sets.Any(s => s.Filters.Any(z => string.IsNullOrWhiteSpace(z.PropertyValue)))) { WinFormsUtil.Error("Empty Filter Value detected."); return; } if (sets.Any(z => !z.Instructions.Any())) { WinFormsUtil.Error("No instructions defined for a modification set."); return; } var emptyVal = sets.SelectMany(s => s.Instructions.Where(z => string.IsNullOrWhiteSpace(z.PropertyValue))).ToArray(); if (emptyVal.Any()) { string props = string.Join(", ", emptyVal.Select(z => z.PropertyName)); string invalid = $"Empty Property Value{(emptyVal.Length > 1 ? "s" : "")} detected:" + Environment.NewLine + props; if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, invalid, "Continue?")) { return; } } string destPath = null; if (RB_Path.Checked) { WinFormsUtil.Alert("Please select the folder where the files will be saved to.", "This can be the same folder as the source of PKM files."); var fbd = new FolderBrowserDialog(); var dr = fbd.ShowDialog(); if (dr != DialogResult.OK) { return; } destPath = fbd.SelectedPath; } FLP_RB.Enabled = RTB_Instructions.Enabled = B_Go.Enabled = false; foreach (var set in sets) { ScreenStrings(set.Filters); ScreenStrings(set.Instructions); } RunBatchEdit(sets, TB_Folder.Text, destPath); }
public static BatchEditor Execute(IList <string> lines, IEnumerable <PKM> data) { var editor = new BatchEditor(); var sets = StringInstructionSet.GetBatchSets(lines).ToArray(); foreach (var pk in data) { foreach (var set in sets) { editor.Process(pk, set.Filters, set.Instructions); } } return(editor); }