Exemplo n.º 1
0
        private void buttonStartProcessing_Click(object sender, EventArgs e)
        {
            // initial checks
            var checkedBtn = groupImportTypes.Controls.OfType <RadioButton>().FirstOrDefault(r => r.Checked);

            if (checkedBtn == null)
            {
                MessageBox.Show("You need to select an import type.");
                return;
            }

            if (!Directory.Exists(textBoxOutputFolder.Text))
            {
                MessageBox.Show("Chosen output folder is not valid");
                return;
            }

            if (listBoxFiles.Items.Count == 0)
            {
                MessageBox.Show("No files chosen for input");
                return;
            }

            List <string> files = new List <string>();

            foreach (var s in listBoxFiles.Items)
            {
                if (s.ToString().Trim() == "")
                {
                    MessageBox.Show($"The selected file: {s}Cannot be found.\n\nSort this out and try again");
                    return;
                }

                files.Add((string)s);
            }

            string res = "";

            if (radioTOSEC.Checked)
            {
                DATParser tp = new TOSECParser((SystemType)Enum.Parse(typeof(SystemType), comboBoxSystemSelect.SelectedValue.ToString()));
                res = tp.ParseDAT(files.ToArray());
            }
            else if (radioNOINTRO.Checked)
            {
                DATParser dp = new NOINTROParser((SystemType)Enum.Parse(typeof(SystemType), comboBoxSystemSelect.SelectedValue.ToString()));
                res = dp.ParseDAT(files.ToArray());
            }

            string fName = $"gamedb_{GameDB.GetSystemCode((SystemType)Enum.Parse(typeof(SystemType), comboBoxSystemSelect.SelectedValue.ToString()))}_DevExport_{DateTime.UtcNow:yyyy-MM-dd_HH_mm_ss}.txt";

            try
            {
                File.WriteAllText(Path.Combine(textBoxOutputFolder.Text, fName), res);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error writing file: {fName}\n\n{ex.Message}");
            }
        }
Exemplo n.º 2
0
        public override string ParseDAT(string[] filePath)
        {
            foreach (var s in filePath)
            {
                try
                {
                    xmls.Add(XDocument.Load(s));
                }
                catch
                {
                    var res = MessageBox.Show("Could not parse document as valid XML:\n\n" + s + "\n\nDo you wish to continue any other processing?", "Parsing Error", MessageBoxButtons.YesNo);
                    if (res != DialogResult.Yes)
                    {
                        return("");
                    }
                }
            }

            int startIndex = 0;

            // actual tosec parsing
            foreach (var obj in xmls)
            {
                startIndex = Data.Count > 0 ? Data.Count - 1 : 0;
                // get header info
                var header      = obj.Root.Descendants("header").First();
                var name        = header.Element("name").Value;
                var version     = header.Element("version").Value;
                var description = header.Element("description").Value + " - " + version;

                // start comment block
                List <string> comments = new List <string>
                {
                    "Type:\tNO-INTRO",
                    $"Source:\t{description}",
                    $"FileGen:\t{DateTime.UtcNow:yyyy-MM-dd HH:mm:ss} (UTC)",
                };

                AddCommentBlock(comments.ToArray());

                // process each entry
                var query = obj.Root.Descendants("game");
                foreach (var g in query)
                {
                    GameDB item = new GameDB();
                    item.Name   = g.Value;
                    item.SHA1   = g.Elements("rom").First().Attribute("sha1").Value.ToUpper();
                    item.MD5    = g.Elements("rom").First().Attribute("md5").Value.ToUpper();
                    item.System = GameDB.GetSystemCode(SysType);

                    ParseNOINTROFlags(item);

                    Data.Add(item);
                }

                // add this file's data to the stringbuilder
                // first we will sort into various ROMSTATUS groups
                var working = Data.Skip(startIndex).ToList();

                var baddump = working.Where(st => st.Status == "B").OrderBy(na => na.Name).ToList();
                AddCommentBlock("Bad Dumps");
                AppendCSVData(baddump);

                var hack = working.Where(st => st.Status == "H").OrderBy(na => na.Name).ToList();
                AddCommentBlock("Hacks");
                AppendCSVData(hack);

                var over = working.Where(st => st.Status == "O").OrderBy(na => na.Name).ToList();
                AddCommentBlock("Over Dumps");
                AppendCSVData(over);

                var trans = working.Where(st => st.Status == "T").OrderBy(na => na.Name).ToList();
                AddCommentBlock("Translated");
                AppendCSVData(trans);

                var good = working.Where(st => st.Status == "" || st.Status == null).OrderBy(na => na.Name).ToList();
                AddCommentBlock("Believed Good");
                AppendCSVData(good);
            }

            string result = sb.ToString();

            return(sb.ToString());
        }
Exemplo n.º 3
0
        private void ParseNOINTROFlags(GameDB g)
        {
            string nameString = g.Name;

            // remove uninteresting options
            string a = RemoveUnneededOptions(nameString);

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

            if (d.Length > 0)
            {
                // name field
            }

            if (d.Length > 1)
            {
                if (d[1].Length >= 3)
                {
                    // country
                    g.Region = d[1].Trim();
                }
            }

            if (d.Length > 2)
            {
                // parse all other () fields
                // because these are not mandatory this can be a confusing process
                for (int i = 4; i < d.Length; i++)
                {
                    string f = d[i].Trim();

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

                    // version - ignore

                    // check development status (not currently implemented)
                    if (IsDevelopmenttStatus(f) == true)
                    {
                        continue;
                    }

                    // check copyright status (not currently implemented)
                    if (IsCopyrightStatus(f) == true)
                    {
                        continue;
                    }

                    // country flag(s)
                    if (IsCountryFlag(f) == true)
                    {
                        g.Region = f;
                        continue;
                    }

                    // language - if present add to notes
                    if (IsLanguageFlag(f) == true)
                    {
                        g.Notes = f;
                        continue;
                    }

                    // Media Type - ignore for now
                    // Media Label - ignore for now
                }

                // process dump info flags and other info contained in []
                if (nameString.Contains("[") && nameString.Contains("]"))
                {
                    var e = nameString.Split('[', ']')
                            .Skip(1)                                   // remove first entry (this is the bit before the [] entries start)
                            .Where(s => !string.IsNullOrWhiteSpace(s)) // remove empty entries
                            .Distinct()
                            .ToList();

                    if (e.Count > 0)
                    {
                        // bizhawk currently only has a few different RomStatus values (not as many as TOSEC anyway)
                        // Parsing priority will be:
                        //	RomStatus.BadDump
                        //	RomStatus.Hack
                        //	RomStatus.Overdump
                        //	RomStatus.GoodDump
                        //	RomStatus.TranslatedRom
                        //	everything else
                        // all tosec cr, h, t etc.. will fall under RomStatus.Hack

                        if (e.Where(str =>
                                    // bad dump
                                    str == "b" || str.StartsWith("b ")).ToList().Count > 0)
                        {
                            // RomStatus.BadDump
                            g.Status = "B";
                        }
                        else if (e.Where(str =>
                                         // BIOS
                                         str == "BIOS" || str.StartsWith("BIOS ")).ToList().Count > 0)
                        {
                            // RomStatus.BIOS
                            g.Status = "I";
                        }
                        else
                        {
                            g.Status = "";
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void ParseTOSECFlags(GameDB g)
        {
            string nameString = g.Name;

            // remove uninteresting options
            string a = RemoveUnneededOptions(nameString);

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

            if (d.Length > 0)
            {
                // name field
            }

            if (d.Length > 1)
            {
                if (d[1].Length > 3)
                {
                    // year field
                }
            }

            if (d.Length > 3)
            {
                // publisher field
            }

            // public domain
            if (nameString.Contains("(PD)"))
            {
                g.Status = "D";
            }

            if (d.Length > 4)
            {
                // parse all other () fields
                // because these are not mandatory this can be a confusing process
                for (int i = 4; i < d.Length; i++)
                {
                    string f = d[i];

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

                    // country flag(s)
                    if (IsCountryFlag(f) == true)
                    {
                        g.Region = f;
                        continue;
                    }

                    // language - if present add to notes
                    if (IsLanguageFlag(f) == true)
                    {
                        g.Notes = f;
                        continue;
                    }

                    // check copyright status (not currently implemented)
                    if (IsCopyrightStatus(f) == true)
                    {
                        continue;
                    }

                    // check development status (not currently implemented)
                    if (IsDevelopmenttStatus(f) == true)
                    {
                        continue;
                    }



                    // Media Type - ignore for now
                    // Media Label - ignore for now
                }

                // process dump info flags and other info contained in []
                if (nameString.Contains("[") && nameString.Contains("]"))
                {
                    var e = nameString.Split('[', ']')
                            .Skip(1)                                   // remove first entry (this is the bit before the [] entries start)
                            .Where(s => !string.IsNullOrWhiteSpace(s)) // remove empty entries
                            .Distinct()
                            .ToList();

                    if (e.Count > 0)
                    {
                        // bizhawk currently only has a few different RomStatus values (not as many as TOSEC anyway)
                        // Parsing priority will be:
                        //	RomStatus.BadDump
                        //	RomStatus.Hack
                        //	RomStatus.Overdump
                        //	RomStatus.GoodDump
                        //	RomStatus.TranslatedRom
                        //	everything else
                        // all tosec cr, h, t etc.. will fall under RomStatus.Hack

                        if (e.Where(str =>
                                    // bad dump
                                    str == "b" || str.StartsWith("b ") ||
                                    // virus
                                    str == "v" || str.StartsWith("v ") ||
                                    // under dump
                                    str == "u" || str.StartsWith("u ")).ToList().Count > 0)
                        {
                            // RomStatus.BadDump
                            g.Status = "B";
                        }
                        else if (e.Where(str =>
                                         // cracked
                                         str == "cr" || str.StartsWith("cr ") ||
                                         // fixed
                                         str == "f" || str.StartsWith("f ") ||
                                         // hack
                                         str == "h" || str.StartsWith("h ") ||
                                         // modified
                                         str == "m" || str.StartsWith("m ") ||
                                         // pirated
                                         str == "p" || str.StartsWith("p ") ||
                                         // trained
                                         str == "t" || str.StartsWith("t ")
                                         ).ToList().Count > 0)
                        {
                            // RomStatus.Hack
                            g.Status = "H";
                        }
                        else if (e.Where(str =>
                                         // over dump
                                         str == "o" || str.StartsWith("o ")).ToList().Count > 0)
                        {
                            // RomStatus.Overdump
                            g.Status = "O";
                        }
                        else if (e.Where(str =>
                                         // known verified dump
                                         str == "!").ToList().Count > 0)
                        {
                            // RomStatus.GoodDump
                            g.Status = "";
                        }
                        else if (e.Where(str =>
                                         // translated
                                         str == "tr" || str.StartsWith("tr ")).ToList().Count > 0)
                        {
                            // RomStatus.TranslatedRom
                            g.Status = "T";
                        }
                    }
                }
            }
        }