mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 04:23:12 +00:00
Upgrade FolderList to show recent/backups
sortable grid like the ReportGrid for pkm, can open/browse individual files
This commit is contained in:
parent
99673706a0
commit
a81c28f114
7 changed files with 317 additions and 18 deletions
|
@ -264,7 +264,7 @@ namespace PKHeX.Core
|
||||||
}
|
}
|
||||||
private int PlayedTimeOffset => Japanese ? 0x2CA0 : 0x2CED;
|
private int PlayedTimeOffset => Japanese ? 0x2CA0 : 0x2CED;
|
||||||
|
|
||||||
protected override string PlayTimeString => !PlayedMaximum ? base.PlayTimeString : $"{base.PlayTimeString} {SaveUtil.CRC16_CCITT(Data):X4}";
|
public override string PlayTimeString => !PlayedMaximum ? base.PlayTimeString : $"{base.PlayTimeString} {SaveUtil.CRC16_CCITT(Data):X4}";
|
||||||
public override int PlayedHours
|
public override int PlayedHours
|
||||||
{
|
{
|
||||||
get => Data[PlayedTimeOffset + 0];
|
get => Data[PlayedTimeOffset + 0];
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace PKHeX.Core
|
||||||
public byte[] Footer { protected get; set; } = new byte[0]; // .dsv
|
public byte[] Footer { protected get; set; } = new byte[0]; // .dsv
|
||||||
public byte[] Header { protected get; set; } = new byte[0]; // .gci
|
public byte[] Header { protected get; set; } = new byte[0]; // .gci
|
||||||
public bool Japanese { get; protected set; }
|
public bool Japanese { get; protected set; }
|
||||||
protected virtual string PlayTimeString => $"{PlayedHours}ː{PlayedMinutes:00}ː{PlayedSeconds:00}"; // not :
|
public virtual string PlayTimeString => $"{PlayedHours}ː{PlayedMinutes:00}ː{PlayedSeconds:00}"; // not :
|
||||||
public bool IndeterminateGame => Version == GameVersion.Unknown;
|
public bool IndeterminateGame => Version == GameVersion.Unknown;
|
||||||
public virtual bool IndeterminateSubVersion => false;
|
public virtual bool IndeterminateSubVersion => false;
|
||||||
public abstract string Extension { get; }
|
public abstract string Extension { get; }
|
||||||
|
@ -392,6 +392,7 @@ namespace PKHeX.Core
|
||||||
public virtual int TID { get; set; }
|
public virtual int TID { get; set; }
|
||||||
public virtual int SID { get; set; }
|
public virtual int SID { get; set; }
|
||||||
public int TrainerID7 => (int)((uint)(TID | (SID << 16)) % 1000000);
|
public int TrainerID7 => (int)((uint)(TID | (SID << 16)) % 1000000);
|
||||||
|
public int TrainerSID7 => (int)((uint)(TID | (SID << 16)) / 1000000);
|
||||||
public virtual string OT { get; set; } = "PKHeX";
|
public virtual string OT { get; set; } = "PKHeX";
|
||||||
public virtual int PlayedHours { get; set; }
|
public virtual int PlayedHours { get; set; }
|
||||||
public virtual int PlayedMinutes { get; set; }
|
public virtual int PlayedMinutes { get; set; }
|
||||||
|
|
|
@ -11,7 +11,7 @@ namespace PKHeX.Core
|
||||||
HeldItems = Legal.HeldItems_USUM;
|
HeldItems = Legal.HeldItems_USUM;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string PlayTimeString => $"{Year:00}{Month:00}{Day:00}_{Hours:00}ː{Minutes:00}";
|
public override string PlayTimeString => $"{Year:00}{Month:00}{Day:00}_{Hours:00}ː{Minutes:00}";
|
||||||
public override string BAKName => $"{FileName} [{PlayTimeString}].bak";
|
public override string BAKName => $"{FileName} [{PlayTimeString}].bak";
|
||||||
private const int GroupNameSize = 0x20;
|
private const int GroupNameSize = 0x20;
|
||||||
private const int BankNameSize = 0x24;
|
private const int BankNameSize = 0x24;
|
||||||
|
|
|
@ -386,7 +386,18 @@ namespace PKHeX.WinForms
|
||||||
C_SAV.SetPKMBoxes(); // refresh
|
C_SAV.SetPKMBoxes(); // refresh
|
||||||
C_SAV.UpdateBoxViewers();
|
C_SAV.UpdateBoxViewers();
|
||||||
}
|
}
|
||||||
private void MainMenuFolder(object sender, EventArgs e) => new SAV_FolderList().ShowDialog();
|
private void MainMenuFolder(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var ofType = Application.OpenForms.OfType<SAV_FolderList>().FirstOrDefault();
|
||||||
|
if (ofType != null)
|
||||||
|
{
|
||||||
|
ofType.CenterToForm(this);
|
||||||
|
ofType.BringToFront();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
new SAV_FolderList(s => OpenSAV(s, s.FilePath)).Show();
|
||||||
|
}
|
||||||
|
|
||||||
// Misc Options
|
// Misc Options
|
||||||
private void ClickShowdownImportPKM(object sender, EventArgs e)
|
private void ClickShowdownImportPKM(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
121
PKHeX.WinForms/Subforms/SAV_FolderList.Designer.cs
generated
121
PKHeX.WinForms/Subforms/SAV_FolderList.Designer.cs
generated
|
@ -28,26 +28,121 @@
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
|
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
|
||||||
|
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
|
||||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SAV_FolderList));
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SAV_FolderList));
|
||||||
this.FLP_Buttons = new System.Windows.Forms.FlowLayoutPanel();
|
this.FLP_Buttons = new System.Windows.Forms.FlowLayoutPanel();
|
||||||
|
this.TC_Tabs = new System.Windows.Forms.TabControl();
|
||||||
|
this.Tab_Recent = new System.Windows.Forms.TabPage();
|
||||||
|
this.dgDataRecent = new System.Windows.Forms.DataGridView();
|
||||||
|
this.Tab_Backup = new System.Windows.Forms.TabPage();
|
||||||
|
this.dgDataBackup = new System.Windows.Forms.DataGridView();
|
||||||
|
this.Tab_Folders = new System.Windows.Forms.TabPage();
|
||||||
|
this.TC_Tabs.SuspendLayout();
|
||||||
|
this.Tab_Recent.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dgDataRecent)).BeginInit();
|
||||||
|
this.Tab_Backup.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dgDataBackup)).BeginInit();
|
||||||
|
this.Tab_Folders.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// FLP_Buttons
|
// FLP_Buttons
|
||||||
//
|
//
|
||||||
this.FLP_Buttons.AutoScroll = true;
|
this.FLP_Buttons.AutoScroll = true;
|
||||||
this.FLP_Buttons.Dock = System.Windows.Forms.DockStyle.Fill;
|
this.FLP_Buttons.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
this.FLP_Buttons.Location = new System.Drawing.Point(0, 0);
|
this.FLP_Buttons.Location = new System.Drawing.Point(0, 0);
|
||||||
this.FLP_Buttons.Name = "FLP_Buttons";
|
this.FLP_Buttons.Name = "FLP_Buttons";
|
||||||
this.FLP_Buttons.Padding = new System.Windows.Forms.Padding(3);
|
this.FLP_Buttons.Padding = new System.Windows.Forms.Padding(3);
|
||||||
this.FLP_Buttons.Size = new System.Drawing.Size(304, 161);
|
this.FLP_Buttons.Size = new System.Drawing.Size(601, 335);
|
||||||
this.FLP_Buttons.TabIndex = 0;
|
this.FLP_Buttons.TabIndex = 0;
|
||||||
//
|
//
|
||||||
|
// TC_Tabs
|
||||||
|
//
|
||||||
|
this.TC_Tabs.Controls.Add(this.Tab_Recent);
|
||||||
|
this.TC_Tabs.Controls.Add(this.Tab_Backup);
|
||||||
|
this.TC_Tabs.Controls.Add(this.Tab_Folders);
|
||||||
|
this.TC_Tabs.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.TC_Tabs.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.TC_Tabs.Name = "TC_Tabs";
|
||||||
|
this.TC_Tabs.SelectedIndex = 0;
|
||||||
|
this.TC_Tabs.Size = new System.Drawing.Size(609, 361);
|
||||||
|
this.TC_Tabs.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// Tab_Recent
|
||||||
|
//
|
||||||
|
this.Tab_Recent.Controls.Add(this.dgDataRecent);
|
||||||
|
this.Tab_Recent.Location = new System.Drawing.Point(4, 22);
|
||||||
|
this.Tab_Recent.Name = "Tab_Recent";
|
||||||
|
this.Tab_Recent.Size = new System.Drawing.Size(601, 335);
|
||||||
|
this.Tab_Recent.TabIndex = 1;
|
||||||
|
this.Tab_Recent.Text = "Recent";
|
||||||
|
this.Tab_Recent.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// dgDataRecent
|
||||||
|
//
|
||||||
|
this.dgDataRecent.AllowUserToAddRows = false;
|
||||||
|
this.dgDataRecent.AllowUserToDeleteRows = false;
|
||||||
|
this.dgDataRecent.AllowUserToOrderColumns = true;
|
||||||
|
this.dgDataRecent.AllowUserToResizeColumns = false;
|
||||||
|
this.dgDataRecent.AllowUserToResizeRows = false;
|
||||||
|
dataGridViewCellStyle1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
|
||||||
|
this.dgDataRecent.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1;
|
||||||
|
this.dgDataRecent.ClipboardCopyMode = System.Windows.Forms.DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
|
||||||
|
this.dgDataRecent.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
|
||||||
|
this.dgDataRecent.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.dgDataRecent.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.dgDataRecent.Margin = new System.Windows.Forms.Padding(0);
|
||||||
|
this.dgDataRecent.Name = "dgDataRecent";
|
||||||
|
this.dgDataRecent.RowHeadersVisible = false;
|
||||||
|
this.dgDataRecent.Size = new System.Drawing.Size(601, 335);
|
||||||
|
this.dgDataRecent.TabIndex = 2;
|
||||||
|
this.dgDataRecent.CellMouseDown += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.DataGridCellMouseDown);
|
||||||
|
//
|
||||||
|
// Tab_Backup
|
||||||
|
//
|
||||||
|
this.Tab_Backup.Controls.Add(this.dgDataBackup);
|
||||||
|
this.Tab_Backup.Location = new System.Drawing.Point(4, 22);
|
||||||
|
this.Tab_Backup.Name = "Tab_Backup";
|
||||||
|
this.Tab_Backup.Size = new System.Drawing.Size(601, 335);
|
||||||
|
this.Tab_Backup.TabIndex = 2;
|
||||||
|
this.Tab_Backup.Text = "Backups";
|
||||||
|
this.Tab_Backup.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// dgDataBackup
|
||||||
|
//
|
||||||
|
this.dgDataBackup.AllowUserToAddRows = false;
|
||||||
|
this.dgDataBackup.AllowUserToDeleteRows = false;
|
||||||
|
this.dgDataBackup.AllowUserToOrderColumns = true;
|
||||||
|
this.dgDataBackup.AllowUserToResizeColumns = false;
|
||||||
|
this.dgDataBackup.AllowUserToResizeRows = false;
|
||||||
|
dataGridViewCellStyle2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
|
||||||
|
this.dgDataBackup.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle2;
|
||||||
|
this.dgDataBackup.ClipboardCopyMode = System.Windows.Forms.DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
|
||||||
|
this.dgDataBackup.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
|
||||||
|
this.dgDataBackup.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.dgDataBackup.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.dgDataBackup.Name = "dgDataBackup";
|
||||||
|
this.dgDataBackup.RowHeadersVisible = false;
|
||||||
|
this.dgDataBackup.Size = new System.Drawing.Size(601, 335);
|
||||||
|
this.dgDataBackup.TabIndex = 1;
|
||||||
|
this.dgDataBackup.CellMouseDown += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.DataGridCellMouseDown);
|
||||||
|
//
|
||||||
|
// Tab_Folders
|
||||||
|
//
|
||||||
|
this.Tab_Folders.Controls.Add(this.FLP_Buttons);
|
||||||
|
this.Tab_Folders.Location = new System.Drawing.Point(4, 22);
|
||||||
|
this.Tab_Folders.Name = "Tab_Folders";
|
||||||
|
this.Tab_Folders.Size = new System.Drawing.Size(601, 335);
|
||||||
|
this.Tab_Folders.TabIndex = 0;
|
||||||
|
this.Tab_Folders.Text = "Folders";
|
||||||
|
this.Tab_Folders.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
// SAV_FolderList
|
// SAV_FolderList
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(304, 161);
|
this.ClientSize = new System.Drawing.Size(609, 361);
|
||||||
this.Controls.Add(this.FLP_Buttons);
|
this.Controls.Add(this.TC_Tabs);
|
||||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
|
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
|
||||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||||
this.MaximizeBox = false;
|
this.MaximizeBox = false;
|
||||||
|
@ -55,6 +150,12 @@
|
||||||
this.Name = "SAV_FolderList";
|
this.Name = "SAV_FolderList";
|
||||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
||||||
this.Text = "Folder List";
|
this.Text = "Folder List";
|
||||||
|
this.TC_Tabs.ResumeLayout(false);
|
||||||
|
this.Tab_Recent.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dgDataRecent)).EndInit();
|
||||||
|
this.Tab_Backup.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dgDataBackup)).EndInit();
|
||||||
|
this.Tab_Folders.ResumeLayout(false);
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -62,5 +163,11 @@
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private System.Windows.Forms.FlowLayoutPanel FLP_Buttons;
|
private System.Windows.Forms.FlowLayoutPanel FLP_Buttons;
|
||||||
|
private System.Windows.Forms.TabControl TC_Tabs;
|
||||||
|
private System.Windows.Forms.TabPage Tab_Folders;
|
||||||
|
private System.Windows.Forms.TabPage Tab_Recent;
|
||||||
|
private System.Windows.Forms.TabPage Tab_Backup;
|
||||||
|
private System.Windows.Forms.DataGridView dgDataBackup;
|
||||||
|
private System.Windows.Forms.DataGridView dgDataRecent;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,18 +1,28 @@
|
||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using PKHeX.Core;
|
||||||
|
using PKHeX.WinForms.Properties;
|
||||||
using static PKHeX.Core.MessageStrings;
|
using static PKHeX.Core.MessageStrings;
|
||||||
|
|
||||||
namespace PKHeX.WinForms
|
namespace PKHeX.WinForms
|
||||||
{
|
{
|
||||||
public partial class SAV_FolderList : Form
|
public partial class SAV_FolderList : Form
|
||||||
{
|
{
|
||||||
public SAV_FolderList()
|
private readonly Action<SaveFile> OpenSaveFile;
|
||||||
|
private readonly List<CustomFolderPath> Paths;
|
||||||
|
private readonly SortableBindingList<SavePreview> Recent;
|
||||||
|
private readonly SortableBindingList<SavePreview> Backup;
|
||||||
|
|
||||||
|
public SAV_FolderList(Action<SaveFile> openSaveFile)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
OpenSaveFile = openSaveFile;
|
||||||
|
|
||||||
// Preprogrammed folders
|
// Preprogrammed folders
|
||||||
var locs = new List<CustomFolderPath>
|
var locs = new List<CustomFolderPath>
|
||||||
|
@ -25,12 +35,24 @@ namespace PKHeX.WinForms
|
||||||
addIfExists(CyberGadgetUtil.GetCacheFolder(), "CGSE Cache");
|
addIfExists(CyberGadgetUtil.GetCacheFolder(), "CGSE Cache");
|
||||||
addIfExists(CyberGadgetUtil.GetTempFolder(), "CGSE Temp");
|
addIfExists(CyberGadgetUtil.GetTempFolder(), "CGSE Temp");
|
||||||
|
|
||||||
var paths = locs.GroupBy(z => z.Path).Select(z => z.First())
|
Paths = locs.GroupBy(z => z.Path).Select(z => z.First())
|
||||||
.OrderByDescending(z => Directory.Exists(z.Path));
|
.OrderByDescending(z => Directory.Exists(z.Path)).ToList();
|
||||||
foreach (var loc in paths)
|
foreach (var loc in Paths)
|
||||||
AddButton(loc.DisplayText, loc.Path);
|
AddButton(loc.DisplayText, loc.Path);
|
||||||
|
|
||||||
|
var recent = PathUtilWindows.GetSaveFiles(Paths.Select(z => z.Path).Where(z => z != Main.BackupPath));
|
||||||
|
Recent = PopulateData(dgDataRecent, recent);
|
||||||
|
var backup = PathUtilWindows.GetSaveFiles(Main.BackupPath);
|
||||||
|
Backup = PopulateData(dgDataBackup, backup);
|
||||||
|
|
||||||
|
dgDataRecent.ContextMenuStrip = GetContextMenu(dgDataRecent);
|
||||||
|
dgDataBackup.ContextMenuStrip = GetContextMenu(dgDataBackup);
|
||||||
|
|
||||||
|
dgDataRecent.DoubleBuffered(true);
|
||||||
|
dgDataBackup.DoubleBuffered(true);
|
||||||
|
|
||||||
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
||||||
|
CenterToParent();
|
||||||
|
|
||||||
void addIfExists(string path, string text)
|
void addIfExists(string path, string text)
|
||||||
{
|
{
|
||||||
|
@ -92,7 +114,7 @@ namespace PKHeX.WinForms
|
||||||
return paths.Select(z => new CustomFolderPath(z));
|
return paths.Select(z => new CustomFolderPath(z));
|
||||||
}
|
}
|
||||||
|
|
||||||
private struct CustomFolderPath
|
private class CustomFolderPath
|
||||||
{
|
{
|
||||||
public readonly string Path;
|
public readonly string Path;
|
||||||
public readonly string DisplayText;
|
public readonly string DisplayText;
|
||||||
|
@ -121,5 +143,155 @@ namespace PKHeX.WinForms
|
||||||
DisplayText = display;
|
DisplayText = display;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string GetParentFolderName(SaveFile first)
|
||||||
|
{
|
||||||
|
var parent = Paths.Find(z => first.FilePath.StartsWith(z.Path));
|
||||||
|
return parent?.DisplayText ?? "???";
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class SaveList<T> : SortableBindingList<T> { }
|
||||||
|
private sealed class SavePreview
|
||||||
|
{
|
||||||
|
public readonly SaveFile Save;
|
||||||
|
|
||||||
|
public SavePreview(SaveFile sav, string parent)
|
||||||
|
{
|
||||||
|
Save = sav;
|
||||||
|
Folder = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string OT => Save.OT;
|
||||||
|
public int G => Save.Generation;
|
||||||
|
public GameVersion Game => Save.Version;
|
||||||
|
|
||||||
|
public string Played => Save.PlayTimeString.PadLeft(9, '0');
|
||||||
|
public string FileTime => new FileInfo(Save.FilePath).LastWriteTime.ToString("yyyy.MM.dd:hh:mm:ss");
|
||||||
|
|
||||||
|
public int TID => Save.Generation >= 7 ? Save.TrainerID7 : Save.TID;
|
||||||
|
public int SID => Save.Generation >= 7 ? Save.TrainerSID7 : Save.SID;
|
||||||
|
|
||||||
|
// ReSharper disable once MemberCanBePrivate.Local
|
||||||
|
// ReSharper disable once UnusedAutoPropertyAccessor.Local
|
||||||
|
public string Folder { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private ContextMenuStrip GetContextMenu(DataGridView dgv)
|
||||||
|
{
|
||||||
|
var mnuOpen = new ToolStripMenuItem
|
||||||
|
{
|
||||||
|
Name = "mnuOpen",
|
||||||
|
Text = "Open",
|
||||||
|
Image = Resources.open,
|
||||||
|
};
|
||||||
|
mnuOpen.Click += (sender, e) => ClickOpenFile(dgv);
|
||||||
|
|
||||||
|
var mnuBrowseAt = new ToolStripMenuItem
|
||||||
|
{
|
||||||
|
Name = "mnuBrowseAt",
|
||||||
|
Text = "Browse...",
|
||||||
|
Image = Resources.folder,
|
||||||
|
};
|
||||||
|
mnuBrowseAt.Click += (sender, e) => ClickOpenFolder(dgv);
|
||||||
|
|
||||||
|
ContextMenuStrip mnu = new ContextMenuStrip();
|
||||||
|
mnu.Items.Add(mnuOpen);
|
||||||
|
mnu.Items.Add(mnuBrowseAt);
|
||||||
|
return mnu;
|
||||||
|
}
|
||||||
|
private void ClickOpenFile(DataGridView dgv)
|
||||||
|
{
|
||||||
|
var sav = GetSaveFile(dgv);
|
||||||
|
if (sav == null)
|
||||||
|
{
|
||||||
|
WinFormsUtil.Alert(MsgFileLoadFail);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
OpenSaveFile(sav.Save);
|
||||||
|
}
|
||||||
|
private void ClickOpenFolder(DataGridView dgv)
|
||||||
|
{
|
||||||
|
var sav = GetSaveFile(dgv);
|
||||||
|
if (sav == null)
|
||||||
|
{
|
||||||
|
WinFormsUtil.Alert(MsgFileLoadFail);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var path = sav.Save.FilePath;
|
||||||
|
Process.Start("explorer.exe", $"/select, \"{path}\"");
|
||||||
|
}
|
||||||
|
private SavePreview GetSaveFile(DataGridView dgData)
|
||||||
|
{
|
||||||
|
var c = dgData.SelectedCells;
|
||||||
|
if (c.Count != 1)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var item = c[0].RowIndex;
|
||||||
|
var parent = dgData == dgDataRecent ? Recent : Backup;
|
||||||
|
return parent[item];
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DataGridCellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.ColumnIndex == -1 || e.RowIndex == -1 || e.Button != MouseButtons.Right)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var c = ((DataGridView) sender)[e.ColumnIndex, e.RowIndex];
|
||||||
|
c.DataGridView.ClearSelection();
|
||||||
|
c.DataGridView.CurrentCell = c;
|
||||||
|
c.Selected = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SaveList<SavePreview> PopulateData(DataGridView dgData, IEnumerable<SaveFile> saves)
|
||||||
|
{
|
||||||
|
var list = new SaveList<SavePreview>();
|
||||||
|
|
||||||
|
var enumerator = saves.GetEnumerator();
|
||||||
|
while (enumerator.Current == null)
|
||||||
|
{
|
||||||
|
if (!enumerator.MoveNext())
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
var first = enumerator.Current;
|
||||||
|
var sav1 = new SavePreview(first, GetParentFolderName(first));
|
||||||
|
LoadEntryInitial(dgData, list, sav1);
|
||||||
|
Task.Run(async () => // load the rest async
|
||||||
|
{
|
||||||
|
while (enumerator.MoveNext())
|
||||||
|
{
|
||||||
|
var next = enumerator.Current;
|
||||||
|
if (next == null)
|
||||||
|
continue;
|
||||||
|
var sav = new SavePreview(next, GetParentFolderName(next));
|
||||||
|
while (!dgData.IsHandleCreated)
|
||||||
|
await Task.Delay(100).ConfigureAwait(false);
|
||||||
|
dgData.Invoke(new Action(() => LoadEntry(dgData, list, sav)));
|
||||||
|
}
|
||||||
|
enumerator.Dispose();
|
||||||
|
});
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void LoadEntryInitial(DataGridView dgData, SaveList<SavePreview> list, SavePreview sav)
|
||||||
|
{
|
||||||
|
list.Add(sav);
|
||||||
|
dgData.DataSource = list;
|
||||||
|
dgData.AutoGenerateColumns = true;
|
||||||
|
for (int i = 0; i < dgData.Columns.Count; i++)
|
||||||
|
dgData.Columns[i].SortMode = DataGridViewColumnSortMode.Automatic;
|
||||||
|
dgData.AutoResizeColumns(); // Trigger Resizing
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void LoadEntry(DataGridView dgData, ICollection<SavePreview> list, SavePreview sav)
|
||||||
|
{
|
||||||
|
dgData.SuspendLayout();
|
||||||
|
list.Add(sav);
|
||||||
|
dgData.AutoResizeColumns();
|
||||||
|
dgData.ResumeLayout();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,12 +90,20 @@ namespace PKHeX.WinForms
|
||||||
return saves.FirstOrDefault(z => z?.ChecksumsValid == true);
|
return saves.FirstOrDefault(z => z?.ChecksumsValid == true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets all detectable save files ordered by most recently saved (by file write time).
|
/// Gets all detectable save files ordered by most recently saved (by file write time).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="extra">Paths to check in addition to the default paths</param>
|
/// <param name="extra">Paths to check in addition to the default paths</param>
|
||||||
/// <returns>Valid save files, if any.</returns>
|
/// <returns>Valid save files, if any.</returns>
|
||||||
public static IEnumerable<SaveFile> GetSaveFiles(params string[] extra)
|
public static IEnumerable<SaveFile> GetSaveFiles(params string[] extra) => GetSaveFiles((IEnumerable<string>)extra);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all detectable save files ordered by most recently saved (by file write time).
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="extra">Paths to check in addition to the default paths</param>
|
||||||
|
/// <returns>Valid save files, if any.</returns>
|
||||||
|
public static IEnumerable<SaveFile> GetSaveFiles(IEnumerable<string> extra)
|
||||||
{
|
{
|
||||||
var foldersToCheck = GetFoldersToCheck(extra);
|
var foldersToCheck = GetFoldersToCheck(extra);
|
||||||
var result = GetSaveFilePathsFromFolders(foldersToCheck, out var possiblePaths);
|
var result = GetSaveFilePathsFromFolders(foldersToCheck, out var possiblePaths);
|
||||||
|
|
Loading…
Reference in a new issue