示例#1
0
        void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            SetProgress(e.ProgressPercentage);
            string status = e.ProgressPercentage + "% , " + HelperTools.GetSize(e.BytesReceived) + " of " +
                            HelperTools.GetSize(e.TotalBytesToReceive);

            SetStatus(status);
        }
        private void CloseAfterFinish1()
        {
            finished = true;
            ManagedMessageBoxResult res = ManagedMessageBox.ShowMessage(
                Program.ResourceManager.GetString("Message_Done") + ", " +
                Program.ResourceManager.GetString("Message_LogFileSavedTo") + " '" + logPath + "'",
                Program.ResourceManager.GetString("MessageCaption_DetectAndDownloadFromTheGamesDB"), new string[] {
                Program.ResourceManager.GetString("Button_Ok"),
                Program.ResourceManager.GetString("Button_OpenLog")
            },
                0, null, ManagedMessageBoxIcon.Info);

            if (res.ClickedButtonIndex == 1)
            {
                try { Process.Start(HelperTools.GetFullPath(logPath)); }
                catch (Exception ex)
                { ManagedMessageBox.ShowErrorMessage(ex.Message); }
            }

            this.Close();
        }
        private void PROCESS()
        {
            // Add listener
            string logFileName = string.Format("{0}-detect and download from the-game-db.txt",
                                               DateTime.Now.ToLocalTime().ToString());

            logFileName = logFileName.Replace(":", "");
            logFileName = logFileName.Replace("/", "-");
            Directory.CreateDirectory("Logs");
            logPath = Path.Combine("Logs", logFileName);
            listner = new TextWriterTraceListener(HelperTools.GetFullPath(logPath));
            Trace.Listeners.Add(listner);
            // Start
            Trace.WriteLine(string.Format("Detect and download from the-game-db.for started at {0}",
                                          DateTime.Now.ToLocalTime()), "Detect And Download From TheGamesDB.net");
            int step_index  = 0;
            int steps_count = 4;

            #region 1 Getting all platform entries from the internet
            Trace.WriteLine("Getting entries for selected platform ...", "Detect And Download From TheGamesDB.net");
            status_master   = "Getting entries for selected platform ...";
            progress_master = 100 / (steps_count - step_index);
            // Get database content
            Platform selectedPlatform = GamesDB.GetPlatform(_db_selected_platform_id);
            List <GameSearchResult> databaseEntries = new List <GameSearchResult>(GamesDB.GetPlatformGames(_db_selected_platform_id));
            Trace.WriteLine("Platform entries done, total of " + databaseEntries.Count + " entries found.", "Detect And Download From TheGamesDB.net");
            #endregion
            #region 2 Get the games
            step_index++;
            Trace.WriteLine("Collecting the roms ...", "Detect And Download From TheGamesDB.net");
            status_master   = "Collecting the roms ...";
            progress_master = 100 / (steps_count - step_index);
            DataSet set = MyNesDB.GetDataSet("GAMES");
            Trace.WriteLine("Roms collected, total of " + set.Tables[0].Rows.Count + " entries", "Detect And Download From TheGamesDB.net");

            // Clear detected files first ?
            if (_clear_info_table)
            {
                MyNesDB.DeleteDetects("INFOS");
            }
            if (_clear_snaps_table)
            {
                MyNesDB.DeleteDetects("SNAPS");
            }
            if (_clear_covers_table)
            {
                MyNesDB.DeleteDetects("COVERS");
            }

            #endregion
            #region 3 Compare and apply stuff
            step_index++;
            Trace.WriteLine("Comparing and applying naming", "Detect And Download From TheGamesDB.net");
            status_master   = "Comparing ...";
            progress_master = 100 / (steps_count - step_index);

            int           gameEntriesCount   = set.Tables[0].Rows.Count;
            int           matchedCount       = 0;
            List <string> matchedRomNames    = new List <string>();
            List <string> notMatchedRomNames = new List <string>();
            for (int game_index = 0; game_index < gameEntriesCount; game_index++)
            {
                string id        = set.Tables[0].Rows[game_index]["Id"].ToString();
                string entryName = set.Tables[0].Rows[game_index]["Name"].ToString().Replace("&apos;", "'");
                string entryPath = set.Tables[0].Rows[game_index]["Path"].ToString().Replace("&apos;", "'");

                status_sub_sub = "";

                // Loop through database entries looking for a match
                for (int entry_index = 0; entry_index < databaseEntries.Count; entry_index++)
                {
                    if (FilterSearch(entryName, entryPath, databaseEntries[entry_index].Title))
                    {
                        Trace.WriteLine("GAME MATCHED [" + id + "] (" + entryName + ")", "Detect And Download From TheGamesDB.net");
                        matchedRomNames.Add(entryName);

                        //  Apply
                        ApplyRom(entryName, id, GamesDB.GetGame(databaseEntries[entry_index].ID));
                        Trace.WriteLine("ROM DATA UPDATED.", "Detect And Download From TheGamesDB.net");

                        matchedCount++;

                        if (_turbo_speed)
                        {
                            databaseEntries.RemoveAt(entry_index);
                        }
                        break;
                    }
                }

                // Progress
                progress_sub = (game_index * 100) / gameEntriesCount;
                status_sub   = string.Format("{0} {1} / {2} ({3} MATCHED) ... {4} %",
                                             Program.ResourceManager.GetString("Status_ApplyingDatabase"), (game_index + 1).ToString(), gameEntriesCount,
                                             matchedCount.ToString(), progress_sub);
            }
            #endregion
            #region 4 Update log with matched and not found roms
            step_index++;
            Trace.WriteLine("Finishing", "Detect And Download From TheGamesDB.net");
            status_master   = "Finishing ...";
            progress_master = 100 / (steps_count - step_index);

            Trace.WriteLine("----------------------------");
            Trace.WriteLine("MATCHED ROMS ( total of " + matchedRomNames.Count + " rom(s) )");
            Trace.WriteLine("------------");
            for (int i = 0; i < matchedRomNames.Count; i++)
            {
                Trace.WriteLine((i + 1).ToString("D8") + "." + matchedRomNames[i]);
            }

            Trace.WriteLine("----------------------------");
            Trace.WriteLine("ROMS NOT FOUND ( total of " + notMatchedRomNames.Count + " rom(s) )");
            Trace.WriteLine("--------------");
            for (int i = 0; i < notMatchedRomNames.Count; i++)
            {
                Trace.WriteLine((i + 1).ToString("D8") + "." + notMatchedRomNames[i]);
            }

            Trace.WriteLine("----------------------------");

            Trace.WriteLine(string.Format("Detect And Download From TheGamesDB.net finished at {0}.", DateTime.Now.ToLocalTime()), "Detect And Download From TheGamesDB.net");
            listner.Flush();
            Trace.Listeners.Remove(listner);
            CloseAfterFinish();
            #endregion
        }