//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); } }
//File and folder actions private async Task FilePicker_Actions() { try { //Get the selected list item DataBindFile selectedItem = (DataBindFile)lb_FilePicker.SelectedItem; //Check if actions are available if (vFilePickerCurrentPath == "PC" && selectedItem.FileType != FileType.FolderDisc) { Debug.WriteLine("File and folders action cancelled, no actions available."); await Notification_Send_Status("Close", "No actions available"); return; } //Check the selected file type if (selectedItem.FileType == FileType.UwpApp) { //Add answers for messagebox List <DataBindString> Answers = new List <DataBindString>(); DataBindString answerUpdate = new DataBindString(); answerUpdate.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/Refresh.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); answerUpdate.Name = "Check application update"; Answers.Add(answerUpdate); DataBindString answerRemove = new DataBindString(); answerRemove.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/RemoveCross.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); answerRemove.Name = "Remove the application"; Answers.Add(answerRemove); //Show the messagebox prompt DataBindString messageResult = await Popup_Show_MessageBox("Application actions", "", "Please select an action that you want to use on: " + selectedItem.Name, Answers); if (messageResult != null) { //Update application if (messageResult == answerUpdate) { await UwpListUpdateApplication(selectedItem); } //Remove application else if (messageResult == answerRemove) { await UwpListRemoveApplication(selectedItem); } } } else if (selectedItem.FileType == FileType.FolderDisc) { //Add answers for messagebox List <DataBindString> Answers = new List <DataBindString>(); DataBindString answerEjectDisc = new DataBindString(); answerEjectDisc.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/Eject.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); answerEjectDisc.Name = "Eject disc or unmount the image"; Answers.Add(answerEjectDisc); //Show the messagebox prompt DataBindString messageResult = await Popup_Show_MessageBox("Application actions", "", "Please select an action that you want to use on: " + selectedItem.Name, Answers); if (messageResult != null && messageResult == answerEjectDisc) { await FilePicker_EjectDrive(selectedItem, selectedItem.PathFile); } } else { //Add answers for messagebox List <DataBindString> Answers = new List <DataBindString>(); //Check the file type bool preFile = selectedItem.FileType == FileType.FolderPre || selectedItem.FileType == FileType.FilePre || selectedItem.FileType == FileType.GoUpPre; //Count checked items int checkedItems = List_FilePicker.Count(x => x.Checked == Visibility.Visible); //Check the sorting type string sortType = string.Empty; if (vFilePickerSortType == SortingType.Name) { sortType = "Sort files and folders by date"; } else { sortType = "Sort files and folders by name"; } DataBindString answerSort = new DataBindString(); answerSort.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/Sorting.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); answerSort.Name = sortType; Answers.Add(answerSort); DataBindString answerCopySingle = new DataBindString(); if (!preFile) { answerCopySingle.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/Copy.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); answerCopySingle.Name = "Copy the file or folder"; Answers.Add(answerCopySingle); } DataBindString answerCopyChecked = new DataBindString(); if (checkedItems > 0) { answerCopyChecked.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/Copy.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); answerCopyChecked.Name = "Copy selected files and folders"; Answers.Add(answerCopyChecked); } DataBindString answerCutSingle = new DataBindString(); if (!preFile) { answerCutSingle.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/Cut.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); answerCutSingle.Name = "Cut the file or folder"; Answers.Add(answerCutSingle); } DataBindString answerCutChecked = new DataBindString(); if (checkedItems > 0) { answerCutChecked.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/Cut.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); answerCutChecked.Name = "Cut selected files and folders"; Answers.Add(answerCutChecked); } DataBindString answerPaste = new DataBindString(); if (vClipboardFiles.Count == 1) { DataBindFile clipboardFile = vClipboardFiles.FirstOrDefault(); answerPaste.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/Paste.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); answerPaste.Name = "Paste (" + clipboardFile.FileType.ToString() + " " + clipboardFile.ClipboardType.ToString() + ") " + clipboardFile.Name; Answers.Add(answerPaste); } else if (vClipboardFiles.Count > 1) { int copyCount = vClipboardFiles.Count(x => x.ClipboardType == ClipboardType.Copy); int cutCount = vClipboardFiles.Count(x => x.ClipboardType == ClipboardType.Cut); string statusCount = string.Empty; if (copyCount > cutCount) { statusCount = "(" + copyCount + "x copy)"; } else { statusCount = "(" + cutCount + "x cut)"; } answerPaste.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/Paste.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); answerPaste.Name = "Paste " + statusCount + " files or folders"; Answers.Add(answerPaste); } DataBindString answerRename = new DataBindString(); if (!preFile) { answerRename.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/Rename.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); answerRename.Name = "Rename the file or folder"; Answers.Add(answerRename); } DataBindString answerRemoveSingle = new DataBindString(); if (!preFile) { answerRemoveSingle.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/Remove.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); answerRemoveSingle.Name = "Remove the file or folder"; Answers.Add(answerRemoveSingle); } DataBindString answerRemoveChecked = new DataBindString(); if (checkedItems > 0) { answerRemoveChecked.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/Remove.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); answerRemoveChecked.Name = "Remove selected files and folders"; Answers.Add(answerRemoveChecked); } DataBindString answerDownloadRomInfo = new DataBindString(); if (!preFile && vFilePickerShowRoms) { answerDownloadRomInfo.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/Download.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); answerDownloadRomInfo.Name = "Download game information"; Answers.Add(answerDownloadRomInfo); } DataBindString answerDownloadConsoleInfo = new DataBindString(); if (!preFile && vFilePickerShowRoms) { answerDownloadConsoleInfo.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/Download.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); answerDownloadConsoleInfo.Name = "Download console information"; Answers.Add(answerDownloadConsoleInfo); } DataBindString answerCreateFolder = new DataBindString(); answerCreateFolder.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/FolderAdd.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); answerCreateFolder.Name = "Create a new folder here"; Answers.Add(answerCreateFolder); DataBindString answerCreateTextFile = new DataBindString(); answerCreateTextFile.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Extensions/Txt.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); answerCreateTextFile.Name = "Create a new text file here"; Answers.Add(answerCreateTextFile); //Show the messagebox prompt DataBindString messageResult = await Popup_Show_MessageBox("File and folder actions", "", "Please select an action that you want to use on: " + selectedItem.Name, Answers); if (messageResult != null) { //Sort files and folders if (messageResult == answerSort) { await FilePicker_SortFilesFoldersSwitch(false); } //Copy file or folder else if (messageResult == answerCopySingle) { await FilePicker_FileCopy_Single(selectedItem); } else if (messageResult == answerCopyChecked) { await FilePicker_FileCopy_Checked(); } //Cut file or folder else if (messageResult == answerCutSingle) { await FilePicker_FileCut_Single(selectedItem); } else if (messageResult == answerCutChecked) { await FilePicker_FileCut_Checked(); } //Paste file or folder else if (messageResult == answerPaste) { async void TaskAction() { try { await FilePicker_FilePaste(); } catch { } } await AVActions.TaskStart(TaskAction); } //Rename file or folder else if (messageResult == answerRename) { await FilePicker_FileRename(selectedItem); } //Create a new folder else if (messageResult == answerCreateFolder) { await FilePicker_CreateFolder(); } //Create a new text file else if (messageResult == answerCreateTextFile) { await FilePicker_CreateTextFile(); } //Remove file or folder else if (messageResult == answerRemoveSingle) { await FilePicker_FileRemove_Single(selectedItem); } else if (messageResult == answerRemoveChecked) { await FilePicker_FileRemove_Checked(); } //Download game information else if (messageResult == answerDownloadRomInfo) { DownloadInfoGame informationDownloaded = await DownloadInfoGame(selectedItem.Name, 210, false); if (informationDownloaded != null) { selectedItem.Description = ApiIGDB_GameSummaryString(informationDownloaded.Details); if (informationDownloaded.ImageBitmap != null) { selectedItem.ImageBitmap = informationDownloaded.ImageBitmap; } } } //Download console information else if (messageResult == answerDownloadConsoleInfo) { DownloadInfoConsole informationDownloaded = await DownloadInfoConsole(selectedItem.Name, 210); if (informationDownloaded != null) { selectedItem.Description = ApiIGDB_ConsoleSummaryString(informationDownloaded.Details); if (informationDownloaded.ImageBitmap != null) { selectedItem.ImageBitmap = informationDownloaded.ImageBitmap; } } } } } } catch { } }