Fix vc backups acting like gb era saves

ends with .dat only works if the real file ends with dat
load the filename data after stripping off the bak filename data
#1787
This commit is contained in:
Kurt
2018-01-28 00:03:49 -08:00
parent 13e7d8ff85
commit eb505303bb
2 changed files with 26 additions and 14 deletions

View File

@@ -1137,5 +1137,25 @@ public static bool IsPKMCompatibleWithModifications(SaveFile SAV, PKM pk)
return true;
}
/// <summary>
/// Sets the details of a path to a <see cref="SaveFile"/> object.
/// </summary>
/// <param name="sav">Save File to set path details to.</param>
/// <param name="path">Full Path of the file</param>
public static void SetFileInfo(this SaveFile sav, string path)
{
if (!sav.Exportable) // Blank save file
{
sav.FilePath = null;
sav.FileName = "Blank Save File";
return;
}
sav.FilePath = Path.GetDirectoryName(path);
sav.FileName = Path.GetExtension(path) == ".bak"
? Path.GetFileName(path).Split(new[] { " [" }, StringSplitOptions.None)[0]
: Path.GetFileName(path);
}
}
}

View File

@@ -736,7 +736,8 @@ private void OpenSAV(SaveFile sav, string path)
if (sav == null || sav.Version == GameVersion.Invalid)
{ WinFormsUtil.Error("Invalid save file loaded. Aborting.", path); return; }
if (!SanityCheckSAV(ref sav, path))
sav.SetFileInfo(path);
if (!SanityCheckSAV(ref sav))
return;
StoreLegalSaveGameData(sav);
PKMUtil.Initialize(sav); // refresh sprite generator
@@ -751,7 +752,7 @@ private void OpenSAV(SaveFile sav, string path)
ResetSAVPKMEditors(sav);
Text = GetProgramTitle(sav, path);
Text = GetProgramTitle(sav);
TryBackupExportCheck(sav, path);
PKMConverter.UpdateConfig(sav.SubRegion, sav.Country, sav.ConsoleRegion, sav.OT, sav.Gender, sav.Language);
@@ -783,7 +784,7 @@ private void ResetSAVPKMEditors(SaveFile sav)
PKME_Tabs.TemplateFields(LoadTemplate(sav));
sav.Edited = false;
}
private static string GetProgramTitle(SaveFile sav, string path)
private static string GetProgramTitle(SaveFile sav)
{
#if DEBUG
var d = File.GetLastWriteTime(System.Reflection.Assembly.GetEntryAssembly().Location);
@@ -793,16 +794,7 @@ private static string GetProgramTitle(SaveFile sav, string path)
#endif
string title = $"PKH{(HaX ? "a" : "e")}X ({date}) - {sav.GetType().Name}: ";
if (!sav.Exportable) // Blank save file
{
sav.FilePath = null;
sav.FileName = "Blank Save File";
return title + $"{sav.FileName} [{sav.OT} ({sav.Version})]";
}
sav.FilePath = Path.GetDirectoryName(path);
sav.FileName = Path.GetExtension(path) == ".bak"
? Path.GetFileName(path).Split(new[] {" ["}, StringSplitOptions.None)[0]
: Path.GetFileName(path);
return title + $"{Path.GetFileNameWithoutExtension(Util.CleanFileName(sav.BAKName))}"; // more descriptive
}
private static bool TryBackupExportCheck(SaveFile sav, string path)
@@ -827,12 +819,12 @@ private static bool TryBackupExportCheck(SaveFile sav, string path)
"If the path is a removable disk (SD card), please ensure the write protection switch is not set.");
return false;
}
private static bool SanityCheckSAV(ref SaveFile sav, string path)
private static bool SanityCheckSAV(ref SaveFile sav)
{
// Finish setting up the save file.
if (sav.Generation < 3)
{
bool vc = path.EndsWith("dat");
bool vc = sav.FileName.EndsWith("dat");
Legal.AllowGBCartEra = !vc; // physical cart selected
Legal.AllowGen1Tradeback = true;
if (Legal.AllowGBCartEra && sav.Generation == 1)