/// <summary> /// Gets a <see cref="PKM"/> from the provided <see cref="file"/> path, which is to be loaded to the <see cref="SaveFile"/>. /// </summary> /// <param name="file"><see cref="PKM"/> or <see cref="MysteryGift"/> file path.</param> /// <param name="sav">Generation Info</param> /// <returns>New <see cref="PKM"/> reference from the file.</returns> public static PKM?GetSingleFromPath(string file, ITrainerInfo sav) { var fi = new FileInfo(file); if (!fi.Exists) { return(null); } if (fi.Length == GP1.SIZE && TryGetGP1(File.ReadAllBytes(file), out var gp1)) { return(gp1?.ConvertToPB7(sav)); } if (!PKX.IsPKM(fi.Length) && !MysteryGift.IsMysteryGift(fi.Length)) { return(null); } var data = File.ReadAllBytes(file); var ext = fi.Extension; var mg = MysteryGift.GetMysteryGift(data, ext); var gift = mg?.ConvertToPKM(sav); if (gift != null) { return(gift); } int prefer = PKX.GetPKMFormatFromExtension(ext, sav.Generation); return(PKMConverter.GetPKMfromBytes(data, prefer: prefer)); }
/// <summary> /// Gets a <see cref="PKM"/> from the provided <see cref="file"/> path, which is to be loaded to the <see cref="SaveFile"/>. /// </summary> /// <param name="file"><see cref="PKM"/> or <see cref="MysteryGift"/> file path.</param> /// <param name="sav">Generation Info</param> /// <returns>New <see cref="PKM"/> reference from the file.</returns> public static PKM?GetSingleFromPath(string file, ITrainerInfo sav) { var fi = new FileInfo(file); if (!fi.Exists) { return(null); } if (fi.Length == GP1.SIZE && TryGetGP1(File.ReadAllBytes(file), out var gp1)) { return(gp1.ConvertToPB7(sav)); } if (!PKX.IsPKM(fi.Length) && !MysteryGift.IsMysteryGift(fi.Length)) { return(null); } var data = File.ReadAllBytes(file); var ext = fi.Extension; var mg = MysteryGift.GetMysteryGift(data, ext); var gift = mg?.ConvertToPKM(sav); if (gift != null) { return(gift); } _ = TryGetPKM(data, out var pk, ext, sav); return(pk); }
/// <summary> /// Gets <see cref="MysteryGift"/> objects from a folder. /// </summary> /// <param name="folder">Folder path</param> /// <returns>Consumable list of gifts.</returns> public static IEnumerable <MysteryGift> GetGiftsFromFolder(string folder) { foreach (var file in Directory.EnumerateFiles(folder, "*", SearchOption.AllDirectories)) { var fi = new FileInfo(file); if (!MysteryGift.IsMysteryGift(fi.Length)) { continue; } yield return(MysteryGift.GetMysteryGift(File.ReadAllBytes(file), fi.Extension)); } }
public static void RefreshMGDB(params string[] paths) { var g4 = GetPCDDB(Util.GetBinaryResource("wc4.pkl")); var g5 = GetPGFDB(Util.GetBinaryResource("pgf.pkl")); var g6 = GetWC6DB(Util.GetBinaryResource("wc6.pkl"), Util.GetBinaryResource("wc6full.pkl")); var g7 = GetWC7DB(Util.GetBinaryResource("wc7.pkl"), Util.GetBinaryResource("wc7full.pkl")); var b7 = GetWB7DB(Util.GetBinaryResource("wb7full.pkl")); foreach (var path in paths.Where(Directory.Exists)) { foreach (var file in Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories)) { var fi = new FileInfo(file); if (!MysteryGift.IsMysteryGift(fi.Length)) { continue; } var gift = MysteryGift.GetMysteryGift(File.ReadAllBytes(file), fi.Extension); switch (gift) { case PCD pcd: g4.Add(pcd); continue; case PGF pgf: g5.Add(pgf); continue; case WC6 wc6: g6.Add(wc6); continue; case WC7 wc7: g7.Add(wc7); continue; case WB7 wb7: b7.Add(wb7); continue; } } } MGDB_G3 = Encounter_WC3; // hardcoded MGDB_G4 = g4.ToArray(); MGDB_G5 = g5.ToArray(); MGDB_G6 = g6.ToArray(); MGDB_G7 = g7.ToArray(); MGDB_G7GG = b7.ToArray(); }
/// <summary> /// Tries to get a <see cref="MysteryGift"/> object from the input parameters. /// </summary> /// <param name="data">Binary data</param> /// <param name="mg">Output result</param> /// <param name="ext">Format hint</param> /// <returns>True if file object reference is valid, false if none found.</returns> public static bool TryGetMysteryGift(byte[] data, out MysteryGift?mg, string ext) { mg = MysteryGift.GetMysteryGift(data, ext); return(mg != null); }