(self, args)
| 1302 | logger.info(f'Run "legendary repair {args.app_name}" to repair your game installation.') |
| 1303 | |
| 1304 | def import_game(self, args): |
| 1305 | if not self.core.lgd.lock_installed(): |
| 1306 | logger.fatal('Failed to acquire installed data lock, only one instance of Legendary may ' |
| 1307 | 'install/import/move applications at a time.') |
| 1308 | return |
| 1309 | |
| 1310 | # make sure path is absolute |
| 1311 | args.app_path = os.path.abspath(args.app_path) |
| 1312 | args.app_name = self._resolve_aliases(args.app_name) |
| 1313 | |
| 1314 | if not os.path.exists(args.app_path): |
| 1315 | logger.error(f'Specified path "{args.app_path}" does not exist!') |
| 1316 | return |
| 1317 | |
| 1318 | if self.core.is_installed(args.app_name): |
| 1319 | logger.error('Game is already installed!') |
| 1320 | return |
| 1321 | |
| 1322 | if not self.core.login(): |
| 1323 | logger.error('Log in failed!') |
| 1324 | return |
| 1325 | |
| 1326 | # do some basic checks |
| 1327 | game = self.core.get_game(args.app_name, update_meta=True, platform=args.platform) |
| 1328 | if not game: |
| 1329 | logger.fatal(f'Did not find game "{args.app_name}" on account.') |
| 1330 | return |
| 1331 | |
| 1332 | if game.is_dlc: |
| 1333 | release_info = game.metadata.get('mainGameItem', {}).get('releaseInfo') |
| 1334 | if release_info: |
| 1335 | main_game_appname = release_info[0]['appId'] |
| 1336 | main_game_title = game.metadata['mainGameItem']['title'] |
| 1337 | if not self.core.is_installed(main_game_appname): |
| 1338 | logger.error(f'Import candidate is DLC but base game "{main_game_title}" ' |
| 1339 | f'(App name: "{main_game_appname}") is not installed!') |
| 1340 | return |
| 1341 | else: |
| 1342 | logger.fatal(f'Unable to get base game information for DLC, cannot continue.') |
| 1343 | return |
| 1344 | |
| 1345 | # get everything needed for import from core, then run additional checks. |
| 1346 | manifest, igame = self.core.import_game(game, args.app_path, platform=args.platform) |
| 1347 | exe_path = os.path.join(args.app_path, manifest.meta.launch_exe.lstrip('/')) |
| 1348 | if os.name != 'nt': |
| 1349 | exe_path = case_insensitive_file_search(exe_path) |
| 1350 | # check if most files at least exist or if user might have specified the wrong directory |
| 1351 | total = len(manifest.file_manifest_list.elements) |
| 1352 | found = sum(os.path.exists(os.path.join(args.app_path, f.filename)) |
| 1353 | for f in manifest.file_manifest_list.elements) |
| 1354 | ratio = found / total |
| 1355 | |
| 1356 | if not found: |
| 1357 | logger.error(f'No files belonging to {"DLC" if game.is_dlc else "Game"} "{game.app_title}" ' |
| 1358 | f'({game.app_name}) found in the specified location, please verify that the path is correct.') |
| 1359 | if not game.is_dlc: |
| 1360 | # check if game folder is in path, suggest alternative |
| 1361 | folder = game.metadata.get('customAttributes', {}).get('FolderName', {}).get('value', game.app_name) |
no test coverage detected