Beispiel #1
0
        public static void LoadCache()
        {
            try
            {
                var xmlDataBasePath = Path.Combine(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "data"), "nescarts.xml");
                Debug.WriteLine("Loading " + xmlDataBasePath);

                if (File.Exists(xmlDataBasePath))
                {
                    var xpath     = new XPathDocument(xmlDataBasePath);
                    var navigator = xpath.CreateNavigator();
                    var iterator  = navigator.Select("/database/game");
                    gameInfoCache = new Dictionary <uint, CachedGameInfo>();
                    while (iterator.MoveNext())
                    {
                        XPathNavigator game       = iterator.Current;
                        var            cartridges = game.Select("cartridge");
                        while (cartridges.MoveNext())
                        {
                            var cartridge = cartridges.Current;
                            try
                            {
                                var crc = Convert.ToUInt32(cartridge.GetAttribute("crc", ""), 16);
                                gameInfoCache[crc] = new CachedGameInfo
                                {
                                    Name        = game.GetAttribute("name", ""),
                                    Players     = (byte)((game.GetAttribute("players", "") != "1") ? 2 : 1),
                                    ReleaseDate = game.GetAttribute("date", ""),
                                    Publisher   = game.GetAttribute("publisher", ""),
                                    Region      = game.GetAttribute("region", "")
                                };
                            }
                            catch { }
                        }
                        ;
                    }
                }
                Debug.WriteLine(string.Format("XML loading done, {0} roms total", gameInfoCache.Count));
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message + ex.StackTrace);
            }
        }
Beispiel #2
0
        public static void LoadCache()
        {
            try
            {
                var xmlDataBasePath = Path.Combine(Path.Combine(Program.BaseDirectoryInternal, "data"), "snescarts.xml");
                Debug.WriteLine("Loading " + xmlDataBasePath);

                if (File.Exists(xmlDataBasePath))
                {
                    var xpath     = new XPathDocument(xmlDataBasePath);
                    var navigator = xpath.CreateNavigator();
                    var iterator  = navigator.Select("/Data");
                    gameInfoCache = new Dictionary <uint, CachedGameInfo>();
                    while (iterator.MoveNext())
                    {
                        XPathNavigator game       = iterator.Current;
                        var            cartridges = game.Select("Game");
                        while (cartridges.MoveNext())
                        {
                            var  cartridge = cartridges.Current;
                            uint crc       = 0;
                            var  info      = new CachedGameInfo();

                            try
                            {
                                var v = cartridge.Select("name");
                                if (v.MoveNext() && !string.IsNullOrEmpty(v.Current.Value))
                                {
                                    info.Name = v.Current.Value;
                                }
                                v = cartridge.Select("players");
                                if (v.MoveNext() && !string.IsNullOrEmpty(v.Current.Value))
                                {
                                    info.Players = byte.Parse(v.Current.Value);
                                }
                                v = cartridge.Select("simultaneous");
                                if (v.MoveNext() && !string.IsNullOrEmpty(v.Current.Value))
                                {
                                    info.Simultaneous = byte.Parse(v.Current.Value) != 0;
                                }
                                v = cartridge.Select("crc");
                                if (v.MoveNext() && !string.IsNullOrEmpty(v.Current.Value))
                                {
                                    crc = Convert.ToUInt32(v.Current.Value, 16);
                                }
                                v = cartridge.Select("date");
                                if (v.MoveNext() && !string.IsNullOrEmpty(v.Current.Value))
                                {
                                    info.ReleaseDate = v.Current.Value;
                                }
                                v = cartridge.Select("publisher");
                                if (v.MoveNext() && !string.IsNullOrEmpty(v.Current.Value))
                                {
                                    info.Publisher = v.Current.Value;
                                }
                                v = cartridge.Select("region");
                                if (v.MoveNext() && !string.IsNullOrEmpty(v.Current.Value))
                                {
                                    info.Region = v.Current.Value;
                                }
                                v = cartridge.Select("cover");
                                if (v.MoveNext() && !string.IsNullOrEmpty(v.Current.Value))
                                {
                                    info.CoverUrl = v.Current.Value;
                                }
                            }
                            catch
                            {
                                Debug.WriteLine($"Invalid XML record for game: {cartridge.OuterXml}");
                            }

                            gameInfoCache[crc] = info;
                        }
                        ;
                    }
                }
                Debug.WriteLine(string.Format("SNES XML loading done, {0} roms total", gameInfoCache.Count));
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message + ex.StackTrace);
            }
        }