Add go park bulk import from folder

Closes #2177
This commit is contained in:
Kurt 2018-11-23 11:01:36 -08:00
parent 17b3732a7d
commit 720be075ec
2 changed files with 50 additions and 4 deletions

View File

@ -63,6 +63,7 @@ private void InitializeComponent()
this.trainerID1 = new PKHeX.WinForms.Controls.TrainerID();
this.GB_Adventure = new System.Windows.Forms.GroupBox();
this.Tab_Complex = new System.Windows.Forms.TabPage();
this.B_ImportGoFiles = new System.Windows.Forms.Button();
this.B_ExportGoFiles = new System.Windows.Forms.Button();
this.L_GoSlotSummary = new System.Windows.Forms.Label();
this.B_Import = new System.Windows.Forms.Button();
@ -391,6 +392,7 @@ private void InitializeComponent()
// Tab_Complex
//
this.Tab_Complex.AllowDrop = true;
this.Tab_Complex.Controls.Add(this.B_ImportGoFiles);
this.Tab_Complex.Controls.Add(this.B_ExportGoFiles);
this.Tab_Complex.Controls.Add(this.L_GoSlotSummary);
this.Tab_Complex.Controls.Add(this.B_Import);
@ -408,6 +410,16 @@ private void InitializeComponent()
this.Tab_Complex.DragDrop += new System.Windows.Forms.DragEventHandler(this.Main_DragDrop);
this.Tab_Complex.DragEnter += new System.Windows.Forms.DragEventHandler(this.Main_DragEnter);
//
// B_ImportGoFiles
//
this.B_ImportGoFiles.Location = new System.Drawing.Point(6, 144);
this.B_ImportGoFiles.Name = "B_ImportGoFiles";
this.B_ImportGoFiles.Size = new System.Drawing.Size(131, 63);
this.B_ImportGoFiles.TabIndex = 7;
this.B_ImportGoFiles.Text = "Dump Individual Files of Go Park Entities";
this.B_ImportGoFiles.UseVisualStyleBackColor = true;
this.B_ImportGoFiles.Click += new System.EventHandler(this.B_ImportGoFiles_Click);
//
// B_ExportGoFiles
//
this.B_ExportGoFiles.Location = new System.Drawing.Point(6, 75);
@ -551,5 +563,6 @@ private void InitializeComponent()
private System.Windows.Forms.Button B_Export;
private System.Windows.Forms.Label L_GoSlotSummary;
private System.Windows.Forms.Button B_ExportGoFiles;
private System.Windows.Forms.Button B_ImportGoFiles;
}
}

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
@ -164,7 +165,6 @@ private void B_ExportGoFiles_Click(object sender, EventArgs e)
private void B_Import_Click(object sender, EventArgs e)
{
var sfd = new OpenFileDialog
{
Filter = GoFilter,
@ -181,6 +181,13 @@ private void B_Import_Click(object sender, EventArgs e)
}
private void ImportGP1From(string path)
{
int index = (int)NUD_GoIndex.Value;
index = Math.Min(GoParkStorage.Count - 1, Math.Max(0, index));
ImportGP1From(path, index);
}
private void ImportGP1From(string path, int index)
{
var data = File.ReadAllBytes(path);
if (data.Length != GP1.SIZE)
@ -188,9 +195,6 @@ private void ImportGP1From(string path)
WinFormsUtil.Error(MessageStrings.MsgFileLoadIncompatible);
return;
}
int index = (int)NUD_GoIndex.Value;
index = Math.Min(GoParkStorage.Count - 1, Math.Max(0, index));
var gp1 = new GP1();
data.CopyTo(gp1.Data);
Park[index] = gp1;
@ -219,6 +223,35 @@ private void B_Export_Click(object sender, EventArgs e)
File.WriteAllBytes(sfd.FileName, data.Data);
}
private void B_ImportGoFiles_Click(object sender, EventArgs e)
{
var fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() != DialogResult.OK)
return;
IEnumerable<string> files = Directory.GetFiles(fbd.SelectedPath);
files = files.Where(z => Path.GetExtension(z) == ".gp1" && new FileInfo(z).Length == GP1.SIZE);
int ctr = 0;
foreach (var f in files)
{
while (true)
{
if (ctr >= GoParkStorage.Count)
return;
if (Park[ctr].Species != 0)
ctr++;
else
break;
}
var data = File.ReadAllBytes(f);
Park[ctr] = new GP1(data);
ctr++;
}
System.Media.SystemSounds.Asterisk.Play();
}
private void NUD_GoIndex_ValueChanged(object sender, EventArgs e) => UpdateGoSummary((int)NUD_GoIndex.Value);
private void UpdateGoSummary(int index)