Пример #1
0
        /// <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="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 bool LoadBoxes(this SaveFile SAV, IEnumerable <PKM> pks, out string result, int boxStart = 0, bool boxClear = false, bool?noSetb = null)
        {
            if (!SAV.HasBox)
            {
                result = MsgSaveBoxFailNone; return(false);
            }

            var compat = GetPKMForSaveFile(SAV, pks);

            if (boxClear)
            {
                SAV.ClearBoxes(boxStart);
            }

            int ctr = SAV.ImportPKMs(compat, boxStart, noSetb);

            if (ctr <= 0)
            {
                result = MsgSaveBoxImportNoFiles;
                return(false);
            }

            result = string.Format(MsgSaveBoxImportSuccess, ctr);
            return(true);
        }
Пример #2
0
    /// <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);
    }
Пример #3
0
        /// <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="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 bool LoadBoxes(this SaveFile SAV, IEnumerable <PKM> pks, out string result, int boxStart = 0, bool boxClear = false, bool?noSetb = null)
        {
            if (!SAV.HasBox)
            {
                result = "Save file does not have boxes."; return(false);
            }

            var compat = GetPKMForSaveFile(SAV, pks);

            if (boxClear)
            {
                SAV.ClearBoxes(boxStart);
            }

            int ctr = SAV.ImportPKMs(compat, boxStart, noSetb);

            if (ctr <= 0)
            {
                result = "No files loaded.";
                return(false);
            }

            result = $"Loaded {ctr} files to boxes.";
            return(true);
        }
Пример #4
0
        /// <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="noSetb">Bypass option to not modify <see cref="PKM"/> properties when setting to Save File.</param>
        /// <returns></returns>
        public static bool LoadBoxes(this SaveFile SAV, string path, out string result, int boxStart = 0, bool boxClear = false, bool?noSetb = null)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                result = "Invalid path specified."; return(false);
            }
            if (!SAV.HasBox)
            {
                result = "Save file does not have boxes."; return(false);
            }

            if (boxClear)
            {
                SAV.ClearBoxes(boxStart);
            }

            int startCount = boxStart * SAV.BoxSlotCount;
            int maxCount   = SAV.BoxCount * SAV.BoxSlotCount;
            int ctr        = startCount;
            int pastctr    = 0;
            var filepaths  = Directory.EnumerateFiles(path, "*.*", SearchOption.TopDirectoryOnly);

            foreach (var file in filepaths)
            {
                if (!PKX.IsPKM(new FileInfo(file).Length))
                {
                    continue;
                }

                // Check for format compatibility with save; if transfer is necessary => convert.
                // format conversion comment
                byte[] data = File.ReadAllBytes(file);
                PKM    temp = PKMConverter.GetPKMfromBytes(data, prefer: SAV.Generation);
                PKM    pk   = PKMConverter.ConvertToType(temp, SAV.PKMType, out string c);

                if (pk == null)
                {
                    Debug.WriteLine(c); continue;
                }

                if (SAV.IsPKMCompatible(pk).Length > 0)
                {
                    continue;
                }

                while (SAV.IsSlotLocked(ctr / SAV.BoxSlotCount, ctr % SAV.BoxSlotCount))
                {
                    ctr++;
                }

                int offset = SAV.GetBoxOffset(ctr / SAV.BoxSlotCount) + ctr % SAV.BoxSlotCount * SAV.SIZE_STORED;
                SAV.SetStoredSlot(pk, offset, noSetb);
                if (pk.Format != temp.Format) // Transferred
                {
                    pastctr++;
                }
                if (++ctr == maxCount) // Boxes full!
                {
                    break;
                }
            }

            ctr -= startCount; // actual imported count
            if (ctr <= 0)
            {
                result = "No files loaded"; return(false);
            }

            result = $"Loaded {ctr} files to boxes.";
            if (pastctr > 0)
            {
                result += Environment.NewLine + $"Conversion successful for {pastctr} past generation files.";
            }

            return(true);
        }