private void toolStripButton_newFile_Click(object sender, EventArgs e) { if (currentID == "") { return; } SaveFileDialog sav = new SaveFileDialog(); sav.Title = Program.ResourceManager.GetString("Title_NewInfoFile"); sav.Filter = Program.ResourceManager.GetString("Filter_InfoFile"); // Determine file name MyNesDBEntryInfo entry = MyNesDB.GetEntry(currentID); sav.FileName = entry.Name + ".txt"; if (sav.ShowDialog(this) == DialogResult.OK) { // Save the file ! switch (Path.GetExtension(sav.FileName).ToLower()) { case ".rtf": case ".doc": richTextBox1.SaveFile(sav.FileName); break; default: File.WriteAllLines(sav.FileName, richTextBox1.Lines, Encoding.UTF8); break; } // Make sure this file isn't exist for selected game bool found = false; if (detects != null) { for (int i = 0; i < detects.Length; i++) { if (detects[i].Path == sav.FileName) { fileIndex = i; ShowCurrentFile(); found = true; return; } } } if (!found) { // Add it ! MyNesDetectEntryInfo newDetect = new MyNesDetectEntryInfo(); newDetect.GameID = currentID; newDetect.Path = sav.FileName; newDetect.Name = Path.GetFileNameWithoutExtension(sav.FileName); newDetect.FileInfo = ""; MyNesDB.AddDetect("INFOS", newDetect); // Refresh RefreshForEntry(currentID); fileIndex = detects.Length - 1; ShowCurrentFile(); } } }
private void AddOverviewConentToGame(string tabName, string folder, string file_content, string gameID) { // Get the files string fileToAdd = tabName + "-" + gameID + ".txt"; fileToAdd = Path.Combine(folder, fileToAdd); int i = 1; while (File.Exists(fileToAdd)) { i++; fileToAdd = tabName + "-" + gameID + "_" + i + ".txt"; fileToAdd = Path.Combine(folder, fileToAdd); } try { status_sub_sub = string.Format("[Saving file at {0} for {1}]", fileToAdd, tabName); File.WriteAllText(fileToAdd, file_content); Trace.WriteLine(string.Format("->File saved for '{0}' at '{1}'", tabName, fileToAdd), "Detect And Download From TheGamesDB.net"); // Add it as detect // Make sure this file isn;t exist for selected game MyNesDetectEntryInfo[] detects = MyNesDB.GetDetects("INFOS", gameID); bool found = false; if (detects != null) { foreach (MyNesDetectEntryInfo inf in detects) { if (inf.Path == fileToAdd) { found = true; break; } } } if (!found) { // Add it ! MyNesDetectEntryInfo newDetect = new MyNesDetectEntryInfo(); newDetect.GameID = gameID; newDetect.Path = fileToAdd; newDetect.Name = Path.GetFileNameWithoutExtension(fileToAdd); newDetect.FileInfo = ""; MyNesDB.AddDetect("INFOS", newDetect); } } catch (Exception ex) { Trace.TraceError(string.Format("XXX Unable to save file for '{0}' at '{1}'; " + ex.Message, tabName, fileToAdd)); } }
private void ManualsViewer_DragDrop(object sender, DragEventArgs e) { if (detects == null) { return; } if (currentID == "") { return; } if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); foreach (string file in files) { if (!extensions.Contains(Path.GetExtension(file).ToLower())) { continue; } // Make sure this file isn't exist for selected game bool found = false; if (detects != null) { foreach (MyNesDetectEntryInfo inf in detects) { if (inf.Path == file) { found = true; break; } } } if (!found) { // Add it ! MyNesDetectEntryInfo newDetect = new MyNesDetectEntryInfo(); newDetect.GameID = currentID; newDetect.Path = file; newDetect.Name = Path.GetFileNameWithoutExtension(file); newDetect.FileInfo = ""; MyNesDB.AddDetect("MANUALS", newDetect); } } RefreshForEntry(currentID); } }
private void toolStripButton_add_Click(object sender, EventArgs e) { OpenFileDialog op = new OpenFileDialog(); op.Title = Program.ResourceManager.GetString("Title_AddMoreManuals"); op.Filter = Program.ResourceManager.GetString("Filter_PDF"); op.Multiselect = true; if (op.ShowDialog(this) == DialogResult.OK) { foreach (string file in op.FileNames) { // Make sure this file isn't exist for selected game bool found = false; if (detects != null) { foreach (MyNesDetectEntryInfo inf in detects) { if (inf.Path == file) { found = true; break; } } } if (!found) { // Add it ! MyNesDetectEntryInfo newDetect = new MyNesDetectEntryInfo(); newDetect.GameID = currentID; newDetect.Path = file; newDetect.Name = Path.GetFileNameWithoutExtension(file); newDetect.FileInfo = ""; MyNesDB.AddDetect("MANUALS", newDetect); } } RefreshForEntry(currentID); } }
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 toolStripButton_search_tgdb_Click(object sender, EventArgs e) { if (currentID == "") { return; } string entryName = MyNesDB.GetEntry(currentID).Name; FormSearchTheGamesDB frm = new FormSearchTheGamesDB(entryName); if (frm.ShowDialog(this) == DialogResult.OK) { TheGamesDBAPI.Game gm = TheGamesDBAPI.GamesDB.GetGame(frm.SelectedResultID); FormTheGamesDBImageMode frm2 = new FormTheGamesDBImageMode(gm.Images); if (frm2.ShowDialog(this) == DialogResult.OK) { // Browse for a folder FolderBrowserDialog fol = new FolderBrowserDialog(); string selectedPath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); switch (MODE) { case DetectMode.COVERS: { if (Program.Settings.Database_FoldersCovers != null) { if (Program.Settings.Database_FoldersCovers.Count > 0) { selectedPath = Program.Settings.Database_FoldersCovers[0]; } } break; } case DetectMode.SNAPS: { if (Program.Settings.Database_FoldersSnapshots != null) { if (Program.Settings.Database_FoldersSnapshots.Count > 0) { selectedPath = Program.Settings.Database_FoldersSnapshots[0]; } } break; } } fol.SelectedPath = selectedPath; fol.Description = Program.ResourceManager.GetString("Title_ChooseWhereToDownloadTheFiles"); if (fol.ShowDialog(this) == DialogResult.OK) { List <string> links = new List <string>(); if (frm2.SelectedBanners) { for (int i = 0; i < gm.Images.Banners.Count; i++) { links.Add(TheGamesDBAPI.GamesDB.BaseImgURL + gm.Images.Banners[i].Path); } } else if (frm2.SelectedBoxArtBack) { links.Add(TheGamesDBAPI.GamesDB.BaseImgURL + gm.Images.BoxartBack.Path); } else if (frm2.SelectedBoxArtFront) { links.Add(TheGamesDBAPI.GamesDB.BaseImgURL + gm.Images.BoxartFront.Path); } else if (frm2.SelectedFanart) { for (int i = 0; i < gm.Images.Fanart.Count; i++) { links.Add(TheGamesDBAPI.GamesDB.BaseImgURL + gm.Images.Fanart[i].Path); } } else if (frm2.SelectedScreenshots) { for (int i = 0; i < gm.Images.Screenshots.Count; i++) { links.Add(TheGamesDBAPI.GamesDB.BaseImgURL + gm.Images.Screenshots[i].Path); } } FormDownloadFiles down = new FormDownloadFiles(fol.SelectedPath, links.ToArray(), entryName); if (down.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { if (down.DownloadedPaths.Count > 0) { foreach (string file in down.DownloadedPaths) { // Make sure this file isn't exist for selected game bool found = false; if (detects != null) { foreach (MyNesDetectEntryInfo inf in detects) { if (inf.Path == file) { found = true; break; } } } if (!found) { // Add it ! MyNesDetectEntryInfo newDetect = new MyNesDetectEntryInfo(); newDetect.GameID = currentID; newDetect.Path = file; newDetect.Name = Path.GetFileNameWithoutExtension(file); newDetect.FileInfo = ""; MyNesDB.AddDetect(MODE.ToString(), newDetect); } } RefreshForEntry(currentID); } // Save folder switch (MODE) { case DetectMode.COVERS: { if (Program.Settings.Database_FoldersCovers != null) { if (!Program.Settings.Database_FoldersCovers.Contains(fol.SelectedPath)) { Program.Settings.Database_FoldersCovers.Insert(0, fol.SelectedPath); } } break; } case DetectMode.SNAPS: { if (Program.Settings.Database_FoldersSnapshots != null) { if (!Program.Settings.Database_FoldersSnapshots.Contains(fol.SelectedPath)) { Program.Settings.Database_FoldersSnapshots.Insert(0, fol.SelectedPath); } } break; } } } } } } }
private void AddTabConentFilesToRom(string tabName, string downloads_folder, List <string> links, string gameID, string tableName) { // Download the files Trace.WriteLine(string.Format("Downloading files for '{0}'", tabName), "Detect And Download From TheGamesDB.net"); string NameOfSavedFiles = tabName + "-" + gameID; int c = 1; List <string> filesToAdd = new List <string>(); foreach (string link in links) { // Try downloading try { Trace.WriteLine(string.Format("Downloading file from '{0}'", link), "Detect And Download From TheGamesDB.net"); Uri uri = new Uri(link); string[] splited = link.Split(new char[] { '/' }); string ext = Path.GetExtension(splited[splited.Length - 1]); int j = 0; while (File.Exists(Path.GetFullPath(downloads_folder + "\\" + NameOfSavedFiles + "(" + (j + 1).ToString() + ")" + ext))) { j++; } client.DownloadFile(uri, Path.GetFullPath(downloads_folder + "\\" + NameOfSavedFiles + "(" + (j + 1).ToString() + ")" + ext)); filesToAdd.Add(downloads_folder + "\\" + NameOfSavedFiles + "(" + (j + 1).ToString() + ")" + ext); status_sub_sub = string.Format("[Downloading file {0} of {1} from {2}]", c, links.Count, link); } catch (Exception ex) { Trace.WriteLine(string.Format("XXX Unable to download file from '{0}'; {1}", link, ex.Message), "Detect And Download From TheGamesDB.net"); } c++; } // Add it ! for (int j = 0; j < filesToAdd.Count; j++) { // Make sure this file isn;t exist for selected game MyNesDetectEntryInfo[] detects = MyNesDB.GetDetects(tableName, gameID); bool found = false; if (detects != null) { foreach (MyNesDetectEntryInfo inf in detects) { if (inf.Path == filesToAdd[j]) { found = true; break; } } } if (!found) { // Add it ! MyNesDetectEntryInfo newDetect = new MyNesDetectEntryInfo(); newDetect.GameID = gameID; newDetect.Path = filesToAdd[j]; newDetect.Name = Path.GetFileNameWithoutExtension(filesToAdd[j]); newDetect.FileInfo = ""; MyNesDB.AddDetect(tableName, newDetect); } } }