Exemple #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}");
            }
        }
        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 category    = header.Element("category").Value;
                var name        = header.Element("name").Value;
                var version     = header.Element("version").Value;
                var description = header.Element("description").Value;

                // start comment block
                List <string> comments = new List <string>
                {
                    $"Type:\t{category}",
                    $"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);

                    ParseTOSECFlags(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 pd = working.Where(st => st.Status == "D").OrderBy(na => na.Name).ToList();
                AddCommentBlock("Home Brew");
                AppendCSVData(pd);

                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());
        }