2022-06-28 02:59:36 +00:00
|
|
|
using System;
|
2016-07-13 05:19:51 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Windows.Forms;
|
2017-01-08 07:54:09 +00:00
|
|
|
using PKHeX.Core;
|
2022-06-28 02:59:36 +00:00
|
|
|
using PKHeX.WinForms.Controls;
|
2018-04-07 04:23:09 +00:00
|
|
|
using static PKHeX.Core.MessageStrings;
|
2016-07-13 05:19:51 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.WinForms;
|
|
|
|
|
|
|
|
public partial class BatchEditor : Form
|
2016-07-13 05:19:51 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
private readonly SaveFile SAV;
|
2022-06-28 02:59:36 +00:00
|
|
|
|
|
|
|
// Mass Editing
|
|
|
|
private Core.BatchEditor editor = new();
|
|
|
|
private readonly EntityInstructionBuilder UC_Builder;
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
public BatchEditor(PKM pk, SaveFile sav)
|
2016-07-13 05:19:51 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
InitializeComponent();
|
|
|
|
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
2022-06-28 02:59:36 +00:00
|
|
|
var above = FLP_RB.Location;
|
|
|
|
UC_Builder = new EntityInstructionBuilder(() => pk)
|
|
|
|
{
|
|
|
|
Location = new() { Y = above.Y + FLP_RB.Height + 6, X = above.X + 1 },
|
|
|
|
Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
|
|
|
|
Width = B_Add.Location.X - above.X - 6,
|
|
|
|
};
|
|
|
|
Controls.Add(UC_Builder);
|
2022-06-18 18:04:24 +00:00
|
|
|
SAV = sav;
|
|
|
|
DragDrop += TabMain_DragDrop;
|
|
|
|
DragEnter += TabMain_DragEnter;
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void B_Open_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (!B_Go.Enabled) return;
|
|
|
|
using var fbd = new FolderBrowserDialog();
|
|
|
|
if (fbd.ShowDialog() != DialogResult.OK)
|
|
|
|
return;
|
2016-07-13 05:19:51 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
TB_Folder.Text = fbd.SelectedPath;
|
|
|
|
TB_Folder.Visible = true;
|
|
|
|
}
|
2016-07-13 05:19:51 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void B_SAV_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
TB_Folder.Text = string.Empty;
|
|
|
|
TB_Folder.Visible = false;
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void B_Go_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
RunBackgroundWorker();
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void B_Add_Click(object sender, EventArgs e)
|
|
|
|
{
|
2022-06-28 02:59:36 +00:00
|
|
|
var s = UC_Builder.Create();
|
|
|
|
if (s.Length == 0)
|
2022-06-18 18:04:24 +00:00
|
|
|
{ WinFormsUtil.Alert(MsgBEPropertyInvalid); return; }
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (RTB_Instructions.Lines.Length != 0 && RTB_Instructions.Lines[^1].Length > 0)
|
|
|
|
s = Environment.NewLine + s;
|
2017-02-11 07:54:36 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
RTB_Instructions.AppendText(s);
|
|
|
|
}
|
2017-02-11 07:54:36 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static void TabMain_DragEnter(object? sender, DragEventArgs? e)
|
|
|
|
{
|
|
|
|
if (e?.Data is null)
|
|
|
|
return;
|
|
|
|
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void TabMain_DragDrop(object? sender, DragEventArgs? e)
|
|
|
|
{
|
|
|
|
if (e?.Data?.GetData(DataFormats.FileDrop) is not string[] {Length: not 0} files)
|
|
|
|
return;
|
|
|
|
if (!Directory.Exists(files[0]))
|
|
|
|
return;
|
|
|
|
|
|
|
|
TB_Folder.Text = files[0];
|
|
|
|
TB_Folder.Visible = true;
|
|
|
|
RB_Boxes.Checked = RB_Party.Checked = false;
|
|
|
|
RB_Path.Checked = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void RunBackgroundWorker()
|
|
|
|
{
|
Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
var lines = RTB_Instructions.Lines;
|
|
|
|
if (Array.Exists(lines, line => line.Length == 0))
|
2022-06-18 18:04:24 +00:00
|
|
|
{ WinFormsUtil.Error(MsgBEInstructionInvalid); return; }
|
|
|
|
|
Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
var sets = StringInstructionSet.GetBatchSets(lines).ToArray();
|
|
|
|
if (Array.Exists(sets, s => s.Filters.Any(z => string.IsNullOrWhiteSpace(z.PropertyValue))))
|
2022-06-18 18:04:24 +00:00
|
|
|
{ WinFormsUtil.Error(MsgBEFilterEmpty); return; }
|
|
|
|
|
Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
if (Array.Exists(sets, z => z.Instructions.Count == 0))
|
2022-06-18 18:04:24 +00:00
|
|
|
{ WinFormsUtil.Error(MsgBEInstructionNone); return; }
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var emptyVal = sets.SelectMany(s => s.Instructions.Where(z => string.IsNullOrWhiteSpace(z.PropertyValue))).ToArray();
|
|
|
|
if (emptyVal.Length > 0)
|
2017-02-11 07:54:36 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
string props = string.Join(", ", emptyVal.Select(z => z.PropertyName));
|
|
|
|
string invalid = MsgBEPropertyEmpty + Environment.NewLine + props;
|
|
|
|
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, invalid, MsgContinue))
|
2021-12-05 06:29:51 +00:00
|
|
|
return;
|
2017-02-11 07:54:36 +00:00
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
string? destPath = null;
|
|
|
|
if (RB_Path.Checked)
|
2017-02-11 07:54:36 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
WinFormsUtil.Alert(MsgExportFolder, MsgExportFolderAdvice);
|
|
|
|
using var fbd = new FolderBrowserDialog();
|
|
|
|
var dr = fbd.ShowDialog();
|
|
|
|
if (dr != DialogResult.OK)
|
2017-02-11 07:54:36 +00:00
|
|
|
return;
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
destPath = fbd.SelectedPath;
|
2017-02-11 07:54:36 +00:00
|
|
|
}
|
2016-07-13 05:19:51 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
FLP_RB.Enabled = RTB_Instructions.Enabled = B_Go.Enabled = false;
|
2016-07-21 05:43:26 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
foreach (var set in sets)
|
2017-07-01 23:07:02 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
BatchEditing.ScreenStrings(set.Filters);
|
|
|
|
BatchEditing.ScreenStrings(set.Instructions);
|
2016-07-13 05:19:51 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
RunBatchEdit(sets, TB_Folder.Text, destPath);
|
|
|
|
}
|
2018-05-18 05:43:07 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void RunBatchEdit(StringInstructionSet[] sets, string source, string? destination)
|
|
|
|
{
|
|
|
|
editor = new Core.BatchEditor();
|
|
|
|
bool finished = false, displayed = false; // hack cuz DoWork event isn't cleared after completion
|
|
|
|
b.DoWork += (sender, e) =>
|
2017-07-01 23:07:02 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (finished)
|
|
|
|
return;
|
|
|
|
if (RB_Boxes.Checked)
|
|
|
|
RunBatchEditSaveFile(sets, boxes: true);
|
|
|
|
else if (RB_Party.Checked)
|
|
|
|
RunBatchEditSaveFile(sets, party: true);
|
|
|
|
else if (destination != null)
|
|
|
|
RunBatchEditFolder(sets, source, destination);
|
|
|
|
finished = true;
|
|
|
|
};
|
|
|
|
b.ProgressChanged += (sender, e) => SetProgressBar(e.ProgressPercentage);
|
|
|
|
b.RunWorkerCompleted += (sender, e) =>
|
|
|
|
{
|
|
|
|
string result = editor.GetEditorResults(sets);
|
|
|
|
if (!displayed) WinFormsUtil.Alert(result);
|
|
|
|
displayed = true;
|
|
|
|
FLP_RB.Enabled = RTB_Instructions.Enabled = B_Go.Enabled = true;
|
|
|
|
SetupProgressBar(0);
|
|
|
|
};
|
|
|
|
b.RunWorkerAsync();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void RunBatchEditFolder(IReadOnlyCollection<StringInstructionSet> sets, string source, string destination)
|
|
|
|
{
|
|
|
|
var files = Directory.GetFiles(source, "*", SearchOption.AllDirectories);
|
|
|
|
SetupProgressBar(files.Length * sets.Count);
|
|
|
|
foreach (var set in sets)
|
|
|
|
ProcessFolder(files, destination, set.Filters, set.Instructions);
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void RunBatchEditSaveFile(IReadOnlyCollection<StringInstructionSet> sets, bool boxes = false, bool party = false)
|
|
|
|
{
|
|
|
|
var data = new List<SlotCache>();
|
|
|
|
if (party)
|
2017-07-01 23:07:02 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
SlotInfoLoader.AddPartyData(SAV, data);
|
|
|
|
process(data);
|
|
|
|
SAV.PartyData = data.ConvertAll(z => z.Entity);
|
2017-07-01 23:07:02 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
if (boxes)
|
2016-07-13 05:19:51 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
SlotInfoLoader.AddBoxData(SAV, data);
|
|
|
|
process(data);
|
|
|
|
SAV.BoxData = data.ConvertAll(z => z.Entity);
|
2016-07-13 05:19:51 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
void process(IList<SlotCache> d)
|
2016-07-13 05:19:51 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
SetupProgressBar(d.Count * sets.Count);
|
|
|
|
foreach (var set in sets)
|
|
|
|
ProcessSAV(d, set.Filters, set.Instructions);
|
2016-07-13 05:19:51 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Progress Bar
|
|
|
|
private void SetupProgressBar(int count)
|
|
|
|
{
|
|
|
|
MethodInvoker mi = () => { PB_Show.Minimum = 0; PB_Show.Step = 1; PB_Show.Value = 0; PB_Show.Maximum = count; };
|
|
|
|
if (PB_Show.InvokeRequired)
|
|
|
|
PB_Show.Invoke(mi);
|
|
|
|
else
|
|
|
|
mi.Invoke();
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void SetProgressBar(int position)
|
|
|
|
{
|
|
|
|
if (PB_Show.InvokeRequired)
|
|
|
|
PB_Show.Invoke((MethodInvoker)(() => PB_Show.Value = position));
|
|
|
|
else
|
|
|
|
PB_Show.Value = position;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ProcessSAV(IList<SlotCache> data, IReadOnlyList<StringInstruction> Filters, IReadOnlyList<StringInstruction> Instructions)
|
|
|
|
{
|
|
|
|
if (data.Count == 0)
|
|
|
|
return;
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var filterMeta = Filters.Where(f => BatchFilters.FilterMeta.Any(z => z.IsMatch(f.PropertyName))).ToArray();
|
|
|
|
if (filterMeta.Length != 0)
|
|
|
|
Filters = Filters.Except(filterMeta).ToArray();
|
2021-07-03 16:28:35 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var max = data[0].Entity.MaxSpeciesID;
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
for (int i = 0; i < data.Count; i++)
|
|
|
|
{
|
|
|
|
var entry = data[i];
|
|
|
|
var pk = data[i].Entity;
|
2021-07-03 16:28:35 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var spec = pk.Species;
|
2022-08-30 22:00:45 +00:00
|
|
|
if (spec == 0 || spec > max)
|
2022-06-18 18:04:24 +00:00
|
|
|
continue;
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (entry.Source is SlotInfoBox info && SAV.GetSlotFlags(info.Box, info.Slot).IsOverwriteProtected())
|
|
|
|
editor.AddSkipped();
|
|
|
|
else if (!BatchEditing.IsFilterMatchMeta(filterMeta, entry))
|
|
|
|
editor.AddSkipped();
|
|
|
|
else
|
|
|
|
editor.Process(pk, Filters, Instructions);
|
|
|
|
|
|
|
|
b.ReportProgress(i);
|
2016-07-13 05:19:51 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void ProcessFolder(IReadOnlyList<string> files, string destDir, IReadOnlyList<StringInstruction> pkFilters, IReadOnlyList<StringInstruction> instructions)
|
|
|
|
{
|
|
|
|
var filterMeta = pkFilters.Where(f => BatchFilters.FilterMeta.Any(z => z.IsMatch(f.PropertyName))).ToArray();
|
|
|
|
if (filterMeta.Length != 0)
|
|
|
|
pkFilters = pkFilters.Except(filterMeta).ToArray();
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
for (int i = 0; i < files.Count; i++)
|
2016-07-13 05:19:51 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
TryProcess(files[i], destDir, filterMeta, pkFilters, instructions);
|
|
|
|
b.ReportProgress(i);
|
2016-07-13 05:19:51 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2020-10-18 18:02:39 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void TryProcess(string source, string destDir, IReadOnlyList<StringInstruction> metaFilters, IReadOnlyList<StringInstruction> pkFilters, IReadOnlyList<StringInstruction> instructions)
|
|
|
|
{
|
|
|
|
var fi = new FileInfo(source);
|
|
|
|
if (!EntityDetection.IsSizePlausible(fi.Length))
|
|
|
|
return;
|
|
|
|
|
|
|
|
byte[] data = File.ReadAllBytes(source);
|
|
|
|
_ = FileUtil.TryGetPKM(data, out var pk, fi.Extension, SAV);
|
|
|
|
if (pk == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var info = new SlotInfoFile(source);
|
|
|
|
var entry = new SlotCache(info, pk);
|
|
|
|
if (!BatchEditing.IsFilterMatchMeta(metaFilters, entry))
|
2020-10-18 18:02:39 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
editor.AddSkipped();
|
|
|
|
return;
|
2020-10-18 18:02:39 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
if (editor.Process(pk, pkFilters, instructions))
|
|
|
|
File.WriteAllBytes(Path.Combine(destDir, Path.GetFileName(source)), pk.DecryptedPartyData);
|
2017-05-28 21:49:36 +00:00
|
|
|
}
|
2016-07-13 05:19:51 +00:00
|
|
|
}
|