public bool WriteTo(SaveFile sav, PKM pkm, PKMImportSetting setting = PKMImportSetting.UseDefault) { if (PartyFormat) { sav.SetSlotFormatParty(pkm, Data, Offset, setting, setting); } else { sav.SetSlotFormatStored(pkm, Data, Offset, setting, setting); } return(true); }
/// <summary> /// Imports compatible <see cref="PKM"/> data to the <see cref="sav"/>, starting at the provided box. /// </summary> /// <param name="sav">Save File that will receive the <see cref="compat"/> data.</param> /// <param name="compat">Compatible <see cref="PKM"/> data that can be set to the <see cref="sav"/> without conversion.</param> /// <param name="overwrite">Overwrite existing full slots. If true, will only overwrite empty slots.</param> /// <param name="boxStart">First box to start loading to. All prior boxes are not modified.</param> /// <param name="noSetb">Bypass option to not modify <see cref="PKM"/> properties when setting to Save File.</param> /// <returns>Count of injected <see cref="PKM"/>.</returns> public static int ImportPKMs(this SaveFile sav, IEnumerable <PKM> compat, bool overwrite = false, int boxStart = 0, PKMImportSetting noSetb = PKMImportSetting.UseDefault) { int startCount = boxStart * sav.BoxSlotCount; int maxCount = sav.SlotCount; int index = startCount; int nonOverwriteImport = 0; foreach (var pk in compat) { if (overwrite) { while (sav.IsSlotOverwriteProtected(index)) { ++index; } // The above will return false if out of range. We need to double-check. if (index >= maxCount) // Boxes full! { break; } sav.SetBoxSlotAtIndex(pk, index, noSetb); } else { index = sav.NextOpenBoxSlot(index - 1); if (index < 0) // Boxes full! { break; } sav.SetBoxSlotAtIndex(pk, index, noSetb); nonOverwriteImport++; } if (++index == maxCount) // Boxes full! { break; } } return(overwrite ? index - startCount : nonOverwriteImport); // actual imported count }
/// <summary> /// Loads a folder of files to the <see cref="SaveFile"/>. /// </summary> /// <param name="sav"><see cref="SaveFile"/> to load folder to.</param> /// <param name="pks">Unconverted <see cref="PKM"/> objects to load.</param> /// <param name="result">Result message from the method.</param> /// <param name="boxStart">First box to start loading to. All prior boxes are not modified.</param> /// <param name="boxClear">Instruction to clear boxes after the starting box.</param> /// <param name="overwrite">Overwrite existing full slots. If true, will only overwrite empty slots.</param> /// <param name="noSetb">Bypass option to not modify <see cref="PKM"/> properties when setting to Save File.</param> /// <returns>True if any files are imported.</returns> public static int LoadBoxes(this SaveFile sav, IEnumerable <PKM> pks, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, PKMImportSetting noSetb = PKMImportSetting.UseDefault) { if (!sav.HasBox) { result = MsgSaveBoxFailNone; return(-1); } var compat = sav.GetCompatible(pks); if (boxClear) { sav.ClearBoxes(boxStart); } int ctr = sav.ImportPKMs(compat, overwrite, boxStart, noSetb); if (ctr <= 0) { result = MsgSaveBoxImportNoFiles; return(-1); } result = string.Format(MsgSaveBoxImportSuccess, ctr); return(ctr); }
/// <summary> /// Loads a folder of files to the <see cref="SaveFile"/>. /// </summary> /// <param name="sav"><see cref="SaveFile"/> to load folder to.</param> /// <param name="encounters">Encounters to create <see cref="PKM"/> files from.</param> /// <param name="result">Result message from the method.</param> /// <param name="boxStart">First box to start loading to. All prior boxes are not modified.</param> /// <param name="boxClear">Instruction to clear boxes after the starting box.</param> /// <param name="overwrite">Overwrite existing full slots. If true, will only overwrite empty slots.</param> /// <param name="noSetb">Bypass option to not modify <see cref="PKM"/> properties when setting to Save File.</param> /// <returns>Count of files imported.</returns> public static int LoadBoxes(this SaveFile sav, IEnumerable <IEncounterConvertible> encounters, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, PKMImportSetting noSetb = PKMImportSetting.UseDefault) { var pks = encounters.Select(z => z.ConvertToPKM(sav)); return(sav.LoadBoxes(pks, out result, boxStart, boxClear, overwrite, noSetb)); }
/// <summary> /// Loads a folder of files to the <see cref="SaveFile"/>. /// </summary> /// <param name="sav"><see cref="SaveFile"/> to load folder to.</param> /// <param name="files">Files to load <see cref="PKM"/> files from.</param> /// <param name="result">Result message from the method.</param> /// <param name="boxStart">First box to start loading to. All prior boxes are not modified.</param> /// <param name="boxClear">Instruction to clear boxes after the starting box.</param> /// <param name="overwrite">Overwrite existing full slots. If true, will only overwrite empty slots.</param> /// <param name="noSetb">Bypass option to not modify <see cref="PKM"/> properties when setting to Save File.</param> /// <returns>Count of files imported.</returns> public static int LoadBoxes(this SaveFile sav, IEnumerable <string> files, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, PKMImportSetting noSetb = PKMImportSetting.UseDefault) { var pks = GetPossiblePKMsFromPaths(sav, files); return(sav.LoadBoxes(pks, out result, boxStart, boxClear, overwrite, noSetb)); }
/// <summary> /// Loads a folder of files to the <see cref="SaveFile"/>. /// </summary> /// <param name="sav"><see cref="SaveFile"/> to load folder to.</param> /// <param name="path">Folder to load <see cref="PKM"/> files from. Files are only loaded from the top directory.</param> /// <param name="result">Result message from the method.</param> /// <param name="boxStart">First box to start loading to. All prior boxes are not modified.</param> /// <param name="boxClear">Instruction to clear boxes after the starting box.</param> /// <param name="overwrite">Overwrite existing full slots. If true, will only overwrite empty slots.</param> /// <param name="noSetb">Bypass option to not modify <see cref="PKM"/> properties when setting to Save File.</param> /// <param name="all">Enumerate all files even in sub-folders.</param> /// <returns>Count of files imported.</returns> public static int LoadBoxes(this SaveFile sav, string path, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, PKMImportSetting noSetb = PKMImportSetting.UseDefault, bool all = false) { if (string.IsNullOrWhiteSpace(path) || !Directory.Exists(path)) { result = MsgSaveBoxExportPathInvalid; return(-1); } var option = all ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; var files = Directory.EnumerateFiles(path, "*.*", option); return(sav.LoadBoxes(files, out result, boxStart, boxClear, overwrite, noSetb)); }
/// <summary> /// Imports compatible <see cref="PKM"/> data to the <see cref="SAV"/>, starting at the provided box. /// </summary> /// <param name="SAV">Save File that will receive the <see cref="compat"/> data.</param> /// <param name="compat">Compatible <see cref="PKM"/> data that can be set to the <see cref="SAV"/> without conversion.</param> /// <param name="overwrite">Overwrite existing full slots. If true, will only overwrite empty slots.</param> /// <param name="boxStart">First box to start loading to. All prior boxes are not modified.</param> /// <param name="noSetb">Bypass option to not modify <see cref="PKM"/> properties when setting to Save File.</param> /// <returns>Count of injected <see cref="PKM"/>.</returns> public static int ImportPKMs(this SaveFile SAV, IEnumerable <PKM> compat, bool overwrite = false, int boxStart = 0, PKMImportSetting noSetb = PKMImportSetting.UseDefault) { int startCount = boxStart * SAV.BoxSlotCount; int maxCount = SAV.SlotCount; int index = startCount; foreach (var pk in compat) { if (overwrite) { while (SAV.IsSlotOverwriteProtected(index)) { ++index; } } else { index = SAV.NextOpenBoxSlot(index - 1); if (index < 0) // Boxes full! { break; } } SAV.SetBoxSlotAtIndex(pk, index, noSetb); if (++index == maxCount) // Boxes full! { break; } } return(index - startCount); // actual imported count }
public bool WriteTo(SaveFile sav, PKM pkm, PKMImportSetting setting = PKMImportSetting.UseDefault) { sav.SetBoxSlotAtIndex(pkm, Box, Slot, setting, setting); return(true); }