async def _update_status_of_already_running_games(self, process_iter_interval, dont_downgrade_status): for running_game in self.running_games.copy(): if not self.running_games[running_game] and dont_downgrade_status: log.info(f"Found 'just launched' game {running_game}") continue elif not self.running_games[running_game]: log.info( f"Found 'just launched' game but its still without pid and its time run out {running_game}" ) self.running_games.pop(running_game) self.update_local_game_status( LocalGame(running_game, LocalGameState.Installed)) continue for process in process_iter(): await asyncio.sleep(process_iter_interval) if process.binary_path in self.running_games[ running_game].execs: return True self.running_games.pop(running_game) self.update_local_game_status( LocalGame(running_game, LocalGameState.Installed))
def _is_running(self) -> bool: for proc in process_iter(): if proc.binary_path is None: continue for proc_name in self._PROC_NAMES: if proc.binary_path.lower().endswith(os.path.join(os.path.sep, proc_name)): return True return False
async def get_running_game(self, games, proc_iter_interval=0.05): if not games: return for process_info in process_iter(): try: await asyncio.sleep(proc_iter_interval) for game in games: if process_info.binary_path.lower() == games[game].lower(): log.info(f"Found a running game! {game}") return RunningGame(name=game, process=process_info) except: continue
async def _scan_running_games(self, process_iter_interval): for process in process_iter(): await asyncio.sleep(process_iter_interval) for local_game in self.local_client.local_games_cache: if not process.binary_path: continue if process.binary_path in self.local_client.local_games_cache[local_game]['execs']: log.info(f"Found a running game! {local_game}") local_id = self.local_client.local_games_cache[local_game]['local_id'] if local_id not in self.running_games: self.update_local_game_status(LocalGame(local_id, LocalGameState.Installed | LocalGameState.Running)) self.running_games[local_id] = RunningGame(self.local_client.local_games_cache[local_game]['execs'], process)
def _get_local_games(self) -> Dict[str, InstalledGame]: installed_games = self._get_installed_games() if not installed_games: return installed_games running_processes = [ proc_info.binary_path for proc_info in process_iter() if proc_info and proc_info.binary_path ] def is_game_running(game_install_path) -> bool: for process_path in running_processes: if process_path.startswith(game_install_path): return True return False for installed_game in installed_games.values(): if is_game_running(installed_game.install_path): installed_game.local_game_state |= LocalGameState.Running return installed_games
async def task_check_for_running_func(self): #skip status update if there is no instances if self._last_state == LocalGameState.None_ and not self._game_instances: await asyncio.sleep(self.SLEEP_CHECK_RUNNING) return #get exe names target_exes = list() for instance in self._game_instances: target_exes.append(instance.exe_name().lower()) #check processes running = False if target_exes: for proc_info in process_iter(): if proc_info.binary_path is None: continue if os.path.basename(proc_info.binary_path).lower() in target_exes: running = True break await asyncio.sleep(self.SLEEP_CHECK_RUNNING_ITER) #update state new_state = None if running: self.persistent_cache['last_played'] = int(time.time()) self.push_cache() new_state = LocalGameState.Installed | LocalGameState.Running elif target_exes: new_state = LocalGameState.Installed else: new_state = LocalGameState.None_ if self._last_state != new_state: self.update_local_game_status(LocalGame('guild_wars_2', new_state)) self._last_state = new_state await asyncio.sleep(self.SLEEP_CHECK_RUNNING)
def _is_launcher_agent_running(self) -> bool: for proc_info in process_iter(): if proc_info.binary_path and proc_info.binary_path.endswith( "TwitchAgent.exe"): return True return False