//Combine all the saved lists to make comparison IEnumerable <DataBindApp> CombineAppLists(bool includeShortcuts, bool includeProcesses, bool includeLaunchers) { try { IEnumerable <DataBindApp> combinedLists = List_Apps.ToList(); combinedLists = combinedLists.Concat(List_Games.ToList()); combinedLists = combinedLists.Concat(List_Emulators.ToList()); if (includeShortcuts) { combinedLists = combinedLists.Concat(List_Shortcuts.ToList()); } if (includeProcesses) { combinedLists = combinedLists.Concat(List_Processes.ToList()); } if (includeLaunchers) { combinedLists = combinedLists.Concat(List_Launchers.ToList()); } return(combinedLists); } catch (Exception ex) { Debug.WriteLine("Failed combining application lists: " + ex.Message); return(null); } }
//Check for empty lists and hide them void ShowHideEmptyList() { try { Visibility visibilityGames = List_Games.Any() ? Visibility.Visible : Visibility.Collapsed; Visibility visibilityApps = List_Apps.Any() ? Visibility.Visible : Visibility.Collapsed; Visibility visibilityEmulators = List_Emulators.Any() ? Visibility.Visible : Visibility.Collapsed; Visibility visibilityLaunchers = List_Launchers.Any() ? Visibility.Visible : Visibility.Collapsed; Visibility visibilityShortcuts = List_Shortcuts.Any() && Convert.ToBoolean(Setting_Load(vConfigurationCtrlUI, "ShowOtherShortcuts")) ? Visibility.Visible : Visibility.Collapsed; Visibility visibilityProcesses = List_Processes.Any() && Convert.ToBoolean(Setting_Load(vConfigurationCtrlUI, "ShowOtherProcesses")) ? Visibility.Visible : Visibility.Collapsed; AVActions.ActionDispatcherInvoke(delegate { sp_Games.Visibility = visibilityGames; sp_Apps.Visibility = visibilityApps; sp_Emulators.Visibility = visibilityEmulators; sp_Launchers.Visibility = visibilityLaunchers; sp_Shortcuts.Visibility = visibilityShortcuts; sp_Processes.Visibility = visibilityProcesses; }); } catch { } }
//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 { } }
//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 { } }