示例#1
0
        /// <summary>
        /// Dumps the <see cref="SaveFile.BoxData"/> to a folder with individual decrypted files.
        /// </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="currentBox">Box contents to be dumped.</param>
        /// <returns>-1 if aborted, otherwise the amount of files dumped.</returns>
        public static int DumpBox(this SaveFile sav, string path, int currentBox)
        {
            if (!sav.HasBox)
            {
                return(-1);
            }

            var boxData = sav.BoxData;
            var ctr     = 0;

            foreach (var pk in boxData)
            {
                if (pk.Species == 0 || !pk.Valid || pk.Box - 1 != currentBox)
                {
                    continue;
                }

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

                File.WriteAllBytes(fileName, pk.DecryptedPartyData);
                ctr++;
            }
            return(ctr);
        }
示例#2
0
        /// <summary>
        /// Dumps the <see cref="SaveFile.BoxData"/> to a folder with individual decrypted files.
        /// </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="currentBox">Box contents to be dumped.</param>
        /// <returns></returns>
        public static bool DumpBox(this SaveFile SAV, string path, out string result, int currentBox)
        {
            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 || pk.Box - 1 != currentBox)
                {
                    continue;
                }

                ctr++;
                string fileName = Util.CleanFileName(pk.FileName);
                if (!File.Exists(Path.Combine(path, fileName)))
                {
                    File.WriteAllBytes(Path.Combine(path, fileName), pk.DecryptedBoxData);
                }
            }

            result = string.Format(MsgSaveBoxExportPathCount, ctr) + Environment.NewLine + path;
            return(true);
        }
示例#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="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);
        }
示例#4
0
        /// <summary>
        /// Gets a Temp location File Name for the <see cref="PKM"/>.
        /// </summary>
        /// <param name="pk">Data to be exported</param>
        /// <param name="encrypt">Data is to be encrypted</param>
        /// <returns>Path to temporary file location to write to.</returns>
        public static string GetPKMTempFileName(PKM pk, bool encrypt)
        {
            string fn       = pk.FileNameWithoutExtension;
            string filename = fn + (encrypt ? $".ek{pk.Format}" : $".{pk.Extension}");

            return(Path.Combine(Path.GetTempPath(), Util.CleanFileName(filename)));
        }
示例#5
0
        /// <summary>
        /// Dumps the <see cref="SaveFile.BoxData"/> to a folder with individual decrypted files.
        /// </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="currentBox">Box contents to be dumped.</param>
        /// <returns>-1 if aborted, otherwise the amount of files dumped.</returns>
        public static int DumpBox(this SaveFile sav, string path, int currentBox)
        {
            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 || box != currentBox)
                {
                    continue;
                }

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

                File.WriteAllBytes(fileName, pk.DecryptedPartyData);
                ctr++;
            }
            return(ctr);
        }
示例#6
0
        /// <summary>
        /// Sets the details of a path to a <see cref="SaveFile"/> object.
        /// </summary>
        /// <param name="sav">Save File to set path details to.</param>
        /// <param name="path">Full Path of the file</param>
        public static void SetFileInfo(this SaveFile sav, string path)
        {
            if (!sav.Exportable) // Blank save file
            {
                sav.FileFolder = sav.FilePath = null;
                sav.FileName   = "Blank Save File";
                return;
            }

            sav.FilePath   = path;
            sav.FileFolder = Path.GetDirectoryName(path);
            sav.FileName   = string.Empty;
            var bakName = Util.CleanFileName(sav.BAKName);

            sav.FileName = Path.GetFileName(path);
            if (sav.FileName?.EndsWith(bakName) == true)
            {
                sav.FileName = sav.FileName.Substring(0, sav.FileName.Length - bakName.Length);
            }
        }
示例#7
0
文件: BoxUtil.cs 项目: ZeroX1ng/PKHeX
        /// <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);
        }
        /// <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);
        }