diff --git a/docs/launcher.md b/docs/launcher.md index 9e4c5768..4009cccc 100644 --- a/docs/launcher.md +++ b/docs/launcher.md @@ -155,7 +155,10 @@ A path the Windows ANSI code page cannot hold breaks the MSYS2 tools, so the too `romfs-check.json` beside the game, and for each damaged texture puts a stand-in, another texture of the same kind under the damaged one's name, in `mods/Damaged file stand-ins`, so the game can load what needs it. A damaged file of any other kind is only reported: only a clean dump restores it. In play the game logs a file it keeps opening - and cannot load (runtime/romfs.c `open_note`). + and cannot load (runtime/romfs.c `open_note`). The launcher shows what the check found (`jobs.Job.note_scan`): + the count in the step's row ("4 Flagged, 3 Stand-Ins"), and after a job in which the check ran a sentence on the + home screen and in `launcher.log`. The four files the check flags on every copy of the game (`jobs.SCAN_EXPECTED`) + are told as that, with nothing for the player to do; other files are counted and `romfs-check.json` named. 6. The game's Cetra Display is decoded for the window. ## Updating diff --git a/launcher/build.py b/launcher/build.py index 1298c0ea..eca68b3d 100644 --- a/launcher/build.py +++ b/launcher/build.py @@ -148,6 +148,17 @@ def built_version(game_dir): return '' +def scan_report(game_dir): + """What the check of the game files found (tools/romfs_check.py writes /romfs-check.json): (the paths of + the damaged files, how many of them got a stand-in), or None when the folder has no readable report.""" + try: + with open(os.path.join(str(game_dir), 'romfs-check.json'), encoding='utf-8') as f: + report = json.load(f) + return sorted(report['damaged']), len(report.get('repaired') or ()) + except (OSError, ValueError, KeyError, TypeError): + return None + + def can_rebuild(game_dir): st = build_state(game_dir) return st.get('version') == 2 and all(s in st.get('steps', {}) for s in ('exefs', 'romfs')) diff --git a/launcher/jobs.py b/launcher/jobs.py index 689c5f59..e6bfc9e6 100644 --- a/launcher/jobs.py +++ b/launcher/jobs.py @@ -40,6 +40,36 @@ WEIGHTS = {'tools': 12, 'tools_update': 4, 'check': 1, 'exefs': 2, 'romfs': 14, 'compile_changed': 55, 'shaders': 18, 'prompts': 4, 'scan': 5, 'ready': 0, 'download': 8, 'verify': 1, 'swap': 6} +# The game files tools/romfs_check.py reports as damaged on every copy of the game looked at so far: they are that +# way in the game's own data, not through a player's dump, so a new dump does not change them. The three textures +# get a stand-in; the game does without the fourth file. +SCAN_EXPECTED = frozenset(( + 'Tex/CmnTex_Map_Soil_FairyFountain_Floor_D_Nrm.bntx.zs', + 'Tex/RBake_Scene_GanonStage_G_2_1_d0_t0.bntx.zs', + 'Tex/Rock_WaterTemple_Gate_M_01_Nrm.bntx.zs', + 'gsys/EnvObjSetMgrParam/Artwork.gsys__EnvObjSetMgrParam.bgyml', +)) + + +def scan_summary(damaged, stood_in): + """(the scan row's value, a sentence for the home screen) for what the check of the game files found + (build.scan_report); ('', '') when nothing is damaged. The files of SCAN_EXPECTED are told as what they are, the + same ones as on every copy: the player learns what the check did and that nothing needs doing. Other files are + counted and pointed to, without advice the check cannot back.""" + n = len(damaged) + if not n: + return '', '' + files = '1 game file' if n == 1 else f'{n} game files' + stand = ('none got a stand-in' if not stood_in else '1 texture got a stand-in' if stood_in == 1 else + f'{stood_in} textures got a stand-in') + value = f'{n} Flagged, {stood_in} Stand-In' + ('' if stood_in == 1 else 's') + if set(damaged) <= SCAN_EXPECTED: + return value, (f'The file check flagged {files}, the same as in every copy of the game: {stand}, and nothing ' + 'needs doing.') + return value, (f'The file check flagged {files} as damaged: {stand}, so what uses them still loads. ' + 'romfs-check.json in the game folder lists them.') + + def prompt_rows(ctx): """The prompts row, for a version with button art (make_game.py draws the prompts after the shaders), or none.""" return ['prompts'] if build.has_prompt_art(ctx.layout) else [] @@ -75,6 +105,7 @@ class Job: self.started = time.time() self.finished = None self.after = None # what the window does next ('restart', ...) + self.note = '' # a sentence for the home screen after the job (note_scan) self._lock = threading.Lock() # ---- state the window reads @@ -212,6 +243,26 @@ class Job: raise NotImplementedError # ---- shared pieces + def note_scan(self, game_dir): + """After a build: what the check of the game files found goes into its row, and when the check ran in this + job, into the note the home screen shows and into the log. The check itself only printed its counts into + the build's lines, which scroll away, so a player never learned that files were flagged or that stand-ins + are in use. A check kept from an earlier build shows its count in the row only.""" + s = self.step('scan') + found = build.scan_report(game_dir) + if not s or s.state not in (DONE, SKIPPED) or not found: + return + value, note = scan_summary(*found) + if not value: + return + if s.state == DONE: + s.value = value + self.note = note + self.ctx.log(f'file check: {note}') + elif s.value == 'Unchanged': + s.value = f'Unchanged · {value}' + self._touch() + def ensure_tools(self, sid): layout = self.ctx.layout self.begin(sid) @@ -317,6 +368,7 @@ class InstallJob(Job): for sid in ('shaders', 'prompts', 'scan'): if self.step(sid) and self.step(sid).state == PENDING: self.skip(sid) + self.note_scan(self.game_dir) self.finish('ready', 'Ready') try: gamefiles.extract_fonts(self.ctx.layout, self.game_dir) @@ -349,6 +401,7 @@ class RebuildJob(Job): for sid in ('lift', 'compile_changed', 'swap', 'shaders', 'prompts', 'scan'): if self.step(sid) and self.step(sid).state == PENDING: self.skip(sid) + self.note_scan(self.game_dir) class UpdateDownloadJob(Job): diff --git a/launcher/ui/app.py b/launcher/ui/app.py index 9527b044..84f6009f 100644 --- a/launcher/ui/app.py +++ b/launcher/ui/app.py @@ -1625,6 +1625,9 @@ class App: self.message = 'The game is rebuilt and up to date.' if j.kind == 'rebuild' else \ f'NX2navi is now {versions.display(self.layout.version)}.' self.release = None + note = getattr(j, 'note', '') # what the file check found (jobs.Job.note_scan) + if note and j.after is None: + self.message = f'{self.message} {note}'.strip() self.reload_fonts_if_new() self.show(self.job_return) if j.kind == 'install' and self.settings.get('auto_check'): diff --git a/tests/launcher_test.py b/tests/launcher_test.py index 12469a23..9e0bceac 100644 --- a/tests/launcher_test.py +++ b/tests/launcher_test.py @@ -2573,7 +2573,8 @@ import json, sys, time def ev(**k): print('@@' + json.dumps(k), flush=True) if '--fail' in open(sys.argv[0] + '.mode').read(): ev(ev='step', step='check', state='start'); ev(ev='error', message='this is not game version 1.1.1'); sys.exit(1) -for s in ('check', 'exefs', 'romfs', 'lift', 'compile', 'shaders', 'prompts'): +mode = open(sys.argv[0] + '.mode').read() +for s in ('check', 'exefs', 'romfs', 'lift', 'compile', 'shaders', 'prompts') + (('scan',) if '--scan' in mode else ()): ev(ev='step', step=s, state='start') if s == 'compile': ev(ev='progress', step=s, done=5, total=10, unit='files'); ev(ev='phase', step=s, phase='link') @@ -2632,6 +2633,78 @@ class JobTest(Tmp): self.assertIn('1.1.1', j.error) self.assertEqual(j.step('check').state, jobs.FAILED) + def scan_job(self, mode, report): + """An install whose fake build ran (mode 'ok --scan') or kept (mode 'ok') the check of the game files, with + report as the romfs-check.json the check left in the game folder.""" + self.patch_tools() + ctx = self.make_ctx(mode) + game = self.tmp / 'game' + game.mkdir() + if report is not None: + (game / 'romfs-check.json').write_text(json.dumps(report)) + j = jobs.InstallJob(ctx, self.tmp / 'g.nup', game).run_inline() + self.assertEqual(j.result, 'ok', j.error) + ctx._file.flush() + return j, (ctx.layout.logs / 'launcher.log').read_text(encoding='utf-8') + + def test_the_file_check_result_is_shown(self): + """What the check of the game files found reaches the player: the count in the scan row, a sentence for the + home screen and a line in the log. The files flagged on every copy are told as expected, with nothing to + do; nothing tells the player to dump again.""" + known = sorted(jobs.SCAN_EXPECTED) + textures = [p for p in known if p.startswith('Tex/')] + report = {'status': 'pass', 'files': 186587, 'damaged': {p: 'no compressed frame at its start' for p in known}, + 'repaired': {p: 'Tex/Other.bntx.zs' for p in textures}, + 'not_repaired': [p for p in known if p not in textures]} + j, log = self.scan_job('ok --scan', report) + self.assertEqual(j.step('scan').state, jobs.DONE) + self.assertEqual(j.step('scan').value, '4 Flagged, 3 Stand-Ins') + self.assertEqual(j.note, 'The file check flagged 4 game files, the same as in every copy of the game: 3 textures ' + 'got a stand-in, and nothing needs doing.') + self.assertIn('file check: The file check flagged 4 game files', log) + for text in (j.note, j.step('scan').value): + self.assertNotIn('dump', text.lower()) + + def test_other_damaged_files_are_counted_and_pointed_to(self): + report = {'damaged': {'Tex/A_Nrm.bntx.zs': 'no compressed frame at its start', 'Model/B.bfres.zs': 'x'}, + 'repaired': {'Tex/A_Nrm.bntx.zs': 'Tex/C_Nrm.bntx.zs'}, 'not_repaired': ['Model/B.bfres.zs']} + j, _ = self.scan_job('ok --scan', report) + self.assertEqual(j.step('scan').value, '2 Flagged, 1 Stand-In') + self.assertIn('flagged 2 game files as damaged: 1 texture got a stand-in', j.note) + self.assertIn('romfs-check.json', j.note) + self.assertNotIn('dump', j.note.lower()) + self.assertEqual(jobs.scan_summary(['Model/B.bfres.zs'], 0)[1], + 'The file check flagged 1 game file as damaged: none got a stand-in, so what uses them still ' + 'loads. romfs-check.json in the game folder lists them.') + + def test_a_clean_or_kept_file_check_says_nothing_on_home(self): + j, _ = self.scan_job('ok --scan', {'damaged': {}, 'repaired': {}, 'not_repaired': []}) + self.assertTrue(j.step('scan').value.startswith('Done')) + self.assertEqual(j.note, '') + shutil.rmtree(self.tmp / 'game') + shutil.rmtree(self.tmp / 'app') + # the check was done by an earlier build (the fake build has no scan step): the row has the count, home nothing + j, _ = self.scan_job('ok', {'damaged': {p: 'x' for p in jobs.SCAN_EXPECTED}, 'repaired': {}}) + self.assertEqual(j.step('scan').state, jobs.SKIPPED) + self.assertEqual(j.step('scan').value, 'Unchanged · 4 Flagged, 0 Stand-Ins') + self.assertEqual(j.note, '') + self.assertIsNone(build.scan_report(self.tmp / 'no game')) + (self.tmp / 'game' / 'romfs-check.json').write_text('not json') + self.assertIsNone(build.scan_report(self.tmp / 'game')) + + def test_home_shows_the_file_check_note(self): + App, a = mock_app(self, self.tmp / 'game') + a.job = mock.Mock(kind='install', result='ok', error='', after=None, + note='The file check flagged 4 game files, the same as in every copy of the game: 3 ' + 'textures got a stand-in, and nothing needs doing.') + a.settings['keep_cache'] = True + with mock.patch('launcher.ui.app.winsys.keep_awake'): + App.job_finished(a) + self.assertEqual(a.message, 'The game is built. Select Play. ' + a.job.note) + a.job.note = '' + App.job_finished(a) + self.assertEqual(a.message, 'The game is built. Select Play.') + def test_an_install_goes_on_from_the_unpacked_game_files(self): """Begin Installation into a folder whose game files an earlier run unpacked builds on from them (--rebuild for this processor's level), so a moved or deleted dump is not asked for; without them it reads the dump."""