Exemplo n.º 1
0
        private void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            FileInfo file       = e.Argument as FileInfo;
            int      totalLines = File.ReadAllLines(file.FullName).Length;


            List <GameFile> gamesList = new List <GameFile>();
            string          system    = "";

            foreach (string line in File.ReadAllLines(file.FullName))
            {
                //int currentLine = line.Count();
                //MessageBox.Show(((currentLine * 100) / totalLines  ).ToString());
                (sender as BackgroundWorker).ReportProgress(1);

                GameFile gf = new GameFile();

                Match systemCheck = Regex.Match(line, "<name>(.*?)<\\/name>");
                if (systemCheck.Success)
                {
                    system = systemCheck.Groups[1].Value;
                }
                gf.Company = system;


                Match elements = Regex.Match(line, "<[^<>]+>");
                if (elements.Success)
                {
                    string game = elements.Value;
                    if (game.StartsWith("<rom name="))
                    {
                        Match gameName = Regex.Match(game, "<rom name=\"(.*?)\"");
                        gf.FileName = gameName.Groups[1].Value;
                        //MessageBox.Show(gf.FileName);
                        Match md5 = Regex.Match(game, "md5=\"(.*?)\"");
                        gf.MD5Hash = md5.Groups[1].Value;
                        //MessageBox.Show(gf.MD5Hash);

                        //gf.FileName = game;
                        if (gameName.Success && md5.Success)
                        {
                            gamesList.Add(gf);
                        }
                    }
                    e.Result = gamesList;
                }
            }
            //objectListView1.AddObject(gamesList);
        }
Exemplo n.º 2
0
        private void compare()
        {
            //Starts loop for all items in ObjectListView
            foreach (GameFile file in masterList)
            {
                file.Match = "No"; //Automatically sets Match to No instead of applying it multiple times in loop

                //Begins looping each table in dataSet1
                foreach (DataTable t in dataSet1.Tables)
                {
                    //Begins looping for each row in the current table
                    foreach (DataRow row in t.Rows)
                    {
                        //Creates a second GameFile from Redump.org data
                        GameFile gf = new GameFile();
                        gf.FileName = row["GameName"].ToString();
                        gf.MD5Hash  = row["MD5"].ToString();

                        //if comparison to check for a matching md5 hash
                        if (file.MD5Hash == gf.MD5Hash)
                        {
                            //MessageBox.Show("Match!");
                            file.Match = "Yes";
                            objectListView1.RefreshObject(file);
                        }
                    }

                    int matches = 0;

                    foreach (GameFile gf in masterList)
                    {
                        if (gf.Match == "Yes")
                        {
                            matches += 1;
                        }
                    }

                    status.Text = "Done parsing table. " + matches + "/" + masterList.Count + " files were verified with Redump.org";

                    objectListView1.BuildList();
                }
            }
        }
Exemplo n.º 3
0
        private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            GameFile gf = e.Result as GameFile;

            //updateListMD5(gf);

            objectListView1.UpdateObject(gf);

            compare();

            //objectListView1.RedrawItems(0,toolStripProgressBar1.Maximum-1, false);
            if (gf.Status == 100)
            {
                batchProgressBar.Value += 1;
            }

            if (batchProgressBar.Value == batchProgressBar.Maximum)
            {
                runBtn.Enabled  = true;
                openBtn.Enabled = true;
                status.Text     = "All hashes calculated...";
            }
        }
Exemplo n.º 4
0
        private void xDocWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            //Retrieves file passed to background worker
            FileInfo file = e.Argument as FileInfo;

            //New Dataset for all tables
            DataSet dataSet = new DataSet();


            string fileName = Path.GetFileNameWithoutExtension(file.FullName); //Extracts only the file name without .dat extension

            fileName = Regex.Replace(fileName, " ", "");                       //Removes blank spaces
            string tableName = "table_" + fileName;                            //Names table after fileName


            //Company tag for all items in file
            string company = "";

            //Creating Table & Columns
            DataTable table1 = new DataTable(tableName);

            table1.Columns.Add("GameName", typeof(String));
            table1.Columns.Add("Company", typeof(String));
            table1.Columns.Add("MD5", typeof(String));

            //Adds current table to dataSet
            dataSet.Tables.Add(table1);

            //Loads .dat file for parsing xml data
            XDocument doc = XDocument.Load(file.FullName);

            //List of GameFile objects for storing redump game info
            List <GameFile> gamesList = new List <GameFile>();

            //Extracts the System Manufactuer from .dat file
            foreach (XElement c in doc.Descendants("name"))
            {
                company = (string)c.Value;
            }

            //Extracts all <game> items from .dat file
            foreach (XElement game in doc.Descendants("game"))
            {
                GameFile gf = new GameFile();

                gf.Company = company;


                //Extracts rom info from game element, inside .dat file
                foreach (XElement rom in game.Elements("rom"))
                {
                    {
                        //Adds info from redump.org to new GameFile
                        gf.FileName = (string)rom.Attribute("name");
                        gf.MD5Hash  = (string)rom.Attribute("md5");

                        //Adds GameFile info to table row
                        DataRow row = table1.NewRow();
                        row["GameName"] = gf.FileName;
                        row["Company"]  = gf.Company;
                        row["MD5"]      = gf.MD5Hash;

                        //Adds new row to current table
                        table1.Rows.Add(row);
                    }

                    (sender as BackgroundWorker).ReportProgress(1);
                    //gamesList.Add(gf);
                }
            }
            e.Result = gamesList; //Sends result as List<> of GameFile
        }
Exemplo n.º 5
0
        private void openBtn_Click(object sender, EventArgs e)
        {
            List <string> alreadyInList = new List <string>();

            runBtn.Enabled  = false;
            openBtn.Enabled = false;
            status.Text     = "Adding game files...";

            batchProgressBar.Value = 0;


            OpenFileDialog openFileDialog1 = new OpenFileDialog
            {
                Multiselect = true,

                InitialDirectory = @"G:\",
                Title            = "Browse .bin Files",

                CheckFileExists = true,
                CheckPathExists = true,

                DefaultExt       = "bin",
                Filter           = "bin files (*.bin)|*.bin",
                FilterIndex      = 2,
                RestoreDirectory = true,

                ReadOnlyChecked = true,
                ShowReadOnly    = true
            };

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                foreach (String file in openFileDialog1.FileNames)
                {
                    string directoryPath = Path.GetFullPath(file);
                    string fileName      = Path.GetFileNameWithoutExtension(file);
                    long   size          = new System.IO.FileInfo(directoryPath).Length;


                    GameFile gf = new GameFile(fileName, directoryPath, size, "");


                    if (checkExist(gf))
                    {
                        alreadyInList.Add(gf.FileName);
                        //batchProgressBar.Value += 1;
                    }
                    else
                    {
                        masterList.Add(gf);
                        BackgroundWorker bw = new BackgroundWorker();
                        bw.WorkerReportsProgress = true;
                        bw.DoWork             += new DoWorkEventHandler(bw_DoWork);
                        bw.ProgressChanged    += new ProgressChangedEventHandler(bw_ProgressChanged);
                        bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
                        bw.RunWorkerAsync(gf);
                        bw.Dispose();
                    }
                }

                itemsCount.Text          = masterList.Count.ToString();
                batchProgressBar.Value   = alreadyInList.Count;
                batchProgressBar.Maximum = masterList.Count;

                var message = string.Join(Environment.NewLine, alreadyInList);
                if (alreadyInList.Count != 0)
                {
                    MessageBox.Show("The following items were already imported: " + "\n" + message);
                }

                this.objectListView1.SetObjects(masterList);


                //textBox1.Text = openFileDialog1.FileName;
            }
            else
            {
                MessageBox.Show("Please select .bin files to proceed");
                openBtn.Enabled = true;
            }
        }