2017-01-08 07:54:09 +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;
|
2018-12-11 04:36:18 +00:00
|
|
|
|
using System.Reflection;
|
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
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.WinForms
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2015-09-21 03:34:09 +00:00
|
|
|
|
public partial class Main : Form
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2020-10-18 18:02:39 +00:00
|
|
|
|
private static readonly Version CurrentProgramVersion = Assembly.GetExecutingAssembly().GetName().Version!;
|
2020-02-12 04:11:33 +00:00
|
|
|
|
|
2015-09-21 03:34:09 +00:00
|
|
|
|
public Main()
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2018-12-20 06:10:32 +00:00
|
|
|
|
string[] args = Environment.GetCommandLineArgs();
|
|
|
|
|
FormLoadInitialSettings(args, out bool showChangelog, out bool BAKprompt);
|
|
|
|
|
|
2014-06-28 21:22:05 +00:00
|
|
|
|
InitializeComponent();
|
2020-10-18 18:02:39 +00:00
|
|
|
|
C_SAV.SetEditEnvironment(new SaveDataEditor<PictureBox>(new FakeSaveFile(), PKME_Tabs));
|
2019-01-02 04:27:00 +00:00
|
|
|
|
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
|
2018-12-20 06:10:32 +00:00
|
|
|
|
FormInitializeSecond();
|
2018-04-06 04:25:18 +00:00
|
|
|
|
FormLoadCheckForUpdates();
|
2021-06-04 21:19:22 +00:00
|
|
|
|
|
2021-10-22 05:13:21 +00:00
|
|
|
|
var startup = new StartupArguments();
|
|
|
|
|
startup.ReadArguments(args);
|
|
|
|
|
startup.ReadSettings(Settings.Startup);
|
|
|
|
|
startup.ReadTemplateIfNoEntity(TemplatePath);
|
|
|
|
|
FormLoadInitialFiles(startup);
|
|
|
|
|
|
2021-10-06 21:48:17 +00:00
|
|
|
|
if (Settings.Startup.PluginLoadMethod != PluginLoadSetting.DontLoad)
|
2021-06-04 21:19:22 +00:00
|
|
|
|
FormLoadPlugins();
|
2017-06-18 20:02:02 +00:00
|
|
|
|
|
|
|
|
|
if (HaX)
|
2018-01-29 06:47:03 +00:00
|
|
|
|
{
|
2022-05-31 04:43:52 +00:00
|
|
|
|
EntityConverter.AllowIncompatibleConversion = EntityCompatibilitySetting.AllowIncompatibleAll;
|
2018-04-06 04:25:18 +00:00
|
|
|
|
WinFormsUtil.Alert(MsgProgramIllegalModeActive, MsgProgramIllegalModeBehave);
|
2018-01-29 06:47:03 +00:00
|
|
|
|
}
|
2017-06-18 20:02:02 +00:00
|
|
|
|
else if (showChangelog)
|
2018-07-27 02:34:27 +00:00
|
|
|
|
{
|
2021-07-31 01:05:17 +00:00
|
|
|
|
ShowAboutDialog(AboutPage.Changelog);
|
2018-07-27 02:34:27 +00:00
|
|
|
|
}
|
2017-06-18 20:02:02 +00:00
|
|
|
|
|
|
|
|
|
if (BAKprompt && !Directory.Exists(BackupPath))
|
|
|
|
|
PromptBackup();
|
2020-10-29 00:27:11 +00:00
|
|
|
|
|
|
|
|
|
BringToFront();
|
|
|
|
|
WindowState = FormWindowState.Minimized;
|
|
|
|
|
Show();
|
|
|
|
|
WindowState = FormWindowState.Normal;
|
2017-06-18 20:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Important Variables
|
|
|
|
|
public static string CurrentLanguage
|
|
|
|
|
{
|
|
|
|
|
get => GameInfo.CurrentLanguage;
|
|
|
|
|
private set => GameInfo.CurrentLanguage = value;
|
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2019-10-26 19:33:58 +00:00
|
|
|
|
private static bool _unicode;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-06-18 20:02:02 +00:00
|
|
|
|
public static bool Unicode
|
|
|
|
|
{
|
|
|
|
|
get => _unicode;
|
|
|
|
|
private set
|
2016-08-31 04:12:47 +00:00
|
|
|
|
{
|
2017-06-18 20:02:02 +00:00
|
|
|
|
_unicode = value;
|
2019-01-21 05:55:28 +00:00
|
|
|
|
GenderSymbols = value ? GameInfo.GenderSymbolUnicode : GameInfo.GenderSymbolASCII;
|
2017-06-18 20:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-31 04:12:47 +00:00
|
|
|
|
|
2019-01-21 05:55:28 +00:00
|
|
|
|
public static IReadOnlyList<string> GenderSymbols { get; private set; } = GameInfo.GenderSymbolUnicode;
|
2017-06-19 05:27:40 +00:00
|
|
|
|
public static bool HaX { get; private set; }
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-12-11 04:48:21 +00:00
|
|
|
|
private readonly string[] main_langlist = Enum.GetNames(typeof(ProgramLanguage));
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2020-12-22 07:37:07 +00:00
|
|
|
|
private static readonly List<IPlugin> Plugins = new();
|
2017-06-18 20:02:02 +00:00
|
|
|
|
#endregion
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2017-06-18 20:02:02 +00:00
|
|
|
|
#region Path Variables
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2018-12-11 04:32:08 +00:00
|
|
|
|
public static readonly string WorkingDirectory = Application.StartupPath;
|
|
|
|
|
public static readonly string DatabasePath = Path.Combine(WorkingDirectory, "pkmdb");
|
|
|
|
|
public static readonly string MGDatabasePath = Path.Combine(WorkingDirectory, "mgdb");
|
2021-04-12 01:09:54 +00:00
|
|
|
|
public static readonly string ConfigPath = Path.Combine(WorkingDirectory, "cfg.json");
|
2018-12-11 04:32:08 +00:00
|
|
|
|
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");
|
2022-01-04 03:33:10 +00:00
|
|
|
|
private static readonly string TrainerPath = Path.Combine(WorkingDirectory, "trainers");
|
2018-12-11 04:32:08 +00:00
|
|
|
|
private static readonly string PluginPath = Path.Combine(WorkingDirectory, "plugins");
|
2018-05-12 19:28:48 +00:00
|
|
|
|
private const string ThreadPath = "https://projectpokemon.org/pkhex/";
|
2017-06-18 20:02:02 +00:00
|
|
|
|
|
2021-04-12 01:09:54 +00:00
|
|
|
|
public static readonly PKHeXSettings Settings = PKHeXSettings.GetSettings(ConfigPath);
|
|
|
|
|
|
2017-06-18 20:02:02 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region //// MAIN MENU FUNCTIONS ////
|
2021-10-22 05:13:21 +00:00
|
|
|
|
private static void FormLoadInitialSettings(IEnumerable<string> args, out bool showChangelog, out bool BAKprompt)
|
2017-06-18 20:02:02 +00:00
|
|
|
|
{
|
|
|
|
|
showChangelog = false;
|
|
|
|
|
BAKprompt = false;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2018-01-29 06:47:03 +00:00
|
|
|
|
HaX = args.Any(x => string.Equals(x.Trim('-'), nameof(HaX), StringComparison.CurrentCultureIgnoreCase))
|
2020-11-14 16:20:48 +00:00
|
|
|
|
|| Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().MainModule!.FileName!).EndsWith(nameof(HaX));
|
2018-01-29 06:47:03 +00:00
|
|
|
|
|
2021-04-12 01:09:54 +00:00
|
|
|
|
FormLoadConfig(out BAKprompt, out showChangelog);
|
|
|
|
|
HaX |= Settings.Startup.ForceHaXOnLaunch;
|
2017-06-18 20:02:02 +00:00
|
|
|
|
|
2021-04-12 01:09:54 +00:00
|
|
|
|
WinFormsUtil.AddSaveFileExtensions(Settings.Backup.OtherSaveFileExtensions);
|
2020-04-14 17:59:16 +00:00
|
|
|
|
SaveFinder.CustomBackupPaths.Clear();
|
2021-04-12 01:09:54 +00:00
|
|
|
|
SaveFinder.CustomBackupPaths.AddRange(Settings.Backup.OtherBackupPaths.Where(Directory.Exists));
|
2018-09-03 17:40:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 20:02:02 +00:00
|
|
|
|
private void FormLoadAddEvents()
|
|
|
|
|
{
|
|
|
|
|
C_SAV.Menu_Redo = Menu_Redo;
|
|
|
|
|
C_SAV.Menu_Undo = Menu_Undo;
|
2017-07-06 06:05:49 +00:00
|
|
|
|
dragout.GiveFeedback += (sender, e) => e.UseDefaultCursors = false;
|
|
|
|
|
GiveFeedback += (sender, e) => e.UseDefaultCursors = false;
|
2017-06-18 20:02:02 +00:00
|
|
|
|
PKME_Tabs.EnableDragDrop(Main_DragEnter, Main_DragDrop);
|
|
|
|
|
C_SAV.EnableDragDrop(Main_DragEnter, Main_DragDrop);
|
2014-06-28 21:22:05 +00:00
|
|
|
|
|
2015-11-19 05:37:30 +00:00
|
|
|
|
// ToolTips for Drag&Drop
|
2021-10-31 05:04:44 +00:00
|
|
|
|
toolTip.SetToolTip(dragout, "PKM QuickSave");
|
2015-11-19 05:37:30 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
// Box to Tabs D&D
|
|
|
|
|
dragout.AllowDrop = true;
|
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
// Add ContextMenus
|
|
|
|
|
var mnu = new ContextMenuPKM();
|
2020-10-18 18:02:39 +00:00
|
|
|
|
mnu.RequestEditorLegality += (o, args) => ClickLegality(mnu, args);
|
|
|
|
|
mnu.RequestEditorQR += (o, args) => ClickQR(mnu, args);
|
|
|
|
|
mnu.RequestEditorSaveAs += (o, args) => MainMenuSave(mnu, args);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
dragout.ContextMenuStrip = mnu.mnuL;
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
|
C_SAV.menu.RequestEditorLegality = DisplayLegalityReport;
|
2017-06-18 20:02:02 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2021-10-22 05:13:21 +00:00
|
|
|
|
private void FormLoadInitialFiles(StartupArguments args)
|
2017-06-18 20:02:02 +00:00
|
|
|
|
{
|
2021-10-22 05:13:21 +00:00
|
|
|
|
var sav = args.SAV!;
|
|
|
|
|
var path = sav.Metadata.FilePath ?? string.Empty;
|
|
|
|
|
OpenSAV(sav, path);
|
2018-12-20 06:10:32 +00:00
|
|
|
|
|
2021-10-22 05:13:21 +00:00
|
|
|
|
var pkm = args.Entity!;
|
|
|
|
|
OpenPKM(pkm);
|
2021-07-06 15:42:15 +00:00
|
|
|
|
|
2021-10-22 05:13:21 +00:00
|
|
|
|
if (args.Error is { } ex)
|
|
|
|
|
ErrorWindow.ShowErrorDialog(MsgFileLoadFailAuto, ex, true);
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2019-01-16 08:27:29 +00:00
|
|
|
|
private void LoadBlankSaveFile(GameVersion ver)
|
|
|
|
|
{
|
2020-10-04 15:59:33 +00:00
|
|
|
|
var current = C_SAV?.SAV;
|
|
|
|
|
var lang = SaveUtil.GetSafeLanguage(current);
|
|
|
|
|
var tr = SaveUtil.GetSafeTrainerName(current, lang);
|
2020-10-03 18:22:06 +00:00
|
|
|
|
var sav = SaveUtil.GetBlankSAV(ver, tr, lang);
|
2019-01-16 08:27:29 +00:00
|
|
|
|
if (sav.Version == GameVersion.Invalid) // will fail to load
|
2022-05-31 04:43:52 +00:00
|
|
|
|
{
|
|
|
|
|
ver = (GameVersion)GameInfo.VersionDataSource.Max(z => z.Value);
|
|
|
|
|
sav = SaveUtil.GetBlankSAV(ver, tr, lang);
|
|
|
|
|
}
|
2020-10-18 18:02:39 +00:00
|
|
|
|
OpenSAV(sav, string.Empty);
|
2020-12-05 13:36:23 +00:00
|
|
|
|
C_SAV!.SAV.State.Edited = false; // Prevents form close warning from showing until changes are made
|
2019-01-16 08:27:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 20:02:02 +00:00
|
|
|
|
private void FormLoadCheckForUpdates()
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2022-02-09 18:47:07 +00:00
|
|
|
|
Task.Run(async () =>
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2020-10-18 18:02:39 +00:00
|
|
|
|
Version? latestVersion;
|
2020-09-09 19:47:24 +00:00
|
|
|
|
// User might not be connected to the internet or with a flaky connection.
|
2021-02-21 23:01:28 +00:00
|
|
|
|
try { latestVersion = UpdateUtil.GetLatestPKHeXVersion(); }
|
2018-12-11 04:36:18 +00:00
|
|
|
|
catch (Exception ex)
|
2018-05-07 05:24:25 +00:00
|
|
|
|
{
|
2018-12-11 04:36:18 +00:00
|
|
|
|
Debug.WriteLine($"Exception while checking for latest version: {ex}");
|
2020-09-09 19:47:24 +00:00
|
|
|
|
return;
|
2018-12-11 04:48:21 +00:00
|
|
|
|
}
|
2022-02-09 18:47:07 +00:00
|
|
|
|
if (latestVersion is null || latestVersion <= CurrentProgramVersion)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
while (!IsHandleCreated) // Wait for form to be ready
|
|
|
|
|
await Task.Delay(2_000).ConfigureAwait(false);
|
|
|
|
|
Invoke(() => NotifyNewVersionAvailable(latestVersion)); // invoke on GUI thread
|
2018-12-11 04:36:18 +00:00
|
|
|
|
});
|
2017-06-18 20:02:02 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2019-02-23 22:58:48 +00:00
|
|
|
|
private void NotifyNewVersionAvailable(Version ver)
|
|
|
|
|
{
|
|
|
|
|
var date = $"{2000 + ver.Major:00}{ver.Minor:00}{ver.Build:00}";
|
|
|
|
|
L_UpdateAvailable.Text = $"{MsgProgramUpdateAvailable} {date}";
|
2022-02-09 18:47:07 +00:00
|
|
|
|
L_UpdateAvailable.Click += (_, _) => Process.Start(ThreadPath);
|
|
|
|
|
L_UpdateAvailable.Visible = true;
|
2019-02-23 22:58:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void FormLoadConfig(out bool BAKprompt, out bool showChangelog)
|
2016-12-07 07:29:57 +00:00
|
|
|
|
{
|
|
|
|
|
BAKprompt = false;
|
|
|
|
|
showChangelog = false;
|
2017-01-10 03:15:46 +00:00
|
|
|
|
|
2016-12-07 07:29:57 +00:00
|
|
|
|
// Version Check
|
2021-05-20 22:03:15 +00:00
|
|
|
|
if (Settings.Startup.Version.Length > 0 && Settings.Startup.ShowChangelogOnUpdate) // already run on system
|
2016-12-07 07:29:57 +00:00
|
|
|
|
{
|
2021-04-12 01:09:54 +00:00
|
|
|
|
bool parsed = Version.TryParse(Settings.Startup.Version, out var lastrev);
|
2018-12-11 04:48:21 +00:00
|
|
|
|
showChangelog = parsed && lastrev < CurrentProgramVersion;
|
2016-12-07 07:29:57 +00:00
|
|
|
|
}
|
2021-04-12 01:09:54 +00:00
|
|
|
|
Settings.Startup.Version = CurrentProgramVersion.ToString(); // set current ver so this doesn't happen until the user updates next time
|
2016-12-07 07:29:57 +00:00
|
|
|
|
|
|
|
|
|
// BAK Prompt
|
2021-04-12 01:09:54 +00:00
|
|
|
|
if (!Settings.Backup.BAKPrompt)
|
|
|
|
|
BAKprompt = Settings.Backup.BAKPrompt = true;
|
2016-12-07 07:29:57 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2020-12-22 07:37:07 +00:00
|
|
|
|
public static DrawConfig Draw { get; private set; } = new();
|
2019-02-17 22:51:35 +00:00
|
|
|
|
|
2018-12-20 06:10:32 +00:00
|
|
|
|
private void FormInitializeSecond()
|
|
|
|
|
{
|
2021-04-12 01:09:54 +00:00
|
|
|
|
var settings = Settings;
|
|
|
|
|
Draw = C_SAV.M.Hover.Draw = PKME_Tabs.Draw = settings.Draw;
|
2018-12-20 06:10:32 +00:00
|
|
|
|
ReloadProgramSettings(settings);
|
|
|
|
|
CB_MainLanguage.Items.AddRange(main_langlist);
|
|
|
|
|
PB_Legal.Visible = !HaX;
|
2021-06-18 05:48:31 +00:00
|
|
|
|
C_SAV.HaX = PKME_Tabs.HaX = HaX;
|
2018-12-20 06:10:32 +00:00
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
DevUtil.AddControl(Menu_Tools);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Select Language
|
2021-04-12 01:09:54 +00:00
|
|
|
|
CB_MainLanguage.SelectedIndex = GameLanguage.GetLanguageIndex(settings.Startup.Language);
|
2018-12-20 06:10:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-13 19:49:26 +00:00
|
|
|
|
private void FormLoadPlugins()
|
|
|
|
|
{
|
2018-07-24 04:36:26 +00:00
|
|
|
|
#if !MERGED // merged should load dlls from within too, folder is no longer required
|
2018-05-13 19:49:26 +00:00
|
|
|
|
if (!Directory.Exists(PluginPath))
|
|
|
|
|
return;
|
2018-07-24 04:36:26 +00:00
|
|
|
|
#endif
|
2021-05-03 01:27:04 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2021-10-06 21:48:17 +00:00
|
|
|
|
Plugins.AddRange(PluginLoader.LoadPlugins<IPlugin>(PluginPath, Settings.Startup.PluginLoadMethod));
|
2021-05-03 01:27:04 +00:00
|
|
|
|
}
|
|
|
|
|
catch (InvalidCastException c)
|
|
|
|
|
{
|
|
|
|
|
WinFormsUtil.Error(MsgPluginFailLoad, c);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-06-30 22:02:17 +00:00
|
|
|
|
foreach (var p in Plugins.OrderBy(z => z.Priority))
|
2020-09-26 06:55:31 +00:00
|
|
|
|
p.Initialize(C_SAV, PKME_Tabs, menuStrip1, CurrentProgramVersion);
|
2018-05-13 19:49:26 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2014-12-13 22:48:34 +00:00
|
|
|
|
// Main Menu Strip UI Functions
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void MainMenuOpen(object sender, EventArgs e)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2020-10-18 18:02:39 +00:00
|
|
|
|
if (WinFormsUtil.OpenSAVPKMDialog(C_SAV.SAV.PKMExtensions, out var path))
|
|
|
|
|
OpenQuick(path!);
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void MainMenuSave(object sender, EventArgs e)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2019-02-10 01:07:44 +00:00
|
|
|
|
if (!PKME_Tabs.EditsComplete)
|
|
|
|
|
return;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
PKM pk = PreparePKM();
|
2017-05-18 05:00:06 +00:00
|
|
|
|
WinFormsUtil.SavePKMDialog(pk);
|
2014-12-13 22:48:34 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void MainMenuExit(object sender, EventArgs e)
|
2014-12-13 22:48:34 +00:00
|
|
|
|
{
|
2017-06-08 05:19:45 +00:00
|
|
|
|
if (ModifierKeys == Keys.Control) // triggered via hotkey
|
2018-07-27 02:34:27 +00:00
|
|
|
|
{
|
2017-06-08 05:19:45 +00:00
|
|
|
|
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Quit PKHeX?"))
|
|
|
|
|
return;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2017-06-08 05:19:45 +00:00
|
|
|
|
Close();
|
2014-12-13 22:48:34 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2021-07-31 01:05:17 +00:00
|
|
|
|
private void MainMenuAbout(object sender, EventArgs e) => ShowAboutDialog(AboutPage.Shortcuts);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2021-07-31 01:05:17 +00:00
|
|
|
|
private static void ShowAboutDialog(AboutPage index)
|
2019-02-23 22:58:48 +00:00
|
|
|
|
{
|
2019-10-08 01:40:09 +00:00
|
|
|
|
using var form = new About(index);
|
|
|
|
|
form.ShowDialog();
|
2019-02-23 22:58:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-03 04:22:53 +00:00
|
|
|
|
// Sub Menu Options
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void MainMenuBoxReport(object sender, EventArgs e)
|
2014-12-13 22:48:34 +00:00
|
|
|
|
{
|
2019-10-08 01:40:09 +00:00
|
|
|
|
if (this.OpenWindowExists<ReportGrid>())
|
2019-02-23 22:58:48 +00:00
|
|
|
|
return;
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2019-02-23 22:58:48 +00:00
|
|
|
|
var report = new ReportGrid();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
report.Show();
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
|
var list = new List<SlotCache>();
|
|
|
|
|
SlotInfoLoader.AddFromSaveFile(C_SAV.SAV, list);
|
|
|
|
|
report.PopulateData(list);
|
2014-12-13 22:48:34 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void MainMenuDatabase(object sender, EventArgs e)
|
2016-01-30 02:02:54 +00:00
|
|
|
|
{
|
2016-11-12 18:19:17 +00:00
|
|
|
|
if (ModifierKeys == Keys.Shift)
|
|
|
|
|
{
|
2019-10-08 01:40:09 +00:00
|
|
|
|
if (!this.OpenWindowExists<KChart>())
|
2017-05-23 04:55:05 +00:00
|
|
|
|
new KChart(C_SAV.SAV).Show();
|
2016-11-12 18:19:17 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-23 22:58:48 +00:00
|
|
|
|
if (!Directory.Exists(DatabasePath))
|
|
|
|
|
{
|
|
|
|
|
WinFormsUtil.Alert(MsgDatabase, string.Format(MsgDatabaseAdvice, DatabasePath));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-01-30 02:02:54 +00:00
|
|
|
|
|
2019-10-08 01:40:09 +00:00
|
|
|
|
if (!this.OpenWindowExists<SAV_Database>())
|
2017-05-23 04:55:05 +00:00
|
|
|
|
new SAV_Database(PKME_Tabs, C_SAV).Show();
|
2016-01-30 02:02:54 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-11-14 03:23:16 +00:00
|
|
|
|
private void Menu_EncDatabase_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2022-01-04 03:33:10 +00:00
|
|
|
|
if (this.OpenWindowExists<SAV_Encounters>())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var db = new TrainerDatabase();
|
|
|
|
|
var sav = C_SAV.SAV;
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
2022-02-05 01:36:51 +00:00
|
|
|
|
var dir = TrainerPath;
|
|
|
|
|
if (!Directory.Exists(dir))
|
|
|
|
|
return;
|
2022-01-04 03:33:10 +00:00
|
|
|
|
var files = Directory.EnumerateFiles(TrainerPath, "*.*", SearchOption.AllDirectories);
|
|
|
|
|
var pkm = BoxUtil.GetPKMsFromPaths(files, sav.Generation);
|
|
|
|
|
foreach (var f in pkm)
|
|
|
|
|
db.RegisterCopy(f);
|
|
|
|
|
});
|
|
|
|
|
new SAV_Encounters(PKME_Tabs, db).Show();
|
2018-11-14 03:23:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void MainMenuMysteryDB(object sender, EventArgs e)
|
2016-09-04 17:38:53 +00:00
|
|
|
|
{
|
2019-10-08 01:40:09 +00:00
|
|
|
|
if (!this.OpenWindowExists<SAV_MysteryGiftDB>())
|
2019-02-23 22:58:48 +00:00
|
|
|
|
new SAV_MysteryGiftDB(PKME_Tabs, C_SAV).Show();
|
2016-09-04 17:38:53 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2021-07-03 19:46:52 +00:00
|
|
|
|
private static void ClosePopups()
|
|
|
|
|
{
|
2021-07-31 01:05:17 +00:00
|
|
|
|
var forms = Application.OpenForms.OfType<Form>().Where(IsPopupFormType).ToArray();
|
2021-07-03 19:46:52 +00:00
|
|
|
|
foreach (var f in forms)
|
|
|
|
|
f.Close();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-31 01:05:17 +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
|
|
|
|
private void MainMenuSettings(object sender, EventArgs e)
|
2014-12-13 22:48:34 +00:00
|
|
|
|
{
|
2021-04-12 01:09:54 +00:00
|
|
|
|
var settings = Settings;
|
|
|
|
|
using var form = new SettingsEditor(settings);
|
2019-10-08 01:40:09 +00:00
|
|
|
|
form.ShowDialog();
|
2018-03-24 05:54:26 +00:00
|
|
|
|
|
2018-08-14 02:11:58 +00:00
|
|
|
|
// Reload text (if OT details hidden)
|
|
|
|
|
Text = GetProgramTitle(C_SAV.SAV);
|
2018-03-24 05:54:26 +00:00
|
|
|
|
// Update final settings
|
2021-04-12 01:09:54 +00:00
|
|
|
|
ReloadProgramSettings(Settings);
|
2018-03-24 05:54:26 +00:00
|
|
|
|
|
2021-10-22 05:13:21 +00:00
|
|
|
|
if (form.BlankChanged) // changed by user
|
2019-01-16 08:27:29 +00:00
|
|
|
|
{
|
2021-04-12 01:09:54 +00:00
|
|
|
|
LoadBlankSaveFile(Settings.Startup.DefaultSaveVersion);
|
2019-01-16 08:27:29 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-03 01:08:14 +00:00
|
|
|
|
PKME_Tabs_UpdatePreviewSprite(sender, e);
|
2018-03-24 05:54:26 +00:00
|
|
|
|
if (C_SAV.SAV.HasBox)
|
|
|
|
|
C_SAV.ReloadSlots();
|
2018-01-03 01:08:14 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2021-04-12 01:09:54 +00:00
|
|
|
|
private void ReloadProgramSettings(PKHeXSettings settings)
|
2018-08-20 01:22:07 +00:00
|
|
|
|
{
|
2019-02-17 22:51:35 +00:00
|
|
|
|
Draw.LoadBrushes();
|
2021-04-12 01:09:54 +00:00
|
|
|
|
PKME_Tabs.Unicode = Unicode = settings.Display.Unicode;
|
2018-08-20 01:22:07 +00:00
|
|
|
|
PKME_Tabs.UpdateUnicode(GenderSymbols);
|
2021-08-25 02:52:06 +00:00
|
|
|
|
SpriteName.AllowShinySprite = settings.Sprite.ShinySprites;
|
2022-02-05 22:54:01 +00:00
|
|
|
|
SpriteBuilderUtil.SpriterPreference = settings.Sprite.SpritePreference;
|
2021-04-12 01:09:54 +00:00
|
|
|
|
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;
|
2022-04-09 08:39:34 +00:00
|
|
|
|
EntityConverter.AllowIncompatibleConversion = settings.Advanced.AllowIncompatibleConversion;
|
2022-05-31 04:43:52 +00:00
|
|
|
|
EntityConverter.RejuvenateHOME = settings.Advanced.AllowGuessRejuvenateHOME;
|
2021-06-18 05:48:31 +00:00
|
|
|
|
WinFormsUtil.DetectSaveFileOnFileOpen = settings.Startup.TryDetectRecentSave;
|
2021-08-25 02:52:06 +00:00
|
|
|
|
|
|
|
|
|
SpriteBuilder.LoadSettings(settings.Sprite);
|
2018-08-20 01:22:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void MainMenuBoxLoad(object sender, EventArgs e)
|
2015-10-25 01:16:22 +00:00
|
|
|
|
{
|
2020-10-18 18:02:39 +00:00
|
|
|
|
string? path = null;
|
2016-01-03 04:22:53 +00:00
|
|
|
|
if (Directory.Exists(DatabasePath))
|
2015-10-25 01:16:22 +00:00
|
|
|
|
{
|
2018-04-06 04:25:18 +00:00
|
|
|
|
var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgDatabaseLoad);
|
2017-05-13 19:51:33 +00:00
|
|
|
|
if (dr == DialogResult.Yes)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
path = DatabasePath;
|
2016-01-03 04:22:53 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (C_SAV.LoadBoxes(out string result, path))
|
|
|
|
|
WinFormsUtil.Alert(result);
|
2016-01-03 04:22:53 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void MainMenuBoxDump(object sender, EventArgs e)
|
2016-01-03 04:22:53 +00:00
|
|
|
|
{
|
|
|
|
|
// Dump all of box content to files.
|
2020-10-18 18:02:39 +00:00
|
|
|
|
string? path = null;
|
2018-04-06 04:25:18 +00:00
|
|
|
|
DialogResult ld = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgDatabaseExport);
|
2016-01-03 04:22:53 +00:00
|
|
|
|
if (ld == DialogResult.Yes)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
path = DatabasePath;
|
|
|
|
|
else if (ld != DialogResult.No)
|
|
|
|
|
return;
|
2015-10-25 01:16:22 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (C_SAV.DumpBoxes(out string result, path))
|
2017-05-13 19:51:33 +00:00
|
|
|
|
WinFormsUtil.Alert(result);
|
2016-01-03 04:22:53 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void MainMenuBoxDumpSingle(object sender, EventArgs e)
|
2017-03-21 07:21:03 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (C_SAV.DumpBox(out string result))
|
|
|
|
|
WinFormsUtil.Alert(result);
|
2017-03-21 07:21:03 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void MainMenuBatchEditor(object sender, EventArgs e)
|
2016-07-13 05:19:51 +00:00
|
|
|
|
{
|
2019-10-08 01:40:09 +00:00
|
|
|
|
using var form = new BatchEditor(PKME_Tabs.PreparePKM(), C_SAV.SAV);
|
|
|
|
|
form.ShowDialog();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
C_SAV.SetPKMBoxes(); // refresh
|
|
|
|
|
C_SAV.UpdateBoxViewers();
|
2016-07-13 05:19:51 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-07-16 00:48:31 +00:00
|
|
|
|
private void MainMenuFolder(object sender, EventArgs e)
|
|
|
|
|
{
|
2019-10-26 19:58:55 +00:00
|
|
|
|
if (this.OpenWindowExists<SAV_FolderList>())
|
|
|
|
|
return;
|
2021-07-06 15:42:15 +00:00
|
|
|
|
var form = new SAV_FolderList(s => OpenSAV(s.Clone(), s.Metadata.FilePath!));
|
2019-10-26 19:58:55 +00:00
|
|
|
|
form.Show();
|
2018-07-16 00:48:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-03 04:22:53 +00:00
|
|
|
|
// Misc Options
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickShowdownImportPKM(object sender, EventArgs e)
|
2016-01-03 04:22:53 +00:00
|
|
|
|
{
|
|
|
|
|
if (!Clipboard.ContainsText())
|
2018-04-06 04:25:18 +00:00
|
|
|
|
{ WinFormsUtil.Alert(MsgClipboardFailRead); return; }
|
2016-01-03 04:22:53 +00:00
|
|
|
|
|
|
|
|
|
// Get Simulator Data
|
2020-04-12 20:05:29 +00:00
|
|
|
|
var Set = new ShowdownSet(Clipboard.GetText());
|
2016-01-03 04:22:53 +00:00
|
|
|
|
|
|
|
|
|
if (Set.Species < 0)
|
2018-04-06 04:25:18 +00:00
|
|
|
|
{ WinFormsUtil.Alert(MsgSimulatorFailClipboard); return; }
|
2016-01-03 04:22:53 +00:00
|
|
|
|
|
2021-07-06 15:42:15 +00:00
|
|
|
|
var maxLength = C_SAV.SAV.NickLength;
|
|
|
|
|
if (Set.Nickname.Length > maxLength)
|
|
|
|
|
Set.Nickname = Set.Nickname[..maxLength];
|
2016-09-20 02:20:55 +00:00
|
|
|
|
|
2018-04-06 04:25:18 +00:00
|
|
|
|
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgSimulatorLoad, Set.Text))
|
2017-06-19 05:27:40 +00:00
|
|
|
|
return;
|
2016-01-03 04:22:53 +00:00
|
|
|
|
|
2018-05-12 19:28:48 +00:00
|
|
|
|
if (Set.InvalidLines.Count > 0)
|
2018-04-06 04:25:18 +00:00
|
|
|
|
WinFormsUtil.Alert(MsgSimulatorInvalid, string.Join(Environment.NewLine, Set.InvalidLines));
|
2016-09-04 06:14:05 +00:00
|
|
|
|
|
2016-01-03 04:22:53 +00:00
|
|
|
|
// Set Species & Nickname
|
2017-06-19 05:27:40 +00:00
|
|
|
|
PKME_Tabs.LoadShowdownSet(Set);
|
2016-01-03 04:22:53 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickShowdownExportPKM(object sender, EventArgs e)
|
2016-01-03 04:22:53 +00:00
|
|
|
|
{
|
2019-02-10 01:07:44 +00:00
|
|
|
|
if (!PKME_Tabs.EditsComplete)
|
2017-06-19 05:27:40 +00:00
|
|
|
|
{
|
2018-04-06 04:25:18 +00:00
|
|
|
|
WinFormsUtil.Alert(MsgSimulatorExportBadFields);
|
2017-06-19 05:27:40 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2016-01-03 04:22:53 +00:00
|
|
|
|
|
2018-05-19 02:33:11 +00:00
|
|
|
|
var pk = PreparePKM();
|
2020-12-29 05:42:54 +00:00
|
|
|
|
var text = ShowdownParsing.GetShowdownText(pk);
|
2019-11-23 05:23:00 +00:00
|
|
|
|
bool success = WinFormsUtil.SetClipboardText(text);
|
2019-12-29 02:57:36 +00:00
|
|
|
|
if (!success || !Clipboard.GetText().Equals(text))
|
2018-04-06 04:25:18 +00:00
|
|
|
|
WinFormsUtil.Alert(MsgClipboardFailWrite, MsgSimulatorExportFail);
|
2017-06-19 05:27:40 +00:00
|
|
|
|
else
|
2018-04-06 04:25:18 +00:00
|
|
|
|
WinFormsUtil.Alert(MsgSimulatorExportSuccess, text);
|
2016-01-03 04:22:53 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-05-19 02:33:11 +00:00
|
|
|
|
private void ClickShowdownExportParty(object sender, EventArgs e) => C_SAV.ClickShowdownExportParty(sender, e);
|
2018-06-17 04:56:16 +00:00
|
|
|
|
private void ClickShowdownExportCurrentBox(object sender, EventArgs e) => C_SAV.ClickShowdownExportCurrentBox(sender, e);
|
2014-06-28 21:22:05 +00:00
|
|
|
|
|
2014-12-13 22:48:34 +00:00
|
|
|
|
// Main Menu Subfunctions
|
2019-02-23 22:58:48 +00:00
|
|
|
|
private void OpenQuick(string path)
|
2014-12-13 22:48:34 +00:00
|
|
|
|
{
|
2019-02-23 22:58:48 +00:00
|
|
|
|
if (!CanFocus)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
SystemSounds.Asterisk.Play();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-02-23 22:58:48 +00:00
|
|
|
|
OpenFromPath(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OpenFromPath(string path)
|
|
|
|
|
{
|
2018-05-15 00:30:56 +00:00
|
|
|
|
if (Plugins.Any(p => p.TryLoadFile(path)))
|
|
|
|
|
return; // handled by plugin
|
|
|
|
|
|
2014-12-13 22:48:34 +00:00
|
|
|
|
// detect if it is a folder (load into boxes or not)
|
|
|
|
|
if (Directory.Exists(path))
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{ C_SAV.LoadBoxes(out string _, path); return; }
|
2014-08-17 01:42:51 +00:00
|
|
|
|
|
2018-07-27 02:34:27 +00:00
|
|
|
|
var fi = new FileInfo(path);
|
2017-06-04 07:12:35 +00:00
|
|
|
|
if (!fi.Exists)
|
|
|
|
|
return;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-08-18 06:23:44 +00:00
|
|
|
|
if (FileUtil.IsFileTooBig(fi.Length))
|
2018-07-27 02:34:27 +00:00
|
|
|
|
{
|
2018-04-06 04:25:18 +00:00
|
|
|
|
WinFormsUtil.Error(MsgFileSizeLarge + Environment.NewLine + string.Format(MsgFileSize, fi.Length), path);
|
2018-07-27 02:34:27 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2018-08-18 06:23:44 +00:00
|
|
|
|
if (FileUtil.IsFileTooSmall(fi.Length))
|
2014-12-13 22:48:34 +00:00
|
|
|
|
{
|
2018-07-27 02:34:27 +00:00
|
|
|
|
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
|
|
|
|
|
2019-02-23 22:58:48 +00:00
|
|
|
|
string ext = fi.Extension;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
#if DEBUG
|
2021-07-06 15:42:15 +00:00
|
|
|
|
OpenFile(input, path, ext);
|
2018-07-27 02:34:27 +00:00
|
|
|
|
#else
|
2021-07-06 15:42:15 +00:00
|
|
|
|
try { OpenFile(input, path, ext); }
|
|
|
|
|
catch (Exception e) { WinFormsUtil.Error(MsgFileLoadFail + "\nPath: " + path, e); }
|
2018-07-27 02:34:27 +00:00
|
|
|
|
#endif
|
2014-12-13 22:48:34 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-12-22 06:55:33 +00:00
|
|
|
|
private void OpenFile(byte[] input, string path, string ext)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2018-08-18 06:23:44 +00:00
|
|
|
|
var obj = FileUtil.GetSupportedFile(input, ext, C_SAV.SAV);
|
|
|
|
|
if (obj != null && LoadFile(obj, path))
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2019-05-13 22:58:36 +00:00
|
|
|
|
bool isSAV = WinFormsUtil.IsFileExtensionSAV(path);
|
|
|
|
|
var msg = isSAV ? MsgFileUnsupported : MsgPKMUnsupported;
|
|
|
|
|
WinFormsUtil.Error(msg,
|
2018-04-06 04:25:18 +00:00
|
|
|
|
$"{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
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2020-10-18 18:02:39 +00:00
|
|
|
|
private bool LoadFile(object? input, string path)
|
2014-12-13 22:48:34 +00:00
|
|
|
|
{
|
2018-08-18 06:23:44 +00:00
|
|
|
|
if (input == null)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return false;
|
2014-08-15 04:27:53 +00:00
|
|
|
|
|
2018-08-18 06:23:44 +00:00
|
|
|
|
switch (input)
|
2016-09-24 01:47:03 +00:00
|
|
|
|
{
|
2018-08-18 06:23:44 +00:00
|
|
|
|
case PKM pk: return OpenPKM(pk);
|
|
|
|
|
case SaveFile s: return OpenSAV(s, path);
|
2020-11-04 04:12:42 +00:00
|
|
|
|
case IPokeGroup b: return OpenGroup(b);
|
2018-08-18 06:23:44 +00:00
|
|
|
|
case MysteryGift g: return OpenMysteryGift(g, path);
|
|
|
|
|
case IEnumerable<byte[]> pkms: return OpenPCBoxBin(pkms);
|
2021-07-14 00:33:23 +00:00
|
|
|
|
case IEncounterConvertible enc: return OpenPKM(enc.ConvertToPKM(C_SAV.SAV));
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2018-08-18 06:23:44 +00:00
|
|
|
|
case SAV3GCMemoryCard gc:
|
|
|
|
|
if (!CheckGCMemoryCard(gc, path))
|
|
|
|
|
return true;
|
|
|
|
|
var mcsav = SaveUtil.GetVariantSAV(gc);
|
2021-07-06 15:42:15 +00:00
|
|
|
|
if (mcsav is null)
|
|
|
|
|
return false;
|
2018-08-18 06:23:44 +00:00
|
|
|
|
return OpenSAV(mcsav, path);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-08-18 06:23:44 +00:00
|
|
|
|
private bool OpenPKM(PKM pk)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2022-04-09 18:58:52 +00:00
|
|
|
|
var destType = C_SAV.SAV.PKMType;
|
|
|
|
|
var tmp = EntityConverter.ConvertToType(pk, destType, out var c);
|
|
|
|
|
Debug.WriteLine(c.GetDisplayString(pk, destType));
|
2020-10-18 18:02:39 +00:00
|
|
|
|
if (tmp == null)
|
2018-12-20 06:10:32 +00:00
|
|
|
|
return false;
|
2020-10-31 05:44:08 +00:00
|
|
|
|
C_SAV.SAV.AdaptPKM(tmp);
|
2020-10-18 18:02:39 +00:00
|
|
|
|
PKME_Tabs.PopulateFields(tmp);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2020-11-04 04:12:42 +00:00
|
|
|
|
private bool OpenGroup(IPokeGroup b)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2020-11-04 04:12:42 +00:00
|
|
|
|
bool result = C_SAV.OpenGroup(b, out string c);
|
2021-10-31 19:20:19 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(c))
|
|
|
|
|
WinFormsUtil.Alert(c);
|
2017-07-02 02:43:51 +00:00
|
|
|
|
Debug.WriteLine(c);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-08-18 06:23:44 +00:00
|
|
|
|
private bool OpenMysteryGift(MysteryGift tg, string path)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
if (!tg.IsPokémon)
|
2015-12-27 00:05:26 +00:00
|
|
|
|
{
|
2018-04-06 04:25:18 +00:00
|
|
|
|
WinFormsUtil.Alert(MsgPKMMysteryGiftFail, path);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-10-12 02:11:24 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var temp = tg.ConvertToPKM(C_SAV.SAV);
|
2022-04-09 18:58:52 +00:00
|
|
|
|
var destType = C_SAV.SAV.PKMType;
|
|
|
|
|
var pk = EntityConverter.ConvertToType(temp, destType, out var c);
|
2016-10-12 02:11:24 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (pk == null)
|
|
|
|
|
{
|
2022-04-09 18:58:52 +00:00
|
|
|
|
WinFormsUtil.Alert(c.GetDisplayString(temp, destType));
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return true;
|
2015-12-27 00:05:26 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2020-10-31 05:44:08 +00:00
|
|
|
|
C_SAV.SAV.AdaptPKM(pk);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
PKME_Tabs.PopulateFields(pk);
|
2017-07-02 02:43:51 +00:00
|
|
|
|
Debug.WriteLine(c);
|
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
|
|
|
|
|
2018-08-18 06:23:44 +00:00
|
|
|
|
private bool OpenPCBoxBin(IEnumerable<byte[]> pkms)
|
2014-12-31 06:18:41 +00:00
|
|
|
|
{
|
2021-07-31 01:05:17 +00:00
|
|
|
|
var data = pkms.SelectMany(z => z).ToArray();
|
|
|
|
|
if (!C_SAV.OpenPCBoxBin(data, out string c))
|
2015-03-11 01:44:51 +00:00
|
|
|
|
{
|
2018-08-18 06:23:44 +00:00
|
|
|
|
WinFormsUtil.Alert(MsgFileLoadIncompatible, c);
|
|
|
|
|
return true;
|
2014-12-31 06:18:41 +00:00
|
|
|
|
}
|
2017-02-09 08:44:38 +00:00
|
|
|
|
|
2018-08-18 06:23:44 +00:00
|
|
|
|
WinFormsUtil.Alert(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
|
|
|
|
|
2021-07-05 21:32:09 +00:00
|
|
|
|
private static GameVersion SelectMemoryCardSaveGame(SAV3GCMemoryCard memCard)
|
2017-04-02 14:53:46 +00:00
|
|
|
|
{
|
2021-07-05 21:32:09 +00:00
|
|
|
|
if (memCard.SaveGameCount == 1)
|
|
|
|
|
return memCard.SelectedGameVersion;
|
2017-04-02 14:53:46 +00:00
|
|
|
|
|
2021-07-31 01:05:17 +00:00
|
|
|
|
var games = GetMemoryCardGameSelectionList(memCard);
|
2019-02-12 06:39:12 +00:00
|
|
|
|
var dialog = new SAV_GameSelect(games, MsgFileLoadSaveMultiple, MsgFileLoadSaveSelectGame);
|
2017-04-02 20:42:42 +00:00
|
|
|
|
dialog.ShowDialog();
|
|
|
|
|
return dialog.Result;
|
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2021-07-31 01:05:17 +00:00
|
|
|
|
private static List<ComboItem> GetMemoryCardGameSelectionList(SAV3GCMemoryCard memCard)
|
|
|
|
|
{
|
|
|
|
|
var games = new List<ComboItem>();
|
|
|
|
|
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));
|
|
|
|
|
return games;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-05 21:32:09 +00:00
|
|
|
|
private static bool CheckGCMemoryCard(SAV3GCMemoryCard memCard, string path)
|
2017-04-02 14:53:46 +00:00
|
|
|
|
{
|
2021-07-05 21:32:09 +00:00
|
|
|
|
var state = memCard.GetMemoryCardState();
|
2018-08-18 06:23:44 +00:00
|
|
|
|
switch (state)
|
2017-04-02 14:53:46 +00:00
|
|
|
|
{
|
2020-12-25 18:58:33 +00:00
|
|
|
|
case GCMemoryCardState.NoPkmSaveGame:
|
|
|
|
|
WinFormsUtil.Error(MsgFileGameCubeNoGames, path);
|
|
|
|
|
return false;
|
|
|
|
|
|
2017-04-02 20:42:42 +00:00
|
|
|
|
case GCMemoryCardState.DuplicateCOLO:
|
|
|
|
|
case GCMemoryCardState.DuplicateXD:
|
2020-12-25 18:58:33 +00:00
|
|
|
|
case GCMemoryCardState.DuplicateRSBOX:
|
|
|
|
|
WinFormsUtil.Error(MsgFileGameCubeDuplicate, path);
|
|
|
|
|
return false;
|
|
|
|
|
|
2017-04-02 14:53:46 +00:00
|
|
|
|
case GCMemoryCardState.MultipleSaveGame:
|
2021-07-31 01:05:17 +00:00
|
|
|
|
var game = SelectMemoryCardSaveGame(memCard);
|
2021-07-06 15:42:15 +00:00
|
|
|
|
if (game == GameVersion.Invalid) //Cancel
|
|
|
|
|
return false;
|
|
|
|
|
memCard.SelectSaveGame(game);
|
|
|
|
|
break;
|
|
|
|
|
|
2021-07-31 01:05:17 +00:00
|
|
|
|
case GCMemoryCardState.SaveGameCOLO: memCard.SelectSaveGame(GameVersion.COLO); break;
|
|
|
|
|
case GCMemoryCardState.SaveGameXD: memCard.SelectSaveGame(GameVersion.XD); break;
|
2021-07-05 21:32:09 +00:00
|
|
|
|
case GCMemoryCardState.SaveGameRSBOX: memCard.SelectSaveGame(GameVersion.RSBOX); break;
|
2020-12-25 18:58:33 +00:00
|
|
|
|
|
|
|
|
|
default:
|
2021-07-05 21:32:09 +00:00
|
|
|
|
WinFormsUtil.Error(!SaveUtil.IsSizeValid(memCard.Data.Length) ? MsgFileGameCubeBad : MsgFileLoadSaveLoadFail, path);
|
2020-12-25 18:58:33 +00:00
|
|
|
|
return false;
|
2017-04-02 14:53:46 +00:00
|
|
|
|
}
|
2018-08-18 06:23:44 +00:00
|
|
|
|
return true;
|
2017-04-02 14:53:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-18 05:00:06 +00:00
|
|
|
|
private static void StoreLegalSaveGameData(SaveFile sav)
|
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-12-19 01:15:35 +00:00
|
|
|
|
if (sav is SAV3 sav3)
|
2020-07-19 03:51:55 +00:00
|
|
|
|
EReaderBerrySettings.LoadFrom(sav3);
|
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
|
|
|
|
|
2021-07-06 15:42:15 +00:00
|
|
|
|
private bool OpenSAV(SaveFile sav, string path)
|
2014-12-13 22:48:34 +00:00
|
|
|
|
{
|
2021-07-06 15:42:15 +00:00
|
|
|
|
if (sav.Version == GameVersion.Invalid)
|
2019-11-16 05:33:23 +00:00
|
|
|
|
{
|
2020-05-24 18:03:23 +00:00
|
|
|
|
WinFormsUtil.Error(MsgFileLoadSaveLoadFail, path);
|
|
|
|
|
return true;
|
2019-11-16 05:33:23 +00:00
|
|
|
|
}
|
2016-10-12 02:11:24 +00:00
|
|
|
|
|
2020-12-05 13:36:23 +00:00
|
|
|
|
sav.Metadata.SetExtraInfo(path);
|
2018-01-28 08:03:49 +00:00
|
|
|
|
if (!SanityCheckSAV(ref sav))
|
2018-08-18 06:23:44 +00:00
|
|
|
|
return true;
|
2019-12-21 23:33:20 +00:00
|
|
|
|
|
2021-04-12 01:09:54 +00:00
|
|
|
|
if (C_SAV.SAV.State.Edited && Settings.SlotWrite.ModifyUnset)
|
2020-05-24 18:03:23 +00:00
|
|
|
|
{
|
|
|
|
|
var prompt = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgProgramCloseUnsaved, MsgProgramSaveFileConfirm);
|
|
|
|
|
if (prompt != DialogResult.Yes)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-03 19:46:52 +00:00
|
|
|
|
ClosePopups();
|
|
|
|
|
|
2019-12-21 23:33:20 +00:00
|
|
|
|
PKME_Tabs.Focus(); // flush any pending changes
|
2017-05-23 04:55:05 +00:00
|
|
|
|
StoreLegalSaveGameData(sav);
|
2022-04-09 08:39:34 +00:00
|
|
|
|
RecentTrainerCache.SetRecentTrainer(sav);
|
2019-11-16 01:34:18 +00:00
|
|
|
|
SpriteUtil.Initialize(sav); // refresh sprite generator
|
|
|
|
|
dragout.Size = new Size(SpriteUtil.Spriter.Width, SpriteUtil.Spriter.Height);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
|
|
|
|
// clean fields
|
2020-12-05 13:36:23 +00:00
|
|
|
|
Menu_ExportSAV.Enabled = sav.State.Exportable;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
|
|
|
|
// No changes made yet
|
|
|
|
|
Menu_Undo.Enabled = false;
|
|
|
|
|
Menu_Redo.Enabled = false;
|
|
|
|
|
|
2019-06-22 17:50:32 +00:00
|
|
|
|
GameInfo.FilteredSources = new FilteredGameDataSource(sav, GameInfo.Sources, HaX);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
ResetSAVPKMEditors(sav);
|
2018-12-20 06:10:32 +00:00
|
|
|
|
C_SAV.M.Reset();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
|
2018-01-28 08:03:49 +00:00
|
|
|
|
Text = GetProgramTitle(sav);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
TryBackupExportCheck(sav, path);
|
|
|
|
|
|
2018-06-17 04:56:16 +00:00
|
|
|
|
Menu_ShowdownExportParty.Visible = sav.HasParty;
|
|
|
|
|
Menu_ShowdownExportCurrentBox.Visible = sav.HasBox;
|
|
|
|
|
|
2021-04-12 01:09:54 +00:00
|
|
|
|
Settings.Startup.LoadSaveFile(path);
|
|
|
|
|
if (Settings.Sounds.PlaySoundSAVLoad)
|
2020-01-03 23:29:12 +00:00
|
|
|
|
SystemSounds.Asterisk.Play();
|
2018-08-18 06:23:44 +00:00
|
|
|
|
return true;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ResetSAVPKMEditors(SaveFile sav)
|
|
|
|
|
{
|
2019-11-16 01:34:18 +00:00
|
|
|
|
C_SAV.SetEditEnvironment(new SaveDataEditor<PictureBox>(sav, PKME_Tabs));
|
2017-06-18 01:37:19 +00:00
|
|
|
|
|
2019-02-15 08:50:23 +00:00
|
|
|
|
var pk = sav.LoadTemplate(TemplatePath);
|
2018-12-20 06:10:32 +00:00
|
|
|
|
PKME_Tabs.CurrentPKM = pk;
|
2021-11-20 02:23:49 +00:00
|
|
|
|
|
|
|
|
|
bool init = PKME_Tabs.IsInitialized;
|
2020-10-18 18:02:39 +00:00
|
|
|
|
if (!init)
|
2018-12-20 06:10:32 +00:00
|
|
|
|
{
|
|
|
|
|
PKME_Tabs.InitializeBinding();
|
2021-11-20 02:23:49 +00:00
|
|
|
|
PKME_Tabs.SetPKMFormatMode(pk);
|
|
|
|
|
PKME_Tabs.ChangeLanguage(sav, pk);
|
2018-12-20 06:10:32 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-11-20 02:23:49 +00:00
|
|
|
|
PKME_Tabs.SetPKMFormatMode(pk);
|
2018-12-20 06:10:32 +00:00
|
|
|
|
}
|
2021-11-20 02:23:49 +00:00
|
|
|
|
PKME_Tabs.PopulateFields(pk);
|
2018-12-20 06:10:32 +00:00
|
|
|
|
|
2017-06-19 05:27:40 +00:00
|
|
|
|
// Initialize Overall Info
|
2021-07-31 01:05:17 +00:00
|
|
|
|
Menu_LoadBoxes.Enabled = Menu_DumpBoxes.Enabled = Menu_DumpBox.Enabled = Menu_Report.Enabled = C_SAV.SAV.HasBox;
|
2017-06-19 05:27:40 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
// Initialize Subviews
|
2017-06-19 05:27:40 +00:00
|
|
|
|
bool WindowTranslationRequired = false;
|
|
|
|
|
WindowTranslationRequired |= PKME_Tabs.ToggleInterface(sav, pk);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
WindowTranslationRequired |= C_SAV.ToggleInterface();
|
|
|
|
|
if (WindowTranslationRequired) // force update -- re-added controls may be untranslated
|
2017-06-18 01:37:19 +00:00
|
|
|
|
WinFormsUtil.TranslateInterface(this, CurrentLanguage);
|
2017-06-19 05:27:40 +00:00
|
|
|
|
|
2018-12-20 06:10:32 +00:00
|
|
|
|
PKME_Tabs.PopulateFields(pk);
|
2021-07-31 01:05:17 +00:00
|
|
|
|
|
|
|
|
|
sav.State.Edited = false;
|
2018-05-13 19:49:26 +00:00
|
|
|
|
foreach (var p in Plugins)
|
|
|
|
|
p.NotifySaveLoaded();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-05-07 05:24:25 +00:00
|
|
|
|
private static string GetProgramTitle()
|
2017-06-18 01:37:19 +00:00
|
|
|
|
{
|
2018-12-30 08:05:19 +00:00
|
|
|
|
#if DEBUG
|
2020-10-18 18:02:39 +00:00
|
|
|
|
var date = File.GetLastWriteTime(Assembly.GetEntryAssembly()!.Location);
|
2018-12-30 08:05:19 +00:00
|
|
|
|
string version = $"d-{date:yyyyMMdd}";
|
|
|
|
|
#else
|
2018-12-15 17:21:36 +00:00
|
|
|
|
var ver = CurrentProgramVersion;
|
|
|
|
|
string version = $"{2000+ver.Major:00}{ver.Minor:00}{ver.Build:00}";
|
|
|
|
|
#endif
|
2018-12-11 04:36:18 +00:00
|
|
|
|
return $"PKH{(HaX ? "a" : "e")}X ({version})";
|
2018-05-07 05:24:25 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-05-07 05:24:25 +00:00
|
|
|
|
private static string GetProgramTitle(SaveFile sav)
|
|
|
|
|
{
|
|
|
|
|
string title = GetProgramTitle() + $" - {sav.GetType().Name}: ";
|
2020-09-26 06:41:20 +00:00
|
|
|
|
if (sav is ISaveFileRevision rev)
|
|
|
|
|
title = title.Insert(title.Length - 2, rev.SaveRevisionString);
|
2018-12-22 21:16:16 +00:00
|
|
|
|
var ver = GameInfo.GetVersionName(sav.Version);
|
2021-04-12 01:09:54 +00:00
|
|
|
|
if (Settings.Privacy.HideSAVDetails)
|
2018-12-22 21:16:16 +00:00
|
|
|
|
return title + $"[{ver}]";
|
2020-12-05 13:36:23 +00:00
|
|
|
|
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
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static bool TryBackupExportCheck(SaveFile sav, string path)
|
|
|
|
|
{
|
2021-04-12 01:09:54 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(path) || !Settings.Backup.BAKEnabled) // not actual save
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// If backup folder exists, save a backup.
|
2020-12-05 13:36:23 +00:00
|
|
|
|
string backupName = Path.Combine(BackupPath, Util.CleanFileName(sav.Metadata.BAKName));
|
|
|
|
|
if (sav.State.Exportable && Directory.Exists(BackupPath) && !File.Exists(backupName))
|
2022-02-10 00:48:55 +00:00
|
|
|
|
{
|
|
|
|
|
var src = sav.Metadata.FilePath;
|
|
|
|
|
if (src is { } x && File.Exists(x))
|
2022-03-26 02:25:07 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
File.Copy(x, backupName);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
WinFormsUtil.Error(MsgBackupUnable, ex);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-10 00:48:55 +00:00
|
|
|
|
}
|
2020-09-19 05:11:13 +00:00
|
|
|
|
if (!FileUtil.IsFileLocked(path))
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
2018-07-27 02:34:27 +00:00
|
|
|
|
WinFormsUtil.Alert(MsgFileWriteProtected + Environment.NewLine + path, MsgFileWriteProtectedAdvice);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-01-28 08:03:49 +00:00
|
|
|
|
private static bool SanityCheckSAV(ref SaveFile sav)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2019-02-02 07:08:03 +00:00
|
|
|
|
ParseSettings.InitFromSaveFileData(sav); // physical GB, no longer used in logic
|
2017-03-18 05:27:59 +00:00
|
|
|
|
|
2020-12-05 13:36:23 +00:00
|
|
|
|
if (sav.State.Exportable && sav is SAV3 s3)
|
2017-04-02 20:42:42 +00:00
|
|
|
|
{
|
2021-04-01 20:37:39 +00:00
|
|
|
|
if (ModifierKeys == Keys.Control || s3.IsCorruptPokedexFF())
|
2018-12-28 04:24: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));
|
2019-02-12 06:39:12 +00:00
|
|
|
|
var msg = string.Format(MsgFileLoadVersionDetect, $"3 ({s3.Version})");
|
2019-10-08 01:40:09 +00:00
|
|
|
|
using var dialog = new SAV_GameSelect(games, msg, MsgFileLoadSaveSelectVersion);
|
2018-12-28 04:24:24 +00:00
|
|
|
|
dialog.ShowDialog();
|
2021-04-07 00:26:13 +00:00
|
|
|
|
if (dialog.Result is GameVersion.Invalid)
|
|
|
|
|
return false;
|
2018-12-28 04:24:24 +00:00
|
|
|
|
|
2022-02-10 00:48:55 +00:00
|
|
|
|
var s = s3.ForceLoad(dialog.Result);
|
|
|
|
|
if (s is SAV3FRLG frlg)
|
2019-09-03 02:30:58 +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)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-02-10 00:48:55 +00:00
|
|
|
|
var origin = sav.Metadata.FilePath;
|
|
|
|
|
if (origin is not null)
|
|
|
|
|
s.Metadata.SetExtraInfo(origin);
|
|
|
|
|
sav = s;
|
2018-12-28 04:24:24 +00:00
|
|
|
|
}
|
2021-03-16 06:51:58 +00:00
|
|
|
|
else if (s3 is SAV3FRLG frlg) // IndeterminateSubVersion
|
2018-12-28 04:24:24 +00:00
|
|
|
|
{
|
|
|
|
|
string fr = GameInfo.GetVersionName(GameVersion.FR);
|
|
|
|
|
string lg = GameInfo.GetVersionName(GameVersion.LG);
|
2019-02-12 06:39:12 +00:00
|
|
|
|
string dual = "{1}/{2} " + MsgFileLoadVersionDetect;
|
2018-12-28 04:24:24 +00:00
|
|
|
|
var g = new[] { GameVersion.FR, GameVersion.LG };
|
|
|
|
|
var games = g.Select(z => GameInfo.VersionDataSource.First(v => v.Value == (int)z));
|
2019-02-12 06:39:12 +00:00
|
|
|
|
var msg = string.Format(dual, "3", fr, lg);
|
2019-10-08 01:40:09 +00:00
|
|
|
|
using var dialog = new SAV_GameSelect(games, msg, MsgFileLoadSaveSelectVersion);
|
2018-12-28 04:24:24 +00:00
|
|
|
|
dialog.ShowDialog();
|
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;
|
|
|
|
|
}
|
2017-04-02 20:42:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-10-12 02:11:24 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static void SetCountrySubRegion(ComboBox CB, string type)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
int index = CB.SelectedIndex;
|
2018-09-29 19:22:13 +00:00
|
|
|
|
string cl = GameInfo.CurrentLanguage;
|
2019-02-15 19:47:35 +00:00
|
|
|
|
CB.DataSource = Util.GetCountryRegionList(type, cl);
|
2017-03-19 23:19:59 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (index > 0 && index < CB.Items.Count)
|
|
|
|
|
CB.SelectedIndex = index;
|
2016-11-13 21:11:53 +00:00
|
|
|
|
}
|
2014-12-13 22:48:34 +00:00
|
|
|
|
|
|
|
|
|
// Language Translation
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ChangeMainLanguage(object sender, EventArgs e)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2021-06-18 05:48:31 +00:00
|
|
|
|
var index = CB_MainLanguage.SelectedIndex;
|
|
|
|
|
if ((uint)index < CB_MainLanguage.Items.Count)
|
|
|
|
|
CurrentLanguage = GameLanguage.Language2Char(index);
|
2017-03-24 18:18:14 +00:00
|
|
|
|
|
|
|
|
|
// Set the culture (makes it easy to pass language to other forms)
|
2021-06-18 05:48:31 +00:00
|
|
|
|
var lang = CurrentLanguage;
|
|
|
|
|
Settings.Startup.Language = lang;
|
|
|
|
|
var ci = new CultureInfo(lang[..2]);
|
|
|
|
|
Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = ci;
|
2017-03-24 18:18:14 +00:00
|
|
|
|
|
2014-12-13 22:48:34 +00:00
|
|
|
|
Menu_Options.DropDown.Close();
|
2017-06-19 05:27:40 +00:00
|
|
|
|
|
2021-06-18 05:48:31 +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);
|
|
|
|
|
|
|
|
|
|
if (sav is not FakeSaveFile)
|
2018-12-20 06:10:32 +00:00
|
|
|
|
{
|
2019-02-10 01:07:44 +00:00
|
|
|
|
var pk = PKME_Tabs.CurrentPKM.Clone();
|
|
|
|
|
|
|
|
|
|
PKME_Tabs.ChangeLanguage(sav, pk);
|
2021-11-20 02:23:49 +00:00
|
|
|
|
PKME_Tabs.PopulateFields(pk); // put data back in form
|
2019-02-10 01:07:44 +00:00
|
|
|
|
Text = GetProgramTitle(sav);
|
2018-12-20 06:10:32 +00:00
|
|
|
|
}
|
2014-12-13 22:48:34 +00:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
2014-06-28 21:22:05 +00:00
|
|
|
|
|
2014-12-13 22:48:34 +00:00
|
|
|
|
#region //// PKX WINDOW FUNCTIONS ////
|
2017-03-12 23:36:23 +00:00
|
|
|
|
private bool QR6Notified;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickQR(object sender, EventArgs e)
|
2015-02-25 04:10:47 +00:00
|
|
|
|
{
|
2015-02-27 08:40:57 +00:00
|
|
|
|
if (ModifierKeys == Keys.Alt)
|
2017-06-22 04:57:59 +00:00
|
|
|
|
{
|
2017-07-03 04:27:22 +00:00
|
|
|
|
string url = Clipboard.GetText();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(url))
|
|
|
|
|
{
|
2018-12-27 01:31:23 +00:00
|
|
|
|
if (url.StartsWith("http") && !url.Contains('\n')) // qr payload
|
2017-07-03 04:27:22 +00:00
|
|
|
|
ImportQRToTabs(url);
|
2018-12-27 01:31:23 +00:00
|
|
|
|
else
|
|
|
|
|
ClickShowdownImportPKM(sender, e);
|
2017-07-03 04:27:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-06-22 04:57:59 +00:00
|
|
|
|
}
|
2017-07-03 04:27:22 +00:00
|
|
|
|
ExportQRFromTabs();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
}
|
2015-03-14 02:59:51 +00:00
|
|
|
|
|
2017-07-03 04:27:22 +00:00
|
|
|
|
private void ImportQRToTabs(string url)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
{
|
2019-09-29 16:47:06 +00:00
|
|
|
|
var msg = QRDecode.GetQRData(url, out var input);
|
|
|
|
|
if (msg != 0)
|
|
|
|
|
{
|
|
|
|
|
WinFormsUtil.Alert(msg.ConvertMsg());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-02 07:08:03 +00:00
|
|
|
|
if (input.Length == 0)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return;
|
2016-10-12 05:59:19 +00:00
|
|
|
|
|
2017-10-23 22:49:52 +00:00
|
|
|
|
var sav = C_SAV.SAV;
|
2021-01-17 08:05:07 +00:00
|
|
|
|
if (FileUtil.TryGetPKM(input, out var pk, sav.Generation.ToString(), sav))
|
2018-08-18 06:23:44 +00:00
|
|
|
|
{
|
|
|
|
|
OpenPKM(pk);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return;
|
2018-08-18 06:23:44 +00:00
|
|
|
|
}
|
2021-01-17 08:05:07 +00:00
|
|
|
|
if (FileUtil.TryGetMysteryGift(input, out var mg, url))
|
2018-08-18 06:23:44 +00:00
|
|
|
|
{
|
|
|
|
|
OpenMysteryGift(mg, url);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return;
|
2018-08-18 06:23:44 +00:00
|
|
|
|
}
|
2017-10-23 22:49:52 +00:00
|
|
|
|
|
2018-04-06 04:25:18 +00:00
|
|
|
|
WinFormsUtil.Alert(MsgQRDecodeFail, string.Format(MsgQRDecodeSize, input.Length));
|
2017-06-18 01:37:19 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-06-18 20:02:02 +00:00
|
|
|
|
private void ExportQRFromTabs()
|
2017-06-18 01:37:19 +00:00
|
|
|
|
{
|
2019-02-10 01:07:44 +00:00
|
|
|
|
if (!PKME_Tabs.EditsComplete)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return;
|
2015-03-14 02:59:51 +00:00
|
|
|
|
|
2019-09-29 16:47:06 +00:00
|
|
|
|
PKM pk = PreparePKM();
|
|
|
|
|
if (pk.Format == 6 && !QR6Notified) // hint that the user should not be using QR6 injection
|
2017-06-18 01:37:19 +00:00
|
|
|
|
{
|
2019-09-29 16:47:06 +00:00
|
|
|
|
WinFormsUtil.Alert(MsgQRDeprecated, MsgQRAlternative);
|
|
|
|
|
QR6Notified = true;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
}
|
2015-02-27 08:40:57 +00:00
|
|
|
|
|
2019-09-29 16:47:06 +00:00
|
|
|
|
var qr = QREncode.GenerateQRCode(pk);
|
2017-02-05 20:55:17 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var sprite = dragout.Image;
|
2019-02-15 19:47:35 +00:00
|
|
|
|
var la = new LegalityAnalysis(pk, C_SAV.SAV.Personal);
|
|
|
|
|
if (la.Parsed && pk.Species != 0)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
{
|
2019-09-29 16:47:06 +00:00
|
|
|
|
var img = SpriteUtil.GetLegalIndicator(la.Valid);
|
2019-12-24 04:16:34 +00:00
|
|
|
|
sprite = ImageUtil.LayerImage(sprite, img, sprite.Width - img.Width, 0);
|
2015-02-26 07:12:38 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
|
2019-02-15 19:47:35 +00:00
|
|
|
|
string[] r = pk.GetQRLines();
|
2018-05-07 05:24:25 +00:00
|
|
|
|
string refer = GetProgramTitle();
|
2019-10-08 01:40:09 +00:00
|
|
|
|
using var form = new QR(qr, sprite, pk, r[0], r[1], r[2], $"{refer} ({pk.GetType().Name})");
|
|
|
|
|
form.ShowDialog();
|
2015-02-25 04:10:47 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
|
|
|
|
|
private void ClickLegality(object sender, EventArgs e)
|
2014-12-13 22:48:34 +00:00
|
|
|
|
{
|
2019-02-10 01:07:44 +00:00
|
|
|
|
if (!PKME_Tabs.EditsComplete)
|
2019-02-13 04:17:09 +00:00
|
|
|
|
{ SystemSounds.Hand.Play(); return; }
|
2014-12-13 22:48:34 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var pk = PreparePKM();
|
2014-12-13 22:48:34 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (pk.Species == 0 || !pk.ChecksumValid)
|
2019-02-13 04:17:09 +00:00
|
|
|
|
{ SystemSounds.Hand.Play(); return; }
|
2015-08-07 04:16:25 +00:00
|
|
|
|
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
|
var la = new LegalityAnalysis(pk, C_SAV.SAV.Personal);
|
|
|
|
|
PKME_Tabs.UpdateLegality(la);
|
|
|
|
|
DisplayLegalityReport(la);
|
2017-06-04 20:35:51 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
|
private static void DisplayLegalityReport(LegalityAnalysis la)
|
2017-06-04 20:35:51 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
bool verbose = ModifierKeys == Keys.Control;
|
|
|
|
|
var report = la.Report(verbose);
|
|
|
|
|
if (verbose)
|
2016-07-29 05:54:29 +00:00
|
|
|
|
{
|
2018-04-06 04:25:18 +00:00
|
|
|
|
var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, report, MsgClipboardLegalityExport);
|
2021-06-04 00:59:53 +00:00
|
|
|
|
if (dr != DialogResult.Yes)
|
|
|
|
|
return;
|
|
|
|
|
#if DEBUG
|
|
|
|
|
var enc = SummaryPreviewer.GetTextLines(la.EncounterOriginal);
|
|
|
|
|
report += Environment.NewLine + Environment.NewLine + string.Join(Environment.NewLine, enc);
|
|
|
|
|
#endif
|
|
|
|
|
WinFormsUtil.SetClipboardText(report);
|
2016-07-29 05:54:29 +00:00
|
|
|
|
}
|
2021-04-12 01:09:54 +00:00
|
|
|
|
else if (Settings.Display.IgnoreLegalPopup && la.Valid)
|
2019-02-13 04:17:09 +00:00
|
|
|
|
{
|
2021-04-12 01:09:54 +00:00
|
|
|
|
if (Settings.Sounds.PlaySoundLegalityCheck)
|
2020-01-03 23:29:12 +00:00
|
|
|
|
SystemSounds.Asterisk.Play();
|
2019-02-13 04:17:09 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
else
|
2018-07-27 02:34:27 +00:00
|
|
|
|
{
|
2021-04-12 01:09:54 +00:00
|
|
|
|
WinFormsUtil.Alert(Settings.Sounds.PlaySoundLegalityCheck, report);
|
2018-07-27 02:34:27 +00:00
|
|
|
|
}
|
2014-12-13 22:48:34 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickClone(object sender, EventArgs e)
|
2014-12-13 22:48:34 +00:00
|
|
|
|
{
|
2019-02-10 01:07:44 +00:00
|
|
|
|
if (!PKME_Tabs.EditsComplete)
|
|
|
|
|
return; // don't copy garbage to the box
|
2017-06-18 01:37:19 +00:00
|
|
|
|
PKM pk = PKME_Tabs.PreparePKM();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
C_SAV.SetClonesToBox(pk);
|
2014-12-13 22:48:34 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2020-10-18 18:02:39 +00:00
|
|
|
|
private void GetPreview(PictureBox pb, PKM? pk = null)
|
2014-12-13 22:48:34 +00:00
|
|
|
|
{
|
2019-10-05 03:10:50 +00:00
|
|
|
|
pk ??= PreparePKM(false); // don't perform control loss click
|
2016-10-31 02:15:48 +00:00
|
|
|
|
|
2019-01-05 23:40:25 +00:00
|
|
|
|
dragout.ContextMenuStrip.Enabled = pk.Species != 0 || HaX; // Species
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2018-09-01 04:35:53 +00:00
|
|
|
|
pb.Image = pk.Sprite(C_SAV.SAV, -1, -1, flagIllegal: false);
|
2022-03-26 22:51:12 +00:00
|
|
|
|
if (pb.BackColor == SlotUtil.BadDataColor)
|
|
|
|
|
pb.BackColor = SlotUtil.GoodDataColor;
|
2014-12-13 22:48:34 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void PKME_Tabs_UpdatePreviewSprite(object sender, EventArgs e) => GetPreview(dragout);
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private void PKME_Tabs_LegalityChanged(object sender, EventArgs e)
|
2015-09-26 04:56:15 +00:00
|
|
|
|
{
|
2019-01-05 23:40:25 +00:00
|
|
|
|
if (HaX)
|
2015-09-26 04:56:15 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
PB_Legal.Visible = false;
|
|
|
|
|
return;
|
2015-09-26 04:56:15 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
|
|
|
|
PB_Legal.Visible = true;
|
2021-10-31 05:04:44 +00:00
|
|
|
|
bool isValid = sender as bool? != false;
|
|
|
|
|
PB_Legal.Image = SpriteUtil.GetLegalIndicator(isValid);
|
|
|
|
|
toolTip.SetToolTip(PB_Legal, isValid ? "Valid" : "Invalid: Click for more info");
|
2015-09-26 04:56:15 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +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);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private SaveFile PKME_Tabs_SaveFileRequested(object sender, EventArgs e) => C_SAV.SAV;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private PKM PreparePKM(bool click = true) => PKME_Tabs.PreparePKM(click);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
|
|
|
|
// Drag & Drop Events
|
2021-12-05 06:29:51 +00:00
|
|
|
|
private static void Main_DragEnter(object? sender, DragEventArgs? e)
|
2015-09-27 17:00:45 +00:00
|
|
|
|
{
|
2021-12-05 06:29:51 +00:00
|
|
|
|
if (e is null)
|
|
|
|
|
return;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (e.AllowedEffect == (DragDropEffects.Copy | DragDropEffects.Link)) // external file
|
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
|
|
|
|
else if (e.Data != null) // within
|
2022-05-08 20:01:08 +00:00
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2021-12-05 06:29:51 +00:00
|
|
|
|
private void Main_DragDrop(object? sender, DragEventArgs? e)
|
2014-12-14 20:15:53 +00:00
|
|
|
|
{
|
2021-12-05 06:29:51 +00:00
|
|
|
|
if (e?.Data?.GetData(DataFormats.FileDrop) is not string[] { Length: not 0 } files)
|
2017-06-13 01:15:26 +00:00
|
|
|
|
return;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
OpenQuick(files[0]);
|
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
2014-12-14 20:15:53 +00:00
|
|
|
|
}
|
2019-09-11 05:07:50 +00:00
|
|
|
|
|
2022-03-23 06:02:46 +00:00
|
|
|
|
private async void Dragout_MouseDown(object sender, MouseEventArgs e)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2021-03-14 23:16:55 +00:00
|
|
|
|
if (e.Button != MouseButtons.Left)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (ModifierKeys is Keys.Alt or Keys.Shift)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
ClickQR(sender, e);
|
2015-10-15 01:33:51 +00:00
|
|
|
|
return;
|
2021-03-14 23:16:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-10 01:07:44 +00:00
|
|
|
|
if (!PKME_Tabs.EditsComplete)
|
2014-08-07 00:10:29 +00:00
|
|
|
|
return;
|
2014-08-17 01:42:51 +00:00
|
|
|
|
|
2022-03-26 22:51:12 +00:00
|
|
|
|
// Gather data
|
2019-02-23 22:58:48 +00:00
|
|
|
|
var pk = PreparePKM();
|
|
|
|
|
var encrypt = ModifierKeys == Keys.Control;
|
2019-11-16 22:03:25 +00:00
|
|
|
|
var data = encrypt ? pk.EncryptedPartyData : pk.DecryptedPartyData;
|
2022-03-26 22:51:12 +00:00
|
|
|
|
|
|
|
|
|
// Create Temp File to Drag
|
|
|
|
|
var newfile = FileUtil.GetPKMTempFileName(pk, encrypt);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
try
|
2016-10-02 23:48:12 +00:00
|
|
|
|
{
|
2019-02-23 22:58:48 +00:00
|
|
|
|
File.WriteAllBytes(newfile, data);
|
2019-02-15 08:50:23 +00:00
|
|
|
|
|
|
|
|
|
var pb = (PictureBox)sender;
|
2022-03-26 22:51:12 +00:00
|
|
|
|
if (pb.Image is Bitmap img)
|
|
|
|
|
C_SAV.M.Drag.Info.Cursor = Cursor = new Cursor(img.GetHicon());
|
|
|
|
|
|
2022-03-23 06:02:46 +00:00
|
|
|
|
DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Copy);
|
2016-10-02 23:48:12 +00:00
|
|
|
|
}
|
2020-09-19 05:11:13 +00:00
|
|
|
|
// Tons of things can happen with drag & drop; don't try to handle things, just indicate failure.
|
2017-05-23 04:55:05 +00:00
|
|
|
|
catch (Exception x)
|
2019-01-03 03:32:23 +00:00
|
|
|
|
{ WinFormsUtil.Error("Drag && Drop Error", x); }
|
2022-03-26 22:51:12 +00:00
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
C_SAV.M.Drag.ResetCursor(this);
|
|
|
|
|
await DeleteAsync(newfile, 20_000).ConfigureAwait(false);
|
|
|
|
|
}
|
2022-03-23 06:02:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static async Task DeleteAsync(string path, int delay)
|
|
|
|
|
{
|
|
|
|
|
await Task.Delay(delay).ConfigureAwait(true);
|
|
|
|
|
if (!File.Exists(path))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
try { File.Delete(path); }
|
|
|
|
|
catch (Exception ex) { Debug.WriteLine(ex.Message); }
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2022-05-08 20:01:08 +00:00
|
|
|
|
private void Dragout_DragOver(object sender, DragEventArgs e) => e.Effect = DragDropEffects.Copy;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void DragoutEnter(object sender, EventArgs e)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2019-11-16 01:34:18 +00:00
|
|
|
|
dragout.BackgroundImage = PKME_Tabs.Entity.Species > 0 ? SpriteUtil.Spriter.Set : SpriteUtil.Spriter.Delete;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
Cursor = Cursors.Hand;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void DragoutLeave(object sender, EventArgs e)
|
2015-01-24 19:16:20 +00:00
|
|
|
|
{
|
2019-11-16 01:34:18 +00:00
|
|
|
|
dragout.BackgroundImage = SpriteUtil.Spriter.Transparent;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (Cursor == Cursors.Hand)
|
|
|
|
|
Cursor = Cursors.Default;
|
2015-01-24 19:16:20 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2021-12-05 06:29:51 +00:00
|
|
|
|
private void DragoutDrop(object? sender, DragEventArgs? e)
|
2016-05-06 01:52:43 +00:00
|
|
|
|
{
|
2021-12-05 06:29:51 +00:00
|
|
|
|
if (e?.Data?.GetData(DataFormats.FileDrop) is not string[] { Length: not 0 } files)
|
|
|
|
|
return;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
OpenQuick(files[0]);
|
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
2015-10-24 03:13:32 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
Cursor = DefaultCursor;
|
2014-07-27 01:00:17 +00:00
|
|
|
|
}
|
2017-04-05 01:58:32 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private void Main_FormClosing(object sender, FormClosingEventArgs e)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2020-12-05 13:36:23 +00:00
|
|
|
|
if (C_SAV.SAV.State.Edited || PKME_Tabs.PKMIsUnsaved)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2018-04-06 04:25:18 +00:00
|
|
|
|
var prompt = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgProgramCloseUnsaved, MsgProgramCloseConfirm);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (prompt != DialogResult.Yes)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
e.Cancel = true;
|
|
|
|
|
return;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2021-04-12 01:09:54 +00:00
|
|
|
|
PKHeXSettings.SaveSettings(ConfigPath, Settings);
|
2019-02-17 22:51:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region //// SAVE FILE FUNCTIONS ////
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickExportSAV(object sender, EventArgs e)
|
2014-12-14 19:06:17 +00:00
|
|
|
|
{
|
2020-09-19 05:11:13 +00:00
|
|
|
|
if (!Menu_ExportSAV.Enabled)
|
|
|
|
|
return; // hot-keys can't cheat the system!
|
|
|
|
|
|
|
|
|
|
C_SAV.ExportSaveFile();
|
|
|
|
|
Text = GetProgramTitle(C_SAV.SAV);
|
2014-12-14 19:06:17 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickSaveFileName(object sender, EventArgs e)
|
2017-06-18 20:02:02 +00:00
|
|
|
|
{
|
2021-10-22 05:13:21 +00:00
|
|
|
|
try
|
2020-10-18 18:02:39 +00:00
|
|
|
|
{
|
2021-10-22 05:13:21 +00:00
|
|
|
|
if (!SaveFinder.TryDetectSaveFile(out var sav))
|
|
|
|
|
return;
|
2018-07-15 20:35:58 +00:00
|
|
|
|
|
2021-10-22 05:13:21 +00:00
|
|
|
|
var path = sav.Metadata.FilePath!;
|
2022-02-05 01:36:51 +00:00
|
|
|
|
var time = new FileInfo(path).CreationTime;
|
|
|
|
|
var timeStamp = time.ToString(CultureInfo.CurrentCulture);
|
|
|
|
|
if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgFileLoadSaveDetectReload, path, timeStamp) == DialogResult.Yes)
|
2021-10-22 05:13:21 +00:00
|
|
|
|
LoadFile(sav, path); // load save
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
WinFormsUtil.Error(ex.Message); // `path` contains the error message
|
|
|
|
|
}
|
2017-04-14 06:05:19 +00:00
|
|
|
|
}
|
2017-06-18 20:02:02 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static void PromptBackup()
|
2016-08-05 11:04:56 +00:00
|
|
|
|
{
|
2018-07-27 02:34:27 +00:00
|
|
|
|
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, string.Format(MsgBackupCreateLocation, BackupPath), MsgBackupCreateQuestion))
|
2018-04-06 04:25:18 +00:00
|
|
|
|
return;
|
2016-08-26 01:50:51 +00:00
|
|
|
|
|
2017-01-26 06:51:52 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2018-04-06 04:25:18 +00:00
|
|
|
|
Directory.CreateDirectory(BackupPath);
|
|
|
|
|
WinFormsUtil.Alert(MsgBackupSuccess, string.Format(MsgBackupDelete, BackupPath));
|
2016-09-14 04:17:07 +00:00
|
|
|
|
}
|
2020-09-19 05:11:13 +00:00
|
|
|
|
catch (Exception ex)
|
|
|
|
|
// Maybe they put their exe in a folder that we can't create files/folders to.
|
|
|
|
|
{ WinFormsUtil.Error($"{MsgBackupUnable} @ {BackupPath}", ex); }
|
2014-11-26 04:43:02 +00:00
|
|
|
|
}
|
2016-08-26 01:50:51 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickUndo(object sender, EventArgs e) => C_SAV.ClickUndo();
|
|
|
|
|
private void ClickRedo(object sender, EventArgs e) => C_SAV.ClickRedo();
|
2014-12-13 22:48:34 +00:00
|
|
|
|
#endregion
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2015-03-03 17:11:21 +00:00
|
|
|
|
}
|