Exemplo n.º 1
0
        public bool LoadFolder(string path)
        {
            Clear();
            Files.Clear();
            if (!Directory.Exists(path))
            {
                return(false);
            }

            var loadedAny  = false;
            var files      = Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories);
            var matchFiles = LoadUtil.GetFilesOfSize(files, ExpectedSize);

            int surpriseBlocked = 0;

            foreach (var file in matchFiles)
            {
                var data = File.ReadAllBytes(file);
                var pkm  = PKMConverter.GetPKMfromBytes(data);
                if (!(pkm is T dest))
                {
                    continue;
                }

                if (dest.Species == 0 || !new LegalityAnalysis(dest).Valid || !(dest is PK8 pk8))
                {
                    LogUtil.LogInfo("SKIPPED: Provided pk8 is not valid: " + dest.FileName, nameof(PokemonPool <T>));
                    continue;
                }

                if (DisallowSurpriseTrade(pk8))
                {
                    LogUtil.LogInfo("Provided pk8 has a special ribbon and can't be Surprise Traded: " + dest.FileName, nameof(PokemonPool <T>));
                    surpriseBlocked++;
                }

                if (Settings.ResetHOMETracker)
                {
                    pk8.Tracker = 0;
                }

                Add(dest);
                var fn = Path.GetFileNameWithoutExtension(file);
                Files.Add(fn, new LedyRequest <T>(dest, fn));
                loadedAny = true;
            }

            if (surpriseBlocked == Count)
            {
                LogUtil.LogInfo("Surprise trading will fail; failed to load any compatible files.", nameof(PokemonPool <T>));
            }

            return(loadedAny);
        }
Exemplo n.º 2
0
        public bool LoadFolder(string path)
        {
            Clear();
            if (!Directory.Exists(path))
            {
                return(false);
            }

            var loadedAny  = false;
            var files      = Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories);
            var matchFiles = LoadUtil.GetFilesOfSize(files, ExpectedSize);
            var matchPKM   = LoadUtil.GetPKMFilesOfType <T>(matchFiles);

            foreach (var dest in matchPKM)
            {
                if (dest.Species == 0 || !new LegalityAnalysis(dest).Valid || !(dest is PK8 pk8))
                {
                    Console.WriteLine("SKIPPED: Provided pk8 is not valid: " + dest.FileName);
                    continue;
                }
                if (pk8.RibbonClassic || pk8.RibbonPremier || pk8.RibbonBirthday)
                {
                    Console.WriteLine("SKIPPED: Provided pk8 has a special ribbon and can't be Surprise Traded: " + dest.FileName);
                    continue;
                }

                if (Settings.ResetHOMETracker)
                {
                    pk8.Tracker = 0;
                }

                Add(dest);
                loadedAny = true;
            }
            return(loadedAny);
        }
Exemplo n.º 3
0
        public bool LoadFolder(string path)
        {
            Clear();
            Files.Clear();
            if (!Directory.Exists(path))
            {
                return(false);
            }

            var loadedAny  = false;
            var files      = Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories);
            var matchFiles = LoadUtil.GetFilesOfSize(files, ExpectedSize);

            int surpriseBlocked = 0;

            foreach (var file in matchFiles)
            {
                var data = File.ReadAllBytes(file);
                var pkm  = PKMConverter.GetPKMfromBytes(data);
                if (!(pkm is T dest))
                {
                    continue;
                }

                if (dest.Species == 0 || !(dest is PK8 pk8))
                {
                    LogUtil.LogInfo("SKIPPED: Provided pk8 is not valid: " + dest.FileName, nameof(PokemonPool <T>));
                    continue;
                }

                if (!dest.CanBeTraded())
                {
                    LogUtil.LogInfo("SKIPPED: Provided pk8 cannot be traded: " + dest.FileName, nameof(PokemonPool <T>));
                    continue;
                }

                var la = new LegalityAnalysis(pk8);
                if (!la.Valid && Settings.Legality.VerifyLegality)
                {
                    var reason = la.Report();
                    LogUtil.LogInfo($"SKIPPED: Provided pk8 is not legal: {dest.FileName} -- {reason}", nameof(PokemonPool <T>));
                    continue;
                }

                if (DisallowSurpriseTrade(pk8))
                {
                    LogUtil.LogInfo("Provided pk8 was loaded but can't be Surprise Traded: " + dest.FileName, nameof(PokemonPool <T>));
                    surpriseBlocked++;
                }

                if (Settings.Legality.ResetHOMETracker)
                {
                    pk8.Tracker = 0;
                }

                var fn = Path.GetFileNameWithoutExtension(file);
                fn = StringsUtil.Sanitize(fn);

                // Since file names can be sanitized to the same string, only add one of them.
                if (!Files.ContainsKey(fn))
                {
                    Add(dest);
                    Files.Add(fn, new LedyRequest <T>(dest, fn));
                }
                else
                {
                    LogUtil.LogInfo("Provided pk8 was not added due to duplicate name: " + dest.FileName, nameof(PokemonPool <T>));
                }
                loadedAny = true;
            }

            if (surpriseBlocked == Count)
            {
                LogUtil.LogInfo("Surprise trading will fail; failed to load any compatible files.", nameof(PokemonPool <T>));
            }

            return(loadedAny);
        }