2022-06-18 18:04:24 +00:00
|
|
|
using System;
|
2014-06-28 21:22:05 +00:00
|
|
|
using System.Collections.Generic;
|
2016-01-03 04:22:53 +00:00
|
|
|
using System.Diagnostics;
|
2014-06-28 21:22:05 +00:00
|
|
|
using System.Drawing;
|
2016-08-31 04:12:47 +00:00
|
|
|
using System.Globalization;
|
2014-06-28 21:22:05 +00:00
|
|
|
using System.IO;
|
2015-02-13 04:26:23 +00:00
|
|
|
using System.Linq;
|
2016-01-03 18:47:44 +00:00
|
|
|
using System.Media;
|
2015-02-13 04:26:23 +00:00
|
|
|
using System.Threading;
|
2017-06-18 01:37:19 +00:00
|
|
|
using System.Threading.Tasks;
|
2015-02-13 04:26:23 +00:00
|
|
|
using System.Windows.Forms;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
using PKHeX.Core;
|
2019-09-29 16:47:06 +00:00
|
|
|
using PKHeX.Drawing;
|
2021-11-27 23:48:08 +00:00
|
|
|
using PKHeX.Drawing.Misc;
|
|
|
|
using PKHeX.Drawing.PokeSprite;
|
2017-05-23 04:55:05 +00:00
|
|
|
using PKHeX.WinForms.Controls;
|
2018-04-06 04:25:18 +00:00
|
|
|
using static PKHeX.Core.MessageStrings;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.WinForms;
|
|
|
|
|
|
|
|
public partial class Main : Form
|
2014-06-28 21:22:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
public Main()
|
2014-06-28 21:22:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
string[] args = Environment.GetCommandLineArgs();
|
|
|
|
FormLoadInitialSettings(args, out bool showChangelog, out bool BAKprompt);
|
|
|
|
|
|
|
|
InitializeComponent();
|
2023-05-09 17:50:15 +00:00
|
|
|
if (Settings.Display.DisableScalingDpi)
|
|
|
|
AutoScaleMode = AutoScaleMode.Font;
|
2022-06-18 18:04:24 +00:00
|
|
|
C_SAV.SetEditEnvironment(new SaveDataEditor<PictureBox>(new FakeSaveFile(), PKME_Tabs));
|
|
|
|
FormLoadAddEvents();
|
|
|
|
#if DEBUG // translation updater -- all controls are added at this point -- call translate now
|
|
|
|
if (DevUtil.IsUpdatingTranslations)
|
|
|
|
WinFormsUtil.TranslateInterface(this, CurrentLanguage); // Translate the UI to language.
|
|
|
|
#endif
|
|
|
|
FormInitializeSecond();
|
|
|
|
FormLoadCheckForUpdates();
|
2020-02-12 04:11:33 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var startup = new StartupArguments();
|
|
|
|
startup.ReadArguments(args);
|
|
|
|
startup.ReadSettings(Settings.Startup);
|
|
|
|
startup.ReadTemplateIfNoEntity(TemplatePath);
|
2017-06-18 20:02:02 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (Settings.Startup.PluginLoadMethod != PluginLoadSetting.DontLoad)
|
|
|
|
FormLoadPlugins();
|
2020-10-29 00:27:11 +00:00
|
|
|
|
2023-09-28 14:04:12 +00:00
|
|
|
FormLoadInitialFiles(startup);
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (HaX)
|
|
|
|
{
|
|
|
|
EntityConverter.AllowIncompatibleConversion = EntityCompatibilitySetting.AllowIncompatibleAll;
|
|
|
|
WinFormsUtil.Alert(MsgProgramIllegalModeActive, MsgProgramIllegalModeBehave);
|
2017-06-18 20:02:02 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else if (showChangelog)
|
2017-06-18 20:02:02 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
ShowAboutDialog(AboutPage.Changelog);
|
2017-06-18 20:02:02 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (BAKprompt && !Directory.Exists(BackupPath))
|
|
|
|
PromptBackup();
|
|
|
|
|
|
|
|
BringToFront();
|
|
|
|
WindowState = FormWindowState.Minimized;
|
|
|
|
Show();
|
|
|
|
WindowState = FormWindowState.Normal;
|
|
|
|
}
|
|
|
|
|
|
|
|
#region Important Variables
|
|
|
|
public static string CurrentLanguage
|
|
|
|
{
|
|
|
|
get => GameInfo.CurrentLanguage;
|
|
|
|
private set => GameInfo.CurrentLanguage = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static bool _unicode;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public static bool Unicode
|
|
|
|
{
|
|
|
|
get => _unicode;
|
|
|
|
private set
|
2017-06-18 20:02:02 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
_unicode = value;
|
|
|
|
GenderSymbols = value ? GameInfo.GenderSymbolUnicode : GameInfo.GenderSymbolASCII;
|
2017-06-18 20:02:02 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2016-08-31 04:12:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public static IReadOnlyList<string> GenderSymbols { get; private set; } = GameInfo.GenderSymbolUnicode;
|
|
|
|
public static bool HaX { get; private set; }
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private readonly string[] main_langlist = Enum.GetNames(typeof(ProgramLanguage));
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static readonly List<IPlugin> Plugins = new();
|
|
|
|
#endregion
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
#region Path Variables
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public static readonly string WorkingDirectory = Path.GetDirectoryName(Environment.ProcessPath)!;
|
2022-06-18 18:04:24 +00:00
|
|
|
public static readonly string DatabasePath = Path.Combine(WorkingDirectory, "pkmdb");
|
|
|
|
public static readonly string MGDatabasePath = Path.Combine(WorkingDirectory, "mgdb");
|
|
|
|
public static readonly string ConfigPath = Path.Combine(WorkingDirectory, "cfg.json");
|
|
|
|
public static readonly string BackupPath = Path.Combine(WorkingDirectory, "bak");
|
|
|
|
public static readonly string CryPath = Path.Combine(WorkingDirectory, "sounds");
|
|
|
|
private static readonly string TemplatePath = Path.Combine(WorkingDirectory, "template");
|
|
|
|
private static readonly string TrainerPath = Path.Combine(WorkingDirectory, "trainers");
|
|
|
|
private static readonly string PluginPath = Path.Combine(WorkingDirectory, "plugins");
|
|
|
|
private const string ThreadPath = "https://projectpokemon.org/pkhex/";
|
2017-06-18 20:02:02 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public static readonly PKHeXSettings Settings = PKHeXSettings.GetSettings(ConfigPath);
|
2021-04-12 01:09:54 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
#endregion
|
2017-06-18 20:02:02 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
#region //// MAIN MENU FUNCTIONS ////
|
|
|
|
private static void FormLoadInitialSettings(IEnumerable<string> args, out bool showChangelog, out bool BAKprompt)
|
|
|
|
{
|
|
|
|
showChangelog = false;
|
|
|
|
BAKprompt = false;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
FormLoadConfig(out BAKprompt, out showChangelog);
|
|
|
|
HaX = Settings.Startup.ForceHaXOnLaunch || GetIsHaX(args);
|
2017-06-18 20:02:02 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
WinFormsUtil.AddSaveFileExtensions(Settings.Backup.OtherSaveFileExtensions);
|
|
|
|
SaveFinder.CustomBackupPaths.Clear();
|
|
|
|
SaveFinder.CustomBackupPaths.AddRange(Settings.Backup.OtherBackupPaths.Where(Directory.Exists));
|
|
|
|
}
|
2018-09-03 17:40:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static bool GetIsHaX(IEnumerable<string> args)
|
|
|
|
{
|
|
|
|
foreach (var x in args)
|
2022-06-11 16:51:43 +00:00
|
|
|
{
|
2023-07-15 18:22:48 +00:00
|
|
|
var arg = x.AsSpan().Trim('-');
|
|
|
|
if (arg.Equals(nameof(HaX), StringComparison.CurrentCultureIgnoreCase))
|
2022-06-18 18:04:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
2022-06-11 16:51:43 +00:00
|
|
|
|
2023-07-14 05:18:34 +00:00
|
|
|
ReadOnlySpan<char> path = Environment.ProcessPath!;
|
2022-06-18 18:04:24 +00:00
|
|
|
return Path.GetFileNameWithoutExtension(path).EndsWith(nameof(HaX));
|
|
|
|
}
|
2022-06-11 16:51:43 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void FormLoadAddEvents()
|
|
|
|
{
|
|
|
|
C_SAV.Menu_Redo = Menu_Redo;
|
|
|
|
C_SAV.Menu_Undo = Menu_Undo;
|
|
|
|
dragout.GiveFeedback += (sender, e) => e.UseDefaultCursors = false;
|
|
|
|
GiveFeedback += (sender, e) => e.UseDefaultCursors = false;
|
|
|
|
PKME_Tabs.EnableDragDrop(Main_DragEnter, Main_DragDrop);
|
|
|
|
C_SAV.EnableDragDrop(Main_DragEnter, Main_DragDrop);
|
|
|
|
|
|
|
|
// ToolTips for Drag&Drop
|
|
|
|
toolTip.SetToolTip(dragout, "PKM QuickSave");
|
|
|
|
|
|
|
|
// Box to Tabs D&D
|
|
|
|
dragout.AllowDrop = true;
|
|
|
|
|
|
|
|
// Add ContextMenus
|
|
|
|
var mnu = new ContextMenuPKM();
|
|
|
|
mnu.RequestEditorLegality += (o, args) => ClickLegality(mnu, args);
|
|
|
|
mnu.RequestEditorQR += (o, args) => ClickQR(mnu, args);
|
|
|
|
mnu.RequestEditorSaveAs += (o, args) => MainMenuSave(mnu, args);
|
|
|
|
dragout.ContextMenuStrip = mnu.mnuL;
|
|
|
|
C_SAV.menu.RequestEditorLegality = DisplayLegalityReport;
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void FormLoadInitialFiles(StartupArguments args)
|
|
|
|
{
|
|
|
|
var sav = args.SAV!;
|
|
|
|
var path = sav.Metadata.FilePath ?? string.Empty;
|
|
|
|
OpenSAV(sav, path);
|
2018-12-20 06:10:32 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var pk = args.Entity!;
|
|
|
|
OpenPKM(pk);
|
2021-07-06 15:42:15 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (args.Error is { } ex)
|
|
|
|
ErrorWindow.ShowErrorDialog(MsgFileLoadFailAuto, ex, true);
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void LoadBlankSaveFile(GameVersion ver)
|
|
|
|
{
|
|
|
|
var current = C_SAV?.SAV;
|
|
|
|
var lang = SaveUtil.GetSafeLanguage(current);
|
|
|
|
var tr = SaveUtil.GetSafeTrainerName(current, lang);
|
|
|
|
var sav = SaveUtil.GetBlankSAV(ver, tr, lang);
|
|
|
|
if (sav.Version == GameVersion.Invalid) // will fail to load
|
2019-01-16 08:27:29 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
var max = GameInfo.VersionDataSource.MaxBy(z => z.Value) ?? throw new Exception();
|
|
|
|
ver = (GameVersion)max.Value;
|
2022-06-18 18:04:24 +00:00
|
|
|
sav = SaveUtil.GetBlankSAV(ver, tr, lang);
|
2019-01-16 08:27:29 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
OpenSAV(sav, string.Empty);
|
|
|
|
C_SAV!.SAV.State.Edited = false; // Prevents form close warning from showing until changes are made
|
|
|
|
}
|
2019-01-16 08:27:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void FormLoadCheckForUpdates()
|
|
|
|
{
|
|
|
|
Task.Run(async () =>
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
Version? latestVersion;
|
|
|
|
// User might not be connected to the internet or with a flaky connection.
|
|
|
|
try { latestVersion = UpdateUtil.GetLatestPKHeXVersion(); }
|
|
|
|
catch (Exception ex)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
Debug.WriteLine($"Exception while checking for latest version: {ex}");
|
|
|
|
return;
|
|
|
|
}
|
2023-01-22 07:32:18 +00:00
|
|
|
if (latestVersion is null || latestVersion <= Program.CurrentVersion)
|
2022-06-18 18:04:24 +00:00
|
|
|
return;
|
2022-02-09 18:47:07 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
while (!IsHandleCreated) // Wait for form to be ready
|
|
|
|
await Task.Delay(2_000).ConfigureAwait(false);
|
|
|
|
Invoke(() => NotifyNewVersionAvailable(latestVersion)); // invoke on GUI thread
|
|
|
|
});
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void NotifyNewVersionAvailable(Version ver)
|
|
|
|
{
|
|
|
|
var date = $"{2000 + ver.Major:00}{ver.Minor:00}{ver.Build:00}";
|
2023-02-05 23:00:31 +00:00
|
|
|
var lbl = L_UpdateAvailable;
|
|
|
|
lbl.Text = $"{MsgProgramUpdateAvailable} {date}";
|
|
|
|
lbl.Click += (_, _) => Process.Start(new ProcessStartInfo(ThreadPath) { UseShellExecute = true });
|
|
|
|
lbl.Visible = lbl.TabStop = lbl.Enabled = true;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void FormLoadConfig(out bool BAKprompt, out bool showChangelog)
|
|
|
|
{
|
|
|
|
BAKprompt = false;
|
|
|
|
showChangelog = false;
|
|
|
|
|
|
|
|
// Version Check
|
|
|
|
if (Settings.Startup.Version.Length > 0 && Settings.Startup.ShowChangelogOnUpdate) // already run on system
|
2019-02-23 22:58:48 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
bool parsed = Version.TryParse(Settings.Startup.Version, out var lastrev);
|
2023-01-22 07:32:18 +00:00
|
|
|
showChangelog = parsed && lastrev < Program.CurrentVersion;
|
2019-02-23 22:58:48 +00:00
|
|
|
}
|
2023-01-22 07:32:18 +00:00
|
|
|
Settings.Startup.Version = Program.CurrentVersion.ToString(); // set current ver so this doesn't happen until the user updates next time
|
2019-02-23 22:58:48 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// BAK Prompt
|
|
|
|
if (!Settings.Backup.BAKPrompt)
|
|
|
|
BAKprompt = Settings.Backup.BAKPrompt = true;
|
|
|
|
}
|
2017-01-10 03:15:46 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public static DrawConfig Draw { get; private set; } = new();
|
2016-12-07 07:29:57 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void FormInitializeSecond()
|
|
|
|
{
|
|
|
|
var settings = Settings;
|
|
|
|
Draw = C_SAV.M.Hover.Draw = PKME_Tabs.Draw = settings.Draw;
|
|
|
|
ReloadProgramSettings(settings);
|
|
|
|
CB_MainLanguage.Items.AddRange(main_langlist);
|
|
|
|
PB_Legal.Visible = !HaX;
|
|
|
|
C_SAV.HaX = PKME_Tabs.HaX = HaX;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
#if DEBUG
|
|
|
|
DevUtil.AddControl(Menu_Tools);
|
|
|
|
#endif
|
2019-02-17 22:51:35 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Select Language
|
|
|
|
CB_MainLanguage.SelectedIndex = GameLanguage.GetLanguageIndex(settings.Startup.Language);
|
|
|
|
}
|
2018-12-20 06:10:32 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void FormLoadPlugins()
|
|
|
|
{
|
|
|
|
#if !MERGED // merged should load dlls from within too, folder is no longer required
|
|
|
|
if (!Directory.Exists(PluginPath))
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
try
|
2018-05-13 19:49:26 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
Plugins.AddRange(PluginLoader.LoadPlugins<IPlugin>(PluginPath, Settings.Startup.PluginLoadMethod));
|
2018-05-13 19:49:26 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
catch (InvalidCastException c)
|
2014-06-28 21:22:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
WinFormsUtil.Error(MsgPluginFailLoad, c);
|
|
|
|
return;
|
2014-06-28 21:22:05 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
foreach (var p in Plugins.OrderBy(z => z.Priority))
|
2023-01-22 07:32:18 +00:00
|
|
|
p.Initialize(C_SAV, PKME_Tabs, menuStrip1, Program.CurrentVersion);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Main Menu Strip UI Functions
|
|
|
|
private void MainMenuOpen(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (WinFormsUtil.OpenSAVPKMDialog(C_SAV.SAV.PKMExtensions, out var path))
|
|
|
|
OpenQuick(path!);
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void MainMenuSave(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (!PKME_Tabs.EditsComplete)
|
|
|
|
return;
|
|
|
|
PKM pk = PreparePKM();
|
|
|
|
WinFormsUtil.SavePKMDialog(pk);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void MainMenuExit(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (ModifierKeys == Keys.Control) // triggered via hotkey
|
2014-06-28 21:22:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Quit PKHeX?"))
|
2019-02-10 01:07:44 +00:00
|
|
|
return;
|
2014-12-13 22:48:34 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
Close();
|
|
|
|
}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void MainMenuAbout(object sender, EventArgs e) => ShowAboutDialog(AboutPage.Shortcuts);
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static void ShowAboutDialog(AboutPage index)
|
|
|
|
{
|
|
|
|
using var form = new About(index);
|
|
|
|
form.ShowDialog();
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Sub Menu Options
|
|
|
|
private void MainMenuBoxReport(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (this.OpenWindowExists<ReportGrid>())
|
|
|
|
return;
|
|
|
|
|
|
|
|
var report = new ReportGrid();
|
|
|
|
report.Show();
|
|
|
|
var list = new List<SlotCache>();
|
|
|
|
SlotInfoLoader.AddFromSaveFile(C_SAV.SAV, list);
|
|
|
|
report.PopulateData(list);
|
|
|
|
}
|
2019-02-23 22:58:48 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void MainMenuDatabase(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (ModifierKeys == Keys.Shift)
|
2014-12-13 22:48:34 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!this.OpenWindowExists<KChart>())
|
|
|
|
new KChart(C_SAV.SAV).Show();
|
|
|
|
return;
|
2014-12-13 22:48:34 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!Directory.Exists(DatabasePath))
|
2016-01-30 02:02:54 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
WinFormsUtil.Alert(MsgDatabase, string.Format(MsgDatabaseAdvice, DatabasePath));
|
|
|
|
return;
|
2016-01-30 02:02:54 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!this.OpenWindowExists<SAV_Database>())
|
|
|
|
new SAV_Database(PKME_Tabs, C_SAV).Show();
|
|
|
|
}
|
2018-11-14 03:23:16 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void Menu_EncDatabase_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (this.OpenWindowExists<SAV_Encounters>())
|
|
|
|
return;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var db = new TrainerDatabase();
|
|
|
|
var sav = C_SAV.SAV;
|
|
|
|
Task.Run(() =>
|
2021-07-03 19:46:52 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var dir = TrainerPath;
|
|
|
|
if (!Directory.Exists(dir))
|
|
|
|
return;
|
|
|
|
var files = Directory.EnumerateFiles(TrainerPath, "*.*", SearchOption.AllDirectories);
|
|
|
|
var pk = BoxUtil.GetPKMsFromPaths(files, sav.Context);
|
|
|
|
foreach (var f in pk)
|
|
|
|
db.RegisterCopy(f);
|
|
|
|
});
|
|
|
|
new SAV_Encounters(PKME_Tabs, db).Show();
|
|
|
|
}
|
2021-07-03 19:46:52 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void MainMenuMysteryDB(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (!this.OpenWindowExists<SAV_MysteryGiftDB>())
|
|
|
|
new SAV_MysteryGiftDB(PKME_Tabs, C_SAV).Show();
|
|
|
|
}
|
2021-07-31 01:05:17 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static void ClosePopups()
|
|
|
|
{
|
|
|
|
var forms = Application.OpenForms.OfType<Form>().Where(IsPopupFormType).ToArray();
|
|
|
|
foreach (var f in forms)
|
2023-02-03 20:52:52 +00:00
|
|
|
{
|
|
|
|
if (f.InvokeRequired)
|
|
|
|
continue; // from another thread, not our scope.
|
2022-06-18 18:04:24 +00:00
|
|
|
f.Close();
|
2023-02-03 20:52:52 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-03-24 05:54:26 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static bool IsPopupFormType(Form z) => z is not (Main or SplashScreen or SAV_FolderList);
|
2018-03-24 05:54:26 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void MainMenuSettings(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
var settings = Settings;
|
|
|
|
using var form = new SettingsEditor(settings);
|
|
|
|
form.ShowDialog();
|
2019-01-16 08:27:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Reload text (if OT details hidden)
|
|
|
|
Text = GetProgramTitle(C_SAV.SAV);
|
|
|
|
// Update final settings
|
|
|
|
ReloadProgramSettings(Settings);
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (form.BlankChanged) // changed by user
|
2018-08-20 01:22:07 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
LoadBlankSaveFile(Settings.Startup.DefaultSaveVersion);
|
|
|
|
return;
|
2018-08-20 01:22:07 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
PKME_Tabs_UpdatePreviewSprite(sender, e);
|
|
|
|
if (C_SAV.SAV.HasBox)
|
|
|
|
C_SAV.ReloadSlots();
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ReloadProgramSettings(PKHeXSettings settings)
|
|
|
|
{
|
|
|
|
Draw.LoadBrushes();
|
|
|
|
PKME_Tabs.Unicode = Unicode = settings.Display.Unicode;
|
|
|
|
PKME_Tabs.UpdateUnicode(GenderSymbols);
|
|
|
|
SpriteName.AllowShinySprite = settings.Sprite.ShinySprites;
|
|
|
|
SpriteBuilderUtil.SpriterPreference = settings.Sprite.SpritePreference;
|
|
|
|
SaveFile.SetUpdateDex = settings.SlotWrite.SetUpdateDex ? PKMImportSetting.Update : PKMImportSetting.Skip;
|
|
|
|
SaveFile.SetUpdatePKM = settings.SlotWrite.SetUpdatePKM ? PKMImportSetting.Update : PKMImportSetting.Skip;
|
|
|
|
C_SAV.ModifyPKM = PKME_Tabs.ModifyPKM = settings.SlotWrite.SetUpdatePKM;
|
|
|
|
CommonEdits.ShowdownSetIVMarkings = settings.Import.ApplyMarkings;
|
|
|
|
CommonEdits.ShowdownSetBehaviorNature = settings.Import.ApplyNature;
|
|
|
|
C_SAV.FlagIllegal = settings.Display.FlagIllegal;
|
|
|
|
C_SAV.M.Hover.GlowHover = settings.Hover.HoverSlotGlowEdges;
|
|
|
|
ParseSettings.InitFromSettings(settings.Legality);
|
|
|
|
PKME_Tabs.HideSecretValues = C_SAV.HideSecretDetails = settings.Privacy.HideSecretDetails;
|
|
|
|
EntityConverter.AllowIncompatibleConversion = settings.Advanced.AllowIncompatibleConversion;
|
|
|
|
EntityConverter.RejuvenateHOME = settings.Advanced.AllowGuessRejuvenateHOME;
|
|
|
|
WinFormsUtil.DetectSaveFileOnFileOpen = settings.Startup.TryDetectRecentSave;
|
2023-02-07 02:11:30 +00:00
|
|
|
SelectablePictureBox.FocusBorderDeflate = GenderToggle.FocusBorderDeflate = settings.Display.FocusBorderDeflate;
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
SpriteBuilder.LoadSettings(settings.Sprite);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void MainMenuBoxLoad(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
string? path = null;
|
|
|
|
if (Directory.Exists(DatabasePath))
|
2016-01-03 04:22:53 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgDatabaseLoad);
|
|
|
|
if (dr == DialogResult.Yes)
|
2017-05-23 04:55:05 +00:00
|
|
|
path = DatabasePath;
|
2016-01-03 04:22:53 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
if (C_SAV.LoadBoxes(out string result, path))
|
|
|
|
WinFormsUtil.Alert(result);
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void MainMenuBoxDump(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Dump all of box content to files.
|
|
|
|
string? path = null;
|
|
|
|
DialogResult ld = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgDatabaseExport);
|
|
|
|
if (ld == DialogResult.Yes)
|
|
|
|
path = DatabasePath;
|
|
|
|
else if (ld != DialogResult.No)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (C_SAV.DumpBoxes(out string result, path))
|
|
|
|
WinFormsUtil.Alert(result);
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void MainMenuBoxDumpSingle(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (C_SAV.DumpBox(out string result))
|
|
|
|
WinFormsUtil.Alert(result);
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void MainMenuBatchEditor(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
using var form = new BatchEditor(PKME_Tabs.PreparePKM(), C_SAV.SAV);
|
|
|
|
form.ShowDialog();
|
|
|
|
C_SAV.SetPKMBoxes(); // refresh
|
|
|
|
C_SAV.UpdateBoxViewers();
|
|
|
|
}
|
2018-07-16 00:48:31 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void MainMenuFolder(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (this.OpenWindowExists<SAV_FolderList>())
|
|
|
|
return;
|
|
|
|
var form = new SAV_FolderList(s => OpenSAV(s.Clone(), s.Metadata.FilePath!));
|
|
|
|
form.Show();
|
|
|
|
}
|
2016-01-03 04:22:53 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Misc Options
|
|
|
|
private void ClickShowdownImportPKM(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (!Clipboard.ContainsText())
|
|
|
|
{ WinFormsUtil.Alert(MsgClipboardFailRead); return; }
|
2016-01-03 04:22:53 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Get Simulator Data
|
|
|
|
var Set = new ShowdownSet(Clipboard.GetText());
|
2016-01-03 04:22:53 +00:00
|
|
|
|
2022-08-30 22:00:45 +00:00
|
|
|
if (Set.Species == 0)
|
2022-06-18 18:04:24 +00:00
|
|
|
{ WinFormsUtil.Alert(MsgSimulatorFailClipboard); return; }
|
2016-09-20 02:20:55 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgSimulatorLoad, Set.Text))
|
|
|
|
return;
|
2016-09-04 06:14:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (Set.InvalidLines.Count > 0)
|
|
|
|
WinFormsUtil.Alert(MsgSimulatorInvalid, string.Join(Environment.NewLine, Set.InvalidLines));
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
PKME_Tabs.LoadShowdownSet(Set);
|
|
|
|
}
|
2016-01-03 04:22:53 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ClickShowdownExportPKM(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (!PKME_Tabs.EditsComplete)
|
|
|
|
{
|
|
|
|
WinFormsUtil.Alert(MsgSimulatorExportBadFields);
|
|
|
|
return;
|
2016-01-03 04:22:53 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var pk = PreparePKM();
|
|
|
|
var text = ShowdownParsing.GetShowdownText(pk);
|
|
|
|
bool success = WinFormsUtil.SetClipboardText(text);
|
|
|
|
if (!success || !Clipboard.GetText().Equals(text))
|
|
|
|
WinFormsUtil.Alert(MsgClipboardFailWrite, MsgSimulatorExportFail);
|
|
|
|
else
|
|
|
|
WinFormsUtil.Alert(MsgSimulatorExportSuccess, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ClickShowdownExportParty(object sender, EventArgs e) => C_SAV.ClickShowdownExportParty(sender, e);
|
|
|
|
private void ClickShowdownExportCurrentBox(object sender, EventArgs e) => C_SAV.ClickShowdownExportCurrentBox(sender, e);
|
2014-06-28 21:22:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Main Menu Subfunctions
|
|
|
|
private void OpenQuick(string path)
|
|
|
|
{
|
|
|
|
if (!CanFocus)
|
2014-12-13 22:48:34 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
SystemSounds.Asterisk.Play();
|
|
|
|
return;
|
2019-02-23 22:58:48 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
OpenFromPath(path);
|
|
|
|
}
|
2019-02-23 22:58:48 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void OpenFromPath(string path)
|
|
|
|
{
|
|
|
|
if (Plugins.Any(p => p.TryLoadFile(path)))
|
|
|
|
return; // handled by plugin
|
2018-05-15 00:30:56 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// detect if it is a folder (load into boxes or not)
|
|
|
|
if (Directory.Exists(path))
|
|
|
|
{ C_SAV.LoadBoxes(out string _, path); return; }
|
2014-08-17 01:42:51 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var fi = new FileInfo(path);
|
|
|
|
if (!fi.Exists)
|
|
|
|
return;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (FileUtil.IsFileTooBig(fi.Length))
|
|
|
|
{
|
|
|
|
WinFormsUtil.Error(MsgFileSizeLarge + Environment.NewLine + string.Format(MsgFileSize, fi.Length), path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (FileUtil.IsFileTooSmall(fi.Length))
|
|
|
|
{
|
|
|
|
WinFormsUtil.Error(MsgFileSizeSmall + Environment.NewLine + string.Format(MsgFileSize, fi.Length), path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
byte[] input; try { input = File.ReadAllBytes(path); }
|
|
|
|
catch (Exception e) { WinFormsUtil.Error(MsgFileInUse + path, e); return; }
|
2014-12-13 22:48:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
string ext = fi.Extension;
|
|
|
|
#if DEBUG
|
|
|
|
OpenFile(input, path, ext);
|
|
|
|
#else
|
2021-07-06 15:42:15 +00:00
|
|
|
try { OpenFile(input, path, ext); }
|
|
|
|
catch (Exception e) { WinFormsUtil.Error(MsgFileLoadFail + "\nPath: " + path, e); }
|
2022-06-18 18:04:24 +00:00
|
|
|
#endif
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void OpenFile(byte[] input, string path, string ext)
|
|
|
|
{
|
|
|
|
var obj = FileUtil.GetSupportedFile(input, ext, C_SAV.SAV);
|
|
|
|
if (obj != null && LoadFile(obj, path))
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool isSAV = WinFormsUtil.IsFileExtensionSAV(path);
|
|
|
|
var msg = isSAV ? MsgFileUnsupported : MsgPKMUnsupported;
|
|
|
|
WinFormsUtil.Error(msg,
|
|
|
|
$"{MsgFileLoad}{Environment.NewLine}{path}",
|
|
|
|
$"{string.Format(MsgFileSize, input.Length)}{Environment.NewLine}{input.Length} bytes (0x{input.Length:X4})");
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private bool LoadFile(object? input, string path)
|
|
|
|
{
|
|
|
|
if (input == null)
|
|
|
|
return false;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
switch (input)
|
2014-12-13 22:48:34 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
case PKM pk: return OpenPKM(pk);
|
|
|
|
case SaveFile s: return OpenSAV(s, path);
|
|
|
|
case IPokeGroup b: return OpenGroup(b);
|
|
|
|
case MysteryGift g: return OpenMysteryGift(g, path);
|
|
|
|
case IEnumerable<byte[]> pkms: return OpenPCBoxBin(pkms);
|
|
|
|
case IEncounterConvertible enc: return OpenPKM(enc.ConvertToPKM(C_SAV.SAV));
|
2014-08-15 04:27:53 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
case SAV3GCMemoryCard gc:
|
|
|
|
if (!CheckGCMemoryCard(gc, path))
|
|
|
|
return true;
|
|
|
|
var mcsav = SaveUtil.GetVariantSAV(gc);
|
|
|
|
if (mcsav is null)
|
|
|
|
return false;
|
2023-05-01 23:51:17 +00:00
|
|
|
mcsav.Metadata.SetExtraInfo(path);
|
2022-06-18 18:04:24 +00:00
|
|
|
return OpenSAV(mcsav, path);
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool OpenPKM(PKM pk)
|
|
|
|
{
|
|
|
|
var destType = C_SAV.SAV.PKMType;
|
|
|
|
var tmp = EntityConverter.ConvertToType(pk, destType, out var c);
|
|
|
|
Debug.WriteLine(c.GetDisplayString(pk, destType));
|
|
|
|
if (tmp == null)
|
|
|
|
return false;
|
|
|
|
C_SAV.SAV.AdaptPKM(tmp);
|
|
|
|
PKME_Tabs.PopulateFields(tmp);
|
|
|
|
return true;
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private bool OpenGroup(IPokeGroup b)
|
|
|
|
{
|
|
|
|
bool result = C_SAV.OpenGroup(b, out string c);
|
|
|
|
if (!string.IsNullOrWhiteSpace(c))
|
|
|
|
WinFormsUtil.Alert(c);
|
|
|
|
Debug.WriteLine(c);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool OpenMysteryGift(MysteryGift tg, string path)
|
|
|
|
{
|
|
|
|
if (!tg.IsEntity)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
WinFormsUtil.Alert(MsgPKMMysteryGiftFail, path);
|
2017-05-23 04:55:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var temp = tg.ConvertToPKM(C_SAV.SAV);
|
|
|
|
var destType = C_SAV.SAV.PKMType;
|
|
|
|
var pk = EntityConverter.ConvertToType(temp, destType, out var c);
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (pk == null)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
WinFormsUtil.Alert(c.GetDisplayString(temp, destType));
|
2017-05-23 04:55:05 +00:00
|
|
|
return true;
|
2014-12-13 22:48:34 +00:00
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
C_SAV.SAV.AdaptPKM(pk);
|
|
|
|
PKME_Tabs.PopulateFields(pk);
|
|
|
|
Debug.WriteLine(c);
|
|
|
|
return true;
|
|
|
|
}
|
2017-02-09 08:44:38 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private bool OpenPCBoxBin(IEnumerable<byte[]> pkms)
|
|
|
|
{
|
|
|
|
var data = pkms.SelectMany(z => z).ToArray();
|
|
|
|
if (!C_SAV.OpenPCBoxBin(data, out string c))
|
|
|
|
{
|
|
|
|
WinFormsUtil.Alert(MsgFileLoadIncompatible, c);
|
2017-02-09 08:44:38 +00:00
|
|
|
return true;
|
2014-12-31 06:18:41 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
WinFormsUtil.Alert(c);
|
|
|
|
return true;
|
|
|
|
}
|
2017-04-02 14:53:46 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static GameVersion SelectMemoryCardSaveGame(SAV3GCMemoryCard memCard)
|
|
|
|
{
|
|
|
|
if (memCard.SaveGameCount == 1)
|
|
|
|
return memCard.SelectedGameVersion;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var games = GetMemoryCardGameSelectionList(memCard);
|
|
|
|
var dialog = new SAV_GameSelect(games, MsgFileLoadSaveMultiple, MsgFileLoadSaveSelectGame);
|
|
|
|
dialog.ShowDialog();
|
|
|
|
return dialog.Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static List<ComboItem> GetMemoryCardGameSelectionList(SAV3GCMemoryCard memCard)
|
|
|
|
{
|
|
|
|
var games = new List<ComboItem>();
|
2023-04-22 03:47:04 +00:00
|
|
|
if (memCard.HasCOLO) games.Add(new ComboItem(MsgGameColosseum, (int)GameVersion.COLO));
|
|
|
|
if (memCard.HasXD) games.Add(new ComboItem(MsgGameXD, (int)GameVersion.XD));
|
|
|
|
if (memCard.HasRSBOX) games.Add(new ComboItem(MsgGameRSBOX, (int)GameVersion.RSBOX));
|
2022-06-18 18:04:24 +00:00
|
|
|
return games;
|
|
|
|
}
|
2021-07-31 01:05:17 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static bool CheckGCMemoryCard(SAV3GCMemoryCard memCard, string path)
|
|
|
|
{
|
|
|
|
var state = memCard.GetMemoryCardState();
|
|
|
|
switch (state)
|
2017-04-02 14:53:46 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
case GCMemoryCardState.NoPkmSaveGame:
|
|
|
|
WinFormsUtil.Error(MsgFileGameCubeNoGames, path);
|
|
|
|
return false;
|
2020-12-25 18:58:33 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
case GCMemoryCardState.DuplicateCOLO:
|
|
|
|
case GCMemoryCardState.DuplicateXD:
|
|
|
|
case GCMemoryCardState.DuplicateRSBOX:
|
|
|
|
WinFormsUtil.Error(MsgFileGameCubeDuplicate, path);
|
|
|
|
return false;
|
2020-12-25 18:58:33 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
case GCMemoryCardState.MultipleSaveGame:
|
|
|
|
var game = SelectMemoryCardSaveGame(memCard);
|
|
|
|
if (game == GameVersion.Invalid) //Cancel
|
|
|
|
return false;
|
|
|
|
memCard.SelectSaveGame(game);
|
|
|
|
break;
|
2021-07-06 15:42:15 +00:00
|
|
|
|
2023-04-22 03:47:04 +00:00
|
|
|
case GCMemoryCardState.SaveGameCOLO: memCard.SelectSaveGame(GameVersion.COLO); break;
|
|
|
|
case GCMemoryCardState.SaveGameXD: memCard.SelectSaveGame(GameVersion.XD); break;
|
2022-06-18 18:04:24 +00:00
|
|
|
case GCMemoryCardState.SaveGameRSBOX: memCard.SelectSaveGame(GameVersion.RSBOX); break;
|
2020-12-25 18:58:33 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
default:
|
|
|
|
WinFormsUtil.Error(!SaveUtil.IsSizeValid(memCard.Data.Length) ? MsgFileGameCubeBad : MsgFileLoadSaveLoadFail, path);
|
|
|
|
return false;
|
2017-04-02 14:53:46 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void StoreLegalSaveGameData(SaveFile sav)
|
|
|
|
{
|
|
|
|
if (sav is SAV3 sav3)
|
|
|
|
EReaderBerrySettings.LoadFrom(sav3);
|
|
|
|
}
|
2017-04-02 14:53:46 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private bool OpenSAV(SaveFile sav, string path)
|
|
|
|
{
|
|
|
|
if (sav.Version == GameVersion.Invalid)
|
Encounter Type fix and detection of pokemon that should have evolve on trade (#1105)
* Detect encounter trades that evolve on trade and have not been evolved
Detect generation 1 pokemon with special catch rates : krabby trade and Pokemon Stadium
Detect generation 1 pokemon that evolve on trade and have been traded but not evolved
Detect pokemon with tradeback status any but with only encounters from the other GB generation, that means they are WasTradeback
Detect pokemon with moves from the other GB generation, change tradebackstatus to WasTradeback
* Fix dppt surfing and fishing encounter type, is is surfing because the battle background is the same as other surfingfishing encounters
Fix headbutt encounter type, the encounter type depends on the battle background used when battle a pokemon, for headbutt it changes with the player tile, is the player is in a city it will be building encounter, in a grass tile tall grass, in water it is surfingfishing and cave inside a cave. Some locations have more than one possible encounter type, for example routes with trees near the grass, near the water and near non-combat tiles.
Also added slot type headbutt special for the special trees, those trees are all in routes and are only adjacent to non-combat tiles
* Fix encounter type for missing areas with multiple grass encounters types: Mt Coronet, Mt Silver Cave and Stark Mountain (Issue # 1095)
* Fixes and typos
* Check for non-japanese e-reader pokemon, is unreleased
2017-05-01 15:07:20 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
WinFormsUtil.Error(MsgFileLoadSaveLoadFail, path);
|
|
|
|
return true;
|
Encounter Type fix and detection of pokemon that should have evolve on trade (#1105)
* Detect encounter trades that evolve on trade and have not been evolved
Detect generation 1 pokemon with special catch rates : krabby trade and Pokemon Stadium
Detect generation 1 pokemon that evolve on trade and have been traded but not evolved
Detect pokemon with tradeback status any but with only encounters from the other GB generation, that means they are WasTradeback
Detect pokemon with moves from the other GB generation, change tradebackstatus to WasTradeback
* Fix dppt surfing and fishing encounter type, is is surfing because the battle background is the same as other surfingfishing encounters
Fix headbutt encounter type, the encounter type depends on the battle background used when battle a pokemon, for headbutt it changes with the player tile, is the player is in a city it will be building encounter, in a grass tile tall grass, in water it is surfingfishing and cave inside a cave. Some locations have more than one possible encounter type, for example routes with trees near the grass, near the water and near non-combat tiles.
Also added slot type headbutt special for the special trees, those trees are all in routes and are only adjacent to non-combat tiles
* Fix encounter type for missing areas with multiple grass encounters types: Mt Coronet, Mt Silver Cave and Stark Mountain (Issue # 1095)
* Fixes and typos
* Check for non-japanese e-reader pokemon, is unreleased
2017-05-01 15:07:20 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
sav.Metadata.SetExtraInfo(path);
|
|
|
|
if (!SanityCheckSAV(ref sav))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (C_SAV.SAV.State.Edited && Settings.SlotWrite.ModifyUnset)
|
2014-12-13 22:48:34 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var prompt = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgProgramCloseUnsaved, MsgProgramSaveFileConfirm);
|
|
|
|
if (prompt != DialogResult.Yes)
|
2020-05-24 18:03:23 +00:00
|
|
|
return true;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2016-10-12 02:11:24 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
ClosePopups();
|
2019-12-21 23:33:20 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
PKME_Tabs.Focus(); // flush any pending changes
|
|
|
|
StoreLegalSaveGameData(sav);
|
2022-09-11 16:59:00 +00:00
|
|
|
ParseSettings.InitFromSaveFileData(sav); // physical GB, no longer used in logic
|
2022-06-18 18:04:24 +00:00
|
|
|
RecentTrainerCache.SetRecentTrainer(sav);
|
|
|
|
SpriteUtil.Initialize(sav); // refresh sprite generator
|
|
|
|
dragout.Size = new Size(SpriteUtil.Spriter.Width, SpriteUtil.Spriter.Height);
|
2020-05-24 18:03:23 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// clean fields
|
|
|
|
Menu_ExportSAV.Enabled = sav.State.Exportable;
|
2021-07-03 19:46:52 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// No changes made yet
|
|
|
|
Menu_Undo.Enabled = false;
|
|
|
|
Menu_Redo.Enabled = false;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
GameInfo.FilteredSources = new FilteredGameDataSource(sav, GameInfo.Sources, HaX);
|
|
|
|
ResetSAVPKMEditors(sav);
|
|
|
|
C_SAV.M.Reset();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
Text = GetProgramTitle(sav);
|
|
|
|
TryBackupExportCheck(sav, path);
|
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
|
|
|
CheckLoadPath(path);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
Menu_ShowdownExportParty.Visible = sav.HasParty;
|
|
|
|
Menu_ShowdownExportCurrentBox.Visible = sav.HasBox;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
Settings.Startup.LoadSaveFile(path);
|
|
|
|
if (Settings.Sounds.PlaySoundSAVLoad)
|
|
|
|
SystemSounds.Asterisk.Play();
|
|
|
|
return true;
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ResetSAVPKMEditors(SaveFile sav)
|
|
|
|
{
|
|
|
|
C_SAV.SetEditEnvironment(new SaveDataEditor<PictureBox>(sav, PKME_Tabs));
|
2018-06-17 04:56:16 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var pk = sav.LoadTemplate(TemplatePath);
|
|
|
|
PKME_Tabs.CurrentPKM = pk;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
bool init = PKME_Tabs.IsInitialized;
|
|
|
|
if (!init)
|
2017-06-18 01:37:19 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
PKME_Tabs.InitializeBinding();
|
|
|
|
PKME_Tabs.SetPKMFormatMode(pk);
|
|
|
|
PKME_Tabs.ChangeLanguage(sav);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PKME_Tabs.SetPKMFormatMode(pk);
|
|
|
|
}
|
|
|
|
PKME_Tabs.PopulateFields(pk);
|
2018-12-20 06:10:32 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Initialize Overall Info
|
|
|
|
Menu_LoadBoxes.Enabled = Menu_DumpBoxes.Enabled = Menu_DumpBox.Enabled = Menu_Report.Enabled = C_SAV.SAV.HasBox;
|
2017-06-19 05:27:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Initialize Subviews
|
|
|
|
bool WindowTranslationRequired = false;
|
|
|
|
WindowTranslationRequired |= PKME_Tabs.ToggleInterface(sav, pk);
|
|
|
|
WindowTranslationRequired |= C_SAV.ToggleInterface();
|
|
|
|
if (WindowTranslationRequired) // force update -- re-added controls may be untranslated
|
|
|
|
WinFormsUtil.TranslateInterface(this, CurrentLanguage);
|
2017-06-19 05:27:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
PKME_Tabs.PopulateFields(pk);
|
2021-07-31 01:05:17 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
sav.State.Edited = false;
|
|
|
|
foreach (var p in Plugins)
|
|
|
|
p.NotifySaveLoaded();
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static string GetProgramTitle()
|
|
|
|
{
|
|
|
|
#if DEBUG
|
2023-01-22 04:02:33 +00:00
|
|
|
// Get the file path that started this exe.
|
|
|
|
var date = File.GetLastWriteTime(Environment.ProcessPath!);
|
2022-06-18 18:04:24 +00:00
|
|
|
string version = $"d-{date:yyyyMMdd}";
|
|
|
|
#else
|
2023-01-22 07:32:18 +00:00
|
|
|
var ver = Program.CurrentVersion;
|
2023-01-22 04:02:33 +00:00
|
|
|
string version = $"{2000+ver.Major:00}{ver.Minor:00}{ver.Build:00}";
|
2022-06-18 18:04:24 +00:00
|
|
|
#endif
|
|
|
|
return $"PKH{(HaX ? "a" : "e")}X ({version})";
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static string GetProgramTitle(SaveFile sav)
|
|
|
|
{
|
|
|
|
string title = GetProgramTitle() + $" - {sav.GetType().Name}: ";
|
|
|
|
if (sav is ISaveFileRevision rev)
|
|
|
|
title = title.Insert(title.Length - 2, rev.SaveRevisionString);
|
|
|
|
var ver = GameInfo.GetVersionName(sav.Version);
|
|
|
|
if (Settings.Privacy.HideSAVDetails)
|
|
|
|
return title + $"[{ver}]";
|
|
|
|
if (!sav.State.Exportable) // Blank save file
|
|
|
|
return title + $"{sav.Metadata.FileName} [{sav.OT} ({ver})]";
|
|
|
|
return title + Path.GetFileNameWithoutExtension(Util.CleanFileName(sav.Metadata.BAKName)); // more descriptive
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static bool TryBackupExportCheck(SaveFile sav, string path)
|
|
|
|
{
|
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 backup folder exists, save a backup.
|
|
|
|
if (string.IsNullOrWhiteSpace(path))
|
|
|
|
return false; // not actual save
|
|
|
|
if (!Settings.Backup.BAKEnabled)
|
|
|
|
return false;
|
|
|
|
if (!sav.State.Exportable)
|
|
|
|
return false; // not actual save
|
|
|
|
var dir = BackupPath;
|
|
|
|
if (!Directory.Exists(dir))
|
2022-06-18 18:04:24 +00:00
|
|
|
return false;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
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 meta = sav.Metadata;
|
|
|
|
string backupName = Path.Combine(dir, Util.CleanFileName(meta.BAKName));
|
|
|
|
if (File.Exists(backupName))
|
|
|
|
return false; // Already backed up.
|
|
|
|
|
|
|
|
// Ensure the file we are copying exists.
|
|
|
|
var src = meta.FilePath;
|
|
|
|
if (src is not { } x || !File.Exists(x))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
try
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
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
|
|
|
// Don't need to force overwrite, but on the off-chance it was written externally, we force ours.
|
|
|
|
File.Copy(x, backupName, true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
WinFormsUtil.Error(MsgBackupUnable, ex);
|
|
|
|
return false;
|
2017-06-18 01:37:19 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
private static bool CheckLoadPath(string path)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrWhiteSpace(path))
|
|
|
|
return false; // not actual save
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!FileUtil.IsFileLocked(path))
|
|
|
|
return true;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
WinFormsUtil.Alert(MsgFileWriteProtected + Environment.NewLine + path, MsgFileWriteProtectedAdvice);
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-18 05:27:59 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static bool SanityCheckSAV(ref SaveFile sav)
|
|
|
|
{
|
|
|
|
if (sav.State.Exportable && sav is SAV3 s3)
|
|
|
|
{
|
|
|
|
if (ModifierKeys == Keys.Control || s3.IsCorruptPokedexFF())
|
2017-04-02 20:42:42 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var g = new[] { GameVersion.R, GameVersion.S, GameVersion.E, GameVersion.FR, GameVersion.LG };
|
|
|
|
var games = g.Select(z => GameInfo.VersionDataSource.First(v => v.Value == (int)z));
|
|
|
|
var msg = string.Format(MsgFileLoadVersionDetect, $"3 ({s3.Version})");
|
|
|
|
using var dialog = new SAV_GameSelect(games, msg, MsgFileLoadSaveSelectVersion);
|
|
|
|
dialog.ShowDialog();
|
|
|
|
if (dialog.Result is GameVersion.Invalid)
|
|
|
|
return false;
|
2018-12-28 04:24:24 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var s = s3.ForceLoad(dialog.Result);
|
|
|
|
if (s is SAV3FRLG frlg)
|
2018-12-28 04:24:24 +00:00
|
|
|
{
|
2021-03-16 06:51:58 +00:00
|
|
|
bool result = frlg.ResetPersonal(dialog.Result);
|
2019-09-03 02:30:58 +00:00
|
|
|
if (!result)
|
2018-12-28 04:24:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
var origin = sav.Metadata.FilePath;
|
|
|
|
if (origin is not null)
|
|
|
|
s.Metadata.SetExtraInfo(origin);
|
|
|
|
sav = s;
|
|
|
|
}
|
|
|
|
else if (s3 is SAV3FRLG frlg) // IndeterminateSubVersion
|
|
|
|
{
|
|
|
|
string fr = GameInfo.GetVersionName(GameVersion.FR);
|
|
|
|
string lg = GameInfo.GetVersionName(GameVersion.LG);
|
|
|
|
string dual = "{1}/{2} " + MsgFileLoadVersionDetect;
|
|
|
|
var g = new[] { GameVersion.FR, GameVersion.LG };
|
|
|
|
var games = g.Select(z => GameInfo.VersionDataSource.First(v => v.Value == (int)z));
|
|
|
|
var msg = string.Format(dual, "3", fr, lg);
|
|
|
|
using var dialog = new SAV_GameSelect(games, msg, MsgFileLoadSaveSelectVersion);
|
|
|
|
dialog.ShowDialog();
|
|
|
|
bool result = frlg.ResetPersonal(dialog.Result);
|
|
|
|
if (!result)
|
|
|
|
return false;
|
2017-04-02 20:42:42 +00:00
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2016-10-12 02:11:24 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-03-19 23:19:59 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public static void SetCountrySubRegion(ComboBox CB, string type)
|
|
|
|
{
|
|
|
|
int index = CB.SelectedIndex;
|
|
|
|
string cl = GameInfo.CurrentLanguage;
|
|
|
|
CB.DataSource = Util.GetCountryRegionList(type, cl);
|
2014-12-13 22:48:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (index > 0 && index < CB.Items.Count)
|
|
|
|
CB.SelectedIndex = index;
|
|
|
|
}
|
2017-03-24 18:18:14 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Language Translation
|
|
|
|
private void ChangeMainLanguage(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
var index = CB_MainLanguage.SelectedIndex;
|
|
|
|
if ((uint)index < CB_MainLanguage.Items.Count)
|
|
|
|
CurrentLanguage = GameLanguage.Language2Char(index);
|
2017-03-24 18:18:14 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Set the culture (makes it easy to pass language to other forms)
|
|
|
|
var lang = CurrentLanguage;
|
|
|
|
Settings.Startup.Language = lang;
|
|
|
|
var ci = new CultureInfo(lang[..2]);
|
|
|
|
Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = ci;
|
2017-06-19 05:27:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
Menu_Options.DropDown.Close();
|
2021-06-18 05:48:31 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var sav = C_SAV.SAV;
|
|
|
|
LocalizeUtil.InitializeStrings(lang, sav, HaX);
|
|
|
|
WinFormsUtil.TranslateInterface(this, lang); // Translate the UI to language.
|
|
|
|
LocalizedDescriptionAttribute.Localizer = WinFormsTranslator.GetDictionary(lang);
|
2019-02-10 01:07:44 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (sav is not FakeSaveFile)
|
|
|
|
{
|
|
|
|
var pk = PKME_Tabs.CurrentPKM.Clone();
|
|
|
|
|
|
|
|
PKME_Tabs.ChangeLanguage(sav);
|
|
|
|
PKME_Tabs.PopulateFields(pk); // put data back in form
|
|
|
|
Text = GetProgramTitle(sav);
|
2014-12-13 22:48:34 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
#endregion
|
2014-06-28 21:22:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
#region //// PKX WINDOW FUNCTIONS ////
|
|
|
|
private bool QR6Notified;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ClickQR(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (ModifierKeys == Keys.Alt)
|
2015-02-25 04:10:47 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
string url = Clipboard.GetText();
|
|
|
|
if (!string.IsNullOrWhiteSpace(url))
|
2017-06-22 04:57:59 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (url.StartsWith("http") && !url.Contains('\n')) // qr payload
|
|
|
|
ImportQRToTabs(url);
|
|
|
|
else
|
|
|
|
ClickShowdownImportPKM(sender, e);
|
|
|
|
return;
|
2017-06-22 04:57:59 +00:00
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
ExportQRFromTabs();
|
|
|
|
}
|
2015-03-14 02:59:51 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ImportQRToTabs(string url)
|
|
|
|
{
|
|
|
|
var msg = QRDecode.GetQRData(url, out var input);
|
|
|
|
if (msg != 0)
|
2017-06-18 01:37:19 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
WinFormsUtil.Alert(msg.ConvertMsg());
|
|
|
|
return;
|
|
|
|
}
|
2019-09-29 16:47:06 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (input.Length == 0)
|
|
|
|
return;
|
2016-10-12 05:59:19 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var sav = C_SAV.SAV;
|
|
|
|
if (FileUtil.TryGetPKM(input, out var pk, sav.Generation.ToString(), sav))
|
|
|
|
{
|
|
|
|
OpenPKM(pk);
|
|
|
|
return;
|
2017-06-18 01:37:19 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
if (FileUtil.TryGetMysteryGift(input, out var mg, url))
|
2017-06-18 01:37:19 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
OpenMysteryGift(mg, url);
|
|
|
|
return;
|
|
|
|
}
|
2015-02-27 08:40:57 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
WinFormsUtil.Alert(MsgQRDecodeFail, string.Format(MsgQRDecodeSize, input.Length));
|
|
|
|
}
|
2017-02-05 20:55:17 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ExportQRFromTabs()
|
|
|
|
{
|
|
|
|
if (!PKME_Tabs.EditsComplete)
|
|
|
|
return;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
PKM pk = PreparePKM();
|
|
|
|
if (pk.Format == 6 && !QR6Notified) // hint that the user should not be using QR6 injection
|
|
|
|
{
|
|
|
|
WinFormsUtil.Alert(MsgQRDeprecated, MsgQRAlternative);
|
|
|
|
QR6Notified = true;
|
2015-02-25 04:10:47 +00:00
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var qr = QREncode.GenerateQRCode(pk);
|
|
|
|
|
|
|
|
var sprite = dragout.Image;
|
|
|
|
var la = new LegalityAnalysis(pk, C_SAV.SAV.Personal);
|
|
|
|
if (la.Parsed && pk.Species != 0)
|
2014-12-13 22:48:34 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var img = SpriteUtil.GetLegalIndicator(la.Valid);
|
|
|
|
sprite = ImageUtil.LayerImage(sprite, img, sprite.Width - img.Width, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
string[] r = pk.GetQRLines();
|
|
|
|
string refer = GetProgramTitle();
|
|
|
|
using var form = new QR(qr, sprite, pk, r[0], r[1], r[2], $"{refer} ({pk.GetType().Name})");
|
|
|
|
form.ShowDialog();
|
|
|
|
}
|
2014-12-13 22:48:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ClickLegality(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (!PKME_Tabs.EditsComplete)
|
|
|
|
{ SystemSounds.Hand.Play(); return; }
|
2014-12-13 22:48:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var pk = PreparePKM();
|
2015-08-07 04:16:25 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (pk.Species == 0 || !pk.ChecksumValid)
|
|
|
|
{ SystemSounds.Hand.Play(); return; }
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var la = new LegalityAnalysis(pk, C_SAV.SAV.Personal);
|
|
|
|
PKME_Tabs.UpdateLegality(la);
|
|
|
|
DisplayLegalityReport(la);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void DisplayLegalityReport(LegalityAnalysis la)
|
|
|
|
{
|
|
|
|
bool verbose = ModifierKeys == Keys.Control;
|
|
|
|
var report = la.Report(verbose);
|
|
|
|
if (verbose)
|
2017-06-04 20:35:51 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, report, MsgClipboardLegalityExport);
|
|
|
|
if (dr != DialogResult.Yes)
|
|
|
|
return;
|
2021-06-04 00:59:53 +00:00
|
|
|
#if DEBUG
|
2023-04-15 08:58:37 +00:00
|
|
|
var enc = la.EncounterOriginal.GetTextLines();
|
2022-06-18 18:04:24 +00:00
|
|
|
report += Environment.NewLine + Environment.NewLine + string.Join(Environment.NewLine, enc);
|
2021-06-04 00:59:53 +00:00
|
|
|
#endif
|
2022-06-18 18:04:24 +00:00
|
|
|
WinFormsUtil.SetClipboardText(report);
|
2014-12-13 22:48:34 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else if (Settings.Display.IgnoreLegalPopup && la.Valid)
|
2014-12-13 22:48:34 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (Settings.Sounds.PlaySoundLegalityCheck)
|
|
|
|
SystemSounds.Asterisk.Play();
|
2014-12-13 22:48:34 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else
|
2014-12-13 22:48:34 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
WinFormsUtil.Alert(Settings.Sounds.PlaySoundLegalityCheck, report);
|
2014-12-13 22:48:34 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ClickClone(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (!PKME_Tabs.EditsComplete)
|
|
|
|
return; // don't copy garbage to the box
|
|
|
|
PKM pk = PKME_Tabs.PreparePKM();
|
|
|
|
C_SAV.SetClonesToBox(pk);
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void GetPreview(PictureBox pb, PKM? pk = null)
|
|
|
|
{
|
|
|
|
pk ??= PreparePKM(false); // don't perform control loss click
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
var menu = dragout.ContextMenuStrip;
|
|
|
|
if (menu != null)
|
|
|
|
menu.Enabled = pk.Species != 0 || HaX; // Species
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
pb.Image = pk.Sprite(C_SAV.SAV, -1, -1, flagIllegal: false);
|
|
|
|
if (pb.BackColor == SlotUtil.BadDataColor)
|
|
|
|
pb.BackColor = SlotUtil.GoodDataColor;
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void PKME_Tabs_UpdatePreviewSprite(object sender, EventArgs e) => GetPreview(dragout);
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void PKME_Tabs_LegalityChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (HaX)
|
2014-12-14 20:15:53 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
PB_Legal.Visible = false;
|
|
|
|
return;
|
2014-12-14 20:15:53 +00:00
|
|
|
}
|
2019-09-11 05:07:50 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
PB_Legal.Visible = true;
|
|
|
|
bool isValid = (sender as bool?) != false;
|
|
|
|
PB_Legal.Image = SpriteUtil.GetLegalIndicator(isValid);
|
|
|
|
toolTip.SetToolTip(PB_Legal, isValid ? "Valid" : "Invalid: Click for more info");
|
|
|
|
}
|
2014-08-17 01:42:51 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void PKME_Tabs_RequestShowdownExport(object sender, EventArgs e) => ClickShowdownExportPKM(sender, e);
|
|
|
|
private void PKME_Tabs_RequestShowdownImport(object sender, EventArgs e) => ClickShowdownImportPKM(sender, e);
|
|
|
|
private SaveFile PKME_Tabs_SaveFileRequested(object sender, EventArgs e) => C_SAV.SAV;
|
|
|
|
private PKM PreparePKM(bool click = true) => PKME_Tabs.PreparePKM(click);
|
2022-03-26 22:51:12 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Drag & Drop Events
|
|
|
|
private static void Main_DragEnter(object? sender, DragEventArgs? e)
|
|
|
|
{
|
|
|
|
if (e is null)
|
|
|
|
return;
|
|
|
|
if (e.AllowedEffect == (DragDropEffects.Copy | DragDropEffects.Link)) // external file
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
|
|
|
else if (e.Data != null) // within
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
|
|
|
}
|
2019-02-15 08:50:23 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void Main_DragDrop(object? sender, DragEventArgs? e)
|
|
|
|
{
|
|
|
|
if (e?.Data?.GetData(DataFormats.FileDrop) is not string[] { Length: not 0 } files)
|
|
|
|
return;
|
|
|
|
OpenQuick(files[0]);
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
|
|
|
}
|
2022-03-26 22:51:12 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private async void Dragout_MouseDown(object sender, MouseEventArgs e)
|
|
|
|
{
|
|
|
|
if (e.Button != MouseButtons.Left)
|
|
|
|
return;
|
2022-03-23 06:02:46 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (ModifierKeys is Keys.Alt or Keys.Shift)
|
2022-03-23 06:02:46 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
ClickQR(sender, e);
|
|
|
|
return;
|
2014-06-28 21:22:05 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!PKME_Tabs.EditsComplete)
|
|
|
|
return;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Gather data
|
|
|
|
var pk = PreparePKM();
|
|
|
|
var encrypt = ModifierKeys == Keys.Control;
|
|
|
|
var data = encrypt ? pk.EncryptedPartyData : pk.DecryptedPartyData;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Create Temp File to Drag
|
|
|
|
var newfile = FileUtil.GetPKMTempFileName(pk, encrypt);
|
|
|
|
try
|
2015-01-24 19:16:20 +00:00
|
|
|
{
|
2023-01-22 19:43:13 +00:00
|
|
|
await File.WriteAllBytesAsync(newfile, data).ConfigureAwait(true);
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var pb = (PictureBox)sender;
|
|
|
|
if (pb.Image is Bitmap img)
|
|
|
|
C_SAV.M.Drag.Info.Cursor = Cursor = new Cursor(img.GetHicon());
|
2015-10-24 03:13:32 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Copy);
|
2014-07-27 01:00:17 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
// Tons of things can happen with drag & drop; don't try to handle things, just indicate failure.
|
|
|
|
catch (Exception x)
|
|
|
|
{ WinFormsUtil.Error("Drag && Drop Error", x); }
|
|
|
|
finally
|
2014-06-28 21:22:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
C_SAV.M.Drag.ResetCursor(this);
|
|
|
|
await DeleteAsync(newfile, 20_000).ConfigureAwait(false);
|
2019-02-17 22:51:35 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-02-17 22:51:35 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static async Task DeleteAsync(string path, int delay)
|
|
|
|
{
|
|
|
|
await Task.Delay(delay).ConfigureAwait(true);
|
|
|
|
if (!File.Exists(path))
|
|
|
|
return;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
try { File.Delete(path); }
|
|
|
|
catch (Exception ex) { Debug.WriteLine(ex.Message); }
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void Dragout_DragOver(object sender, DragEventArgs e) => e.Effect = DragDropEffects.Copy;
|
2020-09-19 05:11:13 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void DragoutEnter(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
dragout.BackgroundImage = PKME_Tabs.Entity.Species > 0 ? SpriteUtil.Spriter.Set : SpriteUtil.Spriter.Delete;
|
|
|
|
Cursor = Cursors.Hand;
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void DragoutLeave(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
dragout.BackgroundImage = SpriteUtil.Spriter.Transparent;
|
|
|
|
if (Cursor == Cursors.Hand)
|
|
|
|
Cursor = Cursors.Default;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void DragoutDrop(object? sender, DragEventArgs? e)
|
|
|
|
{
|
|
|
|
if (e?.Data?.GetData(DataFormats.FileDrop) is not string[] { Length: not 0 } files)
|
|
|
|
return;
|
|
|
|
OpenQuick(files[0]);
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
|
|
|
|
|
|
|
Cursor = DefaultCursor;
|
|
|
|
}
|
|
|
|
|
2023-01-24 07:31:41 +00:00
|
|
|
private async void Main_FormClosing(object sender, FormClosingEventArgs e)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
if (C_SAV.SAV.State.Edited || PKME_Tabs.PKMIsUnsaved)
|
2017-06-18 20:02:02 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var prompt = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgProgramCloseUnsaved, MsgProgramCloseConfirm);
|
|
|
|
if (prompt != DialogResult.Yes)
|
2020-10-18 18:02:39 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
e.Cancel = true;
|
|
|
|
return;
|
2021-10-22 05:13:21 +00:00
|
|
|
}
|
2017-04-14 06:05:19 +00:00
|
|
|
}
|
2017-06-18 20:02:02 +00:00
|
|
|
|
2023-01-24 07:31:41 +00:00
|
|
|
await PKHeXSettings.SaveSettings(ConfigPath, Settings).ConfigureAwait(false);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region //// SAVE FILE FUNCTIONS ////
|
|
|
|
|
|
|
|
private void ClickExportSAV(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (!Menu_ExportSAV.Enabled)
|
|
|
|
return; // hot-keys can't cheat the system!
|
|
|
|
|
|
|
|
C_SAV.ExportSaveFile();
|
|
|
|
Text = GetProgramTitle(C_SAV.SAV);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ClickSaveFileName(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
try
|
2016-08-05 11:04:56 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!SaveFinder.TryDetectSaveFile(out var sav))
|
2018-04-06 04:25:18 +00:00
|
|
|
return;
|
2016-08-26 01:50:51 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var path = sav.Metadata.FilePath!;
|
|
|
|
var time = new FileInfo(path).CreationTime;
|
|
|
|
var timeStamp = time.ToString(CultureInfo.CurrentCulture);
|
|
|
|
if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgFileLoadSaveDetectReload, path, timeStamp) == DialogResult.Yes)
|
|
|
|
LoadFile(sav, path); // load save
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
WinFormsUtil.Error(ex.Message); // `path` contains the error message
|
2014-11-26 04:43:02 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void PromptBackup()
|
|
|
|
{
|
|
|
|
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, string.Format(MsgBackupCreateLocation, BackupPath), MsgBackupCreateQuestion))
|
|
|
|
return;
|
2016-08-26 01:50:51 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
Directory.CreateDirectory(BackupPath);
|
|
|
|
WinFormsUtil.Alert(MsgBackupSuccess, string.Format(MsgBackupDelete, BackupPath));
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
2023-04-22 03:47:04 +00:00
|
|
|
// Maybe they put their exe in a folder that we can't create files/folders to.
|
2022-06-18 18:04:24 +00:00
|
|
|
{ WinFormsUtil.Error($"{MsgBackupUnable} @ {BackupPath}", ex); }
|
2014-06-28 21:22:05 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
private void ClickUndo(object sender, EventArgs e) => C_SAV.ClickUndo();
|
|
|
|
private void ClickRedo(object sender, EventArgs e) => C_SAV.ClickRedo();
|
|
|
|
#endregion
|
2015-03-03 17:11:21 +00:00
|
|
|
}
|