Exemplo n.º 1
0
        /// <summary>
        /// Dumps a folder of files to the <see cref="SaveFile"/>.
        /// </summary>
        /// <param name="SAV"><see cref="SaveFile"/> that is being dumped from.</param>
        /// <param name="path">Folder to store <see cref="PKM"/> files.</param>
        /// <param name="boxFolders">Option to save in child folders with the Box Name as the folder name.</param>
        /// <returns>-1 if aborted, otherwise the amount of files dumped.</returns>
        public static int DumpBoxes(this SaveFile SAV, string path, bool boxFolders = false)
        {
            if (!SAV.HasBox)
            {
                return(-1);
            }

            var boxdata = SAV.BoxData;
            int ctr     = 0;

            foreach (PKM pk in boxdata)
            {
                if (pk.Species == 0 || !pk.Valid)
                {
                    continue;
                }

                ctr++;
                string fileName  = Util.CleanFileName(pk.FileName);
                string boxfolder = string.Empty;
                if (boxFolders)
                {
                    boxfolder = SAV.GetBoxName(pk.Box - 1);
                    Directory.CreateDirectory(Path.Combine(path, boxfolder));
                }
                if (!File.Exists(Path.Combine(Path.Combine(path, boxfolder), fileName)))
                {
                    File.WriteAllBytes(Path.Combine(Path.Combine(path, boxfolder), fileName), pk.DecryptedBoxData);
                }
            }
            return(ctr);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Dumps a folder of files to the <see cref="SaveFile"/>.
        /// </summary>
        /// <param name="SAV"><see cref="SaveFile"/> that is being dumped from.</param>
        /// <param name="path">Folder to store <see cref="PKM"/> files.</param>
        /// <param name="result">Result message from the method.</param>
        /// <param name="boxFolders">Option to save in child folders with the Box Name as the folder name.</param>
        /// <returns></returns>
        public static bool DumpBoxes(this SaveFile SAV, string path, out string result, bool boxFolders = false)
        {
            var boxdata = SAV.BoxData;

            if (boxdata == null)
            {
                result = MsgSaveBoxExportInvalid; return(false);
            }

            int ctr = 0;

            foreach (PKM pk in boxdata)
            {
                if (pk.Species == 0 || !pk.Valid)
                {
                    continue;
                }

                ctr++;
                string fileName  = Util.CleanFileName(pk.FileName);
                string boxfolder = string.Empty;
                if (boxFolders)
                {
                    boxfolder = SAV.GetBoxName(pk.Box - 1);
                    Directory.CreateDirectory(Path.Combine(path, boxfolder));
                }
                if (!File.Exists(Path.Combine(Path.Combine(path, boxfolder), fileName)))
                {
                    File.WriteAllBytes(Path.Combine(Path.Combine(path, boxfolder), fileName), pk.DecryptedBoxData);
                }
            }

            result = string.Format(MsgSaveBoxExportPathCount, ctr) + Environment.NewLine + path;
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Dumps a folder of files to the <see cref="SaveFile"/>.
        /// </summary>
        /// <param name="sav"><see cref="SaveFile"/> that is being dumped from.</param>
        /// <param name="path">Folder to store <see cref="PKM"/> files.</param>
        /// <param name="boxFolders">Option to save in child folders with the Box Name as the folder name.</param>
        /// <returns>-1 if aborted, otherwise the amount of files dumped.</returns>
        public static int DumpBoxes(this SaveFile sav, string path, bool boxFolders = false)
        {
            if (!sav.HasBox)
            {
                return(-1);
            }

            var boxData      = sav.BoxData;
            int boxSlotCount = sav.BoxSlotCount;
            var ctr          = 0;

            for (var slot = 0; slot < boxData.Count; slot++)
            {
                var pk  = boxData[slot];
                var box = slot / boxSlotCount;
                if (pk.Species == 0 || !pk.Valid)
                {
                    continue;
                }

                var boxFolder = path;
                if (boxFolders)
                {
                    var boxName = Util.CleanFileName(sav.GetBoxName(box));
                    boxFolder = Path.Combine(path, boxName);
                    Directory.CreateDirectory(boxFolder);
                }

                var fileName = Util.CleanFileName(pk.FileName);
                var fn       = Path.Combine(boxFolder, fileName);
                if (File.Exists(fn))
                {
                    continue;
                }

                File.WriteAllBytes(fn, pk.DecryptedPartyData);
                ctr++;
            }
            return(ctr);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets box names for all boxes in the save file.
        /// </summary>
        /// <param name="sav"><see cref="SaveFile"/> that box names are being dumped for.</param>
        /// <returns>Returns default English box names in the event the save file does not have names (not exportable), or fails to return a box name.</returns>
        public static string[] GetBoxNames(SaveFile sav)
        {
            int count  = sav.BoxCount;
            var result = new string[count];

            if (!sav.State.Exportable)
            {
                for (int i = 0; i < count; i++)
                {
                    result[i] = $"Box {i + 1}";
                }
                return(result);
            }

            for (int i = 0; i < count; i++)
            {
                try { result[i] = sav.GetBoxName(i); }
                catch { result[i] = $"Box {i + 1}"; }
            }

            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Dumps a folder of files to the <see cref="SaveFile"/>.
        /// </summary>
        /// <param name="SAV"><see cref="SaveFile"/> that is being dumped from.</param>
        /// <param name="path">Folder to store <see cref="PKM"/> files.</param>
        /// <param name="boxFolders">Option to save in child folders with the Box Name as the folder name.</param>
        /// <returns>-1 if aborted, otherwise the amount of files dumped.</returns>
        public static int DumpBoxes(this SaveFile SAV, string path, bool boxFolders = false)
        {
            if (!SAV.HasBox)
            {
                return(-1);
            }

            var boxdata = SAV.BoxData;
            var ctr     = 0;

            foreach (var pk in boxdata)
            {
                if (pk.Species == 0 || !pk.Valid)
                {
                    continue;
                }

                var boxfolder = path;
                if (boxFolders)
                {
                    var boxName = Util.CleanFileName(SAV.GetBoxName(pk.Box - 1));
                    boxfolder = Path.Combine(path, boxName);
                    Directory.CreateDirectory(boxfolder);
                }

                var fileName = Util.CleanFileName(pk.FileName);
                var fn       = Path.Combine(boxfolder, fileName);
                if (File.Exists(fn))
                {
                    continue;
                }

                File.WriteAllBytes(fn, pk.DecryptedBoxData);
                ctr++;
            }
            return(ctr);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets box names for all boxes in the save file.
        /// </summary>
        /// <param name="sav"><see cref="SaveFile"/> that box names are being dumped for.</param>
        /// <returns>Returns default English box names in the event the save file does not have names (not exportable), or fails to return a box name.</returns>
        public static string[] GetBoxNames(SaveFile sav)
        {
            int count  = sav.BoxCount;
            var result = new string[count];

            if (!sav.Exportable)
            {
                for (int i = 0; i < count; i++)
                {
                    result[i] = $"Box {i + 1}";
                }
                return(result);
            }

            for (int i = 0; i < count; i++)
            {
                try { result[i] = sav.GetBoxName(i); }
#pragma warning disable CA1031 // Do not catch general exception types
                catch { result[i] = $"Box {i + 1}"; }
#pragma warning restore CA1031 // Do not catch general exception types
            }

            return(result);
        }