Ejemplo n.º 1
0
        private void clickSet(object sender, EventArgs e)
        {
            // Don't care what slot was clicked, just add it to the database
            if (!m_parent.verifiedPKM())
            {
                return;
            }

            PKM pk = m_parent.preparePKM();

            if (!Directory.Exists(DatabasePath))
            {
                Directory.CreateDirectory(DatabasePath);
            }

            string path = Path.Combine(DatabasePath, Util.CleanFileName(pk.FileName));

            if (RawDB.Any(p => p.Identifier == path))
            {
                Util.Alert("File already exists in database!");
                return;
            }

            File.WriteAllBytes(path, pk.Data.Take(pk.SIZE_STORED).ToArray());
            pk.Identifier = path;

            int pre = RawDB.Count;

            RawDB.Add(pk);
            RawDB = new List <PKM>(RawDB.Distinct()); // just in case
            int post = RawDB.Count;

            if (pre == post)
            {
                Util.Alert("Pokémon already exists in database."); return;
            }
            Results.Add(pk);

            // Refresh database view.
            L_Count.Text = string.Format(Counter, Results.Count);
            slotSelected = Results.Count - 1;
            slotColor    = Properties.Resources.slotSet;
            if ((SCR_Box.Maximum + 1) * 6 < Results.Count)
            {
                SCR_Box.Maximum += 1;
            }
            SCR_Box.Value = Math.Max(0, SCR_Box.Maximum - PKXBOXES.Length / 6 + 1);
            FillPKXBoxes(SCR_Box.Value);
            Util.Alert("Added Pokémon from tabs to database.");
        }