예제 #1
0
        public static List <ToSecObject> Parse(string dat, int systemId)
        {
            List <ToSecObject> list = new List <ToSecObject>();

            // replace illegal characters
            dat = dat.Replace(" & ", " &amp; ").Replace(" and ", " &amp; ");

            // parse into an xml document
            XDocument xmlDoc = XDocument.Parse(dat);

            //var games = xmlDoc.Descendants("game");

            // iterate through each game
            foreach (XElement element in xmlDoc.Root.Elements("game"))
            {
                string nameString = (string)element.Attribute("name");

                ToSecObject no = StringConverterToSec.ParseString(nameString);
                no.SystemId = systemId;

                no.Description = (string)element.Element("description");
                IEnumerable <XElement> roms = element.Elements("rom");

                foreach (XElement rom in roms)
                {
                    ToSecObject t = new ToSecObject
                    {
                        Name              = no.Name,
                        CloneOf           = no.CloneOf,
                        Copyright         = no.Copyright,
                        Country           = no.Country,
                        CRC               = (string)rom.Attribute("crc"),
                        Size              = (string)rom.Attribute("size"),
                        MD5               = (string)rom.Attribute("md5"),
                        SHA1              = (string)rom.Attribute("sha1"),
                        DevelopmentStatus = no.DevelopmentStatus,
                        Language          = no.Language,
                        RomName           = (string)rom.Attribute("name"),
                        SystemId          = no.SystemId,
                        OtherFlags        = no.OtherFlags,
                        Publisher         = no.Publisher,
                        Description       = no.Description,
                        Year              = no.Year
                    };

                    list.Add(t);
                }
            }
            return(list);
        }
예제 #2
0
        public static ToSecObject ParseString(string nameString)
        {
            ToSecObject no = new ToSecObject();

            // get name without any options (integrating demo flag if available)
            //no.Name = nameString.Split(new string[] { " ) " }, StringSplitOptions.RemoveEmptyEntries)[0].Trim() + ")";

            // remove any unwanted options from string
            string a = RemoveUnneededOptions(nameString);

            // process data contained in ()
            string[] d = a.ToString().Split('(', ')');

            if (d.Length > 0)
            {
                no.Name = d[0].Trim();
            }


            if (d.Length > 1)
            {
                if (d[1].Length > 3)
                {
                    no.Year = d[1].Substring(0, 4);     // take only the year (first 4 characters)
                }
            }


            if (d.Length > 3)
            {
                no.Publisher = d[3].Trim();
            }


            if (d.Length > 4)
            {
                // iterate through remaining array of () data and determine values
                for (int i = 4; i < d.Length; i++)
                {
                    string f = d[i];

                    // Check for system field
                    if (f == "Aladdin Deck Enhancer" ||
                        f == "PlayChoice-10" ||
                        f == "VS DualSystem" ||
                        f == "VS UniSystem")
                    {
                        // ignore for now
                        continue;
                    }

                    // check for country/region flag
                    if (IsCountryFlag(f) == true)
                    {
                        no.Country = f;
                        continue;
                    }

                    // check for language
                    if (IsLanguageFlag(f) == true)
                    {
                        no.Language = f;
                        continue;
                    }

                    // check copyright status
                    if (IsCopyrightStatus(f) == true)
                    {
                        no.Copyright = f;
                        continue;
                    }

                    // check development status
                    if (IsDevelopmenttStatus(f) == true)
                    {
                        no.DevelopmentStatus = f;
                        continue;
                    }

                    // Media Type - ignore for now

                    // Media Label - ignore for now
                }

                if (no.Copyright == null)
                {
                    no.Copyright = "Commercial";
                }
                if (no.DevelopmentStatus == null)
                {
                    no.DevelopmentStatus = "Release";
                }
                if (no.Language == null)
                {
                    no.Language = "en";
                }
            }

            // process dump info flags and other info contained in []
            if (nameString.Contains("[") && nameString.Contains("]"))
            {
                List <string> e = nameString.ToString().Split('[', ']').ToList();
                if (e.Count > 0)
                {
                    StringBuilder sb    = new StringBuilder();
                    int           count = 0;
                    foreach (string s in e)
                    {
                        if (count == 0 || s == "")
                        {
                            count++;
                            continue;
                        }


                        sb.Append("[");
                        sb.Append(s);
                        sb.Append("]");
                        count++;
                    }

                    no.OtherFlags = sb.ToString().Trim();
                }
            }
            return(no);
        }