//Go up a folder in the file picker async Task FilePicker_GoFolderUp() { try { if (grid_Popup_FilePicker_button_ControllerUp.Visibility == Visibility.Visible) { //Read the root path DataBindFile dataBindFile = List_FilePicker.Where(x => x.FileType == FileType.GoUpPre).FirstOrDefault(); if (dataBindFile != null) { Debug.WriteLine("Folder up: " + dataBindFile.PathFile); await Popup_Show_FilePicker(dataBindFile.PathFile, -1, true, null); } else { Debug.WriteLine("No folder to navigate go up / no up."); await Notification_Send_Status("Up", "No folder to go up"); } } } catch { Debug.WriteLine("No folder to navigate go up / catch."); await Notification_Send_Status("Up", "No folder to go up"); } }
//File Picker focus on item async Task <bool> FilePicker_Focus(int targetIndex, string targetPath) { try { //Get navigation history index if (targetIndex == -1) { targetIndex = FilePicker_NavigationHistoryGetIndex(targetPath); } //Check the navigation index if (targetIndex == -1 && !string.IsNullOrWhiteSpace(vFilePickerSourcePath)) { DataBindFile sourceFileItem = List_FilePicker.Where(x => x.PathFile == vFilePickerSourcePath).FirstOrDefault(); if (sourceFileItem != null) { Debug.WriteLine("Source file path found: " + vFilePickerSourcePath); //Focus on the file picker listbox item await ListBoxFocusItem(lb_FilePicker, sourceFileItem, vProcessCurrent.MainWindowHandle); return(true); } } //Focus on the file picker listbox index await ListboxFocusIndex(lb_FilePicker, false, false, targetIndex, vProcessCurrent.MainWindowHandle); return(true); } catch { } return(false); }
//Close file picker popup async Task Popup_Close_FilePicker(bool IsCompleted, bool CurrentFolder) { try { PlayInterfaceSound(vConfigurationCtrlUI, "PopupClose", false, false); //Cancel file picker load while (vFilePickerLoadBusy) { vFilePickerLoadCancel = true; await Task.Delay(100); } //Reset file picker variables vFilePickerOpen = false; if (IsCompleted) { vFilePickerCompleted = true; if (CurrentFolder) { DataBindFile targetPath = new DataBindFile(); targetPath.PathFile = vFilePickerCurrentPath; vFilePickerResult = targetPath; } else { vFilePickerResult = (DataBindFile)lb_FilePicker.SelectedItem; } } else { vFilePickerCancelled = true; } //Update the navigation history index FilePicker_NavigationHistoryAddUpdate(vFilePickerCurrentPath, lb_FilePicker.SelectedIndex); //Update the previous picker path if (vFilePickerCurrentPath[1] == ':') { vFilePickerPreviousPath = vFilePickerCurrentPath; } //Clear the current file picker list List_FilePicker.Clear(); //Hide the popup Popup_Hide_Element(grid_Popup_FilePicker); //Focus on the previous focus element await FrameworkElementFocusFocus(vFilePickerElementFocus, vProcessCurrent.MainWindowHandle); } catch { } }
async Task FilePicker_FileRemove_Checked() { try { //Confirm file remove prompt List <DataBindString> messageAnswers = new List <DataBindString>(); DataBindString answerRecycle = new DataBindString(); answerRecycle.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/Remove.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); answerRecycle.Name = "Move files or folders to recycle bin*"; messageAnswers.Add(answerRecycle); DataBindString answerPerma = new DataBindString(); answerPerma.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/RemoveCross.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); answerPerma.Name = "Remove files or folders permanently"; messageAnswers.Add(answerPerma); bool useRecycleBin = true; string deleteString = "Do you want to remove the selected files or folders?"; DataBindString messageResult = await Popup_Show_MessageBox("Remove files or folders", "* Files and folders on a network drive get permanently deleted.", deleteString, messageAnswers); if (messageResult == null) { Debug.WriteLine("Cancelled files or folders removal."); return; } else if (messageResult == answerPerma) { useRecycleBin = false; } await Notification_Send_Status("Remove", "Removing files or folders"); //Remove the files or folders foreach (DataBindFile dataBindFile in List_FilePicker.Where(x => x.Checked == Visibility.Visible).ToList()) { Debug.WriteLine("Removing files or folders: " + dataBindFile.Name + " path: " + dataBindFile.PathFile); await FilePicker_FileRemove_Remove(dataBindFile, useRecycleBin); } //Update the clipboard status text Clipboard_UpdateStatusText(); } catch { } }
async Task FilePicker_FileCopy_Checked() { try { await Notification_Send_Status("Copy", "Copying files and folders"); Debug.WriteLine("Clipboard copy checked files and folders."); //Reset and clear the clipboard Clipboard_ResetClear(); //Add file to the clipboard foreach (DataBindFile dataBindFile in List_FilePicker.Where(x => x.Checked == Visibility.Visible)) { await FilePicker_FileCopy_Clipboard(dataBindFile); } //Update the clipboard status text Clipboard_UpdateStatusText(); } catch { } }
//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 { } }
//Show the File Picker Popup async Task Popup_Show_FilePicker_Task(string targetPath, int targetIndex, bool storeIndex, FrameworkElement previousFocus) { try { //Check if the popup is already open if (!vFilePickerOpen) { //Play the popup opening sound PlayInterfaceSound(vConfigurationCtrlUI, "PopupOpen", false, false); //Save the previous focus element FrameworkElementFocusSave(vFilePickerElementFocus, previousFocus); } //Reset file picker variables vFilePickerCompleted = false; vFilePickerCancelled = false; vFilePickerResult = null; vFilePickerOpen = true; //Check file picker busy status while (vFilePickerLoadBusy) { vFilePickerLoadCancel = true; await Task.Delay(100); } vFilePickerLoadBusy = true; AVActions.ActionDispatcherInvoke(delegate { //Show file picker loading animation gif_FilePicker_Loading.Show(); //Set file picker header texts grid_Popup_FilePicker_txt_Title.Text = vFilePickerTitle; grid_Popup_FilePicker_txt_Description.Text = vFilePickerDescription; //Change the list picker item style if (vFilePickerShowRoms) { lb_FilePicker.Style = Application.Current.Resources["ListBoxWrapPanelVertical"] as Style; lb_FilePicker.ItemTemplate = Application.Current.Resources["ListBoxItemRom"] as DataTemplate; grid_Popup_Filepicker_Row1.HorizontalAlignment = HorizontalAlignment.Center; } else { lb_FilePicker.Style = Application.Current.Resources["ListBoxVertical"] as Style; lb_FilePicker.ItemTemplate = Application.Current.Resources["ListBoxItemFile"] as DataTemplate; grid_Popup_Filepicker_Row1.HorizontalAlignment = HorizontalAlignment.Stretch; } //Update the navigation history index if (storeIndex) { FilePicker_NavigationHistoryAddUpdate(vFilePickerCurrentPath, lb_FilePicker.SelectedIndex); } //Clear the current file picker list List_FilePicker.Clear(); }); //Show the popup Popup_Show_Element(grid_Popup_FilePicker); //Update the current picker path vFilePickerSourcePath = vFilePickerCurrentPath; vFilePickerCurrentPath = targetPath; //Check target type if (targetPath == "PC") { //Get and list all the disk drives await PickerLoadPC(); } else if (targetPath == "UWP") { //Get and list all uwp applications await PickerLoadUwpApps(); } else { //Get and list all files and folders await PickerLoadFilesFolders(targetPath, targetIndex); } //Update file picker loading status vFilePickerLoadCancel = false; vFilePickerLoadBusy = false; //Hide file picker loading animation AVActions.ActionDispatcherInvoke(delegate { gif_FilePicker_Loading.Hide(); }); //File Picker focus on item await FilePicker_Focus(targetIndex, targetPath); } catch (Exception ex) { Debug.WriteLine("Failed loading filepicker: " + ex.Message); await Notification_Send_Status("Close", "Picker loading failed"); await FilePicker_GoFolderUp(); } }
//Show the File Picker Popup async Task Popup_Show_FilePicker_Task(string targetPath, int targetIndex, bool storeIndex, FrameworkElement previousFocus) { try { //Check if the popup is already open if (!vFilePickerOpen) { //Play the popup opening sound PlayInterfaceSound(vConfigurationCtrlUI, "PopupOpen", false); //Save the previous focus element FrameworkElementFocusSave(vFilePickerElementFocus, previousFocus); } //Reset file picker variables vFilePickerCompleted = false; vFilePickerCancelled = false; vFilePickerResult = null; vFilePickerOpen = true; AVActions.ActionDispatcherInvoke(delegate { //Disable the file picker list lb_FilePicker.IsEnabled = false; gif_FilePicker_Loading.Show(); //Set file picker header texts grid_Popup_FilePicker_txt_Title.Text = vFilePickerTitle; grid_Popup_FilePicker_txt_Description.Text = vFilePickerDescription; //Change the list picker item style if (vFilePickerShowRoms) { lb_FilePicker.Style = Application.Current.Resources["ListBoxWrapPanelVertical"] as Style; lb_FilePicker.ItemTemplate = Application.Current.Resources["ListBoxItemRom"] as DataTemplate; grid_Popup_Filepicker_Row1.HorizontalAlignment = HorizontalAlignment.Center; } else { lb_FilePicker.Style = Application.Current.Resources["ListBoxVertical"] as Style; lb_FilePicker.ItemTemplate = Application.Current.Resources["ListBoxItemFile"] as DataTemplate; grid_Popup_Filepicker_Row1.HorizontalAlignment = HorizontalAlignment.Stretch; } //Update the navigation history index if (storeIndex) { FilePicker_NavigationHistoryAddUpdate(vFilePickerCurrentPath, lb_FilePicker.SelectedIndex); } //Clear the current file picker list List_FilePicker.Clear(); }); //Show the popup Popup_Show_Element(grid_Popup_FilePicker); //Update the current picker path vFilePickerSourcePath = vFilePickerCurrentPath; vFilePickerCurrentPath = targetPath; //Get and list all the disk drives if (targetPath == "PC") { AVActions.ActionDispatcherInvoke(delegate { //Enable or disable selection button in the list grid_Popup_FilePicker_button_SelectFolder.Visibility = Visibility.Collapsed; //Enable or disable file and folder availability grid_Popup_FilePicker_textblock_NoFilesAvailable.Visibility = Visibility.Collapsed; //Enable or disable the side navigate buttons grid_Popup_FilePicker_button_ControllerLeft.Visibility = Visibility.Visible; grid_Popup_FilePicker_button_ControllerUp.Visibility = Visibility.Collapsed; grid_Popup_FilePicker_button_ControllerStart.Visibility = Visibility.Collapsed; //Enable or disable the copy paste status if (vClipboardFiles.Any()) { grid_Popup_FilePicker_textblock_ClipboardStatus.Visibility = Visibility.Visible; } //Enable or disable the current path grid_Popup_FilePicker_textblock_CurrentPath.Visibility = Visibility.Collapsed; }); //Load folder images BitmapImage imageFolder = FileToBitmapImage(new string[] { "Assets/Default/Icons/Folder.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); BitmapImage imageFolderDisc = FileToBitmapImage(new string[] { "Assets/Default/Icons/FolderDisc.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); BitmapImage imageFolderNetwork = FileToBitmapImage(new string[] { "Assets/Default/Icons/FolderNetwork.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); BitmapImage imageFolderPrevious = FileToBitmapImage(new string[] { "Assets/Default/Icons/Restart.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); BitmapImage imageFolderDocuments = FileToBitmapImage(new string[] { "Assets/Default/Icons/Copy.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); BitmapImage imageFolderDesktop = FileToBitmapImage(new string[] { "Assets/Default/Icons/Desktop.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); BitmapImage imageFolderDownload = FileToBitmapImage(new string[] { "Assets/Default/Icons/Download.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); BitmapImage imageFolderPictures = FileToBitmapImage(new string[] { "Assets/Default/Icons/Background.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); BitmapImage imageFolderVideos = FileToBitmapImage(new string[] { "Assets/Default/Icons/BackgroundVideo.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); BitmapImage imageFolderMusic = FileToBitmapImage(new string[] { "Assets/Default/Icons/Music.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); //Add launch without a file option if (vFilePickerShowNoFile) { string fileDescription = "Launch application without a file"; BitmapImage fileImage = FileToBitmapImage(new string[] { "Assets/Default/Icons/AppLaunch.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); DataBindFile dataBindFileWithoutFile = new DataBindFile() { FileType = FileType.FilePre, Name = fileDescription, Description = fileDescription + ".", ImageBitmap = fileImage, PathFile = string.Empty }; await ListBoxAddItem(lb_FilePicker, List_FilePicker, dataBindFileWithoutFile, false, false); } //Check and add the previous path if (!string.IsNullOrWhiteSpace(vFilePickerPreviousPath)) { DataBindFile dataBindFilePreviousPath = new DataBindFile() { FileType = FileType.FolderPre, Name = "Previous", NameSub = "(" + vFilePickerPreviousPath + ")", ImageBitmap = imageFolderPrevious, PathFile = vFilePickerPreviousPath }; await ListBoxAddItem(lb_FilePicker, List_FilePicker, dataBindFilePreviousPath, false, false); } //Add special folders DataBindFile dataBindFileDesktop = new DataBindFile() { FileType = FileType.FolderPre, Name = "My Desktop", ImageBitmap = imageFolderDesktop, PathFile = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) }; await ListBoxAddItem(lb_FilePicker, List_FilePicker, dataBindFileDesktop, false, false); DataBindFile dataBindFileDocuments = new DataBindFile() { FileType = FileType.FolderPre, Name = "My Documents", ImageBitmap = imageFolderDocuments, PathFile = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) }; await ListBoxAddItem(lb_FilePicker, List_FilePicker, dataBindFileDocuments, false, false); try { string downloadsPath = Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "{374DE290-123F-4565-9164-39C4925E467B}", string.Empty).ToString(); if (!string.IsNullOrWhiteSpace(downloadsPath) && Directory.Exists(downloadsPath)) { DataBindFile dataBindFileDownloads = new DataBindFile() { FileType = FileType.FolderPre, Name = "My Downloads", ImageBitmap = imageFolderDownload, PathFile = downloadsPath }; await ListBoxAddItem(lb_FilePicker, List_FilePicker, dataBindFileDownloads, false, false); } } catch { } DataBindFile dataBindFileMusic = new DataBindFile() { FileType = FileType.FolderPre, Name = "My Music", ImageBitmap = imageFolderMusic, PathFile = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic) }; await ListBoxAddItem(lb_FilePicker, List_FilePicker, dataBindFileMusic, false, false); DataBindFile dataBindFilePictures = new DataBindFile() { FileType = FileType.FolderPre, Name = "My Pictures", ImageBitmap = imageFolderPictures, PathFile = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) }; await ListBoxAddItem(lb_FilePicker, List_FilePicker, dataBindFilePictures, false, false); DataBindFile dataBindFileVideos = new DataBindFile() { FileType = FileType.FolderPre, Name = "My Videos", ImageBitmap = imageFolderVideos, PathFile = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos) }; await ListBoxAddItem(lb_FilePicker, List_FilePicker, dataBindFileVideos, false, false); //Add all disk drives that are connected DriveInfo[] diskDrives = DriveInfo.GetDrives(); foreach (DriveInfo disk in diskDrives) { try { //Skip network drive depending on the setting if (disk.DriveType == DriveType.Network && Convert.ToBoolean(Setting_Load(vConfigurationCtrlUI, "HideNetworkDrives"))) { continue; } //Check if the disk is currently connected if (disk.IsReady) { //Get the current disk size string freeSpace = AVFunctions.ConvertBytesSizeToString(disk.TotalFreeSpace); string usedSpace = AVFunctions.ConvertBytesSizeToString(disk.TotalSize); string diskSpace = freeSpace + "/" + usedSpace; DataBindFile dataBindFileDisk = new DataBindFile() { FileType = FileType.Folder, Name = disk.Name, NameSub = disk.VolumeLabel, NameDetail = diskSpace, PathFile = disk.Name }; if (disk.DriveType == DriveType.CDRom) { dataBindFileDisk.FileType = FileType.FolderDisc; dataBindFileDisk.ImageBitmap = imageFolderDisc; } else if (disk.DriveType == DriveType.Network) { dataBindFileDisk.ImageBitmap = imageFolderNetwork; } else { dataBindFileDisk.ImageBitmap = imageFolder; } await ListBoxAddItem(lb_FilePicker, List_FilePicker, dataBindFileDisk, false, false); } } catch { } } //Add Json file locations foreach (ProfileShared Locations in vCtrlLocationsFile) { try { if (Directory.Exists(Locations.String2)) { //Check if the location is a root folder FileType locationType = FileType.FolderPre; DirectoryInfo locationInfo = new DirectoryInfo(Locations.String2); if (locationInfo.Parent == null) { locationType = FileType.Folder; } //Get the current disk size string diskSpace = string.Empty; DriveType disktype = DriveType.Unknown; try { DriveInfo driveInfo = new DriveInfo(Locations.String2); disktype = driveInfo.DriveType; string freeSpace = AVFunctions.ConvertBytesSizeToString(driveInfo.TotalFreeSpace); string usedSpace = AVFunctions.ConvertBytesSizeToString(driveInfo.TotalSize); diskSpace = freeSpace + "/" + usedSpace; } catch { } DataBindFile dataBindFileLocation = new DataBindFile() { FileType = locationType, Name = Locations.String2, NameSub = Locations.String1, NameDetail = diskSpace, PathFile = Locations.String2 }; if (disktype == DriveType.CDRom) { dataBindFileLocation.FileType = FileType.FolderDisc; dataBindFileLocation.ImageBitmap = imageFolderDisc; } else if (disktype == DriveType.Network) { dataBindFileLocation.ImageBitmap = imageFolderNetwork; } else { dataBindFileLocation.ImageBitmap = imageFolder; } await ListBoxAddItem(lb_FilePicker, List_FilePicker, dataBindFileLocation, false, false); } } catch { } } } //Get and list all the UWP applications else if (targetPath == "UWP") { AVActions.ActionDispatcherInvoke(delegate { //Enable or disable selection button in the list grid_Popup_FilePicker_button_SelectFolder.Visibility = Visibility.Collapsed; //Enable or disable file and folder availability grid_Popup_FilePicker_textblock_NoFilesAvailable.Visibility = Visibility.Collapsed; //Enable or disable the side navigate buttons grid_Popup_FilePicker_button_ControllerLeft.Visibility = Visibility.Visible; grid_Popup_FilePicker_button_ControllerUp.Visibility = Visibility.Collapsed; grid_Popup_FilePicker_button_ControllerStart.Visibility = Visibility.Collapsed; //Enable or disable the copy paste status grid_Popup_FilePicker_textblock_ClipboardStatus.Visibility = Visibility.Collapsed; //Enable or disable the current path grid_Popup_FilePicker_textblock_CurrentPath.Visibility = Visibility.Collapsed; }); //Add uwp applications to the filepicker list await ListLoadAllUwpApplications(lb_FilePicker, List_FilePicker); } else { //Clean the target path string targetPath = Path.GetFullPath(targetPath); //Add the Go up directory to the list if (Path.GetPathRoot(targetPath) != targetPath) { BitmapImage imageBack = FileToBitmapImage(new string[] { "Assets/Default/Icons/Up.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); DataBindFile dataBindFileGoUp = new DataBindFile() { FileType = FileType.GoUpPre, Name = "Go up", Description = "Go up to the previous folder.", ImageBitmap = imageBack, PathFile = Path.GetDirectoryName(targetPath) }; await ListBoxAddItem(lb_FilePicker, List_FilePicker, dataBindFileGoUp, false, false); } else { BitmapImage imageBack = FileToBitmapImage(new string[] { "Assets/Default/Icons/Up.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); DataBindFile dataBindFileGoUp = new DataBindFile() { FileType = FileType.GoUpPre, Name = "Go up", Description = "Go up to the previous folder.", ImageBitmap = imageBack, PathFile = "PC" }; await ListBoxAddItem(lb_FilePicker, List_FilePicker, dataBindFileGoUp, false, false); } AVActions.ActionDispatcherInvoke(delegate { //Enable or disable the copy paste status if (vClipboardFiles.Any()) { grid_Popup_FilePicker_textblock_ClipboardStatus.Visibility = Visibility.Visible; } //Enable or disable the current path grid_Popup_FilePicker_textblock_CurrentPath.Text = "Current path: " + targetPath; grid_Popup_FilePicker_textblock_CurrentPath.Visibility = Visibility.Visible; }); //Add launch emulator options if (vFilePickerShowRoms) { string fileDescription = "Launch the emulator without a rom loaded"; BitmapImage fileImage = FileToBitmapImage(new string[] { "Assets/Default/Icons/Emulator.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); DataBindFile dataBindFileWithoutRom = new DataBindFile() { FileType = FileType.FilePre, Name = fileDescription, Description = fileDescription + ".", ImageBitmap = fileImage, PathFile = string.Empty }; await ListBoxAddItem(lb_FilePicker, List_FilePicker, dataBindFileWithoutRom, false, false); string romDescription = "Launch the emulator with this folder as rom"; BitmapImage romImage = FileToBitmapImage(new string[] { "Assets/Default/Icons/Emulator.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); DataBindFile dataBindFileFolderRom = new DataBindFile() { FileType = FileType.FilePre, Name = romDescription, Description = romDescription + ".", ImageBitmap = romImage, PathFile = targetPath }; await ListBoxAddItem(lb_FilePicker, List_FilePicker, dataBindFileFolderRom, false, false); } //Enable or disable the side navigate buttons AVActions.ActionDispatcherInvoke(delegate { grid_Popup_FilePicker_button_ControllerLeft.Visibility = Visibility.Visible; grid_Popup_FilePicker_button_ControllerUp.Visibility = Visibility.Visible; grid_Popup_FilePicker_button_ControllerStart.Visibility = Visibility.Visible; }); //Get all the top files and folders DirectoryInfo directoryInfo = new DirectoryInfo(targetPath); DirectoryInfo[] directoryFolders = null; FileInfo[] directoryFiles = null; if (vFilePickerSortType == SortingType.Name) { directoryFolders = directoryInfo.GetDirectories("*", SearchOption.TopDirectoryOnly).OrderBy(x => x.Name).ToArray(); directoryFiles = directoryInfo.GetFiles("*", SearchOption.TopDirectoryOnly).OrderBy(x => x.Name).ToArray(); } else { directoryFolders = directoryInfo.GetDirectories("*", SearchOption.TopDirectoryOnly).OrderByDescending(x => x.LastWriteTime).ToArray(); directoryFiles = directoryInfo.GetFiles("*", SearchOption.TopDirectoryOnly).OrderByDescending(x => x.LastWriteTime).ToArray(); } //Get all rom images and descriptions FileInfo[] directoryRomImages = new FileInfo[] { }; FileInfo[] directoryRomDescriptions = new FileInfo[] { }; if (vFilePickerShowRoms) { string[] imageFilter = { "jpg", "png" }; string[] descriptionFilter = { "json" }; DirectoryInfo directoryInfoRomsUser = new DirectoryInfo("Assets/User/Games"); FileInfo[] directoryPathsRomsUser = directoryInfoRomsUser.GetFiles("*", SearchOption.AllDirectories); DirectoryInfo directoryInfoRomsDefault = new DirectoryInfo("Assets/Default/Games"); FileInfo[] directoryPathsRomsDefault = directoryInfoRomsDefault.GetFiles("*", SearchOption.AllDirectories); IEnumerable <FileInfo> directoryPathsRoms = directoryPathsRomsUser.Concat(directoryPathsRomsDefault); FileInfo[] romsImages = directoryPathsRoms.Where(file => imageFilter.Any(filter => file.Name.EndsWith(filter, StringComparison.InvariantCultureIgnoreCase))).ToArray(); FileInfo[] filesImages = directoryFiles.Where(file => imageFilter.Any(filter => file.Name.EndsWith(filter, StringComparison.InvariantCultureIgnoreCase))).ToArray(); directoryRomImages = filesImages.Concat(romsImages).OrderByDescending(x => x.Name.Length).ToArray(); FileInfo[] romsDescriptions = directoryPathsRoms.Where(file => descriptionFilter.Any(filter => file.Name.EndsWith(filter, StringComparison.InvariantCultureIgnoreCase))).ToArray(); FileInfo[] filesDescriptions = directoryFiles.Where(file => descriptionFilter.Any(filter => file.Name.EndsWith(filter, StringComparison.InvariantCultureIgnoreCase))).ToArray(); directoryRomDescriptions = filesDescriptions.Concat(romsDescriptions).OrderByDescending(x => x.Name.Length).ToArray(); } //Get all the directories from target directory if (vFilePickerShowDirectories) { try { //Fill the file picker listbox with folders foreach (DirectoryInfo listFolder in directoryFolders) { try { BitmapImage listImage = null; string listDescription = string.Empty; //Load image files for the list if (vFilePickerShowRoms) { GetRomDetails(listFolder.Name, listFolder.FullName, directoryRomImages, directoryRomDescriptions, ref listImage, ref listDescription); } else { listImage = FileToBitmapImage(new string[] { "Assets/Default/Icons/Folder.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0); } //Get the folder size //string folderSize = AVFunctions.ConvertBytesSizeToString(GetDirectorySize(listDirectory)); //Get the folder date string folderDate = listFolder.LastWriteTime.ToShortDateString().Replace("-", "/"); //Set the detailed text string folderDetailed = folderDate; //Check the copy cut type ClipboardType clipboardType = ClipboardType.None; DataBindFile clipboardFile = vClipboardFiles.Where(x => x.PathFile == listFolder.FullName).FirstOrDefault(); if (clipboardFile != null) { clipboardType = clipboardFile.ClipboardType; } //Add folder to the list bool systemFileFolder = listFolder.Attributes.HasFlag(FileAttributes.System); bool hiddenFileFolder = listFolder.Attributes.HasFlag(FileAttributes.Hidden); if (!systemFileFolder && (!hiddenFileFolder || Convert.ToBoolean(Setting_Load(vConfigurationCtrlUI, "ShowHiddenFilesFolders")))) { DataBindFile dataBindFileFolder = new DataBindFile() { FileType = FileType.Folder, ClipboardType = clipboardType, Name = listFolder.Name, NameDetail = folderDetailed, Description = listDescription, DateModified = listFolder.LastWriteTime, ImageBitmap = listImage, PathFile = listFolder.FullName }; await ListBoxAddItem(lb_FilePicker, List_FilePicker, dataBindFileFolder, false, false); } } catch { } } } catch { } } //Get all the files from target directory if (vFilePickerShowFiles) { try { //Enable or disable selection button in the list AVActions.ActionDispatcherInvoke(delegate { grid_Popup_FilePicker_button_SelectFolder.Visibility = Visibility.Collapsed; }); //Filter files in and out if (vFilePickerFilterIn.Any()) { directoryFiles = directoryFiles.Where(file => vFilePickerFilterIn.Any(filter => file.Name.EndsWith(filter, StringComparison.InvariantCultureIgnoreCase))).ToArray(); } if (vFilePickerFilterOut.Any()) { directoryFiles = directoryFiles.Where(file => !vFilePickerFilterOut.Any(filter => file.Name.EndsWith(filter, StringComparison.InvariantCultureIgnoreCase))).ToArray(); } //Fill the file picker listbox with files foreach (FileInfo listFile in directoryFiles) { try { BitmapImage listImage = null; string listDescription = string.Empty; //Load image files for the list if (vFilePickerShowRoms) { GetRomDetails(listFile.Name, string.Empty, directoryRomImages, directoryRomDescriptions, ref listImage, ref listDescription); } else { string listFileFullNameLower = listFile.FullName.ToLower(); string listFileExtensionLower = listFile.Extension.ToLower().Replace(".", string.Empty); if (listFileFullNameLower.EndsWith(".jpg") || listFileFullNameLower.EndsWith(".png") || listFileFullNameLower.EndsWith(".gif")) { listImage = FileToBitmapImage(new string[] { listFile.FullName }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, 50, 0); } else { listImage = FileToBitmapImage(new string[] { "Assets/Default/Extensions/" + listFileExtensionLower + ".png", "Assets/Default/Icons/File.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, 50, 0); } } //Get the file size string fileSize = AVFunctions.ConvertBytesSizeToString(listFile.Length); //Get the file date string fileDate = listFile.LastWriteTime.ToShortDateString().Replace("-", "/"); //Set the detailed text string fileDetailed = fileSize + " (" + fileDate + ")"; //Check the copy cut type ClipboardType clipboardType = ClipboardType.None; DataBindFile clipboardFile = vClipboardFiles.Where(x => x.PathFile == listFile.FullName).FirstOrDefault(); if (clipboardFile != null) { clipboardType = clipboardFile.ClipboardType; } //Add file to the list bool systemFileFolder = listFile.Attributes.HasFlag(FileAttributes.System); bool hiddenFileFolder = listFile.Attributes.HasFlag(FileAttributes.Hidden); if (!systemFileFolder && (!hiddenFileFolder || Convert.ToBoolean(Setting_Load(vConfigurationCtrlUI, "ShowHiddenFilesFolders")))) { FileType fileType = FileType.File; string fileExtension = Path.GetExtension(listFile.Name); if (fileExtension == ".url" || fileExtension == ".lnk") { fileType = FileType.Link; } DataBindFile dataBindFileFile = new DataBindFile() { FileType = fileType, ClipboardType = clipboardType, Name = listFile.Name, NameDetail = fileDetailed, Description = listDescription, DateModified = listFile.LastWriteTime, ImageBitmap = listImage, PathFile = listFile.FullName }; await ListBoxAddItem(lb_FilePicker, List_FilePicker, dataBindFileFile, false, false); } } catch { } } } catch { } } else { //Enable or disable selection button in the list AVActions.ActionDispatcherInvoke(delegate { grid_Popup_FilePicker_button_SelectFolder.Visibility = Visibility.Visible; }); } //Check if there are files or folders FilePicker_CheckFilesAndFoldersCount(); } //Enable the file picker list AVActions.ActionDispatcherInvoke(delegate { lb_FilePicker.IsEnabled = true; gif_FilePicker_Loading.Hide(); }); //Get navigation history index if (targetIndex == -1) { targetIndex = FilePicker_NavigationHistoryGetIndex(targetPath); } //Check the navigation index if (targetIndex == -1 && !string.IsNullOrWhiteSpace(vFilePickerSourcePath)) { DataBindFile sourceFileItem = List_FilePicker.Where(x => x.PathFile == vFilePickerSourcePath).FirstOrDefault(); if (sourceFileItem != null) { Debug.WriteLine("Source file path found: " + vFilePickerSourcePath); //Focus on the file picker listbox item await ListBoxFocusItem(lb_FilePicker, sourceFileItem, vProcessCurrent.MainWindowHandle); return; } } //Focus on the file picker listbox index await ListboxFocusIndex(lb_FilePicker, false, false, targetIndex, vProcessCurrent.MainWindowHandle); } catch (Exception ex) { Debug.WriteLine("Failed loading filepicker: " + ex.Message); await FilePicker_Failed(); } }