Example #1
0
 //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");
     }
 }
Example #2
0
        async Task <bool> FilePicker_EjectDrive(DataBindFile dataBindFile, string driveLetter)
        {
            try
            {
                Debug.WriteLine("Ejecting the disc drive: " + driveLetter);
                await Notification_Send_Status("FolderDisc", "Ejecting the drive");

                //Get the drive
                int        ssfDRIVES  = 17;
                Shell      shell      = new Shell();
                Folder     folder     = shell.NameSpace(ssfDRIVES);
                FolderItem folderItem = folder.ParseName(driveLetter);

                //Eject the disc or image
                folderItem.InvokeVerb("Eject");

                //Remove drive from the listbox
                await ListBoxRemoveItem(lb_FilePicker, List_FilePicker, dataBindFile, true);

                await Notification_Send_Status("FolderDisc", "Ejected the drive");

                return(true);
            }
            catch { }
            await Notification_Send_Status("Close", "Failed to eject drive");

            return(false);
        }
Example #3
0
        //Load rom information when selection has changed
        void Lb_FilePicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                if (vFilePickerShowRoms)
                {
                    ListBox      ListboxSender = (ListBox)sender;
                    DataBindFile SelectedItem  = (DataBindFile)ListboxSender.SelectedItem;
                    //Debug.WriteLine("File picker selection has changed to: " + SelectedItem.Name);

                    //Show the rom information
                    grid_Popup_FilePicker_stackpanel_Description.Visibility = Visibility.Visible;

                    //Set image binding
                    Binding imageBinding = new Binding();
                    imageBinding.Path   = new PropertyPath("ImageBitmap");
                    imageBinding.Source = SelectedItem;
                    grid_Popup_FilePicker_image_Description.SetBinding(Image.SourceProperty, imageBinding);

                    //Set text binding
                    Binding textBinding = new Binding();
                    textBinding.Path   = new PropertyPath("Description");
                    textBinding.Source = SelectedItem;
                    grid_Popup_FilePicker_textblock_Description.SetBinding(TextBlock.TextProperty, textBinding);
                }
            }
            catch { }
        }
Example #4
0
        //File Picker check item
        void FilePicker_CheckItem()
        {
            try
            {
                DataBindFile dataBindFile = (DataBindFile)lb_FilePicker.SelectedItem;

                //Check the file or folder
                if (vFilePickerCurrentPath == "PC" || dataBindFile.FileType == FileType.FolderPre || dataBindFile.FileType == FileType.FilePre || dataBindFile.FileType == FileType.GoUpPre)
                {
                    Debug.WriteLine("Invalid file type, cannot be selected.");
                    return;
                }

                //Check or uncheck item
                if (dataBindFile.Checked != Visibility.Visible)
                {
                    dataBindFile.Checked = Visibility.Visible;
                }
                else
                {
                    dataBindFile.Checked = Visibility.Collapsed;
                }
            }
            catch { }
        }
Example #5
0
        //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);
        }
Example #6
0
        async Task FilePicker_CreateFolder()
        {
            try
            {
                await Notification_Send_Status("FolderAdd", "Creating new folder");

                Debug.WriteLine("Creating new folder in: " + vFilePickerCurrentPath);

                //Show the text input popup
                string textInputString = await Popup_ShowHide_TextInput("Create folder", string.Empty, "Create new folder", false);

                //Check the folder create name
                if (!string.IsNullOrWhiteSpace(textInputString))
                {
                    string newFolderPath = Path.Combine(vFilePickerCurrentPath, textInputString);

                    //Check if the folder exists
                    if (Directory.Exists(newFolderPath))
                    {
                        await Notification_Send_Status("FolderAdd", "Folder already exists");

                        Debug.WriteLine("Create folder already exists.");
                        return;
                    }

                    //Create the new folder
                    DirectoryInfo listDirectory = Directory.CreateDirectory(newFolderPath);

                    //Create new folder databindfile
                    BitmapImage  folderImage        = FileToBitmapImage(new string[] { "Assets/Default/Icons/Folder.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0);
                    DataBindFile dataBindFileFolder = new DataBindFile()
                    {
                        FileType = FileType.Folder, Name = listDirectory.Name, DateModified = listDirectory.LastWriteTime, ImageBitmap = folderImage, PathFile = listDirectory.FullName
                    };

                    //Add the new listbox item
                    await ListBoxAddItem(lb_FilePicker, List_FilePicker, dataBindFileFolder, false, false);

                    //Focus on the listbox item
                    await ListboxFocusIndex(lb_FilePicker, false, true, -1, vProcessCurrent.MainWindowHandle);

                    //Check if there are files or folders
                    FilePicker_CheckFilesAndFoldersCount();

                    await Notification_Send_Status("FolderAdd", "Created new folder");

                    Debug.WriteLine("Created new folder in: " + newFolderPath);
                }
            }
            catch (Exception ex)
            {
                await Notification_Send_Status("FolderAdd", "Failed creating folder");

                Debug.WriteLine("Failed creating new folder: " + ex.Message);
            }
        }
Example #7
0
        //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 { }
        }
Example #8
0
        //Update uwp application
        async Task UwpListUpdateApplication(DataBindFile selectedItem)
        {
            try
            {
                await Notification_Send_Status("Refresh", "Updating " + selectedItem.Name);

                //Update application from list
                UwpUpdateApplicationByAppUserModelId(selectedItem.PathFile);
            }
            catch { }
        }
Example #9
0
        //Remove uwp application
        async Task UwpListRemoveApplication(DataBindFile selectedItem)
        {
            try
            {
                await Notification_Send_Status("RemoveCross", "Removing " + selectedItem.Name);

                //Remove application from pc
                bool uwpRemoved = UwpRemoveApplicationByPackageFullName(selectedItem.PathFull);

                //Remove application from list
                if (uwpRemoved)
                {
                    await ListBoxRemoveItem(lb_FilePicker, List_FilePicker, selectedItem, true);
                }
            }
            catch { }
        }
Example #10
0
        async Task FilePicker_FileCopy_Clipboard(DataBindFile dataBindFile)
        {
            try
            {
                //Check the file or folder
                if (dataBindFile.FileType == FileType.FolderPre || dataBindFile.FileType == FileType.FilePre || dataBindFile.FileType == FileType.GoUpPre)
                {
                    await Notification_Send_Status("Close", "Invalid file or folder");

                    Debug.WriteLine("Invalid file or folder: " + dataBindFile.Name + " path: " + dataBindFile.PathFile);
                    return;
                }

                //Set the clipboard variables
                dataBindFile.ClipboardType = ClipboardType.Copy;
                vClipboardFiles.Add(dataBindFile);
            }
            catch { }
        }
Example #11
0
        async Task FilePicker_FileCopy_Single(DataBindFile dataBindFile)
        {
            try
            {
                await Notification_Send_Status("Copy", "Copying file or folder");

                Debug.WriteLine("Clipboard copy file or folder: " + dataBindFile.Name + " path: " + dataBindFile.PathFile);

                //Reset and clear the clipboard
                Clipboard_ResetClear();

                //Add file to the clipboard
                await FilePicker_FileCopy_Clipboard(dataBindFile);

                //Update the clipboard status text
                Clipboard_UpdateStatusText();
            }
            catch { }
        }
Example #12
0
        async Task FilePicker_FileRemove_Single(DataBindFile dataBindFile)
        {
            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 file or folder 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 file or folder permanently";
                messageAnswers.Add(answerPerma);

                bool           useRecycleBin = true;
                string         deleteString  = "Do you want to remove: " + dataBindFile.Name + "?";
                DataBindString messageResult = await Popup_Show_MessageBox("Remove file or folder", "* Files and folders on a network drive get permanently deleted.", deleteString, messageAnswers);

                if (messageResult == null)
                {
                    Debug.WriteLine("Cancelled file or folder removal.");
                    return;
                }
                else if (messageResult == answerPerma)
                {
                    useRecycleBin = false;
                }

                await Notification_Send_Status("Remove", "Removing file or folder");

                Debug.WriteLine("Removing file or folder: " + dataBindFile.Name + " path: " + dataBindFile.PathFile);

                //Remove the file or folder
                await FilePicker_FileRemove_Remove(dataBindFile, useRecycleBin);

                //Update the clipboard status text
                Clipboard_UpdateStatusText();
            }
            catch { }
        }
Example #13
0
        //Handle file picker left click
        async Task Listbox_FilePicker_LeftClick()
        {
            try
            {
                if (lb_FilePicker.SelectedItems.Count > 0 && lb_FilePicker.SelectedIndex != -1)
                {
                    DataBindFile SelectedItem = (DataBindFile)lb_FilePicker.SelectedItem;
                    if (SelectedItem.FileType == FileType.Folder || SelectedItem.FileType == FileType.FolderDisc || SelectedItem.FileType == FileType.FolderPre)
                    {
                        await Popup_Show_FilePicker(SelectedItem.PathFile, -1, true, null);
                    }
                    else if (SelectedItem.FileType == FileType.GoUpPre)
                    {
                        await FilePicker_GoFolderUp();
                    }
                    else if (SelectedItem.FileType == FileType.Link)
                    {
                        ShortcutDetails shortcutDetails = ReadShortcutFile(SelectedItem.PathFile);
                        if (Directory.Exists(shortcutDetails.TargetPath))
                        {
                            await Popup_Show_FilePicker(shortcutDetails.TargetPath, -1, true, null);
                        }
                        else if (File.Exists(shortcutDetails.TargetPath))
                        {
                            await Popup_Close_FilePicker(true, false);
                        }
                        else
                        {
                            await Notification_Send_Status("Close", "Link target does not exist");

                            Debug.WriteLine("Link target does not exist");
                        }
                    }
                    else
                    {
                        await Popup_Close_FilePicker(true, false);
                    }
                }
            }
            catch { }
        }
Example #14
0
        //Update the clipboard status text
        void Clipboard_UpdateStatusText()
        {
            try
            {
                AVActions.ActionDispatcherInvoke(delegate
                {
                    if (vClipboardFiles.Count == 1)
                    {
                        DataBindFile clipboardFile = vClipboardFiles.FirstOrDefault();
                        grid_Popup_FilePicker_textblock_ClipboardStatus.Text       = "Clipboard (" + clipboardFile.FileType.ToString() + " " + clipboardFile.ClipboardType.ToString() + ") " + clipboardFile.PathFile;
                        grid_Popup_FilePicker_textblock_ClipboardStatus.Visibility = Visibility.Visible;
                    }
                    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)";
                        }

                        grid_Popup_FilePicker_textblock_ClipboardStatus.Text       = "Clipboard " + statusCount + " files or folders.";
                        grid_Popup_FilePicker_textblock_ClipboardStatus.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        grid_Popup_FilePicker_textblock_ClipboardStatus.Text       = string.Empty;
                        grid_Popup_FilePicker_textblock_ClipboardStatus.Visibility = Visibility.Collapsed;
                    }
                });
            }
            catch { }
        }
Example #15
0
        async Task FilePicker_CreateTextFile()
        {
            try
            {
                await Notification_Send_Status("Font", "Creating text file");

                Debug.WriteLine("Creating new text file in: " + vFilePickerCurrentPath);

                //Show the text input popup
                string textInputString = await Popup_ShowHide_TextInput("Create text file", string.Empty, "Create new text file", false);

                //Check the text file create name
                if (!string.IsNullOrWhiteSpace(textInputString))
                {
                    string fileName    = textInputString + ".txt";
                    string newFilePath = Path.Combine(vFilePickerCurrentPath, fileName);

                    //Check if the text file exists
                    if (File.Exists(newFilePath))
                    {
                        await Notification_Send_Status("Font", "Text file already exists");

                        Debug.WriteLine("Create text file already exists.");
                        return;
                    }

                    //Create the new text file
                    File.Create(newFilePath).Dispose();
                    DateTime dateCreated = DateTime.Now;

                    //Get the file size
                    string fileSize = AVFunctions.ConvertBytesSizeToString(0);

                    //Get the file date
                    string fileDate = dateCreated.ToShortDateString().Replace("-", "/");

                    //Set the detailed text
                    string fileDetailed = fileSize + " (" + fileDate + ")";

                    //Create new file databindfile
                    BitmapImage  fileImage        = FileToBitmapImage(new string[] { "Assets/Default/Extensions/Txt.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0);
                    DataBindFile dataBindFileFile = new DataBindFile()
                    {
                        FileType = FileType.File, Name = fileName, NameDetail = fileDetailed, DateModified = dateCreated, ImageBitmap = fileImage, PathFile = newFilePath
                    };

                    //Add the new listbox item
                    await ListBoxAddItem(lb_FilePicker, List_FilePicker, dataBindFileFile, false, false);

                    //Focus on the listbox item
                    await ListboxFocusIndex(lb_FilePicker, false, true, -1, vProcessCurrent.MainWindowHandle);

                    //Check if there are files or folders
                    FilePicker_CheckFilesAndFoldersCount();

                    await Notification_Send_Status("Font", "Created new text file");

                    Debug.WriteLine("Created new text file in: " + newFilePath);
                }
            }
            catch (Exception ex)
            {
                await Notification_Send_Status("Font", "Failed creating file");

                Debug.WriteLine("Failed creating new text file: " + ex.Message);
            }
        }
Example #16
0
        //List all available uwp applications
        async Task ListLoadAllUwpApplications(ListBox targetListBox, ObservableCollection <DataBindFile> targetList)
        {
            try
            {
                //Set uwp application filters
                string[] whiteListFamilyName   = { "Microsoft.MicrosoftEdge_8wekyb3d8bbwe" };
                string[] blackListFamilyNameId = { "Microsoft.MicrosoftEdge_8wekyb3d8bbwe!PdfReader" };

                //Get all the installed uwp apps
                PackageManager        deployPackageManager = new PackageManager();
                string                currentUserIdentity  = WindowsIdentity.GetCurrent().User.Value;
                IEnumerable <Package> appPackages          = deployPackageManager.FindPackagesForUser(currentUserIdentity);
                foreach (Package appPackage in appPackages)
                {
                    try
                    {
                        //Get basic application information
                        string appFamilyName = appPackage.Id.FamilyName;

                        //Check if the application is in whitelist
                        if (!whiteListFamilyName.Contains(appFamilyName))
                        {
                            //Filter out system apps and others
                            if (appPackage.IsBundle)
                            {
                                continue;
                            }
                            if (appPackage.IsOptional)
                            {
                                continue;
                            }
                            if (appPackage.IsFramework)
                            {
                                continue;
                            }
                            if (appPackage.IsResourcePackage)
                            {
                                continue;
                            }
                            if (appPackage.SignatureKind != PackageSignatureKind.Store)
                            {
                                continue;
                            }
                        }

                        //Get detailed application information
                        AppxDetails appxDetails = UwpGetAppxDetailsFromAppPackage(appPackage);

                        //Check if executable name is valid
                        if (string.IsNullOrWhiteSpace(appxDetails.ExecutableName))
                        {
                            continue;
                        }

                        //Check if application name is valid
                        if (string.IsNullOrWhiteSpace(appxDetails.DisplayName) || appxDetails.DisplayName.StartsWith("ms-resource"))
                        {
                            continue;
                        }

                        //Check if the application is in blacklist
                        if (blackListFamilyNameId.Contains(appxDetails.FamilyNameId))
                        {
                            continue;
                        }

                        //Load the application image
                        BitmapImage uwpListImage = FileToBitmapImage(new string[] { appxDetails.SquareLargestLogoPath, appxDetails.WideLargestLogoPath }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, 50, 0);

                        //Add the application to the list
                        DataBindFile dataBindFile = new DataBindFile()
                        {
                            FileType = FileType.UwpApp, Name = appxDetails.DisplayName, NameExe = appxDetails.ExecutableName, PathFile = appxDetails.FamilyNameId, PathFull = appxDetails.FullPackageName, PathImage = appxDetails.SquareLargestLogoPath, ImageBitmap = uwpListImage
                        };
                        await ListBoxAddItem(targetListBox, targetList, dataBindFile, false, false);
                    }
                    catch { }
                }

                //Sort the application list by name
                SortFunction <DataBindFile> sortFuncName = new SortFunction <DataBindFile>();
                sortFuncName.function = x => x.Name;

                List <SortFunction <DataBindFile> > orderListPicker = new List <SortFunction <DataBindFile> >();
                orderListPicker.Add(sortFuncName);

                SortObservableCollection(lb_FilePicker, List_FilePicker, orderListPicker, null);
            }
            catch { }
        }
Example #17
0
        //Get and list all files and folders
        async Task PickerLoadFilesFolders(string targetPath, int targetIndex)
        {
            try
            {
                //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
                            {
                                //Cancel loading
                                if (vFilePickerLoadCancel)
                                {
                                    Debug.WriteLine("File picker folder load cancelled.");
                                    vFilePickerLoadCancel = false;
                                    vFilePickerLoadBusy   = false;
                                    return;
                                }

                                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
                            {
                                //Cancel loading
                                if (vFilePickerLoadCancel)
                                {
                                    Debug.WriteLine("File picker file load cancelled.");
                                    vFilePickerLoadCancel = false;
                                    vFilePickerLoadBusy   = false;
                                    return;
                                }

                                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();
            }
            catch { }
        }
Example #18
0
        async Task FilePicker_FileRename(DataBindFile dataBindFile)
        {
            try
            {
                //Check the file or folder
                if (dataBindFile.FileType == FileType.FolderPre || dataBindFile.FileType == FileType.FilePre || dataBindFile.FileType == FileType.GoUpPre)
                {
                    await Notification_Send_Status("Close", "Invalid file or folder");

                    Debug.WriteLine("Invalid file or folder: " + dataBindFile.Name + " path: " + dataBindFile.PathFile);
                    return;
                }

                Debug.WriteLine("Renaming file or folder: " + dataBindFile.Name + " path: " + dataBindFile.PathFile);

                //Show the text input popup
                string textInputString = await Popup_ShowHide_TextInput("Rename file or folder", dataBindFile.Name, "Rename the file or folder", false);

                //Check if file name changed
                if (textInputString == dataBindFile.Name)
                {
                    await Notification_Send_Status("Rename", "File name not changed");

                    Debug.WriteLine("The file name did not change.");
                    return;
                }

                //Check the changed file name
                if (!string.IsNullOrWhiteSpace(textInputString))
                {
                    string oldFilePath      = Path.GetFullPath(dataBindFile.PathFile);
                    string newFileName      = Path.GetFileNameWithoutExtension(textInputString);
                    string newFileExtension = Path.GetExtension(textInputString);
                    string newFileDirectory = Path.GetDirectoryName(oldFilePath);
                    string newFilePath      = Path.Combine(newFileDirectory, newFileName + newFileExtension);

                    //Move file or folder
                    FileAttributes fileAttribute = File.GetAttributes(oldFilePath);
                    if (fileAttribute.HasFlag(FileAttributes.Directory))
                    {
                        //Check if the folder exists
                        if (Directory.Exists(newFilePath))
                        {
                            //Count existing file names
                            int fileCount = Directory.GetDirectories(newFileDirectory, "*" + newFileName + "*").Count();

                            //Update the file name
                            newFileName += " - Rename (" + fileCount + ")";
                            newFilePath  = Path.Combine(newFileDirectory, newFileName + newFileExtension);
                        }
                        Directory_Move(oldFilePath, newFilePath, true);
                    }
                    else
                    {
                        //Check if the file exists
                        if (File.Exists(newFilePath))
                        {
                            //Count existing file names
                            int fileCount = Directory.GetFiles(newFileDirectory, "*" + newFileName + "*").Count();

                            //Update the file name
                            newFileName += " - Rename (" + fileCount + ")";
                            newFilePath  = Path.Combine(newFileDirectory, newFileName + newFileExtension);
                        }
                        File_Move(oldFilePath, newFilePath, true);
                    }

                    //Update file name in listbox
                    dataBindFile.Name     = newFileName + newFileExtension;
                    dataBindFile.PathFile = newFilePath;

                    //Update the clipboard status text
                    Clipboard_UpdateStatusText();

                    await Notification_Send_Status("Rename", "Renamed file or folder");

                    Debug.WriteLine("Renamed file or folder to: " + newFileName + newFileExtension);
                }
            }
            catch (Exception ex)
            {
                await Notification_Send_Status("Rename", "Failed renaming");

                Debug.WriteLine("Failed renaming file or folder: " + ex.Message);
            }
        }
Example #19
0
        //Get and list all the disk drives
        async Task PickerLoadPC()
        {
            try
            {
                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);

                //Load file browser settings
                bool hideNetworkDrives     = Convert.ToBoolean(Setting_Load(vConfigurationCtrlUI, "HideNetworkDrives"));
                bool notReadyNetworkDrives = Convert.ToBoolean(Setting_Load(vConfigurationCtrlUI, "NotReadyNetworkDrives"));

                //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 && hideNetworkDrives)
                        {
                            continue;
                        }

                        //Check if the disk is currently connected
                        if (disk.IsReady || (disk.DriveType == DriveType.Network && notReadyNetworkDrives))
                        {
                            //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 { }
                }
            }
            catch { }
        }
Example #20
0
        //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 { }
        }
Example #21
0
        //Get and list all uwp applications
        async Task PickerLoadUwpApps()
        {
            try
            {
                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;
                });

                //Set uwp application filters
                string[] whiteListFamilyName   = { "Microsoft.MicrosoftEdge_8wekyb3d8bbwe" };
                string[] blackListFamilyNameId = { "Microsoft.MicrosoftEdge_8wekyb3d8bbwe!PdfReader" };

                //Get all the installed uwp apps
                PackageManager        deployPackageManager = new PackageManager();
                string                currentUserIdentity  = WindowsIdentity.GetCurrent().User.Value;
                IEnumerable <Package> appPackages          = deployPackageManager.FindPackagesForUser(currentUserIdentity);
                foreach (Package appPackage in appPackages)
                {
                    try
                    {
                        //Cancel loading
                        if (vFilePickerLoadCancel)
                        {
                            Debug.WriteLine("File picker uwp load cancelled.");
                            vFilePickerLoadCancel = false;
                            vFilePickerLoadBusy   = false;
                            return;
                        }

                        //Get basic application information
                        string appFamilyName = appPackage.Id.FamilyName;

                        //Check if the application is in whitelist
                        if (!whiteListFamilyName.Contains(appFamilyName))
                        {
                            //Filter out system apps and others
                            if (appPackage.IsBundle)
                            {
                                continue;
                            }
                            if (appPackage.IsOptional)
                            {
                                continue;
                            }
                            if (appPackage.IsFramework)
                            {
                                continue;
                            }
                            if (appPackage.IsResourcePackage)
                            {
                                continue;
                            }
                            if (appPackage.SignatureKind != PackageSignatureKind.Store)
                            {
                                continue;
                            }
                        }

                        //Get detailed application information
                        AppxDetails appxDetails = UwpGetAppxDetailsFromAppPackage(appPackage);

                        //Check if executable name is valid
                        if (string.IsNullOrWhiteSpace(appxDetails.ExecutableName))
                        {
                            continue;
                        }

                        //Check if application name is valid
                        if (string.IsNullOrWhiteSpace(appxDetails.DisplayName) || appxDetails.DisplayName.StartsWith("ms-resource"))
                        {
                            continue;
                        }

                        //Check if the application is in blacklist
                        if (blackListFamilyNameId.Contains(appxDetails.FamilyNameId))
                        {
                            continue;
                        }

                        //Load the application image
                        BitmapImage uwpListImage = FileToBitmapImage(new string[] { appxDetails.SquareLargestLogoPath, appxDetails.WideLargestLogoPath }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, 50, 0);

                        //Add the application to the list
                        DataBindFile dataBindFile = new DataBindFile()
                        {
                            FileType = FileType.UwpApp, Name = appxDetails.DisplayName, NameExe = appxDetails.ExecutableName, PathFile = appxDetails.FamilyNameId, PathFull = appxDetails.FullPackageName, PathImage = appxDetails.SquareLargestLogoPath, ImageBitmap = uwpListImage
                        };
                        await ListBoxAddItem(lb_FilePicker, List_FilePicker, dataBindFile, false, false);
                    }
                    catch { }
                }

                //Sort the application list by name
                SortFunction <DataBindFile> sortFuncName = new SortFunction <DataBindFile>();
                sortFuncName.function = x => x.Name;

                List <SortFunction <DataBindFile> > orderListPicker = new List <SortFunction <DataBindFile> >();
                orderListPicker.Add(sortFuncName);

                SortObservableCollection(lb_FilePicker, List_FilePicker, orderListPicker, null);
            }
            catch { }
        }
Example #22
0
        //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();
            }
        }
Example #23
0
        async Task SelectNearCharacterFiles(bool selectNextCharacter, ListBox parentListbox)
        {
            try
            {
                //Make sure the list is sorted by name
                await FilePicker_SortFilesFoldersByName(true);

                //Get the current character
                DataBindFile dataBindApp = (DataBindFile)parentListbox.SelectedItem;
                ObservableCollection <DataBindFile> dataBindApplist = (ObservableCollection <DataBindFile>)parentListbox.ItemsSource;
                char currentCharacter = dataBindApp.Name.ToUpper()[0];

                //Set the character filter
                Func <DataBindFile, bool> filterCharacterNoMatch = x => x.Name.ToUpper()[0] != currentCharacter && x.FileType != FileType.FolderPre && x.FileType != FileType.FilePre && x.FileType != FileType.GoUpPre;
                Func <DataBindFile, bool> filterCharacterMatch   = x => x.Name.ToUpper()[0] == currentCharacter && x.FileType != FileType.FolderPre && x.FileType != FileType.FilePre && x.FileType != FileType.GoUpPre;

                //Get the target application
                DataBindFile selectAppCurrent = null;
                if (selectNextCharacter)
                {
                    int currentIndex = parentListbox.SelectedIndex;
                    selectAppCurrent = dataBindApplist.Skip(currentIndex).Where(filterCharacterNoMatch).FirstOrDefault();
                }
                else
                {
                    int currentIndex = dataBindApplist.Count() - parentListbox.SelectedIndex;
                    selectAppCurrent = dataBindApplist.Reverse().Skip(currentIndex).Where(filterCharacterNoMatch).FirstOrDefault();
                    if (selectAppCurrent != null)
                    {
                        currentCharacter = selectAppCurrent.Name.ToUpper()[0];
                        selectAppCurrent = dataBindApplist.Where(filterCharacterMatch).FirstOrDefault();
                    }
                }

                //Select the target application
                if (selectAppCurrent != null)
                {
                    char   selectCharacterCurrent = selectAppCurrent.Name.ToUpper()[0];
                    char   selectCharacterNext1   = (char)(selectCharacterCurrent + 1);
                    char   selectCharacterNext2   = (char)(selectCharacterCurrent + 2);
                    char   selectCharacterNext3   = (char)(selectCharacterCurrent + 3);
                    char   selectCharacterPrev1   = (char)(selectCharacterCurrent - 1);
                    char   selectCharacterPrev2   = (char)(selectCharacterCurrent - 2);
                    char   selectCharacterPrev3   = (char)(selectCharacterCurrent - 3);
                    string selectStringCurrent    = selectCharacterCurrent.ToString();
                    string selectStringNext       = selectCharacterNext1.ToString() + selectCharacterNext2.ToString() + selectCharacterNext3.ToString();
                    string selectStringPrev       = selectCharacterPrev3.ToString() + selectCharacterPrev2.ToString() + selectCharacterPrev1.ToString();

                    //Show character overlay
                    ShowCharacterOverlay(selectStringCurrent, selectStringNext, selectStringPrev);

                    //Listbox focus and select the item
                    await ListBoxFocusItem(parentListbox, selectAppCurrent, vProcessCurrent.MainWindowHandle);

                    Debug.WriteLine("Selected list character: " + selectCharacterCurrent + "/" + selectAppCurrent.Name);
                }

                //Play interface sound
                PlayInterfaceSound(vConfigurationCtrlUI, "Click", false);
            }
            catch { }
        }
Example #24
0
        async Task FilePicker_FileRemove_Remove(DataBindFile dataBindFile, bool useRecycleBin)
        {
            try
            {
                //Check the file or folder
                if (dataBindFile.FileType == FileType.FolderPre || dataBindFile.FileType == FileType.FilePre || dataBindFile.FileType == FileType.GoUpPre)
                {
                    await Notification_Send_Status("Close", "Invalid file or folder");

                    Debug.WriteLine("Invalid file or folder: " + dataBindFile.Name + " path: " + dataBindFile.PathFile);
                    return;
                }

                //Remove file or folder
                SHFILEOPSTRUCT shFileOpstruct = new SHFILEOPSTRUCT();
                shFileOpstruct.wFunc = FILEOP_FUNC.FO_DELETE;
                shFileOpstruct.pFrom = dataBindFile.PathFile + "\0\0";
                if (useRecycleBin)
                {
                    shFileOpstruct.fFlags = FILEOP_FLAGS.FOF_NOCONFIRMATION | FILEOP_FLAGS.FOF_ALLOWUNDO;
                }
                else
                {
                    shFileOpstruct.fFlags = FILEOP_FLAGS.FOF_NOCONFIRMATION;
                }
                int shFileResult = SHFileOperation(ref shFileOpstruct);

                //Check if the removed item is clipboard and reset it
                DataBindFile clipboardFile = vClipboardFiles.Where(x => x.PathFile == dataBindFile.PathFile).FirstOrDefault();
                if (clipboardFile != null)
                {
                    //Remove the clipboard item
                    clipboardFile.ClipboardType = ClipboardType.None;
                    vClipboardFiles.Remove(clipboardFile);
                }

                //Remove file from the listbox
                await ListBoxRemoveItem(lb_FilePicker, List_FilePicker, dataBindFile, true);

                //Check if there are files or folders
                FilePicker_CheckFilesAndFoldersCount();

                //Check file operation status
                if (shFileResult == 0 && !shFileOpstruct.fAnyOperationsAborted)
                {
                    if (useRecycleBin)
                    {
                        await Notification_Send_Status("Remove", "Recycled file or folder");
                    }
                    else
                    {
                        await Notification_Send_Status("Remove", "Removed file or folder");
                    }
                    Debug.WriteLine("Removed file or folder: " + dataBindFile.Name + " path: " + dataBindFile.PathFile);
                }
                else if (shFileOpstruct.fAnyOperationsAborted)
                {
                    await Notification_Send_Status("Remove", "File or folder removal aborted");

                    Debug.WriteLine("File or folder removal aborted: " + dataBindFile.Name + " path: " + dataBindFile.PathFile);
                }
                else
                {
                    await Notification_Send_Status("Remove", "File or folder removal failed");

                    Debug.WriteLine("File or folder removal failed: " + dataBindFile.Name + " path: " + dataBindFile.PathFile);
                }
            }
            catch { }
        }