static public async Task <bool> Feeds(bool Silent, bool EnableUI) { try { if (!Silent) { await EventProgressDisableUI("Downloading latest feeds...", true); } System.Diagnostics.Debug.WriteLine("Downloading latest feeds..."); string[][] RequestHeader = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppVariables.ApplicationSettings["ConnectApiAuth"].ToString() } }; string DownloadString = await AVDownloader.DownloadStringAsync(10000, "News Scroll", RequestHeader, new Uri(ApiConnectionUrl + "subscription/list?output=json")); JObject WebJObject = JObject.Parse(DownloadString); if (WebJObject["subscriptions"] != null && WebJObject["subscriptions"].HasValues) { if (!Silent) { await EventProgressDisableUI("Processing " + WebJObject["subscriptions"].Count() + " feeds...", true); } System.Diagnostics.Debug.WriteLine("Processing " + WebJObject["subscriptions"].Count() + " feeds..."); List <string> ApiFeedIdList = new List <string>(); IReadOnlyList <IStorageItem> LocalFileList = await ApplicationData.Current.LocalFolder.GetItemsAsync(); List <TableFeeds> TableUpdatedFeeds = new List <TableFeeds>(); List <TableFeeds> TableCurrentFeeds = await SQLConnection.Table <TableFeeds>().ToListAsync(); foreach (JToken JTokenRoot in WebJObject["subscriptions"]) { string FeedId = JTokenRoot["sortid"].ToString(); string FeedTitle = JTokenRoot["title"].ToString(); string HtmlUrl = WebUtility.HtmlDecode(JTokenRoot["htmlUrl"].ToString()); HtmlUrl = WebUtility.UrlDecode(HtmlUrl); Uri FullUrl = new Uri(HtmlUrl); ApiFeedIdList.Add(FeedId); TableFeeds TableResult = TableCurrentFeeds.Where(x => x.feed_id == FeedId).FirstOrDefault(); if (TableResult == null) { //System.Diagnostics.Debug.WriteLine("Adding feed: " + FeedTitle); TableFeeds AddFeed = new TableFeeds(); AddFeed.feed_id = FeedId; AddFeed.feed_title = FeedTitle; AddFeed.feed_link = FullUrl.Scheme + "://" + FullUrl.Host; AddFeed.feed_ignore_status = false; if (JTokenRoot["categories"] != null && JTokenRoot["categories"].HasValues) { AddFeed.feed_folder = JTokenRoot["categories"][0]["label"].ToString(); } TableUpdatedFeeds.Add(AddFeed); } else { //System.Diagnostics.Debug.WriteLine("Updating feed: " + FeedTitle); TableResult.feed_title = FeedTitle; TableResult.feed_link = FullUrl.Scheme + "://" + FullUrl.Host; if (JTokenRoot["categories"] != null && JTokenRoot["categories"].HasValues) { TableResult.feed_folder = JTokenRoot["categories"][0]["label"].ToString(); } TableUpdatedFeeds.Add(TableResult); } //Check and download feed logo if (!LocalFileList.Any(x => x.Name == FeedId + ".png")) { try { if (!Silent) { await EventProgressDisableUI("Downloading " + FeedTitle + " icon...", true); } Uri IconUrl = new Uri("https://s2.googleusercontent.com/s2/favicons?domain=" + FullUrl.Host); byte[] HttpFeedIcon = await AVDownloader.DownloadByteAsync(3000, "News Scroll", null, IconUrl); if (HttpFeedIcon != null && HttpFeedIcon.Length > 75) { await AVFile.SaveBytes(FeedId + ".png", HttpFeedIcon); System.Diagnostics.Debug.WriteLine("Downloaded transparent logo: " + HttpFeedIcon.Length + "bytes/" + IconUrl); } else { System.Diagnostics.Debug.WriteLine("No logo found for: " + IconUrl); } } catch { } } } //Update the feeds in database if (TableUpdatedFeeds.Any()) { await SQLConnection.InsertAllAsync(TableUpdatedFeeds, "OR REPLACE"); } //Delete removed feeds from the database List <string> DeletedFeeds = TableCurrentFeeds.Select(x => x.feed_id).Except(ApiFeedIdList).ToList(); System.Diagnostics.Debug.WriteLine("Found deleted feeds: " + DeletedFeeds.Count()); foreach (string DeleteFeedId in DeletedFeeds) { await DeleteFeed(DeleteFeedId); } } if (EnableUI) { await EventProgressEnableUI(); } return(true); } catch { await EventProgressEnableUI(); return(false); } }
//Download console information public async Task <DownloadInfoConsole> DownloadInfoConsole(string nameConsole, int imageWidth) { try { //Filter the name string nameConsoleSave = FilterNameRom(nameConsole, true, false, false, 0); //Show the text input popup string nameConsoleDownload = await Popup_ShowHide_TextInput("Console search", nameConsoleSave, "Search information for the console", true); if (string.IsNullOrWhiteSpace(nameConsoleDownload)) { Debug.WriteLine("No search term entered."); return(null); } nameConsoleDownload = FilterNameRom(nameConsoleDownload, false, true, false, 0); //Search for consoles IEnumerable <ApiIGDBPlatforms> iGDBPlatforms = vApiIGDBPlatforms.Where(x => FilterNameRom(x.name, false, true, false, 0).Contains(nameConsoleDownload) || (x.alternative_name != null && FilterNameRom(x.alternative_name, false, true, false, 0).Contains(nameConsoleDownload))); if (iGDBPlatforms == null || !iGDBPlatforms.Any()) { Debug.WriteLine("No consoles found"); await Notification_Send_Status("Close", "No consoles found"); return(null); } //Ask user which console to download List <DataBindString> Answers = new List <DataBindString>(); BitmapImage imageAnswer = FileToBitmapImage(new string[] { "Assets/Default/Icons/Emulator.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); foreach (ApiIGDBPlatforms infoPlatforms in iGDBPlatforms) { DataBindString answerDownload = new DataBindString(); answerDownload.ImageBitmap = imageAnswer; answerDownload.Name = infoPlatforms.name; answerDownload.NameSub = infoPlatforms.alternative_name; answerDownload.Data1 = infoPlatforms; Answers.Add(answerDownload); } //Get selected result DataBindString messageResult = await Popup_Show_MessageBox("Select a found console (" + Answers.Count() + ")", "* Information will be saved in the \"Assets\\User\\Games\\Downloaded\" folder as:\n" + nameConsoleSave, "Download image and description for the console:", Answers); if (messageResult == null) { Debug.WriteLine("No console selected"); return(null); } //Create downloaded directory AVFiles.Directory_Create("Assets/User/Games/Downloaded", false); //Convert result back to json ApiIGDBPlatforms selectedConsole = (ApiIGDBPlatforms)messageResult.Data1; await Notification_Send_Status("Download", "Downloading information"); Debug.WriteLine("Downloading information for: " + nameConsole); //Get the platform versions id string firstPlatformId = selectedConsole.versions.FirstOrDefault().ToString(); ApiIGDBPlatformVersions[] iGDBPlatformVersions = await ApiIGDBDownloadPlatformVersions(firstPlatformId); if (iGDBPlatformVersions == null || !iGDBPlatformVersions.Any()) { Debug.WriteLine("No information found"); await Notification_Send_Status("Close", "No information found"); return(null); } ApiIGDBPlatformVersions targetPlatformVersions = iGDBPlatformVersions.FirstOrDefault(); await Notification_Send_Status("Download", "Downloading image"); Debug.WriteLine("Downloading image for: " + nameConsole); //Get the image url BitmapImage downloadedBitmapImage = null; string downloadImageId = targetPlatformVersions.platform_logo.ToString(); if (downloadImageId != "0") { ApiIGDBImage[] iGDBImages = await ApiIGDB_DownloadImage(downloadImageId, "platform_logos"); if (iGDBImages == null || !iGDBImages.Any()) { Debug.WriteLine("No images found"); await Notification_Send_Status("Close", "No images found"); return(null); } //Download and save image ApiIGDBImage infoImages = iGDBImages.FirstOrDefault(); Uri imageUri = new Uri("https://images.igdb.com/igdb/image/upload/t_720p/" + infoImages.image_id + ".png"); byte[] imageBytes = await AVDownloader.DownloadByteAsync(5000, "CtrlUI", null, imageUri); if (imageBytes != null && imageBytes.Length > 256) { try { //Convert bytes to a BitmapImage downloadedBitmapImage = BytesToBitmapImage(imageBytes, imageWidth); //Save bytes to image file File.WriteAllBytes("Assets/User/Games/Downloaded/" + nameConsoleSave + ".png", imageBytes); Debug.WriteLine("Saved image: " + imageBytes.Length + "bytes/" + imageUri); } catch { } } } //Json settings JsonSerializerSettings jsonSettings = new JsonSerializerSettings(); jsonSettings.NullValueHandling = NullValueHandling.Ignore; //Json serialize string serializedObject = JsonConvert.SerializeObject(targetPlatformVersions, jsonSettings); //Save json information File.WriteAllText("Assets/User/Games/Downloaded/" + nameConsoleSave + ".json", serializedObject); await Notification_Send_Status("Download", "Downloaded information"); Debug.WriteLine("Downloaded and saved information for: " + nameConsole); //Return the information DownloadInfoConsole downloadInfo = new DownloadInfoConsole(); downloadInfo.ImageBitmap = downloadedBitmapImage; downloadInfo.Details = targetPlatformVersions; return(downloadInfo); } catch (Exception ex) { Debug.WriteLine("Failed downloading console information: " + ex.Message); await Notification_Send_Status("Close", "Failed downloading"); return(null); } }
//Download game information public async Task <DownloadInfoGame> DownloadInfoGame(string nameRom, int imageWidth, bool saveOriginalName) { try { //Filter the game name string nameRomSaveOriginal = FilterNameFile(nameRom); string nameRomSaveFilter = FilterNameRom(nameRom, true, false, true, 0); //Show the text input popup string nameRomDownload = await Popup_ShowHide_TextInput("Game search", nameRomSaveFilter, "Search information for the game", true); if (string.IsNullOrWhiteSpace(nameRomDownload)) { Debug.WriteLine("No search term entered."); return(null); } nameRomDownload = nameRomDownload.ToLower(); await Notification_Send_Status("Download", "Downloading information"); Debug.WriteLine("Downloading information for: " + nameRom); //Download available games IEnumerable <ApiIGDBGames> iGDBGames = await ApiIGDB_DownloadGames(nameRomDownload); if (iGDBGames == null || !iGDBGames.Any()) { Debug.WriteLine("No games found"); await Notification_Send_Status("Close", "No games found"); return(null); } //Ask user which game to download List <DataBindString> Answers = new List <DataBindString>(); BitmapImage imageAnswer = FileToBitmapImage(new string[] { "Assets/Default/Icons/Game.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); foreach (ApiIGDBGames infoGames in iGDBGames) { //Check if information is available if (infoGames.cover == 0 && string.IsNullOrWhiteSpace(infoGames.summary)) { continue; } //Release date string gameReleaseDate = string.Empty; string gameReleaseYear = string.Empty; ApiIGDB_ReleaseDateToString(infoGames, out gameReleaseDate, out gameReleaseYear); //Game platforms string gamePlatforms = string.Empty; if (infoGames.platforms != null) { foreach (int platformId in infoGames.platforms) { ApiIGDBPlatforms apiIGDBPlatforms = vApiIGDBPlatforms.Where(x => x.id == platformId).FirstOrDefault(); gamePlatforms = AVFunctions.StringAdd(gamePlatforms, apiIGDBPlatforms.name, ","); } } DataBindString answerDownload = new DataBindString(); answerDownload.ImageBitmap = imageAnswer; answerDownload.Name = infoGames.name; answerDownload.NameSub = gamePlatforms; answerDownload.NameDetail = gameReleaseYear; answerDownload.Data1 = infoGames; Answers.Add(answerDownload); } //Get selected result DataBindString messageResult = await Popup_Show_MessageBox("Select a found game (" + Answers.Count() + ")", "* Information will be saved in the \"Assets\\User\\Games\\Downloaded\" folder as:\n" + nameRomSaveFilter, "Download image and description for the game:", Answers); if (messageResult == null) { Debug.WriteLine("No game selected"); return(null); } //Create downloaded directory AVFiles.Directory_Create("Assets/User/Games/Downloaded", false); //Convert result back to json ApiIGDBGames selectedGame = (ApiIGDBGames)messageResult.Data1; await Notification_Send_Status("Download", "Downloading image"); Debug.WriteLine("Downloading image for: " + nameRom); //Get the image url BitmapImage downloadedBitmapImage = null; string downloadImageId = selectedGame.cover.ToString(); if (downloadImageId != "0") { ApiIGDBImage[] iGDBImages = await ApiIGDB_DownloadImage(downloadImageId, "covers"); if (iGDBImages == null || !iGDBImages.Any()) { Debug.WriteLine("No images found"); await Notification_Send_Status("Close", "No images found"); return(null); } //Download and save image ApiIGDBImage infoImages = iGDBImages.FirstOrDefault(); Uri imageUri = new Uri("https://images.igdb.com/igdb/image/upload/t_720p/" + infoImages.image_id + ".png"); byte[] imageBytes = await AVDownloader.DownloadByteAsync(5000, "CtrlUI", null, imageUri); if (imageBytes != null && imageBytes.Length > 256) { try { //Convert bytes to a BitmapImage downloadedBitmapImage = BytesToBitmapImage(imageBytes, imageWidth); //Save bytes to image file if (saveOriginalName) { File.WriteAllBytes("Assets/User/Games/Downloaded/" + nameRomSaveOriginal + ".png", imageBytes); } else { File.WriteAllBytes("Assets/User/Games/Downloaded/" + nameRomSaveFilter + ".png", imageBytes); } Debug.WriteLine("Saved image: " + imageBytes.Length + "bytes/" + imageUri); } catch { } } } //Json settings JsonSerializerSettings jsonSettings = new JsonSerializerSettings(); jsonSettings.NullValueHandling = NullValueHandling.Ignore; //Json serialize string serializedObject = JsonConvert.SerializeObject(selectedGame, jsonSettings); //Save json information if (saveOriginalName) { File.WriteAllText("Assets/User/Games/Downloaded/" + nameRomSaveOriginal + ".json", serializedObject); } else { File.WriteAllText("Assets/User/Games/Downloaded/" + nameRomSaveFilter + ".json", serializedObject); } await Notification_Send_Status("Download", "Downloaded information"); Debug.WriteLine("Downloaded and saved information for: " + nameRom); //Return the information DownloadInfoGame downloadInfo = new DownloadInfoGame(); downloadInfo.ImageBitmap = downloadedBitmapImage; downloadInfo.Details = selectedGame; return(downloadInfo); } catch (Exception ex) { Debug.WriteLine("Failed downloading game information: " + ex.Message); await Notification_Send_Status("Close", "Failed downloading"); return(null); } }
//Save the image private async void button_iconSave_Tap(object sender, RoutedEventArgs e) { try { if (!string.IsNullOrWhiteSpace(vBitmapLink)) { //Check internet connection if (!AppVariables.InternetAccess) { await new MessagePopup().OpenPopup("Failed to save", "Failed to save the image, please check your internet connection and try again.", "Ok", "", "", "", "", false); System.Diagnostics.Debug.WriteLine("Failed to download the image, no internet access."); return; } //Get the file name string FileName = "Unknown"; try { FileName = Path.GetFileNameWithoutExtension(vBitmapLink); } catch { } if (string.IsNullOrWhiteSpace(FileName)) { FileName = "Unknown"; } //Get the file extension string FileExtensionFile = ".jpg"; string FileExtensionDisplay = "JPG"; try { FileExtensionFile = Path.GetExtension(vBitmapLink).ToLower(); } catch { } if (string.IsNullOrWhiteSpace(FileExtensionFile)) { FileExtensionFile = ".jpg"; } FileExtensionDisplay = FileExtensionFile.ToUpper().Replace(".", string.Empty); FileSavePicker saveFilePicker = new FileSavePicker(); saveFilePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; saveFilePicker.FileTypeChoices.Add(FileExtensionDisplay, new List <string>() { FileExtensionFile }); saveFilePicker.SuggestedFileName = FileName; StorageFile saveStorageFile = await saveFilePicker.PickSaveFileAsync(); if (saveStorageFile != null) { System.Diagnostics.Debug.WriteLine("Downloading and saving online image: " + vBitmapLink); await EventProgressDisableUI("Downloading and saving image...", false); Uri imageUri = new Uri(vBitmapLink); byte[] ImageBuffer = await AVDownloader.DownloadByteAsync(10000, "News Scroll", null, imageUri); if (ImageBuffer != null) { await FileIO.WriteBytesAsync(saveStorageFile, ImageBuffer); } else { await new MessagePopup().OpenPopup("Failed to save", "Failed to save the image, please check your internet connection and try again.", "Ok", "", "", "", "", false); System.Diagnostics.Debug.WriteLine("Failed to download the image, no internet access."); } await EventProgressEnableUI(); } } } catch (Exception ex) { await new MessagePopup().OpenPopup("Failed to save", "Failed to save the image, please check your internet connection and try again.", "Ok", "", "", "", "", false); System.Diagnostics.Debug.WriteLine("Failed to save the image: " + ex.Message); await EventProgressEnableUI(); } }
//Save the image private async void button_iconSave_Tap(object sender, RoutedEventArgs e) { try { if (vBitmapImage != null && vBitmapImage.PixelHeight > 0) { //Get the url path string UrlPath = string.Empty; try { UrlPath = vBitmapImage.UriSource.AbsolutePath; } catch { } if (string.IsNullOrWhiteSpace(UrlPath)) { UrlPath = vBitmapImage.UriSource.ToString(); } //Get the file name string FileName = "Unknown"; try { FileName = Path.GetFileNameWithoutExtension(UrlPath); } catch { } if (string.IsNullOrWhiteSpace(FileName)) { FileName = "Unknown"; } //Check if network is available bool IsNetworkAvailable = NetworkInterface.GetIsNetworkAvailable(); //Get the file extension string FileExtensionFile = ".jpg"; string FileExtensionDisplay = "JPG"; if (IsNetworkAvailable) { try { FileExtensionFile = Path.GetExtension(UrlPath).ToLower(); } catch { } if (string.IsNullOrWhiteSpace(FileExtensionFile)) { FileExtensionFile = ".jpg"; } FileExtensionDisplay = FileExtensionFile.ToUpper().Replace(".", string.Empty); } else { int MessageResult = await new MessagePopup().Popup("Offline saving", "Saving images while in offline mode may save the image in a lower quality and animations will be saved as a static image.", "Save image", "", "", "", "", true); if (MessageResult == 0) { return; } } FileSavePicker FileSavePicker = new FileSavePicker(); FileSavePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; FileSavePicker.FileTypeChoices.Add(FileExtensionDisplay, new List <string>() { FileExtensionFile }); FileSavePicker.SuggestedFileName = FileName; StorageFile NewFile = await FileSavePicker.PickSaveFileAsync(); if (NewFile != null) { //Download the bitmapimage source uri if (IsNetworkAvailable) { System.Diagnostics.Debug.WriteLine("Saving online image..."); byte[] ImageBuffer = await AVDownloader.DownloadByteAsync(10000, "News Scroll", null, vBitmapImage.UriSource); if (ImageBuffer != null) { await FileIO.WriteBytesAsync(NewFile, ImageBuffer); } else { await new MessagePopup().Popup("Failed to save", "Failed to save the image, please check your internet connection and try again.", "Ok", "", "", "", "", false); System.Diagnostics.Debug.WriteLine("Failed to download the image."); } } //Capture the image displayed in xaml else { System.Diagnostics.Debug.WriteLine("Saving offline image..."); ////Set the image size temporarily to bitmap size //Double PreviousWidth = image_ImageViewer.ActualWidth; //Double PreviousHeight = image_ImageViewer.ActualHeight; //image_ImageViewer.Width = vBitmapImage.PixelWidth; //image_ImageViewer.Height = vBitmapImage.PixelHeight; //Fix RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(); await renderTargetBitmap.RenderAsync(image_source); IBuffer PixelBuffer = await renderTargetBitmap.GetPixelsAsync(); using (IRandomAccessStream fileStream = await NewFile.OpenAsync(FileAccessMode.ReadWrite)) { BitmapEncoder bitmapEncoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, fileStream); bitmapEncoder.SetPixelData( BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)renderTargetBitmap.PixelWidth, (uint)renderTargetBitmap.PixelHeight, DisplayInformation.GetForCurrentView().LogicalDpi, DisplayInformation.GetForCurrentView().LogicalDpi, PixelBuffer.ToArray()); await bitmapEncoder.FlushAsync(); } //System.Diagnostics.Debug.WriteLine("From: " + image_ImageViewer.Width + " setting back: " + PreviousWidth); //image_ImageViewer.Width = PreviousWidth; //image_ImageViewer.Height = PreviousHeight; } } } } catch { await new MessagePopup().Popup("Failed to save", "Failed to save the image, please check your internet connection and try again.", "Ok", "", "", "", "", false); System.Diagnostics.Debug.WriteLine("Failed to save the image."); } }