private void SEARCH() { int matchedRoms = 0; DataSet set = MyNesDB.GetDataSet("GAMES"); List <string> files = new List <string>(); foreach (string folder in foldersToSearch) { files.AddRange(Directory.GetFiles(folder, "*", includeSubFolders ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)); } // Clear detected files first ? if (clearOldRomDetectedFiles) { MyNesDB.DeleteDetects(mode.ToString()); } // Start the operation, loop through roms for (int i = 0; i < set.Tables[0].Rows.Count; i++) { string id = set.Tables[0].Rows[i]["Id"].ToString(); string entryName = set.Tables[0].Rows[i]["Name"].ToString().Replace("'", "'"); string entryPath = set.Tables[0].Rows[i]["Path"].ToString().Replace("'", "'"); // Decode path if (entryPath.StartsWith("(")) { // Decode string[] pathCodes = entryPath.Split(new char[] { '(', ')' }); entryPath = pathCodes[2]; } // Loop through files, look for files for this rom for (int j = 0; j < files.Count; j++) { if (!extensions.Contains(Path.GetExtension(files[j]).ToLower())) { Trace.WriteLine("File ignored (no match for extension): " + files[j], "Detect Files"); // Useless file ... files.RemoveAt(j); j--; continue; } if (FilterSearch(entryName, entryPath, files[j])) { matchedRoms++; // Add it ! // Make sure this file isn;t exist for selected game MyNesDetectEntryInfo[] detects = MyNesDB.GetDetects(mode.ToString(), id); bool found = false; if (detects != null) { foreach (MyNesDetectEntryInfo inf in detects) { if (inf.Path == files[j]) { found = true; break; } } } if (!found) { // Add it ! MyNesDetectEntryInfo newDetect = new MyNesDetectEntryInfo(); newDetect.GameID = id; newDetect.Path = files[j]; newDetect.Name = Path.GetFileNameWithoutExtension(files[j]); newDetect.FileInfo = ""; MyNesDB.AddDetect(mode.ToString(), newDetect); } // To reduce process, delete detected file if (dontAllowSameFileDetectedByMoreThanOneRom) { files.RemoveAt(j); j--; } if (oneFilePerRom) { break; } } } // Update progress process = (i * 100) / set.Tables[0].Rows.Count; status = string.Format(Program.ResourceManager.GetString("Status_Detecting") + " {0} / {1} [{2} " + Program.ResourceManager.GetString("Status_Detected") + "][{3} %]", (i + 1), set.Tables[0].Rows.Count, matchedRoms, process); } // Done ! Trace.WriteLine("Detect process finished at " + DateTime.Now.ToLocalTime().ToString(), "Detect Files"); finished = true; Trace.WriteLine("----------------------------"); CloseWin(); }
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("'", "'"); string entryPath = set.Tables[0].Rows[game_index]["Path"].ToString().Replace("'", "'"); 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 }