/// <summary>
        /// Initializes a new instance of a League of Legends game detector, but does not start the
        /// process detector.
        /// </summary>
        public LeagueProcessWatcherServiceImpl(ProcessWatcherService processWatcherService)
        {
            this.processWatcherService = processWatcherService;
             processWatcherService.Subscribe(HandleNewProcessFound, processNames, false);

             Start();
        }
        /// <summary>
        /// Initializes a new instance of a League of Legends game detector, but does not start the
        /// process detector.
        /// </summary>
        public LeagueProcessWatcherServiceImpl(ProcessWatcherService processWatcherService)
        {
            this.processWatcherService = processWatcherService;
            processWatcherService.Subscribe(HandleNewProcessFound, processNames, false);

            Start();
        }
Ejemplo n.º 3
0
        public ModernAppInfo(int processId, bool trackProcess)
        {
            _processId = processId;

            var appUserModelId = GetAppUserModelIdByPid(processId);

            try
            {
                var shellItem = Shell32.SHCreateItemInKnownFolder(FolderIds.AppsFolder, Shell32.KF_FLAG_DONT_VERIFY, appUserModelId, typeof(IShellItem2).GUID);
                BackgroundColor    = shellItem.GetUInt32(ref PropertyKeys.PKEY_AppUserModel_Background);
                PackageInstallPath = shellItem.GetString(ref PropertyKeys.PKEY_AppUserModel_PackageInstallPath);
                DisplayName        = shellItem.GetString(ref PropertyKeys.PKEY_ItemNameDisplay);
                ExeName            = PackageInstallPath;
                SmallLogoPath      = appUserModelId;
            }
            catch (COMException ex)
            {
                Trace.WriteLine($"ModernAppInfo AppsFolder lookup failed 0x{((uint)ex.HResult).ToString("x")} {appUserModelId}");
            }
            catch (Exception ex)
            {
                Trace.WriteLine($"ModernAppInfo AppsFolder lookup failed {appUserModelId} {ex}");
            }

            if (string.IsNullOrWhiteSpace(DisplayName))
            {
                DisplayName = appUserModelId;
            }

            if (trackProcess)
            {
                ProcessWatcherService.WatchProcess(processId, (pid) => Stopped?.Invoke(this));
            }
        }
Ejemplo n.º 4
0
        public ModernAppInfo(int processId, bool trackProcess)
        {
            this.processId = processId;

            var appUserModelId = GetAppUserModelIdByPid(processId);
            var shellItem      = GetShellItemForAppByAumid(appUserModelId);

            BackgroundColor    = shellItem.GetUInt32(ref PropertyKeys.PKEY_AppUserModel_Background);
            PackageInstallPath = shellItem.GetString(ref PropertyKeys.PKEY_AppUserModel_PackageInstallPath);
            ExeName            = PackageInstallPath;
            DisplayName        = AppsFolder.ReadDisplayName(appUserModelId);

            try
            {
                var rawSmallLogoPath = shellItem.GetString(ref PropertyKeys.PKEY_Tile_SmallLogoPath);
                var smallLogoPath    = Path.Combine(PackageInstallPath, rawSmallLogoPath);
                if (File.Exists(smallLogoPath))
                {
                    SmallLogoPath = smallLogoPath;
                }
                else
                {
                    var mrtResourceManager = (IMrtResourceManager) new MrtResourceManager();
                    mrtResourceManager.InitializeForPackage(shellItem.GetString(ref PropertyKeys.PKEY_AppUserModel_PackageFullName));

                    var map = mrtResourceManager.GetMainResourceMap();
                    SmallLogoPath = Path.Combine(PackageInstallPath, map.GetFilePath(rawSmallLogoPath));

                    Marshal.ReleaseComObject(map);
                    Marshal.ReleaseComObject(mrtResourceManager);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine($"{ex}");
            }

            if (trackProcess)
            {
                ProcessWatcherService.WatchProcess(processId, (pid) => Stopped?.Invoke(this));
            }
        }
Ejemplo n.º 5
0
        public DesktopAppInfo(int processId, bool trackProcess)
        {
            _processId = processId;

            var handle = Kernel32.OpenProcess(Kernel32.ProcessFlags.PROCESS_QUERY_LIMITED_INFORMATION | Kernel32.ProcessFlags.SYNCHRONIZE, false, processId);

            if (handle != IntPtr.Zero)
            {
                try
                {
                    ZombieProcessException.ThrowIfZombie(processId, handle);

                    var  fileNameBuilder = new StringBuilder(260);
                    uint bufferLength    = (uint)fileNameBuilder.Capacity;
                    if (Kernel32.QueryFullProcessImageName(handle, 0, fileNameBuilder, ref bufferLength) != 0)
                    {
                        if (fileNameBuilder.Length > 0)
                        {
                            var processFullPath = fileNameBuilder.ToString();
                            ExeName            = Path.GetFileNameWithoutExtension(processFullPath);
                            SmallLogoPath      = processFullPath;
                            PackageInstallPath = processFullPath;
                        }
                    }
                }
                finally
                {
                    Kernel32.CloseHandle(handle);
                }
            }
            else
            {
                trackProcess = false;

                if (TryGetExecutableNameViaNtByPid(processId, out var imageName))
                {
                    ExeName            = Path.GetFileNameWithoutExtension(imageName);
                    SmallLogoPath      = imageName;
                    PackageInstallPath = imageName;
                }
                else
                {
                    throw new ZombieProcessException(processId);
                }
            }

            // Display Name priority:
            // - AppsFolder
            // - A window caption
            // - Exe Name

            try
            {
                var appResolver = (IApplicationResolver) new ApplicationResolver();
                appResolver.GetAppIDForProcess((uint)processId, out string appId, out _, out _, out _);
                Marshal.ReleaseComObject(appResolver);

                var shellItem = Shell32.SHCreateItemInKnownFolder(FolderIds.AppsFolder, Shell32.KF_FLAG_DONT_VERIFY, appId, typeof(IShellItem2).GUID);
                DisplayName = shellItem.GetString(ref PropertyKeys.PKEY_ItemNameDisplay);
            }
            catch (COMException ex)
            {
                Trace.WriteLine($"DesktopAppInfo DisplayName read failed {ExeName} 0x{((uint)ex.HResult).ToString("x")}");
            }
            catch (Exception ex)
            {
                Trace.WriteLine($"DesktopAppInfo DisplayName read failed {ExeName} {ex}");
            }

            if (string.IsNullOrWhiteSpace(DisplayName))
            {
                try
                {
                    using (var proc = Process.GetProcessById(_processId))
                    {
                        DisplayName = proc.MainWindowTitle;
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex);
                }
            }

            if (trackProcess)
            {
                ProcessWatcherService.WatchProcess(processId, (pid) => Stopped?.Invoke(this));
            }
        }