mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-22 13:05:57 +00:00
Merge pull request #346: Let the installer extract the Switch shared fonts from a firmware folder (fch869)
Conflicts with dev resolved by keeping both sides: the fonts step sits between check and extract, beside the x86-64-v2 check, the pt-BR window language and the xbox-label patches. pt-BR gets the thirteen firmware and fonts texts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
4cece2c848
15 files changed
+395
-60
No files matched your search
+25
-10
@@ -30,7 +30,7 @@ from installer import layout as layouts # noqa: E402
|
||||
from installer import state as statefile # noqa: E402
|
||||
from installer.events import Reporter # noqa: E402
|
||||
from installer.runner import Context # noqa: E402
|
||||
from installer.steps import all_steps # noqa: E402
|
||||
from installer.steps import Fonts, all_steps # noqa: E402
|
||||
from installer.guilogic import (DONE, FAILED, PENDING, RUNNING, SKIPPED, UI_LANGUAGES, Catalog, Form, Model, # noqa: E402
|
||||
Process, amount, describe_event, parse_line, windows_ui_language)
|
||||
|
||||
@@ -38,7 +38,7 @@ INSTALLED = ROOT / 'build' / 'install-test'
|
||||
FIXTURE = ROOT / 'build' / 'inst-gui' / 'e2e-install'
|
||||
COPIED = ('totk.ini', statefile.NAME) # written by a run, so never linked
|
||||
START = {'type': 'start', 'release': 'r1', 'mode': 'install', 'dest': 'D:\\T', 'log': 'D:\\T.log',
|
||||
'steps': ['check', 'extract', 'lift', 'compile', 'prepare', 'cleanup']}
|
||||
'steps': ['check', 'fonts', 'extract', 'lift', 'compile', 'prepare', 'cleanup']}
|
||||
|
||||
|
||||
def fold(*events):
|
||||
@@ -66,7 +66,7 @@ class ModelTest(unittest.TestCase):
|
||||
m = fold(START, {'type': 'plan', 'run': ['check', 'extract'], 'skip': {'lift': 'current', 'compile': 'current'}},
|
||||
{'type': 'step', 'step': 'check', 'state': 'started'})
|
||||
self.assertEqual([m.states[s] for s in m.steps],
|
||||
[RUNNING, PENDING, SKIPPED, SKIPPED, PENDING, PENDING])
|
||||
[RUNNING, PENDING, PENDING, SKIPPED, SKIPPED, PENDING, PENDING])
|
||||
self.assertEqual(m.current, 'check')
|
||||
m.apply({'type': 'step', 'step': 'check', 'state': 'done', 'seconds': 1.0})
|
||||
self.assertEqual(m.states['check'], DONE)
|
||||
@@ -137,10 +137,12 @@ class ModelTest(unittest.TestCase):
|
||||
|
||||
|
||||
class RunStatesTest(unittest.TestCase):
|
||||
OK = [START, {'type': 'plan', 'run': ['check', 'extract'], 'skip': {'lift': 'current', 'compile': 'current',
|
||||
'prepare': 'current', 'cleanup': 'not_needed'}},
|
||||
OK = [START, {'type': 'plan', 'run': ['check', 'extract'], 'skip': {'fonts': 'current', 'lift': 'current',
|
||||
'compile': 'current', 'prepare': 'current',
|
||||
'cleanup': 'not_needed'}},
|
||||
{'type': 'step', 'step': 'check', 'state': 'started'}, {'type': 'step', 'step': 'check', 'state': 'done'},
|
||||
{'type': 'step', 'step': 'extract', 'state': 'started'}, {'type': 'step', 'step': 'extract', 'state': 'done'},
|
||||
{'type': 'step', 'step': 'fonts', 'state': 'skipped'},
|
||||
{'type': 'step', 'step': 'lift', 'state': 'skipped'}, {'type': 'step', 'step': 'compile', 'state': 'skipped'},
|
||||
{'type': 'step', 'step': 'prepare', 'state': 'skipped'}, {'type': 'step', 'step': 'cleanup', 'state': 'done'},
|
||||
{'type': 'end', 'result': 'ok', 'seconds': 1}]
|
||||
@@ -200,11 +202,20 @@ class FormTest(unittest.TestCase):
|
||||
def test_unknown_language(self):
|
||||
self.assertEqual(self.form(lang='xx').problems(), ['ui.need_lang'])
|
||||
|
||||
def test_firmware_folder(self):
|
||||
firmware = self.dir / 'firmware'
|
||||
firmware.mkdir()
|
||||
self.assertEqual(self.form(firmware=str(firmware)).problems(), [])
|
||||
self.assertEqual(self.form(firmware=str(self.dir / 'no-firmware')).problems(), ['ui.missing_firmware'])
|
||||
|
||||
def test_command(self):
|
||||
cmd = self.form().command('py.exe', root=ROOT, temp=self.dir / 't', verify=True)
|
||||
firmware = self.dir / 'firmware'
|
||||
firmware.mkdir()
|
||||
cmd = self.form(firmware=str(firmware)).command('py.exe', root=ROOT, temp=self.dir / 't', verify_hashes=True)
|
||||
self.assertEqual(cmd[:3], ['py.exe', '-m', 'installer'])
|
||||
for flag in ('--base', '--update', '--keys', '--lang', '--dest', '--root', '--temp', '--verify'):
|
||||
for flag in ('--base', '--update', '--keys', '--firmware', '--lang', '--dest', '--root', '--temp', '--verify'):
|
||||
self.assertIn(flag, cmd)
|
||||
self.assertEqual(cmd[cmd.index('--firmware') + 1], str(firmware))
|
||||
self.assertEqual(cmd[cmd.index('--lang') + 1], 'en-US')
|
||||
|
||||
def test_installed_folder_needs_only_itself(self):
|
||||
@@ -248,7 +259,7 @@ class CatalogTest(unittest.TestCase):
|
||||
cat = Catalog('en')
|
||||
ids = ['ui.' + n for n in ('title', 'start', 'cancel', 'open_folder', 'notice', 'space_one', 'space_two',
|
||||
'process_died', 'result_ok', 'result_failed', 'result_cancelled')]
|
||||
ids += [f'step.{s}' for s in ('check', 'extract', 'lift', 'compile', 'prepare', 'cleanup')]
|
||||
ids += [f'step.{s}' for s in ('check', 'fonts', 'extract', 'lift', 'compile', 'prepare', 'cleanup')]
|
||||
ids += ['ui.state_' + n for n in ('started', 'done', 'skipped', 'pending', 'running', 'failed')]
|
||||
for lang in UI_LANGUAGES:
|
||||
cat.set_language(lang)
|
||||
@@ -338,6 +349,10 @@ def make_fixture():
|
||||
ctx = Context(layout, FIXTURE, ROOT / 'build' / 'inst-gui' / 'e2e-temp', Reporter(out=io.StringIO()), options, state=state)
|
||||
ctx.steps = all_steps()
|
||||
ctx.plan()
|
||||
# An install made before the fonts step has no record for it: record it as current when its output is (the
|
||||
# languages that need the fonts have them in shared-fonts/).
|
||||
if Fonts().current(ctx, {}):
|
||||
state['steps'].setdefault('fonts', {'release': state.get('release', ''), 'key': ctx.keys['fonts']})
|
||||
for step_id, record in state['steps'].items():
|
||||
record['key'] = ctx.keys[step_id]
|
||||
statefile.save(FIXTURE, state)
|
||||
@@ -350,7 +365,7 @@ class EndToEndTest(unittest.TestCase):
|
||||
def run_cli(form, temp, tries=1):
|
||||
"""Runs the CLI in --verify mode through Process, up to `tries` times while the RomFS hash reads wrong."""
|
||||
for attempt in range(tries):
|
||||
p = Process(form.command(sys.executable, root=ROOT, temp=temp, verify=True), cwd=ROOT)
|
||||
p = Process(form.command(sys.executable, root=ROOT, temp=temp, verify_hashes=True), cwd=ROOT)
|
||||
model, stray = Model(), []
|
||||
t0, code = time.monotonic(), None
|
||||
while code is None and time.monotonic() - t0 < 600:
|
||||
@@ -388,7 +403,7 @@ class EndToEndTest(unittest.TestCase):
|
||||
|
||||
def test_cancel_during_the_check(self):
|
||||
cmd = Form(dest=str(make_fixture())).command(sys.executable, root=ROOT, temp=ROOT / 'build' / 'inst-gui' / 'e2e-temp',
|
||||
verify=True)
|
||||
verify_hashes=True)
|
||||
p = Process(cmd, cwd=ROOT)
|
||||
model, t0, code, cancelled = Model(), time.monotonic(), None, False
|
||||
while code is None and time.monotonic() - t0 < 120:
|
||||
|
||||
@@ -316,6 +316,108 @@ class BaseGameCheckTest(unittest.TestCase):
|
||||
self.assertEqual(steps.program_nca(records)[0]['title_id'], self.BASE)
|
||||
|
||||
|
||||
class FontsTest(unittest.TestCase):
|
||||
"""The fonts step: keyed by language and firmware, a no-op without firmware, writes dest/shared-fonts."""
|
||||
|
||||
def setUp(self):
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
base = Path(self.tmp.name)
|
||||
self.dest, temp, self.firmware = base / 'dest', base / 'temp', base / 'firmware'
|
||||
temp.mkdir()
|
||||
self.firmware.mkdir()
|
||||
(self.firmware / 'a.nca').write_bytes(b'nca')
|
||||
self.keys = base / 'prod.keys'
|
||||
self.keys.write_text('header_key = 00\n')
|
||||
self.ctx = SimpleNamespace(dest=self.dest, temp=temp, lang='zh-Hans', state={},
|
||||
layout=SimpleNamespace(tools=ROOT / 'tools', root=ROOT),
|
||||
reporter=Reporter(out=io.StringIO()),
|
||||
options=SimpleNamespace(lang='zh-Hans', firmware=self.firmware, keys=str(self.keys)))
|
||||
self.saved_run_tool = steps.run_tool
|
||||
|
||||
def tearDown(self):
|
||||
steps.run_tool = self.saved_run_tool
|
||||
self.ctx.reporter.close()
|
||||
self.tmp.cleanup()
|
||||
|
||||
def fake_tool(self, files=None, code=0):
|
||||
"""Stand-in for extract_shared_fonts.py: writes the requested files where --output points."""
|
||||
def run(ctx, step, script, args):
|
||||
out = Path(args[args.index('--output') + 1])
|
||||
out.mkdir(parents=True)
|
||||
for name in steps.SHARED_FONT_FILES if files is None else files:
|
||||
(out / name).write_bytes(b'bfttf')
|
||||
(out / 'manifest.json').write_text('{}')
|
||||
log = ctx.temp / 'fonts.log'
|
||||
log.write_text('error line\n')
|
||||
return code, log
|
||||
steps.run_tool = run
|
||||
|
||||
def test_all_steps_order(self):
|
||||
self.assertEqual([s.id for s in steps.all_steps()],
|
||||
['check', 'fonts', 'extract', 'lift', 'compile', 'prepare', 'cleanup'])
|
||||
|
||||
def test_extracts_into_the_install_folder(self):
|
||||
self.fake_tool()
|
||||
self.assertEqual(steps.Fonts().run(self.ctx), {'files': 6})
|
||||
self.assertTrue(steps.shared_fonts_ready(self.dest))
|
||||
self.assertEqual(sorted(p.name for p in (self.dest / 'shared-fonts').iterdir()),
|
||||
sorted((*steps.SHARED_FONT_FILES, 'manifest.json')))
|
||||
|
||||
def test_noop_without_firmware(self):
|
||||
self.ctx.options.firmware = None
|
||||
self.fake_tool()
|
||||
self.assertEqual(steps.Fonts().run(self.ctx), {})
|
||||
self.assertFalse((self.dest / 'shared-fonts').exists())
|
||||
|
||||
def test_noop_for_other_languages(self):
|
||||
self.ctx.lang, self.ctx.options.lang = 'en-US', 'en-US'
|
||||
self.fake_tool()
|
||||
self.assertEqual(steps.Fonts().run(self.ctx), {})
|
||||
self.assertFalse((self.dest / 'shared-fonts').exists())
|
||||
|
||||
def test_failed_extraction_keeps_the_old_folder(self):
|
||||
self.fake_tool()
|
||||
steps.Fonts().run(self.ctx)
|
||||
self.fake_tool(code=1)
|
||||
with self.assertRaises(steps.InstallError) as e:
|
||||
steps.Fonts().run(self.ctx)
|
||||
self.assertEqual(e.exception.id, 'fonts.failed')
|
||||
self.assertTrue(steps.shared_fonts_ready(self.dest))
|
||||
|
||||
def test_incomplete_output_is_an_error(self):
|
||||
self.fake_tool(files=steps.SHARED_FONT_FILES[:1])
|
||||
with self.assertRaises(steps.InstallError) as e:
|
||||
steps.Fonts().run(self.ctx)
|
||||
self.assertEqual(e.exception.id, 'fonts.incomplete')
|
||||
|
||||
def test_current_tracks_language_and_output(self):
|
||||
fonts = steps.Fonts()
|
||||
self.assertFalse(fonts.current(self.ctx, {}))
|
||||
self.fake_tool()
|
||||
fonts.run(self.ctx)
|
||||
self.assertTrue(fonts.current(self.ctx, {}))
|
||||
self.ctx.options.lang = 'en-US'
|
||||
self.assertTrue(fonts.current(self.ctx, {}))
|
||||
self.ctx.options.lang = 'zh-Hans'
|
||||
(self.dest / 'shared-fonts' / '0-standard.bfttf').unlink()
|
||||
self.assertFalse(fonts.current(self.ctx, {}))
|
||||
|
||||
def test_key_changes_with_language_and_firmware(self):
|
||||
fonts = steps.Fonts()
|
||||
zh = fonts.key(self.ctx)
|
||||
self.ctx.options.lang = 'en-US'
|
||||
self.assertNotEqual(zh, fonts.key(self.ctx))
|
||||
self.ctx.options.lang = 'zh-Hans'
|
||||
(self.firmware / 'b.nca').write_bytes(b'other')
|
||||
self.assertNotEqual(zh, fonts.key(self.ctx))
|
||||
|
||||
def test_registered_child_is_used(self):
|
||||
nested = self.firmware / 'registered'
|
||||
nested.mkdir()
|
||||
(nested / 'c.nca').write_bytes(b'nca')
|
||||
self.assertEqual(steps.firmware_dir(self.firmware), nested)
|
||||
|
||||
|
||||
class EventsTest(unittest.TestCase):
|
||||
def test_lines_are_json_and_the_log_is_english(self):
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
|
||||
Reference in new issue
Block a user