mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 12:33:06 +00:00
Misc clean
lowercase input parameters
This commit is contained in:
parent
202f911d45
commit
4aa103a320
3 changed files with 86 additions and 90 deletions
|
@ -355,47 +355,45 @@ namespace PKHeX.WinForms.Controls
|
||||||
}
|
}
|
||||||
|
|
||||||
// General Use Functions //
|
// General Use Functions //
|
||||||
|
private void SetDetailsOT(ITrainerInfo tr)
|
||||||
|
|
||||||
private void SetDetailsOT(ITrainerInfo SAV)
|
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(SAV.OT))
|
if (string.IsNullOrWhiteSpace(tr.OT))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Get Save Information
|
// Get Save Information
|
||||||
TB_OT.Text = SAV.OT;
|
TB_OT.Text = tr.OT;
|
||||||
Label_OTGender.Text = gendersymbols[SAV.Gender & 1];
|
Label_OTGender.Text = gendersymbols[tr.Gender & 1];
|
||||||
Label_OTGender.ForeColor = Draw.GetGenderColor(SAV.Gender & 1);
|
Label_OTGender.ForeColor = Draw.GetGenderColor(tr.Gender & 1);
|
||||||
TID_Trainer.LoadInfo(SAV);
|
TID_Trainer.LoadInfo(tr);
|
||||||
|
|
||||||
if (SAV.Game >= 0)
|
if (tr.Game >= 0)
|
||||||
CB_GameOrigin.SelectedValue = SAV.Game;
|
CB_GameOrigin.SelectedValue = tr.Game;
|
||||||
|
|
||||||
var lang = SAV.Language;
|
var lang = tr.Language;
|
||||||
if (lang <= 0)
|
if (lang <= 0)
|
||||||
lang = (int)LanguageID.English;
|
lang = (int)LanguageID.English;
|
||||||
CB_Language.SelectedValue = lang;
|
CB_Language.SelectedValue = lang;
|
||||||
if (SAV.ConsoleRegion != 0)
|
if (tr.ConsoleRegion != 0)
|
||||||
{
|
{
|
||||||
CB_3DSReg.SelectedValue = SAV.ConsoleRegion;
|
CB_3DSReg.SelectedValue = tr.ConsoleRegion;
|
||||||
CB_Country.SelectedValue = SAV.Country;
|
CB_Country.SelectedValue = tr.Country;
|
||||||
CB_SubRegion.SelectedValue = SAV.SubRegion;
|
CB_SubRegion.SelectedValue = tr.SubRegion;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy OT trash bytes for sensitive games (Gen1/2)
|
// Copy OT trash bytes for sensitive games (Gen1/2)
|
||||||
if (SAV is SAV1 s1 && pkm is PK1 p1) p1.OT_Trash = s1.OT_Trash;
|
if (tr is SAV1 s1 && pkm is PK1 p1) p1.OT_Trash = s1.OT_Trash;
|
||||||
else if (SAV is SAV2 s2 && pkm is PK2 p2) p2.OT_Trash = s2.OT_Trash;
|
else if (tr is SAV2 s2 && pkm is PK2 p2) p2.OT_Trash = s2.OT_Trash;
|
||||||
|
|
||||||
UpdateNickname(null, EventArgs.Empty);
|
UpdateNickname(null, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetDetailsHT(ITrainerInfo SAV)
|
private void SetDetailsHT(ITrainerInfo tr)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(SAV.OT))
|
if (string.IsNullOrWhiteSpace(tr.OT))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (TB_OTt2.Text.Length > 0)
|
if (TB_OTt2.Text.Length > 0)
|
||||||
Label_CTGender.Text = gendersymbols[SAV.Gender & 1];
|
Label_CTGender.Text = gendersymbols[tr.Gender & 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetForms()
|
private void SetForms()
|
||||||
|
@ -1238,14 +1236,14 @@ namespace PKHeX.WinForms.Controls
|
||||||
if (ModifierKeys != Keys.Control)
|
if (ModifierKeys != Keys.Control)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var SAV = RequestSaveFile;
|
var sav = RequestSaveFile;
|
||||||
if (SAV == null) // form did not provide the needed info
|
if (sav == null) // form did not provide the needed info
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (tb == TB_Nickname)
|
if (tb == TB_Nickname)
|
||||||
{
|
{
|
||||||
pkm.Nickname = tb.Text;
|
pkm.Nickname = tb.Text;
|
||||||
var d = new TrashEditor(tb, pkm.Nickname_Trash, SAV);
|
var d = new TrashEditor(tb, pkm.Nickname_Trash, sav);
|
||||||
d.ShowDialog();
|
d.ShowDialog();
|
||||||
tb.Text = d.FinalString;
|
tb.Text = d.FinalString;
|
||||||
pkm.Nickname_Trash = d.FinalBytes;
|
pkm.Nickname_Trash = d.FinalBytes;
|
||||||
|
@ -1253,7 +1251,7 @@ namespace PKHeX.WinForms.Controls
|
||||||
else if (tb == TB_OT)
|
else if (tb == TB_OT)
|
||||||
{
|
{
|
||||||
pkm.OT_Name = tb.Text;
|
pkm.OT_Name = tb.Text;
|
||||||
var d = new TrashEditor(tb, pkm.OT_Trash, SAV);
|
var d = new TrashEditor(tb, pkm.OT_Trash, sav);
|
||||||
d.ShowDialog();
|
d.ShowDialog();
|
||||||
tb.Text = d.FinalString;
|
tb.Text = d.FinalString;
|
||||||
pkm.OT_Trash = d.FinalBytes;
|
pkm.OT_Trash = d.FinalBytes;
|
||||||
|
@ -1261,7 +1259,7 @@ namespace PKHeX.WinForms.Controls
|
||||||
else if (tb == TB_OTt2)
|
else if (tb == TB_OTt2)
|
||||||
{
|
{
|
||||||
pkm.HT_Name = tb.Text;
|
pkm.HT_Name = tb.Text;
|
||||||
var d = new TrashEditor(tb, pkm.HT_Trash, SAV);
|
var d = new TrashEditor(tb, pkm.HT_Trash, sav);
|
||||||
d.ShowDialog();
|
d.ShowDialog();
|
||||||
tb.Text = d.FinalString;
|
tb.Text = d.FinalString;
|
||||||
pkm.HT_Trash = d.FinalBytes;
|
pkm.HT_Trash = d.FinalBytes;
|
||||||
|
@ -1304,9 +1302,9 @@ namespace PKHeX.WinForms.Controls
|
||||||
|
|
||||||
// if egg wasn't originally obtained by OT => Link Trade, else => None
|
// if egg wasn't originally obtained by OT => Link Trade, else => None
|
||||||
bool isTraded = false;
|
bool isTraded = false;
|
||||||
var SAV = SaveFileRequested?.Invoke(this, e);
|
var sav = SaveFileRequested?.Invoke(this, e);
|
||||||
if (SAV != null)
|
if (sav != null)
|
||||||
isTraded = SAV.OT != TB_OT.Text || SAV.TID != pkm.TID || SAV.SID != pkm.SID;
|
isTraded = sav.OT != TB_OT.Text || sav.TID != pkm.TID || sav.SID != pkm.SID;
|
||||||
CB_MetLocation.SelectedIndex = isTraded ? 2 : 0;
|
CB_MetLocation.SelectedIndex = isTraded ? 2 : 0;
|
||||||
|
|
||||||
if (!CHK_Nicknamed.Checked)
|
if (!CHK_Nicknamed.Checked)
|
||||||
|
@ -1664,7 +1662,7 @@ namespace PKHeX.WinForms.Controls
|
||||||
PopulateFilteredDataSources(sav);
|
PopulateFilteredDataSources(sav);
|
||||||
PopulateFields(pkm);
|
PopulateFields(pkm);
|
||||||
|
|
||||||
// SAV Specific Limits
|
// Save File Specific Limits
|
||||||
TB_OT.MaxLength = pkm.OTLength;
|
TB_OT.MaxLength = pkm.OTLength;
|
||||||
TB_OTt2.MaxLength = pkm.OTLength;
|
TB_OTt2.MaxLength = pkm.OTLength;
|
||||||
TB_Nickname.MaxLength = pkm.NickLength;
|
TB_Nickname.MaxLength = pkm.NickLength;
|
||||||
|
@ -1758,7 +1756,7 @@ namespace PKHeX.WinForms.Controls
|
||||||
tabMain.SelectedTab = Tab_Main; // first tab
|
tabMain.SelectedTab = Tab_Main; // first tab
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitializeLanguage(SaveFile SAV)
|
private void InitializeLanguage(SaveFile sav)
|
||||||
{
|
{
|
||||||
// Set the various ComboBox DataSources up with their allowed entries
|
// Set the various ComboBox DataSources up with their allowed entries
|
||||||
SetCountrySubRegion(CB_Country, "countries");
|
SetCountrySubRegion(CB_Country, "countries");
|
||||||
|
@ -1770,25 +1768,25 @@ namespace PKHeX.WinForms.Controls
|
||||||
// Sub editors
|
// Sub editors
|
||||||
Stats.InitializeDataSources();
|
Stats.InitializeDataSources();
|
||||||
|
|
||||||
PopulateFilteredDataSources(SAV);
|
PopulateFilteredDataSources(sav);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PopulateFilteredDataSources(SaveFile SAV)
|
private void PopulateFilteredDataSources(SaveFile sav)
|
||||||
{
|
{
|
||||||
GameInfo.Strings.SetItemDataSource(SAV.Version, SAV.Generation, SAV.MaxItemID, SAV.HeldItems, HaX);
|
GameInfo.Strings.SetItemDataSource(sav.Version, sav.Generation, sav.MaxItemID, sav.HeldItems, HaX);
|
||||||
if (SAV.Generation > 1)
|
if (sav.Generation > 1)
|
||||||
CB_HeldItem.DataSource = new BindingSource(GameInfo.ItemDataSource.Where(i => i.Value <= SAV.MaxItemID).ToList(), null);
|
CB_HeldItem.DataSource = new BindingSource(GameInfo.ItemDataSource.Where(i => i.Value <= sav.MaxItemID).ToList(), null);
|
||||||
|
|
||||||
CB_Language.DataSource = GameInfo.LanguageDataSource(SAV.Generation);
|
CB_Language.DataSource = GameInfo.LanguageDataSource(sav.Generation);
|
||||||
|
|
||||||
CB_Ball.DataSource = new BindingSource(GameInfo.BallDataSource.Where(b => b.Value <= SAV.MaxBallID).ToList(), null);
|
CB_Ball.DataSource = new BindingSource(GameInfo.BallDataSource.Where(b => b.Value <= sav.MaxBallID).ToList(), null);
|
||||||
CB_Species.DataSource = new BindingSource(GameInfo.SpeciesDataSource.Where(s => s.Value <= SAV.MaxSpeciesID).ToList(), null);
|
CB_Species.DataSource = new BindingSource(GameInfo.SpeciesDataSource.Where(s => s.Value <= sav.MaxSpeciesID).ToList(), null);
|
||||||
DEV_Ability.DataSource = new BindingSource(GameInfo.AbilityDataSource.Where(a => a.Value <= SAV.MaxAbilityID).ToList(), null);
|
DEV_Ability.DataSource = new BindingSource(GameInfo.AbilityDataSource.Where(a => a.Value <= sav.MaxAbilityID).ToList(), null);
|
||||||
var gamelist = GameUtil.GetVersionsWithinRange(SAV, SAV.Generation).ToList();
|
var gamelist = GameUtil.GetVersionsWithinRange(sav, sav.Generation).ToList();
|
||||||
CB_GameOrigin.DataSource = new BindingSource(GameInfo.VersionDataSource.Where(g => gamelist.Contains((GameVersion)g.Value)).ToList(), null);
|
CB_GameOrigin.DataSource = new BindingSource(GameInfo.VersionDataSource.Where(g => gamelist.Contains((GameVersion)g.Value)).ToList(), null);
|
||||||
|
|
||||||
// Set the Move ComboBoxes too..
|
// Set the Move ComboBoxes too..
|
||||||
MoveDataAllowed = GameInfo.Strings.MoveDataSource = (HaX ? GameInfo.HaXMoveDataSource : GameInfo.LegalMoveDataSource).Where(m => m.Value <= SAV.MaxMoveID).ToList(); // Filter Z-Moves if appropriate
|
MoveDataAllowed = GameInfo.Strings.MoveDataSource = (HaX ? GameInfo.HaXMoveDataSource : GameInfo.LegalMoveDataSource).Where(m => m.Value <= sav.MaxMoveID).ToList(); // Filter Z-Moves if appropriate
|
||||||
foreach (var cb in Moves.Concat(Relearn))
|
foreach (var cb in Moves.Concat(Relearn))
|
||||||
{
|
{
|
||||||
cb.DataSource = new BindingSource(GameInfo.MoveDataSource, null);
|
cb.DataSource = new BindingSource(GameInfo.MoveDataSource, null);
|
||||||
|
|
|
@ -87,53 +87,53 @@ namespace PKHeX.WinForms
|
||||||
return Resources.unknown;
|
return Resources.unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Image GetSprite(PKM pkm, bool isBoxBGRed = false)
|
private static Image GetSprite(PKM pk, bool isBoxBGRed = false)
|
||||||
{
|
{
|
||||||
var img = GetSprite(pkm.Species, pkm.AltForm, pkm.Gender, pkm.SpriteItem, pkm.IsEgg, pkm.IsShiny, pkm.Format, isBoxBGRed);
|
var img = GetSprite(pk.Species, pk.AltForm, pk.Gender, pk.SpriteItem, pk.IsEgg, pk.IsShiny, pk.Format, isBoxBGRed);
|
||||||
if (pkm is IShadowPKM s && s.Purification > 0)
|
if (pk is IShadowPKM s && s.Purification > 0)
|
||||||
{
|
{
|
||||||
if (pkm.Species == 249) // Lugia
|
if (pk.Species == 249) // Lugia
|
||||||
img = Spriter.GetSprite(Resources._249x, 249, pkm.HeldItem, pkm.IsEgg, pkm.IsShiny, pkm.Format, isBoxBGRed);
|
img = Spriter.GetSprite(Resources._249x, 249, pk.HeldItem, pk.IsEgg, pk.IsShiny, pk.Format, isBoxBGRed);
|
||||||
GetSpriteGlow(pkm, new byte[] { 75, 0, 130 }, out var pixels, out var baseSprite, true);
|
GetSpriteGlow(pk, new byte[] { 75, 0, 130 }, out var pixels, out var baseSprite, true);
|
||||||
var glowImg = ImageUtil.GetBitmap(pixels, baseSprite.Width, baseSprite.Height, baseSprite.PixelFormat);
|
var glowImg = ImageUtil.GetBitmap(pixels, baseSprite.Width, baseSprite.Height, baseSprite.PixelFormat);
|
||||||
img = ImageUtil.LayerImage(glowImg, img, 0, 0);
|
img = ImageUtil.LayerImage(glowImg, img, 0, 0);
|
||||||
}
|
}
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Image GetSprite(SaveFile SAV)
|
private static Image GetSprite(SaveFile sav)
|
||||||
{
|
{
|
||||||
string file = "tr_00";
|
string file = "tr_00";
|
||||||
if (SAV.Generation == 6 && (SAV.ORAS || SAV.ORASDEMO))
|
if (sav.Generation == 6 && (sav.ORAS || sav.ORASDEMO))
|
||||||
file = $"tr_{SAV.MultiplayerSpriteID:00}";
|
file = $"tr_{sav.MultiplayerSpriteID:00}";
|
||||||
return Resources.ResourceManager.GetObject(file) as Image;
|
return Resources.ResourceManager.GetObject(file) as Image;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Image GetWallpaper(SaveFile SAV, int box)
|
private static Image GetWallpaper(SaveFile sav, int box)
|
||||||
{
|
{
|
||||||
string s = BoxWallpaper.GetWallpaperResourceName(SAV.Version, SAV.GetBoxWallpaper(box));
|
string s = BoxWallpaper.GetWallpaperResourceName(sav.Version, sav.GetBoxWallpaper(box));
|
||||||
return (Bitmap)(Resources.ResourceManager.GetObject(s) ?? Resources.box_wp16xy);
|
return (Bitmap)(Resources.ResourceManager.GetObject(s) ?? Resources.box_wp16xy);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Image GetSprite(PKM pkm, SaveFile SAV, int box, int slot, bool flagIllegal = false)
|
private static Image GetSprite(PKM pk, SaveFile sav, int box, int slot, bool flagIllegal = false)
|
||||||
{
|
{
|
||||||
if (!pkm.Valid)
|
if (!pk.Valid)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
bool inBox = slot >= 0 && slot < 30;
|
bool inBox = slot >= 0 && slot < 30;
|
||||||
var sprite = pkm.Species == 0 ? null : pkm.Sprite(isBoxBGRed: inBox && BoxWallpaper.IsWallpaperRed(SAV.Version, SAV.GetBoxWallpaper(box)));
|
var sprite = pk.Species == 0 ? null : pk.Sprite(isBoxBGRed: inBox && BoxWallpaper.IsWallpaperRed(sav.Version, sav.GetBoxWallpaper(box)));
|
||||||
|
|
||||||
if (flagIllegal)
|
if (flagIllegal)
|
||||||
{
|
{
|
||||||
if (box >= 0)
|
if (box >= 0)
|
||||||
pkm.Box = box;
|
pk.Box = box;
|
||||||
var la = new LegalityAnalysis(pkm, SAV.Personal);
|
var la = new LegalityAnalysis(pk, sav.Personal);
|
||||||
if (!la.Valid && pkm.Species != 0)
|
if (!la.Valid && pk.Species != 0)
|
||||||
sprite = ImageUtil.LayerImage(sprite, Resources.warn, 0, 14);
|
sprite = ImageUtil.LayerImage(sprite, Resources.warn, 0, 14);
|
||||||
}
|
}
|
||||||
if (inBox) // in box
|
if (inBox) // in box
|
||||||
{
|
{
|
||||||
var flags = SAV.GetSlotFlags(box, slot);
|
var flags = sav.GetSlotFlags(box, slot);
|
||||||
if (flags.HasFlagFast(StorageSlotFlag.Locked))
|
if (flags.HasFlagFast(StorageSlotFlag.Locked))
|
||||||
sprite = ImageUtil.LayerImage(sprite, Resources.locked, 26, 0);
|
sprite = ImageUtil.LayerImage(sprite, Resources.locked, 26, 0);
|
||||||
int team = flags.IsBattleTeam();
|
int team = flags.IsBattleTeam();
|
||||||
|
@ -180,12 +180,12 @@ namespace PKHeX.WinForms
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extension Methods
|
// Extension Methods
|
||||||
public static Image WallpaperImage(this SaveFile SAV, int box) => GetWallpaper(SAV, box);
|
public static Image WallpaperImage(this SaveFile sav, int box) => GetWallpaper(sav, box);
|
||||||
public static Image Sprite(this MysteryGift gift) => GetSprite(gift);
|
public static Image Sprite(this MysteryGift gift) => GetSprite(gift);
|
||||||
public static Image Sprite(this SaveFile SAV) => GetSprite(SAV);
|
public static Image Sprite(this SaveFile sav) => GetSprite(sav);
|
||||||
public static Image Sprite(this PKM pkm, bool isBoxBGRed = false) => GetSprite(pkm, isBoxBGRed);
|
public static Image Sprite(this PKM pk, bool isBoxBGRed = false) => GetSprite(pk, isBoxBGRed);
|
||||||
|
|
||||||
public static Image Sprite(this PKM pkm, SaveFile SAV, int box, int slot, bool flagIllegal = false)
|
public static Image Sprite(this PKM pk, SaveFile sav, int box, int slot, bool flagIllegal = false)
|
||||||
=> GetSprite(pkm, SAV, box, slot, flagIllegal);
|
=> GetSprite(pk, sav, box, slot, flagIllegal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,13 +165,13 @@ namespace PKHeX.WinForms
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Opens a dialog to open a <see cref="SaveFile"/>, <see cref="PKM"/> file, or any other supported file.
|
/// Opens a dialog to open a <see cref="SaveFile"/>, <see cref="PKM"/> file, or any other supported file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="Extensions">Misc extensions of <see cref="PKM"/> files supported by the SAV.</param>
|
/// <param name="extensions">Misc extensions of <see cref="PKM"/> files supported by the Save File.</param>
|
||||||
/// <param name="path">Output result path</param>
|
/// <param name="path">Output result path</param>
|
||||||
/// <returns>Result of whether or not a file is to be loaded from the output path.</returns>
|
/// <returns>Result of whether or not a file is to be loaded from the output path.</returns>
|
||||||
public static bool OpenSAVPKMDialog(IEnumerable<string> Extensions, out string path)
|
public static bool OpenSAVPKMDialog(IEnumerable<string> extensions, out string path)
|
||||||
{
|
{
|
||||||
string supported = string.Join(";", Extensions.Select(s => $"*.{s}").Concat(new[] { "*.pkm" }));
|
string supported = string.Join(";", extensions.Select(s => $"*.{s}").Concat(new[] { "*.pkm" }));
|
||||||
OpenFileDialog ofd = new OpenFileDialog
|
var ofd = new OpenFileDialog
|
||||||
{
|
{
|
||||||
Filter = "All Files|*.*" +
|
Filter = "All Files|*.*" +
|
||||||
$"|Supported Files (*.*)|main;*.bin;{supported};*.bak" + ExtraSaveExtensions +
|
$"|Supported Files (*.*)|main;*.bin;{supported};*.bak" + ExtraSaveExtensions +
|
||||||
|
@ -248,41 +248,47 @@ namespace PKHeX.WinForms
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Opens a dialog to save a <see cref="SaveFile"/> file.
|
/// Opens a dialog to save a <see cref="SaveFile"/> file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="SAV"><see cref="SaveFile"/> to be saved.</param>
|
/// <param name="sav"><see cref="SaveFile"/> to be saved.</param>
|
||||||
/// <param name="CurrentBox">Box the player will be greeted with when accessing the PC ingame.</param>
|
/// <param name="CurrentBox">Box the player will be greeted with when accessing the PC ingame.</param>
|
||||||
/// <returns>Result of whether or not the file was saved.</returns>
|
/// <returns>Result of whether or not the file was saved.</returns>
|
||||||
public static bool SaveSAVDialog(SaveFile SAV, int CurrentBox = 0)
|
public static bool SaveSAVDialog(SaveFile sav, int CurrentBox = 0)
|
||||||
{
|
{
|
||||||
// Chunk Error Checking
|
// Chunk Error Checking
|
||||||
string err = SAV.MiscSaveChecks();
|
string err = sav.MiscSaveChecks();
|
||||||
if (err.Length > 0 && Prompt(MessageBoxButtons.YesNo, err, MsgSaveExportContinue) != DialogResult.Yes)
|
if (err.Length > 0 && Prompt(MessageBoxButtons.YesNo, err, MsgSaveExportContinue) != DialogResult.Yes)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
SaveFileDialog main = new SaveFileDialog
|
SaveFileDialog main = new SaveFileDialog
|
||||||
{
|
{
|
||||||
Filter = SAV.Filter,
|
Filter = sav.Filter,
|
||||||
FileName = SAV.FileName,
|
FileName = sav.FileName,
|
||||||
FilterIndex = 1000, // default to last, All Files
|
FilterIndex = 1000, // default to last, All Files
|
||||||
RestoreDirectory = true
|
RestoreDirectory = true
|
||||||
};
|
};
|
||||||
if (Directory.Exists(SAV.FileFolder))
|
if (Directory.Exists(sav.FileFolder))
|
||||||
main.InitialDirectory = SAV.FileFolder;
|
main.InitialDirectory = sav.FileFolder;
|
||||||
|
|
||||||
// Export
|
// Export
|
||||||
if (main.ShowDialog() != DialogResult.OK)
|
if (main.ShowDialog() != DialogResult.OK)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (SAV.HasBox)
|
if (sav.HasBox)
|
||||||
SAV.CurrentBox = CurrentBox;
|
sav.CurrentBox = CurrentBox;
|
||||||
|
|
||||||
var ext = Path.GetExtension(main.FileName)?.ToLower();
|
ExportSAV(sav, main.FileName);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ExportSAV(SaveFile sav, string path)
|
||||||
|
{
|
||||||
|
var ext = Path.GetExtension(path)?.ToLower();
|
||||||
bool dsv = ext == ".dsv";
|
bool dsv = ext == ".dsv";
|
||||||
bool gci = ext == ".gci";
|
bool gci = ext == ".gci";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File.WriteAllBytes(main.FileName, SAV.Write(dsv, gci));
|
File.WriteAllBytes(path, sav.Write(dsv, gci));
|
||||||
SAV.Edited = false;
|
sav.Edited = false;
|
||||||
Alert(MsgSaveExportSuccessPath, main.FileName);
|
Alert(MsgSaveExportSuccessPath, path);
|
||||||
}
|
}
|
||||||
catch (Exception x)
|
catch (Exception x)
|
||||||
{
|
{
|
||||||
|
@ -290,7 +296,6 @@ namespace PKHeX.WinForms
|
||||||
Error(MsgFileWriteFail + Environment.NewLine + x.Message, MsgFileWriteProtectedAdvice);
|
Error(MsgFileWriteFail + Environment.NewLine + x.Message, MsgFileWriteProtectedAdvice);
|
||||||
else throw;
|
else throw;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -310,14 +315,7 @@ namespace PKHeX.WinForms
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
string path = output.FileName;
|
string path = output.FileName;
|
||||||
|
SaveBackup(path);
|
||||||
if (File.Exists(path))
|
|
||||||
{
|
|
||||||
// File already exists, save a .bak
|
|
||||||
string bakpath = $"{path}.bak";
|
|
||||||
if (!File.Exists(bakpath))
|
|
||||||
File.Move(path, bakpath);
|
|
||||||
}
|
|
||||||
|
|
||||||
File.WriteAllBytes(path, gift.Data);
|
File.WriteAllBytes(path, gift.Data);
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue