private bool ScrapeUnscrapedGames(Profile p, bool doScrape) { if (!doScrape) { WriteLine("Skipping game scraping."); return(true); } bool success = false; Write("Scraping unscraped games..."); try { Queue <int> jobs = new Queue <int>(); foreach (int id in p.GameData.Games.Keys) { DatabaseEntry entry = null; if (id > 0 && !Database.Contains(id, out entry) || entry != null && entry.LastStoreScrape == 0) { jobs.Enqueue(id); } } if (jobs.Count > 0) { using (DbScrapeDlg dialog = new DbScrapeDlg(jobs)) { DialogResult result = dialog.ShowDialog(); if (result == DialogResult.Cancel) { WriteLine("Scraping cancelled."); } else { WriteLine("Scraping complete."); if (dialog.JobsCompleted > 0) { dbModified = true; } } } } else { WriteLine("No unscraped games found."); } success = true; } catch (Exception e) { WriteLine("Error updating database from web: " + e.Message); Logger.Exception("Automatic mode: Error updating db from web.", e); } return(success); }
private bool ScrapeUnscrapedGames(Profile p, bool doScrape) { if (!doScrape) { WriteLine("Skipping game scraping."); return(true); } bool success = false; Write("Scraping unscraped games..."); try { Queue <int> jobs = new Queue <int>(); foreach (int id in p.GameData.Games.Keys) { if (id > 0 && !Program.GameDB.Contains(id) || Program.GameDB.Games[id].LastStoreScrape == 0) { jobs.Enqueue(id); } } if (jobs.Count > 0) { DbScrapeDlg scrapeDlg = new DbScrapeDlg(jobs); DialogResult scrapeRes = scrapeDlg.ShowDialog(); if (scrapeRes == DialogResult.Cancel) { WriteLine("Scraping cancelled."); } else { WriteLine("Scraping complete."); if (scrapeDlg.JobsCompleted > 0) { dbModified = true; } } } else { WriteLine("No unscraped games found."); } success = true; } catch (Exception e) { WriteLine("Error updating database from web: " + e.Message); Program.Logger.WriteException("Automatic mode: Error updating db from web.", e); } return(success); }
public void ChangeLanguage(StoreLanguage language) { StoreLanguage dbLang = language; if (Language == dbLang) { return; } Language = dbLang; //clean DB from data in wrong language foreach (DatabaseEntry g in Games.Values) { if (g.Id <= 0) { continue; } g.Tags = null; g.Flags = null; g.Genres = null; g.SteamReleaseDate = null; g.LastStoreScrape = 1; //pretend it is really old data g.VRSupport = new VRSupport(); g.LanguageSupport = new LanguageSupport(); } //Update DB with data in correct language Queue <int> gamesToUpdate = new Queue <int>(); if (FormMain.CurrentProfile != null) { foreach (GameInfo game in FormMain.CurrentProfile.GameData.Games.Values) { if (game.Id > 0) { gamesToUpdate.Enqueue(game.Id); } } using (DbScrapeDlg dialog = new DbScrapeDlg(gamesToUpdate)) { dialog.ShowDialog(); } } Save(); }
/// <summary> /// Performs a web scrape on the given games. /// </summary> /// <param name="gamesToScrape">Queue of games to scrape</param> private void ScrapeGames(Queue <int> gamesToScrape) { if (gamesToScrape.Count <= 0) { AddStatusMsg(GlobalStrings.DBEditDlg_NoGamesToScrape); return; } using (DbScrapeDlg dialog = new DbScrapeDlg(gamesToScrape)) { DialogResult result = dialog.ShowDialog(); if (dialog.Error != null) { AddStatusMsg(GlobalStrings.DBEditDlg_ErrorUpdatingGames); MessageBox.Show(string.Format(GlobalStrings.DBEditDlg_ErrorWhileUpdatingGames, dialog.Error.Message), GlobalStrings.DBEditDlg_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } switch (result) { case DialogResult.Cancel: AddStatusMsg(GlobalStrings.DBEditDlg_UpdateCanceled); break; case DialogResult.Abort: AddStatusMsg(string.Format(GlobalStrings.DBEditDlg_AbortedUpdate, dialog.JobsCompleted, dialog.JobsTotal)); break; default: AddStatusMsg(string.Format(GlobalStrings.DBEditDlg_UpdatedEntries, dialog.JobsCompleted)); break; } if (dialog.JobsCompleted <= 0) { return; } UnsavedChanges = true; RebuildDisplayList(); } }
public void ChangeLanguage(StoreLanguage language) { StoreLanguage dbLang = language; if (Language == dbLang) { return; } Language = dbLang; //clean DB from data in wrong language foreach (DatabaseEntry g in Values) { if (g.Id <= 0) { continue; } g.Tags = null; g.Flags = null; g.Genres = null; g.SteamReleaseDate = null; g.LastStoreScrape = 1; //pretend it is really old data g.VRSupport = new VRSupport(); g.LanguageSupport = new LanguageSupport(); } // Update DB with data in correct language List <int> appIds = new List <int>(); if (FormMain.CurrentProfile != null) { appIds.AddRange(FormMain.CurrentProfile.GameData.Games.Values.Where(g => g.Id > 0).Select(g => g.Id)); using (DbScrapeDlg dialog = new DbScrapeDlg(appIds)) { dialog.ShowDialog(); } } Save(); }
/// <summary> /// Performs a web scrape on the given games. /// </summary> /// <param name="gamesToScrape">Queue of games to scrape</param> private void ScrapeGames(Queue <int> gamesToScrape) { if (gamesToScrape.Count > 0) { DbScrapeDlg dlg = new DbScrapeDlg(gamesToScrape); DialogResult res = dlg.ShowDialog(); if (dlg.Error != null) { AddStatusMsg(GlobalStrings.DBEditDlg_ErrorUpdatingGames); MessageBox.Show(string.Format(GlobalStrings.DBEditDlg_ErrorWhileUpdatingGames, dlg.Error.Message), GlobalStrings.DBEditDlg_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } if (res == DialogResult.Cancel) { AddStatusMsg(GlobalStrings.DBEditDlg_UpdateCanceled); } else if (res == DialogResult.Abort) { AddStatusMsg(string.Format(GlobalStrings.DBEditDlg_AbortedUpdate, dlg.JobsCompleted, dlg.JobsTotal)); } else { AddStatusMsg(string.Format(GlobalStrings.DBEditDlg_UpdatedEntries, dlg.JobsCompleted)); } if (dlg.JobsCompleted > 0) { UnsavedChanges = true; RebuildDisplayList(); } } else { AddStatusMsg(GlobalStrings.DBEditDlg_NoGamesToScrape); } }
public void ChangeLanguage(StoreLanguage language) { StoreLanguage dbLang = StoreLanguage.en; if (language == StoreLanguage.windows) { CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture; if (Enum.GetNames(typeof(StoreLanguage)).ToList().Contains(currentCulture.TwoLetterISOLanguageName)) { dbLang = (StoreLanguage)Enum.Parse(typeof(StoreLanguage), currentCulture.TwoLetterISOLanguageName); } else { if (currentCulture.Name == "zh-Hans" || currentCulture.Parent.Name == "zh-Hans") { dbLang = StoreLanguage.zh_Hans; } else if (currentCulture.Name == "zh-Hant" || currentCulture.Parent.Name == "zh-Hant") { dbLang = StoreLanguage.zh_Hant; } else if (currentCulture.Name == "pt-BR" || currentCulture.Parent.Name == "pt-BR") { dbLang = StoreLanguage.pt_BR; } } } else { dbLang = language; } if (Language == dbLang) { return; } Language = dbLang; //clean DB from data in wrong language foreach (DatabaseEntry g in Games.Values) { if (g.Id > 0) { g.Tags = null; g.Flags = null; g.Genres = null; g.SteamReleaseDate = null; g.LastStoreScrape = 1; //pretend it is really old data g.VrSupport = new VrSupport(); g.LanguageSupport = new LanguageSupport(); } } //Update DB with data in correct language Queue <int> gamesToUpdate = new Queue <int>(); if (FormMain.CurrentProfile != null) { foreach (GameInfo game in FormMain.CurrentProfile.GameData.Games.Values) { if (game.Id > 0) { gamesToUpdate.Enqueue(game.Id); } } DbScrapeDlg scrapeDlg = new DbScrapeDlg(gamesToUpdate); scrapeDlg.ShowDialog(); } Save("database.json"); }
private void ScrapeGames( Queue<int> gamesToScrape ) { if( gamesToScrape.Count > 0 ) { DbScrapeDlg dlg = new DbScrapeDlg( gamesToScrape ); DialogResult res = dlg.ShowDialog(); if( dlg.Error != null ) { AddStatusMsg(GlobalStrings.DBEditDlg_ErrorUpdatingGames); MessageBox.Show(string.Format(GlobalStrings.DBEditDlg_ErrorWhileUpdatingGames, dlg.Error.Message), GlobalStrings.DBEditDlg_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } if( res == DialogResult.Cancel ) { AddStatusMsg(GlobalStrings.DBEditDlg_UpdateCanceled); } else if( res == DialogResult.Abort ) { AddStatusMsg(string.Format(GlobalStrings.DBEditDlg_AbortedUpdate, dlg.JobsCompleted, dlg.JobsTotal)); } else { AddStatusMsg(string.Format(GlobalStrings.DBEditDlg_UpdatedEntries, dlg.JobsCompleted)); } if( dlg.JobsCompleted > 0 ) { UnsavedChanges = true; RefreshGameList(); } } else { AddStatusMsg(GlobalStrings.DBEditDlg_NoGamesToScrape); } }
private void Autocategorize( bool selectedOnly, AutoCat autoCat ) { if( autoCat == null ) return; // Get a list of games to update List<GameInfo> gamesToUpdate = new List<GameInfo>(); if( selectedOnly ) { foreach( ListViewItem item in lstGames.SelectedItems ) { GameInfo g = item.Tag as GameInfo; if( ( g != null ) && ( g.Id > 0 ) ) { gamesToUpdate.Add( g ); } } } else { foreach( GameInfo g in gameData.Games.Values ) { if( ( g != null ) && ( g.Id > 0 ) ) { gamesToUpdate.Add( g ); } } } int updated = 0; // List of games not found in database, so we can try to scrape data for them List<GameInfo> notFound = new List<GameInfo>(); autoCat.PreProcess( currentProfile.GameData, Program.GameDB ); foreach( GameInfo g in gamesToUpdate ) { AutoCatResult res = autoCat.CategorizeGame( g ); if( res == AutoCatResult.Success ) { updated++; } else if( res == AutoCatResult.NotInDatabase ) { notFound.Add( g ); } } if( notFound.Count > 0 ) { if( MessageBox.Show( string.Format( GlobalStrings.MainForm_GamesNotFoundInGameDB, notFound.Count ), GlobalStrings.DBEditDlg_Confirm, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1 ) == System.Windows.Forms.DialogResult.Yes ) { Queue<int> jobs = new Queue<int>(); foreach( GameInfo g in notFound ) jobs.Enqueue( g.Id ); DbScrapeDlg scrapeDlg = new DbScrapeDlg( jobs ); DialogResult scrapeRes = scrapeDlg.ShowDialog(); if( scrapeRes == System.Windows.Forms.DialogResult.Cancel ) { AddStatus( string.Format( GlobalStrings.MainForm_CanceledDatabaseUpdate ) ); } else { AddStatus( string.Format( GlobalStrings.MainForm_UpdatedDatabaseEntries, scrapeDlg.JobsCompleted ) ); foreach( GameInfo g in notFound ) { AutoCatResult res = autoCat.CategorizeGame( g ); if( res == AutoCatResult.Success ) { updated++; } } } } } autoCat.DeProcess(); AddStatus( string.Format( GlobalStrings.MainForm_UpdatedCategories, updated ) ); if( gamesToUpdate.Count > updated ) AddStatus( string.Format( GlobalStrings.MainForm_FailedToUpdate, gamesToUpdate.Count - updated ) ); if( updated > 0 ) MakeChange( true ); FullListRefresh(); }
private bool ScrapeUnscrapedGames( Profile p, bool doScrape ) { if( !doScrape ) { WriteLine( "Skipping game scraping." ); return true; } bool success = false; Write( "Scraping unscraped games..." ); try { Queue<int> jobs = new Queue<int>(); foreach( int id in p.GameData.Games.Keys ) { if( id > 0 && !Program.GameDB.Contains( id ) || Program.GameDB.Games[id].LastStoreScrape == 0 ) { jobs.Enqueue( id ); } } if( jobs.Count > 0 ) { DbScrapeDlg scrapeDlg = new DbScrapeDlg( jobs ); DialogResult scrapeRes = scrapeDlg.ShowDialog(); if( scrapeRes == System.Windows.Forms.DialogResult.Cancel ) { WriteLine( "Scraping cancelled." ); } else { WriteLine( "Scraping complete." ); if( scrapeDlg.JobsCompleted > 0 ) dbModified = true; } } else { WriteLine( "No unscraped games found." ); } success = true; } catch( Exception e ) { WriteLine( "Error updating database from web: " + e.Message ); Program.Logger.WriteException( "Automatic mode: Error updating db from web.", e ); } return success; }
/// <summary> /// Autocategorizes a set of games. /// </summary> /// <param name="selectedOnly">If true, runs on the selected games, otherwise, runs on all games.</param> /// <param name="autoCat">The autocat object to use.</param> private void Autocategorize(bool selectedOnly, AutoCat autoCat, bool scrape = true, bool refresh = true) { if (autoCat == null) return; Cursor.Current = Cursors.WaitCursor; // Get a list of games to update List<GameInfo> gamesToUpdate = new List<GameInfo>(); if (selectedOnly && (autoCat.Filter == null)) { foreach (GameInfo g in tlstGames.SelectedObjects) { if (g.Id > 0) { gamesToUpdate.Add(g); } } } else if ((tlstGames.Objects.Count > 0) && (autoCat.Filter == null)) { foreach (GameInfo g in tlstGames.Objects) { if (g.Id > 0) { gamesToUpdate.Add(g); } } } else { foreach (GameInfo g in currentProfile.GameData.Games.Values) { if ((g != null) && (g.Id > 0)) { gamesToUpdate.Add(g); } } } int updated = 0; // List of games not found in database, so we can try to scrape data for them Queue<int> notInDb = new Queue<int>(); foreach (GameInfo game in gamesToUpdate) { if (game.Id > 0 && (!Program.GameDB.Contains(game.Id) || Program.GameDB.Games[game.Id].LastStoreScrape == 0)) { notInDb.Enqueue(game.Id); } } if ((notInDb.Count > 0) && scrape) { Cursor.Current = Cursors.Default; if (MessageBox.Show(string.Format(GlobalStrings.MainForm_GamesNotFoundInGameDB, notInDb.Count), GlobalStrings.DBEditDlg_Confirm, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes) { DbScrapeDlg scrapeDlg = new DbScrapeDlg(notInDb); DialogResult scrapeRes = scrapeDlg.ShowDialog(); if (scrapeRes == System.Windows.Forms.DialogResult.Cancel) { AddStatus(string.Format(GlobalStrings.MainForm_CanceledDatabaseUpdate)); } else { AddStatus(string.Format(GlobalStrings.MainForm_UpdatedDatabaseEntries, scrapeDlg.JobsCompleted)); if (scrapeDlg.JobsCompleted > 0 && Settings.Instance.AutosaveDB) { SaveGameDB(); } } } Cursor.Current = Cursors.WaitCursor; } autoCat.PreProcess(currentProfile.GameData, Program.GameDB); foreach (GameInfo g in gamesToUpdate) { AutoCatResult res = autoCat.CategorizeGame(g, currentProfile.GameData.GetFilter(autoCat.Filter)); if (res == AutoCatResult.Success) { updated++; } } autoCat.DeProcess(); AddStatus(string.Format(GlobalStrings.MainForm_UpdatedCategories, updated)); if (gamesToUpdate.Count > updated) AddStatus(string.Format(GlobalStrings.MainForm_FailedToUpdate, gamesToUpdate.Count - updated)); if (updated > 0) MakeChange(true); if (refresh) { FillAllCategoryLists(); FilterGamelist(true); } Cursor.Current = Cursors.Default; }
public void ChangeStoreLanguage(StoreLanguage storeLanguage) { if (Program.GameDB == null) { return; } StoreLanguage dbLanguage = StoreLanguage.en; if (storeLanguage == StoreLanguage.windows) { CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture; if (Enum.GetNames(typeof(StoreLanguage)).ToList().Contains(currentCulture.TwoLetterISOLanguageName)) { dbLanguage = (StoreLanguage)Enum.Parse(typeof(StoreLanguage), currentCulture.TwoLetterISOLanguageName); } else { if (currentCulture.Name == "zh-Hans" || currentCulture.Parent.Name == "zh-Hans") { dbLanguage = StoreLanguage.zh_Hans; } else if (currentCulture.Name == "zh-Hant" || currentCulture.Parent.Name == "zh-Hant") { dbLanguage = StoreLanguage.zh_Hant; } else if (currentCulture.Name == "pt-BR" || currentCulture.Parent.Name == "pt-BR") { dbLanguage = StoreLanguage.pt_BR; } } } else { dbLanguage = storeLanguage; } if (Program.GameDB.dbLanguage != dbLanguage) { Program.GameDB.dbLanguage = dbLanguage; //clean DB from data in wrong language foreach (GameDBEntry g in Program.GameDB.Games.Values) { if (g.Id > 0) { g.Tags = null; g.Flags = null; g.Genres = null; g.SteamReleaseDate = null; g.LastStoreScrape = 0; g.vrSupport = new VrSupport(); g.languageSupport = new LanguageSupport(); } } Program.GameDB.Save("GameDB.xml.gz"); //Update DB with data in correct language Queue <int> gamesToUpdate = new Queue <int>(); if (FormMain.CurrentProfile != null) { foreach (GameInfo game in FormMain.CurrentProfile.GameData.Games.Values) { if (game.Id > 0) { gamesToUpdate.Enqueue(game.Id); } } DbScrapeDlg scrapeDlg = new DbScrapeDlg(gamesToUpdate); DialogResult scrapeRes = scrapeDlg.ShowDialog(); if (scrapeRes != DialogResult.Cancel && scrapeDlg.JobsCompleted > 0) { Program.GameDB.Save("GameDB.xml.gz"); } } } }