public void Add(string sourceFilePath) { if (Path.GetExtension(sourceFilePath) == ".exe") { try { Reporter.Report("Adding " + Title); string destinationDirectory = Path.GetDirectoryName(FilePath); string sourceDirectory = Path.GetDirectoryName(sourceFilePath); string sourceFile = Path.GetFileName(sourceFilePath); string sourceFileAfterMove = destinationDirectory + @"\" + sourceFile; Directory.CreateDirectory(destinationDirectory); Filex.CopyDirectory(sourceDirectory, destinationDirectory); File.Move(sourceFileAfterMove, FilePath); OnPropertyChanged("Included"); } catch { Reporter.Warn("Problem creating directory of moving file."); } } else { Reporter.Warn("The dropped file doesn't look like an executable."); } }
public static bool DownloadFileFromDB(this WebClient webclient, string url, string fileName) { try { webclient.SetStandardHeaders(); DBTimers.Wait(url); Debug.WriteLine($"Hit DB at: {url} {DateTime.Now}"); webclient.DownloadFile(url, fileName); return(true); } catch (WebException ex) { if (ex.Response != null) { var response = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd(); Debug.WriteLine(response); Debug.WriteLine(ex.Message); Debug.WriteLine(ex.Source); Debug.WriteLine(ex.TargetSite); Debug.WriteLine(ex.Status); Debug.WriteLine(ex.HResult); Reporter.Warn($"Failure getting {url}. The website responded:"); Reporter.Report(response); } return(false); } }
/// <summary> /// Implements IDB.CachePlatformdata() Update the local DB cache of platform associated metadata /// </summary> /// <param name="platform">Robin.Platform associated with the DBPlatorm to update.</param> public void CachePlatformData(Platform platform) { Reporter.Tic("Getting " + platform.Title + " data from Games DB...", out int tic1); GDBPlatform gdbPlatform = platform.GDBPlatform; XDocument xdoc; string url; string urlbase = $"{baseUrl}GetPlatform.php?id="; using (WebClient webclient = new WebClient()) { // Assemble the platformsdb url from the platform data and the base API url url = urlbase + gdbPlatform.ID; // Pull down the xml file containing platform data from gamesdb if (webclient.SafeDownloadStringDB(url, out string downloadtext)) { xdoc = XDocument.Parse(downloadtext); gdbPlatform.Title = xdoc.SafeGetB("Platform", "Platform"); gdbPlatform.Developer = xdoc.SafeGetB("Platform", "developer"); gdbPlatform.Manufacturer = xdoc.SafeGetB("Platform", "manufacturer"); gdbPlatform.Cpu = xdoc.SafeGetB("Platform", "cpu"); gdbPlatform.Sound = xdoc.SafeGetB("Platform", "sound"); gdbPlatform.Display = xdoc.SafeGetB("Platform", "display"); gdbPlatform.Media = xdoc.SafeGetB("Platform", "media"); gdbPlatform.Controllers = xdoc.SafeGetB("Platform", "maxcontrollers"); gdbPlatform.Rating = decimal.Parse(xdoc.SafeGetB("Platform", "rating") ?? "0"); gdbPlatform.Overview = xdoc.SafeGetB("Platform", "overview"); string BaseImageUrl = xdoc.SafeGetB("baseImgUrl"); if (BaseImageUrl != null) { string BoxFrontUrl = xdoc.SafeGetBoxArt("front", type: "Platform"); string BoxBackUrl = xdoc.SafeGetBoxArt("back", type: "Platform"); string BannerUrl = xdoc.SafeGetB("Platform", "Images", "banner"); string ConsoleUrl = xdoc.SafeGetB("Platform", "Images", "consoleart"); string ControllerUrl = xdoc.SafeGetB("Platform", "Images", "controllerart"); gdbPlatform.BoxFrontURL = BoxFrontUrl != null ? BaseImageUrl + BoxFrontUrl : null; gdbPlatform.BoxBackURL = BoxBackUrl != null ? BaseImageUrl + BoxBackUrl : null; gdbPlatform.BannerURL = BannerUrl != null ? BaseImageUrl + BannerUrl : null; gdbPlatform.ConsoleURL = ConsoleUrl != null ? BaseImageUrl + ConsoleUrl : null; gdbPlatform.ControllerURL = ControllerUrl != null ? BaseImageUrl + ControllerUrl : null; } } else { Reporter.Warn("Failure getting " + gdbPlatform.Title + " data from Games DB."); } } Reporter.Toc(tic1); }
void EmulatorStackPanel_Drop(object sender, DragEventArgs e) { Emulator emulator = (sender as StackPanel).DataContext as Emulator; if (e.Data.GetDataPresent(DataFormats.FileDrop)) { if (e.Data.GetData(DataFormats.FileDrop, false) is string[] filePath) { emulator.Add(filePath[0]); } else { Reporter.Warn("Something is wrong with the file path you dropped."); } } }
/// <summary> /// Implement IDB.CachePlatfomrReleases(). Go out to giantbomb.com and cache all known releases for the specified platform. Update the list of releases and store metadata for each one. /// </summary> /// <param name="platform">Robin.Platform associated with the GBPlatform to cache.</param> public void CachePlatformReleases(Platform platform, bool reset = false) { using (WebClient webClient = new WebClient()) { GBPlatform gbPlatform = platform.GBPlatform; string startDate = reset ? @"1900-01-01 01:01:01" : gbPlatform.CacheDate.ToString(DATEFORMAT); string endDate = DateTime.Now.ToString(DATEFORMAT); int N_results; bool haveResults; XDocument xdoc; Reporter.Report($"Checking GiantBomb for {gbPlatform.Title} releases..."); string url = $"http://www.giantbomb.com/api/releases/?api_key={Keys.GiantBomb}&filter=date_last_updated:{startDate}|{endDate},platform:{gbPlatform.ID}&field_list=id&sort=id:asc"; if (webClient.SafeDownloadStringDB(url, out string downloadText)) { xdoc = XDocument.Parse(downloadText); haveResults = int.TryParse(xdoc.SafeGetB("number_of_total_results"), out N_results); } else { Reporter.Warn("Error communicating with GiantBomb."); return; } // If there are results, go through them if (haveResults && N_results != 0) { Dictionary <long, GBRelease> existingGbReleaseDict = R.Data.GBReleases.ToDictionary(x => x.ID); ILookup <long?, Release> releaseLookupByGB_ID = R.Data.Releases.Where(x => x.ID_GB != null).ToLookup(x => x.ID_GB); HashSet <GBRelease> newGbReleases = new HashSet <GBRelease>(); int N_pages = N_results / 100; Reporter.Report($"Found {N_results} {gbPlatform.Title} releases in GiantBomb"); // Just do the first page again to save code then go through the rest of the results Reporter.Report("Loading sheet "); for (int i = 0; i <= N_pages; i++) { Reporter.ReportInline(" " + i); url = $"http://www.giantbomb.com/api/releases/?api_key={Keys.GiantBomb}&filter=date_last_updated:{startDate}|{endDate}platform:{gbPlatform.ID}&offset={i * 100}&field_list=id,deck,game,image,region,name,maximum_players,release_date&sort=id:asc"; // Put results into the GB Cache database if (webClient.SafeDownloadStringDB(url, out downloadText)) { xdoc = XDocument.Parse(downloadText); foreach (XElement element in xdoc.Root.Element("results").Elements("release")) { // If the ID XML value was found if (int.TryParse(element.SafeGetA("id"), out int id)) { // Don't create this game if the title is null string title = element.SafeGetA("name"); if (string.IsNullOrEmpty(title)) { continue; } // Check if GBRelease is in database prior to this update, else add it if (!existingGbReleaseDict.TryGetValue(id, out GBRelease gbRelease)) { gbRelease = new GBRelease { ID = id, GBPlatform = platform.GBPlatform }; newGbReleases.Add(gbRelease); } // If a release has changed platforms, catch it and zero out match if (gbRelease.GBPlatform_ID != gbPlatform.ID) { gbRelease.GBPlatform_ID = gbPlatform.ID; if (releaseLookupByGB_ID[gbRelease.ID].Any()) { foreach (Release release in releaseLookupByGB_ID[gbRelease.ID]) { release.ID_GB = null; } } } gbRelease.Title = title; gbRelease.Overview = element.SafeGetA("deck"); if (int.TryParse(element.SafeGetA("game", "id"), out id)) { gbRelease.GBGame_ID = id; } if (int.TryParse(element.SafeGetA("maximum_players"), out id)) { gbRelease.Players = id.ToString(); } gbRelease.GBPlatform_ID = gbPlatform.ID; if (int.TryParse(element.SafeGetA("region", "id"), out id)) { gbRelease.Region = R.Data.Regions.FirstOrDefault(x => x.ID_GB == id) ?? R.Data.Regions.FirstOrDefault(x => x.Title.Contains("Unk")); } gbRelease.Date = DateTimeRoutines.SafeGetDate(element.SafeGetA("release_date")); gbRelease.BoxURL = element.SafeGetA("image", "medium_url"); gbRelease.ScreenURL = element.SafeGetA("image", "screen_url"); } } } else { Reporter.Warn("Failure connecting to GiantBomb"); return; } } R.Data.GBReleases.AddRange(newGbReleases); Reporter.ReportInline("Finished."); } else { Reporter.Report("No releases returned by GiantBomb"); return; } } // end using webclient }
public void CachePlatformGames(Platform platform, bool reset = false) { GBPlatform gbPlatform = platform.GBPlatform; string startDate = reset ? @"1900-01-01 01:01:01" : gbPlatform.CacheDate.ToString(DATEFORMAT); string endDate = DateTime.Now.ToString(DATEFORMAT); using (WebClient webClient = new WebClient()) { int N_results; bool haveResults; XDocument xdoc; Reporter.Report("Checking GiantBomb for " + platform.Title + " games"); var url = $"http://www.giantbomb.com/api/games/?api_key={Keys.GiantBomb}&filter=date_last_updated:{startDate}|{endDate},platforms:{gbPlatform.ID}&field_list=id&sort=id:asc"; if (webClient.SafeDownloadStringDB(url, out var downloadText)) { xdoc = XDocument.Parse(downloadText); haveResults = int.TryParse(xdoc.SafeGetB("number_of_total_results"), out N_results); } else { Reporter.Report("Error communicating with GiantBomb."); return; } // If there are results, go through them if (haveResults && N_results != 0) { int N_pages = N_results / 100; Reporter.Report("Found " + N_results + " games in GiantBomb"); Reporter.Report("Loading sheet "); // Just do the first page again to save code then go through the rest of the results for (int i = 0; i <= N_pages; i++) { Reporter.ReportInline(i + " "); url = $"http://www.giantbomb.com/api/games/?api_key={Keys.GiantBomb}&filter=date_last_updated:{startDate}|{endDate},platforms:{gbPlatform.ID}&offset={i * 100}&field_list=id,deck,developers,publishers,genres,image,name,release_date&sort=id:asc"; // Put results into the GB Cache database if (webClient.SafeDownloadStringDB(url, out downloadText)) { xdoc = XDocument.Parse(downloadText); foreach (XElement element in xdoc.Root.Element("results").Elements("game")) { // If the ID XML value was found if (int.TryParse(element.SafeGetA("id"), out var intCatcher)) { GBGame gbGame = R.Data.GBGames.FirstOrDefault(x => x.ID == intCatcher); if (gbGame == null) { gbGame = new GBGame { ID = intCatcher }; gbPlatform.GBGames.Add(gbGame); } gbGame.Title = element.SafeGetA("name"); gbGame.Overview = element.SafeGetA("deck"); gbGame.GBPlatform_ID = gbPlatform.ID; gbGame.Date = DateTimeRoutines.SafeGetDate(element.SafeGetA("release_date")); gbGame.BoxFrontURL = element.SafeGetA("image", "medium_url"); gbGame.ScreenURL = element.SafeGetA("image", "screen_url"); } } } else { Reporter.Warn("Failure connecting to GiantBomb"); return; } } Reporter.Report("Finished."); } else { Reporter.Report("No results returned by GiantBomb"); return; } } // end using webclient }