2016-07-13 05:19:51 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-03-08 08:16:34 +00:00
|
|
|
|
using System.Drawing;
|
2016-07-13 05:19:51 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
2017-01-08 07:54:09 +00:00
|
|
|
|
using PKHeX.Core;
|
2018-04-07 04:23:09 +00:00
|
|
|
|
using static PKHeX.Core.MessageStrings;
|
2016-07-13 05:19:51 +00:00
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.WinForms
|
2016-07-13 05:19:51 +00:00
|
|
|
|
{
|
|
|
|
|
public partial class BatchEditor : Form
|
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private readonly SaveFile SAV;
|
2019-10-27 19:57:04 +00:00
|
|
|
|
private readonly PKM pkm;
|
|
|
|
|
private int currentFormat = -1;
|
2018-07-29 23:39:15 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
public BatchEditor(PKM pk, SaveFile sav)
|
2016-07-13 05:19:51 +00:00
|
|
|
|
{
|
2018-04-03 03:36:13 +00:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
2019-10-27 19:57:04 +00:00
|
|
|
|
pkm = pk;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
SAV = sav;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
DragDrop += TabMain_DragDrop;
|
|
|
|
|
DragEnter += TabMain_DragEnter;
|
2016-12-07 05:36:31 +00:00
|
|
|
|
|
|
|
|
|
CB_Format.Items.Clear();
|
2018-04-07 04:23:09 +00:00
|
|
|
|
CB_Format.Items.Add(MsgAny);
|
2018-05-18 05:43:07 +00:00
|
|
|
|
foreach (Type t in BatchEditing.Types)
|
2021-06-24 16:16:36 +00:00
|
|
|
|
CB_Format.Items.Add(t.Name.ToLowerInvariant());
|
2018-04-07 04:23:09 +00:00
|
|
|
|
CB_Format.Items.Add(MsgAll);
|
2016-12-07 05:36:31 +00:00
|
|
|
|
|
2016-07-18 00:06:50 +00:00
|
|
|
|
CB_Format.SelectedIndex = CB_Require.SelectedIndex = 0;
|
2019-10-26 19:33:58 +00:00
|
|
|
|
toolTip1.SetToolTip(CB_Property, MsgBEToolTipPropName);
|
|
|
|
|
toolTip2.SetToolTip(L_PropType, MsgBEToolTipPropType);
|
|
|
|
|
toolTip3.SetToolTip(L_PropValue, MsgBEToolTipPropValue);
|
2016-07-13 05:19:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void B_Open_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!B_Go.Enabled) return;
|
2019-10-08 01:40:09 +00:00
|
|
|
|
using var fbd = new FolderBrowserDialog();
|
2016-07-13 05:19:51 +00:00
|
|
|
|
if (fbd.ShowDialog() != DialogResult.OK)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
TB_Folder.Text = fbd.SelectedPath;
|
|
|
|
|
TB_Folder.Visible = true;
|
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
|
2016-07-13 05:19:51 +00:00
|
|
|
|
private void B_SAV_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2018-09-29 19:22:13 +00:00
|
|
|
|
TB_Folder.Text = string.Empty;
|
2016-07-13 05:19:51 +00:00
|
|
|
|
TB_Folder.Visible = false;
|
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
|
2016-07-13 05:19:51 +00:00
|
|
|
|
private void B_Go_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
RunBackgroundWorker();
|
2016-07-13 05:19:51 +00:00
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
|
2017-02-11 07:54:36 +00:00
|
|
|
|
private void B_Add_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (CB_Property.SelectedIndex < 0)
|
2018-04-07 04:23:09 +00:00
|
|
|
|
{ WinFormsUtil.Alert(MsgBEPropertyInvalid); return; }
|
2017-02-11 07:54:36 +00:00
|
|
|
|
|
2019-02-03 18:28:33 +00:00
|
|
|
|
var prefix = StringInstruction.Prefixes;
|
2018-09-29 19:22:13 +00:00
|
|
|
|
string s = prefix[CB_Require.SelectedIndex] + CB_Property.Items[CB_Property.SelectedIndex].ToString() + StringInstruction.SplitInstruction;
|
2021-07-27 06:33:56 +00:00
|
|
|
|
if (RTB_Instructions.Lines.Length != 0 && RTB_Instructions.Lines[^1].Length > 0)
|
2017-02-11 07:54:36 +00:00
|
|
|
|
s = Environment.NewLine + s;
|
|
|
|
|
|
|
|
|
|
RTB_Instructions.AppendText(s);
|
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
|
2017-02-11 07:54:36 +00:00
|
|
|
|
private void CB_Format_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (currentFormat == CB_Format.SelectedIndex)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int format = CB_Format.SelectedIndex;
|
|
|
|
|
CB_Property.Items.Clear();
|
2018-05-18 05:43:07 +00:00
|
|
|
|
CB_Property.Items.AddRange(BatchEditing.Properties[format]);
|
2017-02-11 07:54:36 +00:00
|
|
|
|
CB_Property.SelectedIndex = 0;
|
|
|
|
|
currentFormat = format;
|
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
|
2017-02-11 07:54:36 +00:00
|
|
|
|
private void CB_Property_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2018-05-18 05:43:07 +00:00
|
|
|
|
L_PropType.Text = BatchEditing.GetPropertyType(CB_Property.Text, CB_Format.SelectedIndex);
|
2019-10-27 19:57:04 +00:00
|
|
|
|
if (BatchEditing.TryGetHasProperty(pkm, CB_Property.Text, out var pi))
|
2017-03-08 08:16:34 +00:00
|
|
|
|
{
|
2019-10-27 19:57:04 +00:00
|
|
|
|
L_PropValue.Text = pi.GetValue(pkm)?.ToString();
|
2017-03-08 08:16:34 +00:00
|
|
|
|
L_PropType.ForeColor = L_PropValue.ForeColor; // reset color
|
|
|
|
|
}
|
|
|
|
|
else // no property, flag
|
|
|
|
|
{
|
|
|
|
|
L_PropValue.Text = string.Empty;
|
|
|
|
|
L_PropType.ForeColor = Color.Red;
|
|
|
|
|
}
|
2017-02-11 07:54:36 +00:00
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
|
2021-12-05 06:29:51 +00:00
|
|
|
|
private static void TabMain_DragEnter(object? sender, DragEventArgs? e)
|
2017-02-11 07:54:36 +00:00
|
|
|
|
{
|
2021-12-05 06:29:51 +00:00
|
|
|
|
if (e?.Data is null)
|
|
|
|
|
return;
|
2017-02-11 07:54:36 +00:00
|
|
|
|
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
|
2021-12-05 06:29:51 +00:00
|
|
|
|
private void TabMain_DragDrop(object? sender, DragEventArgs? e)
|
2017-02-11 07:54:36 +00:00
|
|
|
|
{
|
2021-12-05 06:29:51 +00:00
|
|
|
|
if (e?.Data?.GetData(DataFormats.FileDrop) is not string[] {Length: not 0} files)
|
|
|
|
|
return;
|
2017-02-11 07:54:36 +00:00
|
|
|
|
if (!Directory.Exists(files[0]))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
TB_Folder.Text = files[0];
|
|
|
|
|
TB_Folder.Visible = true;
|
2018-05-16 23:51:38 +00:00
|
|
|
|
RB_Boxes.Checked = RB_Party.Checked = false;
|
2017-02-11 07:54:36 +00:00
|
|
|
|
RB_Path.Checked = true;
|
|
|
|
|
}
|
2016-07-13 05:19:51 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void RunBackgroundWorker()
|
2016-07-13 05:19:51 +00:00
|
|
|
|
{
|
2017-07-01 23:07:02 +00:00
|
|
|
|
if (RTB_Instructions.Lines.Any(line => line.Length == 0))
|
2018-04-07 04:23:09 +00:00
|
|
|
|
{ WinFormsUtil.Error(MsgBEInstructionInvalid); return; }
|
2017-07-01 23:07:02 +00:00
|
|
|
|
|
2017-10-14 00:24:26 +00:00
|
|
|
|
var sets = StringInstructionSet.GetBatchSets(RTB_Instructions.Lines).ToArray();
|
|
|
|
|
if (sets.Any(s => s.Filters.Any(z => string.IsNullOrWhiteSpace(z.PropertyValue))))
|
2018-04-07 04:23:09 +00:00
|
|
|
|
{ WinFormsUtil.Error(MsgBEFilterEmpty); return; }
|
2016-07-21 05:43:26 +00:00
|
|
|
|
|
2018-05-12 19:28:48 +00:00
|
|
|
|
if (sets.Any(z => z.Instructions.Count == 0))
|
2018-04-07 04:23:09 +00:00
|
|
|
|
{ WinFormsUtil.Error(MsgBEInstructionNone); return; }
|
2017-07-01 23:07:02 +00:00
|
|
|
|
|
2017-10-14 00:24:26 +00:00
|
|
|
|
var emptyVal = sets.SelectMany(s => s.Instructions.Where(z => string.IsNullOrWhiteSpace(z.PropertyValue))).ToArray();
|
2018-05-12 19:28:48 +00:00
|
|
|
|
if (emptyVal.Length > 0)
|
2016-11-27 21:32:32 +00:00
|
|
|
|
{
|
|
|
|
|
string props = string.Join(", ", emptyVal.Select(z => z.PropertyName));
|
2018-04-07 04:23:09 +00:00
|
|
|
|
string invalid = MsgBEPropertyEmpty + Environment.NewLine + props;
|
|
|
|
|
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, invalid, MsgContinue))
|
2016-11-27 21:32:32 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2016-07-21 05:43:26 +00:00
|
|
|
|
|
2020-10-18 18:02:39 +00:00
|
|
|
|
string? destPath = null;
|
2016-07-31 06:03:41 +00:00
|
|
|
|
if (RB_Path.Checked)
|
|
|
|
|
{
|
2018-04-07 04:23:09 +00:00
|
|
|
|
WinFormsUtil.Alert(MsgExportFolder, MsgExportFolderAdvice);
|
2019-10-08 01:40:09 +00:00
|
|
|
|
using var fbd = new FolderBrowserDialog();
|
2016-07-31 06:03:41 +00:00
|
|
|
|
var dr = fbd.ShowDialog();
|
|
|
|
|
if (dr != DialogResult.OK)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
destPath = fbd.SelectedPath;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-21 05:43:26 +00:00
|
|
|
|
FLP_RB.Enabled = RTB_Instructions.Enabled = B_Go.Enabled = false;
|
|
|
|
|
|
2017-10-14 00:24:26 +00:00
|
|
|
|
foreach (var set in sets)
|
|
|
|
|
{
|
2018-05-18 05:43:07 +00:00
|
|
|
|
BatchEditing.ScreenStrings(set.Filters);
|
|
|
|
|
BatchEditing.ScreenStrings(set.Instructions);
|
2017-10-14 00:24:26 +00:00
|
|
|
|
}
|
|
|
|
|
RunBatchEdit(sets, TB_Folder.Text, destPath);
|
2017-07-01 23:07:02 +00:00
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
|
2020-10-18 18:02:39 +00:00
|
|
|
|
private void RunBatchEdit(StringInstructionSet[] sets, string source, string? destination)
|
2017-07-01 23:07:02 +00:00
|
|
|
|
{
|
2018-05-18 05:43:07 +00:00
|
|
|
|
editor = new Core.BatchEditor();
|
2020-02-12 17:58:46 +00:00
|
|
|
|
bool finished = false, displayed = false; // hack cuz DoWork event isn't cleared after completion
|
2017-07-01 23:07:02 +00:00
|
|
|
|
b.DoWork += (sender, e) =>
|
|
|
|
|
{
|
2019-11-16 01:34:18 +00:00
|
|
|
|
if (finished)
|
|
|
|
|
return;
|
2018-05-16 23:51:38 +00:00
|
|
|
|
if (RB_Boxes.Checked)
|
|
|
|
|
RunBatchEditSaveFile(sets, boxes: true);
|
|
|
|
|
else if (RB_Party.Checked)
|
|
|
|
|
RunBatchEditSaveFile(sets, party: true);
|
2020-10-18 18:02:39 +00:00
|
|
|
|
else if (destination != null)
|
2017-10-14 00:24:26 +00:00
|
|
|
|
RunBatchEditFolder(sets, source, destination);
|
2019-11-16 01:34:18 +00:00
|
|
|
|
finished = true;
|
2016-07-13 05:19:51 +00:00
|
|
|
|
};
|
2017-07-01 23:07:02 +00:00
|
|
|
|
b.ProgressChanged += (sender, e) => SetProgressBar(e.ProgressPercentage);
|
|
|
|
|
b.RunWorkerCompleted += (sender, e) =>
|
2016-07-13 05:19:51 +00:00
|
|
|
|
{
|
2018-05-18 05:43:07 +00:00
|
|
|
|
string result = editor.GetEditorResults(sets);
|
2020-02-12 17:58:46 +00:00
|
|
|
|
if (!displayed) WinFormsUtil.Alert(result);
|
|
|
|
|
displayed = true;
|
2016-07-13 05:19:51 +00:00
|
|
|
|
FLP_RB.Enabled = RTB_Instructions.Enabled = B_Go.Enabled = true;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetupProgressBar(0);
|
2016-07-13 05:19:51 +00:00
|
|
|
|
};
|
|
|
|
|
b.RunWorkerAsync();
|
|
|
|
|
}
|
2018-05-18 05:43:07 +00:00
|
|
|
|
|
2019-10-26 19:33:58 +00:00
|
|
|
|
private void RunBatchEditFolder(IReadOnlyCollection<StringInstructionSet> sets, string source, string destination)
|
2017-07-01 23:07:02 +00:00
|
|
|
|
{
|
|
|
|
|
var files = Directory.GetFiles(source, "*", SearchOption.AllDirectories);
|
2017-10-14 00:24:26 +00:00
|
|
|
|
SetupProgressBar(files.Length * sets.Count);
|
|
|
|
|
foreach (var set in sets)
|
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
|
|
|
|
ProcessFolder(files, destination, set.Filters, set.Instructions);
|
2017-07-01 23:07:02 +00:00
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
|
2019-10-26 19:33:58 +00:00
|
|
|
|
private void RunBatchEditSaveFile(IReadOnlyCollection<StringInstructionSet> sets, bool boxes = false, bool party = false)
|
2017-07-01 23:07:02 +00:00
|
|
|
|
{
|
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
|
|
|
|
var data = new List<SlotCache>();
|
|
|
|
|
if (party)
|
|
|
|
|
{
|
|
|
|
|
SlotInfoLoader.AddPartyData(SAV, data);
|
|
|
|
|
process(data);
|
|
|
|
|
SAV.PartyData = data.ConvertAll(z => z.Entity);
|
|
|
|
|
}
|
|
|
|
|
if (boxes)
|
|
|
|
|
{
|
|
|
|
|
SlotInfoLoader.AddBoxData(SAV, data);
|
|
|
|
|
process(data);
|
|
|
|
|
SAV.BoxData = data.ConvertAll(z => z.Entity);
|
|
|
|
|
}
|
|
|
|
|
void process(IList<SlotCache> d)
|
2017-07-01 23:07:02 +00:00
|
|
|
|
{
|
2017-10-14 00:24:26 +00:00
|
|
|
|
SetupProgressBar(d.Count * sets.Count);
|
|
|
|
|
foreach (var set in sets)
|
2019-09-11 05:07:50 +00:00
|
|
|
|
ProcessSAV(d, set.Filters, set.Instructions);
|
2017-07-01 23:07:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-13 05:19:51 +00:00
|
|
|
|
|
|
|
|
|
// Progress Bar
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void SetupProgressBar(int count)
|
2016-07-13 05:19:51 +00:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
2021-08-06 03:33:25 +00:00
|
|
|
|
private void SetProgressBar(int position)
|
2016-07-13 05:19:51 +00:00
|
|
|
|
{
|
|
|
|
|
if (PB_Show.InvokeRequired)
|
2021-08-06 03:33:25 +00:00
|
|
|
|
PB_Show.Invoke((MethodInvoker)(() => PB_Show.Value = position));
|
2018-07-29 23:39:15 +00:00
|
|
|
|
else
|
2021-08-06 03:33:25 +00:00
|
|
|
|
PB_Show.Value = position;
|
2016-07-13 05:19:51 +00:00
|
|
|
|
}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2016-07-13 05:19:51 +00:00
|
|
|
|
// Mass Editing
|
2020-12-22 07:37:07 +00:00
|
|
|
|
private Core.BatchEditor editor = new();
|
2018-07-29 23:39:15 +00:00
|
|
|
|
|
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
|
|
|
|
private void ProcessSAV(IList<SlotCache> data, IReadOnlyList<StringInstruction> Filters, IReadOnlyList<StringInstruction> Instructions)
|
2016-07-13 05:19:51 +00:00
|
|
|
|
{
|
2021-07-03 16:28:35 +00:00
|
|
|
|
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
|
|
|
|
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
|
|
|
|
var max = data[0].Entity.MaxSpeciesID;
|
|
|
|
|
|
2017-09-29 05:20:27 +00:00
|
|
|
|
for (int i = 0; i < data.Count; i++)
|
2016-07-13 05:19:51 +00:00
|
|
|
|
{
|
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
|
|
|
|
var entry = data[i];
|
|
|
|
|
var pk = data[i].Entity;
|
|
|
|
|
|
2021-07-03 16:28:35 +00:00
|
|
|
|
var spec = pk.Species;
|
|
|
|
|
if (spec <= 0 || spec > max)
|
|
|
|
|
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
|
|
|
|
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);
|
|
|
|
|
|
2016-07-13 05:19:51 +00:00
|
|
|
|
b.ReportProgress(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
|
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
|
|
|
|
private void ProcessFolder(IReadOnlyList<string> files, string destDir, IReadOnlyList<StringInstruction> pkFilters, IReadOnlyList<StringInstruction> instructions)
|
2016-07-13 05:19:51 +00:00
|
|
|
|
{
|
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
|
|
|
|
var filterMeta = pkFilters.Where(f => BatchFilters.FilterMeta.Any(z => z.IsMatch(f.PropertyName))).ToArray();
|
|
|
|
|
if (filterMeta.Length != 0)
|
|
|
|
|
pkFilters = pkFilters.Except(filterMeta).ToArray();
|
|
|
|
|
|
2017-09-29 05:20:27 +00:00
|
|
|
|
for (int i = 0; i < files.Count; i++)
|
2016-07-13 05:19:51 +00:00
|
|
|
|
{
|
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
|
|
|
|
TryProcess(files[i], destDir, filterMeta, pkFilters, instructions);
|
2016-07-13 05:19:51 +00:00
|
|
|
|
b.ReportProgress(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-18 18:02:39 +00:00
|
|
|
|
|
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
|
|
|
|
private void TryProcess(string source, string destDir, IReadOnlyList<StringInstruction> metaFilters, IReadOnlyList<StringInstruction> pkFilters, IReadOnlyList<StringInstruction> instructions)
|
2020-10-18 18:02:39 +00:00
|
|
|
|
{
|
|
|
|
|
var fi = new FileInfo(source);
|
|
|
|
|
if (!PKX.IsPKM(fi.Length))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
byte[] data = File.ReadAllBytes(source);
|
2021-08-05 23:29:32 +00:00
|
|
|
|
_ = FileUtil.TryGetPKM(data, out var pk, fi.Extension, SAV);
|
2020-10-18 18:02:39 +00:00
|
|
|
|
if (pk == null)
|
|
|
|
|
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
|
|
|
|
var info = new SlotInfoFile(source);
|
|
|
|
|
var entry = new SlotCache(info, pk);
|
2021-09-16 00:35:41 +00:00
|
|
|
|
if (!BatchEditing.IsFilterMatchMeta(metaFilters, entry))
|
|
|
|
|
{
|
|
|
|
|
editor.AddSkipped();
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
if (editor.Process(pk, pkFilters, instructions))
|
|
|
|
|
File.WriteAllBytes(Path.Combine(destDir, Path.GetFileName(source)), pk.DecryptedPartyData);
|
2020-10-18 18:02:39 +00:00
|
|
|
|
}
|
2017-05-28 21:49:36 +00:00
|
|
|
|
}
|
2016-07-13 05:19:51 +00:00
|
|
|
|
}
|