mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-10 14:44:24 +00:00
Improve supported extension openfiledialog
Existing code supported 3-x, wasn't updated for gen1/2. Allows gens1/2 to override to their own gen format filter, and allows gen7 to allow finding of pk1 files (not yet converted). Noticed the backup would overwrite an existing backup; thus we only back up if the target file exists AND the backup doesn't already exist.
This commit is contained in:
parent
769f58ea97
commit
ed47e389d4
7 changed files with 51 additions and 26 deletions
|
@ -270,14 +270,7 @@ namespace PKHeX
|
|||
string pkx = pkm.Extension;
|
||||
string ekx = 'e' + pkx.Substring(1, pkx.Length-1);
|
||||
|
||||
string supported = "*.pkm;";
|
||||
for (int i = 3; i <= SAV.Generation; i++)
|
||||
{
|
||||
supported += $"*.pk{i}";
|
||||
if (i != pkm.Format)
|
||||
supported += ";";
|
||||
}
|
||||
|
||||
string supported = string.Join(";", SAV.PKMExtensions.Select(s => "*."+s).Concat(new[] {"*.pkm"}));
|
||||
OpenFileDialog ofd = new OpenFileDialog
|
||||
{
|
||||
Filter = $"Supported Files|main;*.sav;*.bin;*.{ekx};{supported};*.bak" +
|
||||
|
@ -320,8 +313,12 @@ namespace PKHeX
|
|||
if (File.Exists(path))
|
||||
{
|
||||
// File already exists, save a .bak
|
||||
string bakpath = path + ".bak";
|
||||
if (!File.Exists(bakpath))
|
||||
{
|
||||
byte[] backupfile = File.ReadAllBytes(path);
|
||||
File.WriteAllBytes(path + ".bak", backupfile);
|
||||
File.WriteAllBytes(bakpath, backupfile);
|
||||
}
|
||||
}
|
||||
|
||||
if (new[] {".ekx", "."+ekx, ".bin"}.Contains(ext))
|
||||
|
|
|
@ -6,6 +6,7 @@ namespace PKHeX
|
|||
{
|
||||
public abstract class PKM
|
||||
{
|
||||
public static readonly string[] Extensions = PKX.getPKMExtensions();
|
||||
public abstract int SIZE_PARTY { get; }
|
||||
public abstract int SIZE_STORED { get; }
|
||||
public virtual string Extension => "pk" + Format;
|
||||
|
|
|
@ -2523,5 +2523,15 @@ namespace PKHeX
|
|||
.PadRight(value.Length + 1, (char)0); // Null Terminator
|
||||
return Encoding.BigEndianUnicode.GetBytes(TempNick);
|
||||
}
|
||||
|
||||
public static string[] getPKMExtensions()
|
||||
{
|
||||
const int gens = 7;
|
||||
var result = new List<string>();
|
||||
result.AddRange(new [] {"ck3", "xk3", "bk4"}); // Special Cases
|
||||
for (int i = 1; i < gens; i++)
|
||||
result.Add("pk"+i);
|
||||
return result.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,11 @@ namespace PKHeX
|
|||
public override string BAKName => $"{FileName} [{OT} ({Version}) - {PlayTimeString}].bak";
|
||||
public override string Filter => "SAV File|*.sav|All Files|*.*";
|
||||
public override string Extension => ".sav";
|
||||
public override string[] PKMExtensions => PKM.Extensions.Where(f =>
|
||||
{
|
||||
int gen = f.Last() - 0x30;
|
||||
return 1 <= gen && gen <= 2;
|
||||
}).ToArray();
|
||||
|
||||
public SAV1(byte[] data = null)
|
||||
{
|
||||
|
@ -153,10 +158,8 @@ namespace PKHeX
|
|||
|
||||
public override int SIZE_STORED => Japanese ? PKX.SIZE_1JLIST : PKX.SIZE_1ULIST;
|
||||
public override int SIZE_PARTY => Japanese ? PKX.SIZE_1JLIST : PKX.SIZE_1ULIST;
|
||||
|
||||
public int SIZE_BOX => BoxSlotCount*SIZE_STORED;
|
||||
|
||||
public int SIZE_STOREDBOX => PokemonList1.GetDataLength(Japanese ? PokemonList1.CapacityType.StoredJP : PokemonList1.CapacityType.Stored, Japanese);
|
||||
private int SIZE_BOX => BoxSlotCount*SIZE_STORED;
|
||||
private int SIZE_STOREDBOX => PokemonList1.GetDataLength(Japanese ? PokemonList1.CapacityType.StoredJP : PokemonList1.CapacityType.Stored, Japanese);
|
||||
|
||||
public override PKM BlankPKM => new PK1(null, null, Japanese);
|
||||
public override Type PKMType => typeof(PK1);
|
||||
|
|
|
@ -8,6 +8,11 @@ namespace PKHeX
|
|||
public override string BAKName => $"{FileName} [{OT} ({Version}) - {PlayTimeString}].bak";
|
||||
public override string Filter => "SAV File|*.sav|All Files|*.*";
|
||||
public override string Extension => ".sav";
|
||||
public override string[] PKMExtensions => PKM.Extensions.Where(f =>
|
||||
{
|
||||
int gen = f.Last() - 0x30;
|
||||
return 1 <= gen && gen <= 2;
|
||||
}).ToArray();
|
||||
|
||||
public SAV2(byte[] data = null)
|
||||
{
|
||||
|
@ -202,14 +207,12 @@ namespace PKHeX
|
|||
|
||||
public override int SIZE_STORED => Japanese ? PKX.SIZE_2JLIST : PKX.SIZE_2ULIST;
|
||||
public override int SIZE_PARTY => Japanese ? PKX.SIZE_2JLIST : PKX.SIZE_2ULIST;
|
||||
|
||||
public int SIZE_BOX => BoxSlotCount*SIZE_STORED;
|
||||
|
||||
public int SIZE_STOREDBOX => PokemonList2.GetDataLength(Japanese ? PokemonList2.CapacityType.StoredJP : PokemonList2.CapacityType.Stored, Japanese);
|
||||
|
||||
public override PKM BlankPKM => new PK2(null, null, Japanese);
|
||||
public override Type PKMType => typeof(PK2);
|
||||
|
||||
private int SIZE_BOX => BoxSlotCount*SIZE_STORED;
|
||||
private int SIZE_STOREDBOX => PokemonList2.GetDataLength(Japanese ? PokemonList2.CapacityType.StoredJP : PokemonList2.CapacityType.Stored, Japanese);
|
||||
|
||||
public override int MaxMoveID => 251;
|
||||
public override int MaxSpeciesID => Legal.MaxSpeciesID_2;
|
||||
public override int MaxAbilityID => 0;
|
||||
|
|
|
@ -10,6 +10,12 @@ namespace PKHeX
|
|||
public override string BAKName => $"{FileName} [{OT} ({Version}) - {LastSavedTime}].bak";
|
||||
public override string Filter => "Main SAV|*.*";
|
||||
public override string Extension => "";
|
||||
public override string[] PKMExtensions => PKM.Extensions.Where(f =>
|
||||
{
|
||||
int gen = f.Last() - 0x30;
|
||||
return gen == 1 || (3 <= gen && gen <= 7);
|
||||
}).ToArray();
|
||||
|
||||
public SAV7(byte[] data = null)
|
||||
{
|
||||
Data = data == null ? new byte[SaveUtil.SIZE_G7SM] : (byte[])data.Clone();
|
||||
|
|
|
@ -25,6 +25,12 @@ namespace PKHeX
|
|||
public virtual bool IndeterminateGame => false;
|
||||
public virtual bool IndeterminateLanguage => false;
|
||||
public virtual bool IndeterminateSubVersion => false;
|
||||
public abstract string Extension { get; }
|
||||
public virtual string[] PKMExtensions => PKM.Extensions.Where(f =>
|
||||
{
|
||||
int gen = f.Last() - 0x30;
|
||||
return 3 <= gen && gen <= 7;
|
||||
}).ToArray();
|
||||
|
||||
// General PKM Properties
|
||||
public abstract Type PKMType { get; }
|
||||
|
@ -322,7 +328,6 @@ namespace PKHeX
|
|||
public virtual uint Money { get; set; }
|
||||
public abstract int BoxCount { get; }
|
||||
public virtual int PartyCount { get; protected set; }
|
||||
public abstract string Extension { get; }
|
||||
|
||||
// Varied Methods
|
||||
protected abstract void setChecksums();
|
||||
|
|
Loading…
Reference in a new issue