Beispiel #1
0
        public override void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            // Taking in menu items bw argument from Main UI
            List<DatabaseMenu> menuItems = (List <DatabaseMenu>)e.Argument;

            // Build string array of items removing an entry for the Main Menu
            string[] syss = new string[menuItems.Count - 1];

            int i = 0;
            try
            {
                // Add each name from a menu item into the array
                // Making sure it is not the main menu
                foreach (DatabaseMenu item in menuItems)
                {
                    if (item.name != "Main Menu")
                    {
                        syss[i] = item.name;
                        i++;
                    }
                }

                List<DatabaseGame> g = new List<DatabaseGame>();
                Favorites f = new Favorites("", HSPath);

                for (int ii = 0; ii < syss.Length; ii++)
                {
                    if (bw.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }

                    List<string> ls = GetFavoritesFromText(syss[ii]);

                    if (ls.Count != 0)
                    {
                        foreach (var items in ls)
                        {
                            if (bw.CancellationPending)
                            {
                                e.Cancel = true;
                                return;
                            }
                            //item.ToString();
                            f.QueryFavorite(items, syss[ii]);
                        }
                        ii++;
                    }

                }

                e.Result = (List<DatabaseGame>)f.getCurrentGameList();

            }
            catch (Exception)
            {

                e.Cancel = true;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Convert a list of game objects that are favorites into an xml
        /// </summary>
        /// <param name="systemName"></param>
        /// <param name="saveToGenre"></param>
        /// <param name="hsPath"></param>
        public void FavoriteToXml(string systemName, bool saveToGenre, string hsPath)
        {
            Favorites f = new Favorites(systemName, hsPath);
            List<DatabaseGame> g = new List<DatabaseGame>();

            g = (List<DatabaseGame>)f.getCurrentGameList();

            if (g.Count == 0)
            {
                MessageBox.Show("Try saving the xml first to get updated enabled tags.");
            }

            SerializeToXML(g, systemName, "Favorites", hsPath);

            if (saveToGenre)
            {
                List<string> genreList = AddFavoritesToGenre(HSPath + "\\Databases\\" + systemName + "\\Genre.xml");
                DatabaseMenu m = new DatabaseMenu();
                List<DatabaseMenu> mss = new List<DatabaseMenu>();
                //Create the main Genre.xml
                string lastGenre = string.Empty;
                foreach (var itemGenre in genreList)
                {
                    if (itemGenre != string.Empty)
                    {
                        if (lastGenre != itemGenre)
                            mss.Add(new DatabaseMenu(itemGenre));

                        lastGenre = itemGenre;
                    }
                }

                m.SerializeGenreItems(mss, hsPath + @"\Databases\" + systemName + "\\Genre.xml");
            }
        }
Beispiel #3
0
        /// <summary>
        /// Using background worker to build collection of game objects from XML
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            XmlDocument xdoc = new XmlDocument();
            xdoc.Load(HyperspinDatabaseXml);
            DatabaseGameCollection = new ObservableCollection<DatabaseGame>();
            string name = string.Empty, image = string.Empty, desc = string.Empty, cloneof = string.Empty, crc = string.Empty,
                manu = string.Empty, genre = string.Empty, rating = string.Empty;
            int enabled = 0;
            int year = 0;
            string index = string.Empty;
            int i = 0;
            string lastRom = string.Empty;

            DatabaseGameCollection.Add(new DatabaseGame("_Default", "_Default"));
            foreach (XmlNode node in xdoc.SelectNodes("menu/game"))
            {
                if (bw.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                name = node.SelectSingleNode("@name").InnerText;

                char s = name[0];
                char t;

                if (lastRom != string.Empty)
                {
                    t = lastRom[0];
                    if (char.ToLower(s) == char.ToLower(t))
                    {
                        index = string.Empty;
                        image = string.Empty;
                    }
                    else
                    {
                        index = "true";
                        image = char.ToLower(s).ToString();
                    }
                }

                if (SystemName != "Main Menu")
                {
                    if (node.SelectSingleNode("@enabled") != null)
                    {
                        if (node.SelectSingleNode("@enabled").InnerText != null)
                        {
                            enabled = Convert.ToInt32(node.SelectSingleNode("@enabled").InnerText);
                        }
                    }
                    else
                        enabled = 1;

                    desc = node.SelectSingleNode("description").InnerText;

                    if (node.SelectSingleNode("cloneof") != null)
                        cloneof = node.SelectSingleNode("cloneof").InnerText;
                    if (node.SelectSingleNode("crc") != null)
                        crc = node.SelectSingleNode("crc").InnerText;
                    if (node.SelectSingleNode("manufacturer") != null)
                        manu = node.SelectSingleNode("manufacturer").InnerText;
                    if (node.SelectSingleNode("year") != null)
                        if (!string.IsNullOrEmpty(node.SelectSingleNode("year").InnerText))
                            Int32.TryParse(node.SelectSingleNode("year").InnerText, out year);

                    if (node.SelectSingleNode("genre") != null)
                        genre = node.SelectSingleNode("genre").InnerText;
                    if (node.SelectSingleNode("rating") != null)
                        rating = node.SelectSingleNode("rating").InnerText;

                }

                DatabaseGameCollection.Add(new DatabaseGame(name, index, image, desc, cloneof, crc, manu, year, genre, rating, enabled));

                lastRom = name;
                i++;
            }

            /// Scan the favorites text, set the hspath and systemname
            Favorites f = new Favorites();
            f.HSPath = HSPath;
            f.SystemName = SystemName;
            Favorites.dbPath = HSPath + "\\Databases\\";
            List<string> faveText = Favorites.GetFavoritesFromText(f.SystemName);
            Favorites.updateGameListFavorites(DatabaseGameCollection.ToList(), faveText);

            // Return the new collection to the backgroundworker
            e.Result = DatabaseGameCollection;
        }