Beispiel #1
0
        async Task UwpAddApplication(Package appPackage, AppxDetails appxDetails)
        {
            try
            {
                //Get application name
                string appName = appxDetails.DisplayName;

                //Check if application name is ignored
                string appNameLower = appName.ToLower();
                if (vCtrlIgnoreLauncherName.Any(x => x.String1.ToLower() == appNameLower))
                {
                    //Debug.WriteLine("Launcher is on the blacklist skipping: " + appName);
                    await ListBoxRemoveAll(lb_Launchers, List_Launchers, x => x.Name.ToLower() == appNameLower);

                    return;
                }

                //Get basic application information
                string runCommand = appPackage.Id.FamilyName;
                vLauncherAppAvailableCheck.Add(runCommand);

                //Check if application is already added
                DataBindApp launcherExistCheck = List_Launchers.Where(x => x.PathExe.ToLower() == runCommand.ToLower()).FirstOrDefault();
                if (launcherExistCheck != null)
                {
                    //Debug.WriteLine("UWP app already in list: " + appIds);
                    return;
                }

                //Load the application image
                BitmapImage iconBitmapImage = FileToBitmapImage(new string[] { appName, appxDetails.SquareLargestLogoPath, appxDetails.WideLargestLogoPath, "Microsoft" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, 90, 0);

                //Add the application to the list
                DataBindApp dataBindApp = new DataBindApp()
                {
                    Type           = ProcessType.UWP,
                    Launcher       = AppLauncher.UWP,
                    Category       = AppCategory.Launcher,
                    Name           = appName,
                    ImageBitmap    = iconBitmapImage,
                    PathExe        = runCommand,
                    StatusLauncher = vImagePreloadMicrosoft
                };

                await ListBoxAddItem(lb_Launchers, List_Launchers, dataBindApp, false, false);

                //Debug.WriteLine("Added UWP app: " + appName);
            }
            catch
            {
                Debug.WriteLine("Failed adding UWP app: " + appxDetails.DisplayName);
            }
        }
Beispiel #2
0
        async Task UwpScanAddLibrary()
        {
            try
            {
                //Get all the installed uwp games
                IEnumerable <GameListEntry> uwpGameList = (await GameList.FindAllAsync()).Where(x => x.Category == GameListCategory.ConfirmedBySystem);
                if (!uwpGameList.Any())
                {
                    Debug.WriteLine("No installed uwp games found to list.");
                    return;
                }

                //Add all the installed uwp games
                foreach (GameListEntry uwpGame in uwpGameList)
                {
                    try
                    {
                        //Get and check uwp application FamilyName
                        string appFamilyName = uwpGame.Properties.FirstOrDefault(x => x.Key == "PackageFamilyName").Value.ToString();
                        if (string.IsNullOrWhiteSpace(appFamilyName))
                        {
                            continue;
                        }

                        //Get uwp application package
                        Package appPackage = UwpGetAppPackageByFamilyName(appFamilyName);

                        //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;
                        }

                        await UwpAddApplication(appPackage, appxDetails);
                    }
                    catch { }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed adding uwp games library: " + ex.Message);
            }
        }
        //Launch an uwp application manually
        public static async Task <Process> ProcessLauncherUwpAndWin32StoreAsync(string appUserModelId, string runArgument)
        {
            try
            {
                //Prepare the process launch
                Process TaskAction()
                {
                    try
                    {
                        //Show launching message
                        Debug.WriteLine("Launching UWP or Win32Store: " + appUserModelId + " / " + runArgument);

                        //Get detailed application information
                        Package     appPackage  = UwpGetAppPackageByAppUserModelId(appUserModelId);
                        AppxDetails appxDetails = UwpGetAppxDetailsFromAppPackage(appPackage);
                        appUserModelId = appxDetails.FamilyNameId;

                        //Start the process
                        UWPActivationManager UWPActivationManager = new UWPActivationManager();
                        UWPActivationManager.ActivateApplication(appUserModelId, runArgument, UWPActivationManagerOptions.None, out int processId);

                        //Return process
                        Process returnProcess = GetProcessById(processId);
                        Debug.WriteLine("Launched UWP or Win32Store process identifier: " + returnProcess.Id);
                        return(returnProcess);
                    }
                    catch { }
                    Debug.WriteLine("Failed launching UWP or Win32Store: " + appUserModelId + " / " + runArgument);
                    return(null);
                };

                //Launch the process
                return(await AVActions.TaskStartReturn(TaskAction));
            }
            catch { }
            Debug.WriteLine("Failed launching UWP or Win32Store: " + appUserModelId + " / " + runArgument);
            return(null);
        }
Beispiel #4
0
        //Update all uwp application images
        void UpdateUwpApplicationImages()
        {
            try
            {
                Debug.WriteLine("Checking all uwp application images for changes.");
                bool UpdatedImages = false;

                //Update all the uwp apps image paths
                foreach (DataBindApp dataBindApp in CombineAppLists(false, false, false).Where(x => x.Type == ProcessType.UWP || x.Type == ProcessType.Win32Store))
                {
                    try
                    {
                        if (!string.IsNullOrWhiteSpace(dataBindApp.PathImage) && !File.Exists(dataBindApp.PathImage))
                        {
                            Debug.WriteLine("Uwp application image not found: " + dataBindApp.PathImage);

                            //Get detailed application information
                            Package     appPackage  = UwpGetAppPackageByAppUserModelId(dataBindApp.PathExe);
                            AppxDetails appxDetails = UwpGetAppxDetailsFromAppPackage(appPackage);

                            //Update the application icons
                            dataBindApp.PathImage   = appxDetails.SquareLargestLogoPath;
                            dataBindApp.ImageBitmap = FileToBitmapImage(new string[] { dataBindApp.Name, appxDetails.SquareLargestLogoPath, appxDetails.WideLargestLogoPath }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, 90, 0);
                            UpdatedImages           = true;
                        }
                    }
                    catch { }
                }

                //Save the updated uwp application images
                if (UpdatedImages)
                {
                    JsonSaveApplications();
                }
            }
            catch { }
        }
        //Get uwp process by window handle
        public static Process GetUwpProcessByWindowHandle(IntPtr targetWindowHandle)
        {
            try
            {
                //Get process from the window handle
                IntPtr threadWindowHandleEx = FindWindowEx(targetWindowHandle, IntPtr.Zero, "Windows.UI.Core.CoreWindow", null);
                if (threadWindowHandleEx != IntPtr.Zero)
                {
                    int processId = GetProcessIdFromWindowHandle(threadWindowHandleEx);
                    if (processId > 0)
                    {
                        return(GetProcessById(processId));
                    }
                }

                //Get process from the appx package
                string      appUserModelId = GetAppUserModelIdFromWindowHandle(targetWindowHandle);
                Package     appPackage     = UwpGetAppPackageByAppUserModelId(appUserModelId);
                AppxDetails appxDetails    = UwpGetAppxDetailsFromAppPackage(appPackage);
                return(GetUwpProcessByProcessNameAndAppUserModelId(Path.GetFileNameWithoutExtension(appxDetails.ExecutableName), appUserModelId));
            }
            catch { }
            return(null);
        }
Beispiel #6
0
        //Add shortcut to the shortcuts list
        async Task ShortcutAddToListWithDetails(ShortcutDetails shortcutDetails)
        {
            try
            {
                //Check if the shortcut name is set
                if (string.IsNullOrWhiteSpace(shortcutDetails.Title))
                {
                    Debug.WriteLine("Shortcut name is not set, skipping shortcut.");
                    return;
                }

                //Get the shortcut target file name
                string      targetPathLower      = shortcutDetails.TargetPath.ToLower();
                string      targetExtensionLower = Path.GetExtension(targetPathLower).Replace(".", string.Empty);
                Visibility  shortcutUrlProtocol  = Visibility.Collapsed;
                Visibility  shortcutWindowStore  = Visibility.Collapsed;
                Visibility  shortcutAvailable    = Visibility.Collapsed;
                ProcessType shortcutProcessType  = ProcessType.Win32;
                BitmapImage launcherImage        = null;

                //Check if executable or UrlProtocol app shortcut
                if (targetPathLower.EndsWith(".exe"))
                {
                    //Check if the executable still exists
                    if (!File.Exists(targetPathLower))
                    {
                        shortcutAvailable = Visibility.Visible;
                    }
                }
                else if (targetPathLower.EndsWith(".bat"))
                {
                    //Check if the bat file still exists
                    if (!File.Exists(targetPathLower))
                    {
                        shortcutAvailable = Visibility.Visible;
                    }
                    else
                    {
                        shortcutUrlProtocol = Visibility.Visible;
                    }
                }
                else if (targetPathLower.Contains("://"))
                {
                    //Check if shortcut is url protocol
                    shortcutUrlProtocol = Visibility.Visible;

                    //Check if url protocol is a launcher and set icon
                    if (targetPathLower.Contains("steam://"))
                    {
                        launcherImage = vImagePreloadSteam;
                    }
                    else if (targetPathLower.Contains("com.epicgames.launcher://"))
                    {
                        launcherImage = vImagePreloadEpic;
                    }
                    else if (targetPathLower.Contains("uplay://"))
                    {
                        launcherImage = vImagePreloadUbisoft;
                    }
                    else if (targetPathLower.Contains("battlenet://"))
                    {
                        launcherImage = vImagePreloadBattleNet;
                    }
                    else if (targetPathLower.Contains("bethesdanet://"))
                    {
                        launcherImage = vImagePreloadBethesda;
                    }
                    else if (targetPathLower.Contains("origin://"))
                    {
                        launcherImage = vImagePreloadEADesktop;
                    }
                    else if (targetPathLower.Contains("link2ea://"))
                    {
                        launcherImage = vImagePreloadEADesktop;
                    }
                    else if (targetPathLower.Contains("amazon-games://"))
                    {
                        launcherImage = vImagePreloadAmazon;
                    }
                }
                else if (!targetPathLower.Contains("/") && targetPathLower.Contains("!") && targetPathLower.Contains("_"))
                {
                    //Check if shortcut is windows store app
                    shortcutProcessType = ProcessType.UWP;
                    shortcutWindowStore = Visibility.Visible;

                    //Get basic application information
                    Package appPackage = UwpGetAppPackageByAppUserModelId(shortcutDetails.TargetPath);

                    //Check if the app still exists
                    if (appPackage == null)
                    {
                        shortcutAvailable = Visibility.Visible;
                    }
                    else
                    {
                        //Get detailed application information
                        AppxDetails appxDetails = UwpGetAppxDetailsFromAppPackage(appPackage);

                        //Set the application icon path
                        shortcutDetails.IconPath = appxDetails.SquareLargestLogoPath;

                        //Set the applicaton exe name
                        shortcutDetails.NameExe = appxDetails.ExecutableName;
                    }
                }
                else
                {
                    //Debug.WriteLine("Unknown shortcut: " + TargetPathLower);
                    return;
                }

                //Get icon image from the path
                BitmapImage iconBitmapImage = null;
                if (shortcutAvailable == Visibility.Visible)
                {
                    iconBitmapImage = FileToBitmapImage(new string[] { "Unknown" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, 90, 0);
                }
                else
                {
                    iconBitmapImage = FileToBitmapImage(new string[] { shortcutDetails.Title, shortcutDetails.IconPath, targetPathLower, "Assets/Default/Extensions/" + targetExtensionLower + ".png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, 90, shortcutDetails.IconIndex);
                }

                //Add the shortcut to the list
                DataBindApp dataBindApp = new DataBindApp()
                {
                    Type = shortcutProcessType, Category = AppCategory.Shortcut, Name = shortcutDetails.Title, NameExe = shortcutDetails.NameExe, ImageBitmap = iconBitmapImage, PathExe = shortcutDetails.TargetPath, PathLaunch = shortcutDetails.WorkingPath, ShortcutPath = shortcutDetails.ShortcutPath, Argument = shortcutDetails.Argument, StatusStore = shortcutWindowStore, StatusUrlProtocol = shortcutUrlProtocol, StatusLauncher = launcherImage, TimeCreation = shortcutDetails.TimeModify, StatusAvailable = shortcutAvailable
                };
                await ListBoxAddItem(lb_Shortcuts, List_Shortcuts, dataBindApp, false, false);
            }
            catch
            {
                //Debug.WriteLine("Failed to add shortcut to list: " + shortcutDetails.ShortcutPath);
            }
        }
Beispiel #7
0
        //Get all the active Win32 processes and update the lists
        async Task ListLoadCheckProcessesWin32(Process[] processesList, List <int> activeProcessesId, List <IntPtr> activeProcessesWindow, IEnumerable <DataBindApp> currentListApps, bool showStatus)
        {
            try
            {
                //Check if processes list is provided
                if (processesList == null)
                {
                    processesList = Process.GetProcesses();
                }

                //Check if there are active processes
                if (processesList.Any())
                {
                    //Show refresh status message
                    if (showStatus)
                    {
                        await Notification_Send_Status("Refresh", "Refreshing desktop apps");
                    }
                    //Debug.WriteLine("Checking desktop processes.");

                    //Add new running process if needed
                    foreach (Process processApp in processesList)
                    {
                        try
                        {
                            //Process identifier
                            int processIdentifier = processApp.Id;

                            //Process window handle
                            IntPtr processWindowHandle = processApp.MainWindowHandle;

                            //Process application type
                            ProcessType processType = ProcessType.Win32;

                            //Process Windows Store Status
                            Visibility processStatusStore = Visibility.Collapsed;

                            //Get the process title
                            string processTitle = GetWindowTitleFromProcess(processApp);

                            //Check if application title is blacklisted
                            if (vCtrlIgnoreProcessName.Any(x => x.String1.ToLower() == processTitle.ToLower()))
                            {
                                continue;
                            }

                            //Validate the process state
                            if (!ValidateProcessState(processApp, true, true))
                            {
                                continue;
                            }

                            //Validate the window handle
                            bool windowValidation = ValidateWindowHandle(processWindowHandle);

                            //Get the executable path
                            string processPathExe           = GetExecutablePathFromProcess(processApp);
                            string processPathExeLower      = processPathExe.ToLower();
                            string processPathExeImage      = processPathExe;
                            string processNameExe           = Path.GetFileName(processPathExe);
                            string processNameExeLower      = processNameExe.ToLower();
                            string processNameExeNoExt      = Path.GetFileNameWithoutExtension(processPathExe);
                            string processNameExeNoExtLower = processNameExeNoExt.ToLower();

                            //Get the process launch arguments
                            string processArgument = GetLaunchArgumentsFromProcess(processApp, processPathExe);

                            //Check if application name is blacklisted
                            if (vCtrlIgnoreProcessName.Any(x => x.String1.ToLower() == processNameExeNoExtLower))
                            {
                                continue;
                            }

                            //Check explorer process
                            if (processNameExeLower == "explorer.exe")
                            {
                                processTitle = "File Explorer";
                            }

                            //Add active process to the list
                            activeProcessesId.Add(processIdentifier);
                            activeProcessesWindow.Add(processWindowHandle);

                            //Check the process running time
                            int processRunningTime = ProcessRuntimeMinutes(processApp);

                            //Check if the process is suspended
                            Visibility processStatusRunning        = Visibility.Visible;
                            Visibility processStatusSuspended      = Visibility.Collapsed;
                            ProcessThreadCollection processThreads = processApp.Threads;
                            if (CheckProcessSuspended(processThreads))
                            {
                                processStatusRunning   = Visibility.Collapsed;
                                processStatusSuspended = Visibility.Visible;
                            }

                            //Set the application search filters
                            Func <DataBindApp, bool> filterCombinedApp = x => (!string.IsNullOrWhiteSpace(x.PathExe) && Path.GetFileNameWithoutExtension(x.PathExe).ToLower() == processNameExeNoExtLower) || (!string.IsNullOrWhiteSpace(x.NameExe) && x.NameExe.ToLower() == processNameExeLower);
                            Func <DataBindApp, bool> filterProcessApp  = x => x.ProcessMulti.Any(z => z.WindowHandle == processWindowHandle);

                            //Check if process is a Win32Store app
                            string processAppUserModelId = GetAppUserModelIdFromProcess(processApp);
                            if (!string.IsNullOrWhiteSpace(processAppUserModelId))
                            {
                                processType         = ProcessType.Win32Store;
                                processPathExe      = processAppUserModelId;
                                processPathExeLower = processAppUserModelId.ToLower();
                                processStatusStore  = Visibility.Visible;
                                filterCombinedApp   = x => (!string.IsNullOrWhiteSpace(x.PathExe) && x.PathExe.ToLower() == processPathExeLower) || (!string.IsNullOrWhiteSpace(x.NameExe) && x.NameExe.ToLower() == processNameExeLower);

                                //Validate the window handle
                                if (!windowValidation)
                                {
                                    //Debug.WriteLine(processName + " is an invalid Win32Store application.");
                                    continue;
                                }
                                else
                                {
                                    //Debug.WriteLine(processName + " is a Win32Store application.");}
                                }
                            }

                            //Convert Process To ProcessMulti
                            ProcessMulti processMultiNew = new ProcessMulti();
                            processMultiNew.Type         = processType;
                            processMultiNew.Identifier   = processIdentifier;
                            processMultiNew.WindowHandle = processWindowHandle;
                            processMultiNew.Argument     = processArgument;

                            //Check all the lists for the application
                            IEnumerable <DataBindApp> existingCombinedApps = currentListApps.Where(filterCombinedApp);
                            IEnumerable <DataBindApp> existingProcessApps  = List_Processes.Where(filterProcessApp);
                            bool appUpdatedContinueLoop = false;

                            //Check if process is in combined list and update it
                            foreach (DataBindApp existingCombinedApp in existingCombinedApps)
                            {
                                //Update the process running time
                                existingCombinedApp.RunningTime = processRunningTime;

                                //Update the process running status
                                existingCombinedApp.StatusRunning = processStatusRunning;

                                //Update the process suspended status
                                existingCombinedApp.StatusSuspended = processStatusSuspended;

                                //Update the application last runtime
                                existingCombinedApp.RunningTimeLastUpdate = GetSystemTicksMs();

                                //Add the new process multi application
                                if (!existingCombinedApp.ProcessMulti.Any(x => x.WindowHandle == processWindowHandle))
                                {
                                    existingCombinedApp.ProcessMulti.Add(processMultiNew);
                                }

                                //Remove app from processes list
                                if (Convert.ToBoolean(Setting_Load(vConfigurationCtrlUI, "HideAppProcesses")))
                                {
                                    await ListBoxRemoveAll(lb_Processes, List_Processes, filterCombinedApp);

                                    appUpdatedContinueLoop = true;
                                }
                            }
                            if (appUpdatedContinueLoop)
                            {
                                continue;
                            }

                            //Check if process is in process list and update it
                            foreach (DataBindApp existingProcessApp in existingProcessApps)
                            {
                                //Update the process title
                                if (existingProcessApp.Name != processTitle)
                                {
                                    existingProcessApp.Name = processTitle;
                                }

                                //Update the process running time
                                existingProcessApp.RunningTime = processRunningTime;

                                //Update the process suspended status
                                existingProcessApp.StatusSuspended = processStatusSuspended;

                                //Update the process multi identifier
                                foreach (ProcessMulti processMulti in existingProcessApp.ProcessMulti.Where(x => x.Identifier <= 0))
                                {
                                    processMulti.Identifier = processIdentifier;
                                }

                                //Update the process multi window handle
                                foreach (ProcessMulti processMulti in existingProcessApp.ProcessMulti.Where(x => x.WindowHandle == IntPtr.Zero))
                                {
                                    processMulti.WindowHandle = processWindowHandle;
                                }

                                appUpdatedContinueLoop = true;
                            }
                            if (appUpdatedContinueLoop)
                            {
                                continue;
                            }

                            //Validate the window handle
                            if (!windowValidation)
                            {
                                continue;
                            }

                            //Load Windows store application images
                            string storeImageSquare = string.Empty;
                            string storeImageWide   = string.Empty;
                            if (processType == ProcessType.Win32Store)
                            {
                                Package     appPackage  = UwpGetAppPackageByAppUserModelId(processPathExe);
                                AppxDetails appxDetails = UwpGetAppxDetailsFromAppPackage(appPackage);
                                storeImageSquare = appxDetails.SquareLargestLogoPath;
                                storeImageWide   = appxDetails.WideLargestLogoPath;
                            }

                            //Load the application image
                            BitmapImage processImageBitmap = FileToBitmapImage(new string[] { processTitle, processNameExeNoExt, storeImageSquare, storeImageWide, processPathExeImage, processPathExe }, vImageSourceFolders, vImageBackupSource, processWindowHandle, 90, 0);

                            //Create new ProcessMulti list
                            List <ProcessMulti> listProcessMulti = new List <ProcessMulti>();
                            listProcessMulti.Add(processMultiNew);

                            //Add the process to the process list
                            DataBindApp dataBindApp = new DataBindApp()
                            {
                                Type = processType, Category = AppCategory.Process, ProcessMulti = listProcessMulti, ImageBitmap = processImageBitmap, Name = processTitle, NameExe = processNameExe, PathExe = processPathExe, StatusStore = processStatusStore, StatusSuspended = processStatusSuspended, RunningTime = processRunningTime
                            };
                            await ListBoxAddItem(lb_Processes, List_Processes, dataBindApp, false, false);

                            //Add the process to the search list
                            await AddSearchProcess(dataBindApp);
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine("Failed adding Win32 or Win32Store application: " + ex.Message);
                        }
                    }
                }
            }
            catch { }
        }
Beispiel #8
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 { }
        }
Beispiel #9
0
        //Get all the active UWP processes and update the lists
        async Task ListLoadCheckProcessesUwp(List <int> activeProcessesId, List <IntPtr> activeProcessesWindow, IEnumerable <DataBindApp> currentListApps, bool showStatus)
        {
            try
            {
                //Check if there are active processes
                Process frameHostProcess = GetProcessByNameOrTitle("ApplicationFrameHost", false);
                if (frameHostProcess != null)
                {
                    //Show refresh status message
                    if (showStatus)
                    {
                        await Notification_Send_Status("Refresh", "Refreshing store apps");
                    }
                    //Debug.WriteLine("Checking store processes.");

                    //Add new running process if needed
                    foreach (ProcessThread threadProcess in frameHostProcess.Threads)
                    {
                        try
                        {
                            //Process variables
                            Process processApp            = null;
                            int     processIdentifier     = -1;
                            bool    processInterfaceCheck = false;
                            IntPtr  processWindowHandle   = IntPtr.Zero;

                            foreach (IntPtr threadWindowHandle in EnumThreadWindows(threadProcess.Id))
                            {
                                try
                                {
                                    //Get window class name
                                    string classNameString = GetClassNameFromWindowHandle(threadWindowHandle);

                                    //Get information from frame window
                                    if (classNameString == "ApplicationFrameWindow")
                                    {
                                        //Set window handle
                                        processWindowHandle = threadWindowHandle;

                                        //Get app process
                                        IntPtr threadWindowHandleEx = FindWindowEx(threadWindowHandle, IntPtr.Zero, "Windows.UI.Core.CoreWindow", null);
                                        if (threadWindowHandleEx != IntPtr.Zero)
                                        {
                                            processIdentifier = GetProcessIdFromWindowHandle(threadWindowHandleEx);
                                            if (processIdentifier > 0)
                                            {
                                                processApp = GetProcessById(processIdentifier);
                                            }
                                        }
                                    }

                                    //Check if uwp application has interface
                                    if (classNameString == "MSCTFIME UI")
                                    {
                                        processInterfaceCheck = true;
                                    }
                                }
                                catch { }
                            }

                            //Check if uwp application has interface
                            if (processInterfaceCheck)
                            {
                                //Process application type
                                ProcessType processType = ProcessType.UWP;

                                //Process Windows Store Status
                                Visibility processStatusStore = Visibility.Visible;

                                //Get the process title
                                string processTitle = GetWindowTitleFromWindowHandle(processWindowHandle);

                                //Check if application title is blacklisted
                                if (vCtrlIgnoreProcessName.Any(x => x.String1.ToLower() == processTitle.ToLower()))
                                {
                                    continue;
                                }

                                //Get the application user model id
                                string processPathExe = GetAppUserModelIdFromWindowHandle(processWindowHandle);
                                if (string.IsNullOrWhiteSpace(processPathExe))
                                {
                                    processPathExe = GetAppUserModelIdFromProcess(processApp);
                                }
                                string processPathExeLower = processPathExe.ToLower();

                                //Get detailed application information
                                Package     appPackage               = UwpGetAppPackageByAppUserModelId(processPathExe);
                                AppxDetails appxDetails              = UwpGetAppxDetailsFromAppPackage(appPackage);
                                string      processNameExe           = appxDetails.ExecutableName;
                                string      processNameExeLower      = processNameExe.ToLower();
                                string      processNameExeNoExt      = Path.GetFileNameWithoutExtension(processNameExe);
                                string      processNameExeNoExtLower = processNameExeNoExt.ToLower();

                                //Check if application name is blacklisted
                                if (vCtrlIgnoreProcessName.Any(x => x.String1.ToLower() == processNameExeNoExtLower))
                                {
                                    continue;
                                }

                                //Check if the process has been found
                                if (processApp == null)
                                {
                                    processApp        = GetUwpProcessByProcessNameAndAppUserModelId(processNameExeNoExt, processPathExe);
                                    processIdentifier = processApp.Id;
                                }

                                //Add active process to the list
                                activeProcessesId.Add(processIdentifier);
                                activeProcessesWindow.Add(processWindowHandle);

                                //Check the process running time
                                int processRunningTime = ProcessRuntimeMinutes(processApp);

                                //Check if the process is suspended
                                Visibility processStatusRunning        = Visibility.Visible;
                                Visibility processStatusSuspended      = Visibility.Collapsed;
                                ProcessThreadCollection processThreads = processApp.Threads;
                                if (CheckProcessSuspended(processThreads))
                                {
                                    processStatusRunning   = Visibility.Collapsed;
                                    processStatusSuspended = Visibility.Visible;
                                }

                                //Convert Process To ProcessMulti
                                ProcessMulti processMultiNew = new ProcessMulti();
                                processMultiNew.Type         = processType;
                                processMultiNew.Identifier   = processIdentifier;
                                processMultiNew.WindowHandle = processWindowHandle;

                                //Set the application search filters
                                Func <DataBindApp, bool> filterCombinedApp = x => x.PathExe != null && x.PathExe.ToLower() == processPathExeLower;
                                Func <DataBindApp, bool> filterProcessApp  = x => x.ProcessMulti.Any(z => z.WindowHandle == processWindowHandle);

                                //Check all the lists for the application
                                IEnumerable <DataBindApp> existingCombinedApps = currentListApps.Where(filterCombinedApp);
                                IEnumerable <DataBindApp> existingProcessApps  = List_Processes.Where(filterProcessApp);
                                bool appUpdatedContinueLoop = false;

                                //Check if process is in combined list and update it
                                foreach (DataBindApp existingCombinedApp in existingCombinedApps)
                                {
                                    //Update the process running time
                                    existingCombinedApp.RunningTime = processRunningTime;

                                    //Update the process running status
                                    existingCombinedApp.StatusRunning = processStatusRunning;

                                    //Update the process suspended status
                                    existingCombinedApp.StatusSuspended = processStatusSuspended;

                                    //Update the application last runtime
                                    existingCombinedApp.RunningTimeLastUpdate = GetSystemTicksMs();

                                    //Add the new process multi application
                                    if (!existingCombinedApp.ProcessMulti.Any(x => x.WindowHandle == processWindowHandle))
                                    {
                                        existingCombinedApp.ProcessMulti.Add(processMultiNew);
                                    }

                                    //Remove app from processes list
                                    if (Convert.ToBoolean(Setting_Load(vConfigurationCtrlUI, "HideAppProcesses")))
                                    {
                                        await ListBoxRemoveAll(lb_Processes, List_Processes, filterCombinedApp);

                                        appUpdatedContinueLoop = true;
                                    }
                                }
                                if (appUpdatedContinueLoop)
                                {
                                    continue;
                                }

                                //Check if process is in process list and update it
                                foreach (DataBindApp existingProcessApp in existingProcessApps)
                                {
                                    //Update the process title
                                    if (existingProcessApp.Name != processTitle)
                                    {
                                        existingProcessApp.Name = processTitle;
                                    }

                                    //Update the process running time
                                    existingProcessApp.RunningTime = processRunningTime;

                                    //Update the process suspended status
                                    existingProcessApp.StatusSuspended = processStatusSuspended;

                                    //Update the process multi identifier
                                    foreach (ProcessMulti processMulti in existingProcessApp.ProcessMulti.Where(x => x.Identifier <= 0))
                                    {
                                        processMulti.Identifier = processIdentifier;
                                    }

                                    //Update the process multi window handle
                                    foreach (ProcessMulti processMulti in existingProcessApp.ProcessMulti.Where(x => x.WindowHandle == IntPtr.Zero))
                                    {
                                        processMulti.WindowHandle = processWindowHandle;
                                    }

                                    appUpdatedContinueLoop = true;
                                }
                                if (appUpdatedContinueLoop)
                                {
                                    continue;
                                }

                                //Load the application image
                                BitmapImage processImageBitmap = FileToBitmapImage(new string[] { processTitle, processNameExeNoExt, appxDetails.SquareLargestLogoPath, appxDetails.WideLargestLogoPath }, vImageSourceFolders, vImageBackupSource, processWindowHandle, 90, 0);

                                //Create new ProcessMulti list
                                List <ProcessMulti> listProcessMulti = new List <ProcessMulti>();
                                listProcessMulti.Add(processMultiNew);

                                //Add the process to the process list
                                DataBindApp dataBindApp = new DataBindApp()
                                {
                                    Type = processType, Category = AppCategory.Process, ProcessMulti = listProcessMulti, ImageBitmap = processImageBitmap, Name = processTitle, NameExe = processNameExe, PathExe = processPathExe, StatusStore = processStatusStore, StatusSuspended = processStatusSuspended, RunningTime = processRunningTime
                                };
                                await ListBoxAddItem(lb_Processes, List_Processes, dataBindApp, false, false);

                                //Add the process to the search list
                                await AddSearchProcess(dataBindApp);
                            }
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine("Failed adding UWP application: " + ex.Message);
                        }
                    }
                }
            }
            catch { }
        }
Beispiel #10
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 { }
        }
        //Get uwp application details from package
        public static AppxDetails UwpGetAppxDetailsFromAppPackage(Package appPackage)
        {
            IStream      inputStream = null;
            IAppxFactory appxFactory = (IAppxFactory) new AppxFactory();
            AppxDetails  appxDetails = new AppxDetails();

            try
            {
                //Get detailed information from app package
                string appFamilyName = appPackage.Id.FamilyName;
                appxDetails.FullPackageName = appPackage.Id.FullName;
                appxDetails.InstallPath     = appPackage.InstalledLocation.Path;
                string manifestPath = appxDetails.InstallPath + "/AppXManifest.xml";
                //Debug.WriteLine("Reading uwp app manifest file: " + manifestPath);

                //Open the uwp application manifest file
                SHCreateStreamOnFileEx(manifestPath, STGM_MODES.STGM_SHARE_DENY_NONE, 0, false, IntPtr.Zero, out inputStream);
                if (inputStream != null)
                {
                    IAppxManifestReader      appxManifestReader      = appxFactory.CreateManifestReader(inputStream);
                    IAppxManifestApplication appxManifestApplication = appxManifestReader.GetApplications().GetCurrent();

                    //Get and set the application executable name
                    appxManifestApplication.GetStringValue("Executable", out string executableName);
                    appxDetails.ExecutableName = Path.GetFileName(executableName);

                    //Get and set the family name identifier
                    appxManifestApplication.GetStringValue("Id", out string appIdentifier);
                    appxDetails.FamilyNameId = appFamilyName + "!" + appIdentifier;

                    //Get and set the application display name
                    appxManifestApplication.GetStringValue("DisplayName", out string displayName);
                    appxDetails.DisplayName = UwpGetMsResourceString(appIdentifier, appxDetails.FullPackageName, displayName);

                    //Get all the available application logo images
                    appxManifestApplication.GetStringValue("Square30x30Logo", out appxDetails.Square30x30Logo);
                    appxManifestApplication.GetStringValue("Square70x70Logo", out appxDetails.Square70x70Logo);
                    appxManifestApplication.GetStringValue("Square150x150Logo", out appxDetails.Square150x150Logo);
                    appxManifestApplication.GetStringValue("Square310x310Logo", out appxDetails.Square310x310Logo);
                    appxManifestApplication.GetStringValue("Wide310x150Logo", out appxDetails.Wide310x150Logo);

                    //Check the largest available square logo
                    if (!string.IsNullOrWhiteSpace(appxDetails.Square310x310Logo))
                    {
                        appxDetails.SquareLargestLogoPath = Path.Combine(appxDetails.InstallPath, appxDetails.Square310x310Logo);
                    }
                    else if (!string.IsNullOrWhiteSpace(appxDetails.Square150x150Logo))
                    {
                        appxDetails.SquareLargestLogoPath = Path.Combine(appxDetails.InstallPath, appxDetails.Square150x150Logo);
                    }
                    else if (!string.IsNullOrWhiteSpace(appxDetails.Square70x70Logo))
                    {
                        appxDetails.SquareLargestLogoPath = Path.Combine(appxDetails.InstallPath, appxDetails.Square70x70Logo);
                    }
                    else if (!string.IsNullOrWhiteSpace(appxDetails.Square30x30Logo))
                    {
                        appxDetails.SquareLargestLogoPath = Path.Combine(appxDetails.InstallPath, appxDetails.Square30x30Logo);
                    }
                    string originalSquareLargestLogoPath = appxDetails.SquareLargestLogoPath;
                    appxDetails.SquareLargestLogoPath = UwpGetImageSizePath(appxDetails.SquareLargestLogoPath);

                    //Check if the file can be accessed
                    try
                    {
                        if (!string.IsNullOrWhiteSpace(appxDetails.SquareLargestLogoPath))
                        {
                            FileStream fileStream = File.OpenRead(appxDetails.SquareLargestLogoPath);
                            fileStream.Dispose();
                        }
                        else
                        {
                            appxDetails.SquareLargestLogoPath = originalSquareLargestLogoPath;
                        }
                    }
                    catch
                    {
                        //Debug.WriteLine("No permission to open: " + appxDetails.SquareLargestLogoPath);
                        appxDetails.SquareLargestLogoPath = originalSquareLargestLogoPath;
                    }

                    //Check the largest available wide logo
                    if (!string.IsNullOrWhiteSpace(appxDetails.Wide310x150Logo))
                    {
                        appxDetails.WideLargestLogoPath = Path.Combine(appxDetails.InstallPath, appxDetails.Wide310x150Logo);
                    }
                    string originalWideLargestLogoPath = appxDetails.WideLargestLogoPath;
                    appxDetails.WideLargestLogoPath = UwpGetImageSizePath(appxDetails.WideLargestLogoPath);

                    //Check if the file can be accessed
                    try
                    {
                        if (!string.IsNullOrWhiteSpace(appxDetails.WideLargestLogoPath))
                        {
                            FileStream fileStream = File.OpenRead(appxDetails.WideLargestLogoPath);
                            fileStream.Dispose();
                        }
                        else
                        {
                            appxDetails.WideLargestLogoPath = originalWideLargestLogoPath;
                        }
                    }
                    catch
                    {
                        //Debug.WriteLine("No permission to open: " + appxDetails.WideLargestLogoPath);
                        appxDetails.WideLargestLogoPath = originalWideLargestLogoPath;
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed reading details from uwp manifest: " + appPackage.Id.FamilyName + "/" + ex.Message);
            }

            Marshal.ReleaseComObject(inputStream);
            Marshal.ReleaseComObject(appxFactory);
            return(appxDetails);
        }