Skip to content

Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit

feat(setup): download the CJK fonts instead of shipping them

raymondchins4a51b3481e8b
diff --git a/Makefile b/Makefile
index 045b8f0..053ca74 100644
--- a/Makefile
+++ b/Makefile
@@ -633,6 +633,9 @@ sigdb-install:
LAUNCHABLE_BUNDLES := $(HOME)/Desktop/Bridgeplay.app /Applications/Bridgeplay.app
+# The Chinese, Japanese and Korean fonts (about 85 MB) stay out of the app: CJKFonts.swift
+# downloads them from their own release, packed by scripts/package-fonts.sh.
+CJK_FONTS := malgun.ttf msgothic.ttc msyh.ttf msyhbd.ttf simsun.ttc
FONT_FILES := --include='*/' --include='*.ttf' --include='*.ttc' --exclude='*'
fonts-install:
@@ -702,7 +705,7 @@ app-payload: $(TARGET) $(OVERLAY_SHIM) $(ICONMAKER) $(APPINFO)
done
@if [ ! -d build/fonts ]; then echo "build/fonts is missing, run: $(MAKE) fonts" >&2; exit 1; fi
@mkdir -p "$(APP_PAYLOAD)/fonts"
- @rsync -a --delete build/fonts/ "$(APP_PAYLOAD)/fonts/"
+ @rsync -a --delete --delete-excluded $(foreach f,$(CJK_FONTS),--exclude='/$(f)') build/fonts/ "$(APP_PAYLOAD)/fonts/"
@stamp="$$(git log -1 --format=%ct 2>/dev/null)"; \
if [ -z "$$stamp" ]; then echo "build-time needs a git checkout" >&2; exit 1; fi; \
echo "$$stamp" > "$(APP_PAYLOAD)/build-time"
diff --git a/NOTICE b/NOTICE
index f1625c4..705f38d 100644
--- a/NOTICE
+++ b/NOTICE
@@ -174,6 +174,10 @@ with Bridgeplay.
/fonts/ contains the font sources from Valve's Proton repo. Fonts are licensed
under their original licenses, see the LICENSE file in each folder. The build
files from Proton are covered by LICENSE.fonts.
+The fonts built from them ship in the app, except the Chinese, Japanese and
+Korean ones (msyh, msyhbd, simsun and malgun from Source Han Sans, msgothic from
+Ume): Bridgeplay downloads those during setup from the fonts-cjk-* release of
+this repository, with their licences beside them in the archive.
These third party files carry their original notices from the project authors.
Their license texts ship in the app and the installer as LICENSE.jsoncpp
diff --git a/app/Sources/BridgeplayApp/Model/CJKFonts.swift b/app/Sources/BridgeplayApp/Model/CJKFonts.swift
new file mode 100644
index 0000000..ef08655
--- /dev/null
+++ b/app/Sources/BridgeplayApp/Model/CJKFonts.swift
@@ -0,0 +1,84 @@
+// The Chinese, Japanese and Korean fonts the run script links into every prefix
+
+import Foundation
+
+// About 85 MB, so the app doesn't carry them (Makefile CJK_FONTS): they come from their own
+// release, checked against these pins, once Bridgeplay's fonts folder exists. The run script
+// links whatever is in that folder, so a game started before they arrive shows boxes for CJK
+// text until the next refresh brings them. Packed by scripts/package-fonts.sh, which prints
+// these pins.
+enum CJKFonts {
+ static let step = String(localized: "Adding fonts for Chinese, Japanese and Korean")
+
+ static let archive = "fonts-cjk-29ba44d27134.tar.xz"
+ static let sha256 = "2520655a6752299ecb025e5b23fff7181c96e634269e27b74ec16d36558aaaf7"
+ static let bases = [URL(string: "https://github.com/raymondchins/Bridgeplay/releases/download/fonts-cjk-29ba44d27134")!]
+
+ static let files: [String: String] = [
+ "malgun.ttf": "e006f28630a8142a929fdab0097d4d267c4003dcdac0ec3ec51ffecc8d1afcd5",
+ "msgothic.ttc": "75704a3efa6b2e1c2c5af586192cb65b945e27e89bf5fc9076c31328a726dba0",
+ "msyh.ttf": "955e1e0dc1f8d8fdbb3cfb22a395a27b1dd24b8108930c94e2bcda216b560a6b",
+ "msyhbd.ttf": "cef037b3f0e00ab8cab78355aa339aedd426581160b30f27879803a24c988bee",
+ "simsun.ttc": "59e540ec2eacb2d8417add67eceb2efdc8bd978aa2a0a93195db5b2805a43e6a",
+ ]
+ // Their licences, beside them in the archive and in the fonts folder.
+ static let licences = ["source-han-sans/LICENSE.txt", "ume/license.html"]
+
+ typealias Obtain = @Sendable (_ downloads: URL) async throws -> URL
+
+ static let liveObtain: Obtain = { downloads in
+ try await PinnedDownload.obtain(file: archive, sha256: sha256, bases: bases, into: downloads,
+ step: step, from: "GitHub")
+ }
+
+ // Fonts that are absent or differ from their pin. Installs from before the split already
+ // have them from the app, so nothing is downloaded there.
+ static func missing(in fonts: URL = SupportPaths.fonts, pins: [String: String] = files) -> [String] {
+ pins.filter { name, hash in Digest.sha256IfPresent(fonts.appending(path: name)) != hash }.keys.sorted()
+ }
+
+ // Downloads and lays the fonts in when the folder exists (Bridgeplay is set up) and any is
+ // missing. Each font is checked against its pin before it replaces anything.
+ static func install(into fonts: URL = SupportPaths.fonts, downloads: URL = FreeEngine.downloads,
+ pins: [String: String] = files, obtain: Obtain = liveObtain) async throws {
+ let files = FileManager.default
+ guard files.fileExists(atPath: fonts.path(percentEncoded: false)), !missing(in: fonts, pins: pins).isEmpty else { return }
+ try files.createDirectory(at: downloads, withIntermediateDirectories: true)
+ let archive = try await obtain(downloads)
+
+ let work = fonts.deletingLastPathComponent()
+ .appending(path: ".fonts-cjk-\(UUID().uuidString)", directoryHint: .isDirectory)
+ try files.createDirectory(at: work, withIntermediateDirectories: true)
+ defer { try? files.removeItem(at: work) }
+ let unpacked = try Shell.run("/usr/bin/tar", ["-xJf", archive.path(percentEncoded: false),
+ "-C", work.path(percentEncoded: false)])
+ guard unpacked.succeeded else {
+ throw StepFailure(step: step, detail: String(localized: "The font download could not be unpacked."))
+ }
+ for (name, hash) in pins {
+ guard Digest.sha256IfPresent(work.appending(path: name)) == hash else {
+ AppLog.note("fonts: \(name) in \(archive.lastPathComponent) does not match its pin")
+ throw StepFailure(step: step, detail: String(localized: "The font download is damaged."))
+ }
+ }
+ for name in pins.keys.sorted() + licences {
+ let source = work.appending(path: name), destination = fonts.appending(path: name)
+ guard files.fileExists(atPath: source.path(percentEncoded: false)) else { continue }
+ try files.createDirectory(at: destination.deletingLastPathComponent(), withIntermediateDirectories: true)
+ _ = try files.replaceItemAt(destination, withItemAt: source)
+ }
+ AppLog.note("fonts: added \(pins.count) CJK fonts from \(archive.lastPathComponent)")
+ }
+
+ // One background attempt at a time; a failure waits for the next refresh.
+ @MainActor private static var running = false
+
+ @MainActor static func fetchIfNeeded() {
+ guard !running else { return }
+ running = true
+ Task.detached(priority: .utility) {
+ do { try await install() } catch { AppLog.note("fonts: CJK fonts not added: \(error.localizedDescription)") }
+ await MainActor.run { running = false }
+ }
+ }
+}
diff --git a/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstrings b/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstrings
index be4f8fc..d139fe5 100644
--- a/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstrings
+++ b/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstrings
@@ -1372,6 +1372,22 @@
}
}
},
+ "Adding fonts for Chinese, Japanese and Korean" : {
+ "localizations" : {
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Aggiunta dei font per cinese, giapponese e coreano"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "正在添加中文、日文和韩文字体"
+ }
+ }
+ }
+ },
"Adding the certificate…" : {
"localizations" : {
"it" : {
@@ -10565,6 +10581,38 @@
}
}
},
+ "The font download could not be unpacked." : {
+ "localizations" : {
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Non è stato possibile estrarre i font scaricati."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "无法解压下载的字体。"
+ }
+ }
+ }
+ },
+ "The font download is damaged." : {
+ "localizations" : {
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "I font scaricati sono danneggiati."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "下载的字体已损坏。"
+ }
+ }
+ }
+ },
"The game SAVE DATA inside the prefix WILL BE LOST." : {
"localizations" : {
"it" : {
diff --git a/app/Sources/BridgeplayApp/SystemStatus.swift b/app/Sources/BridgeplayApp/SystemStatus.swift
index 6830448..41678d0 100644
--- a/app/Sources/BridgeplayApp/SystemStatus.swift
+++ b/app/Sources/BridgeplayApp/SystemStatus.swift
@@ -873,6 +873,7 @@ final class SystemStatus {
}.value
snapshot = captured
AppLog.note(captured)
+ if !captured.installContent.blocksInstallation { CJKFonts.fetchIfNeeded() }
await refreshSigningIdentity()
await refreshRunnerStorage(cleanTemplates: !captured.installContent.blocksInstallation)
}
diff --git a/app/Tests/BridgeplayAppTests/CJKFontsTests.swift b/app/Tests/BridgeplayAppTests/CJKFontsTests.swift
new file mode 100644
index 0000000..234b7f4
--- /dev/null
+++ b/app/Tests/BridgeplayAppTests/CJKFontsTests.swift
@@ -0,0 +1,83 @@
+import Foundation
+import Testing
+
+@testable import BridgeplayApp
+
+@Suite("CJK fonts")
+struct CJKFontsTests {
+
+ private func directory(_ label: String) throws -> URL {
+ let url = FileManager.default.temporaryDirectory.appending(path: "np-cjk-\(label)-\(UUID().uuidString)", directoryHint: .isDirectory)
+ try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)
+ return url
+ }
+
+ // A small stand-in for the release archive: two "fonts" and the licences, packed the way
+ // scripts/package-fonts.sh packs them.
+ private func archive(in dir: URL, contents: [String: String]) throws -> (URL, [String: String]) {
+ let stage = dir.appending(path: "stage", directoryHint: .isDirectory)
+ var pins: [String: String] = [:]
+ for (name, text) in contents {
+ let file = stage.appending(path: name)
+ try FileManager.default.createDirectory(at: file.deletingLastPathComponent(), withIntermediateDirectories: true)
+ try Data(text.utf8).write(to: file)
+ if !name.contains("/") { pins[name] = Digest.sha256(of: Data(text.utf8)) }
+ }
+ let out = dir.appending(path: "fonts.tar.xz")
+ #expect(try Shell.run("/bin/sh", ["-c", "cd '\(stage.path(percentEncoded: false))' && tar -cJf '\(out.path(percentEncoded: false))' ."]).succeeded)
+ return (out, pins)
+ }
+
+ @Test("The Makefile keeps exactly the pinned fonts out of the app")
+ func makefileMatchesPins() throws {
+ let makefile = URL(filePath: #filePath).deletingLastPathComponent().appending(path: "../../../Makefile").standardized
+ let text = try String(contentsOf: makefile, encoding: .utf8)
+ let line = try #require(text.split(separator: "\n").first { $0.hasPrefix("CJK_FONTS := ") })
+ let names = line.dropFirst("CJK_FONTS := ".count).split(separator: " ").map(String.init).sorted()
+ #expect(names == CJKFonts.files.keys.sorted())
+ #expect(CJKFonts.archive.hasPrefix("fonts-cjk-") && CJKFonts.bases.allSatisfy { $0.host() == "github.com" })
+ }
+
+ @Test("Missing fonts are downloaded, checked and laid in with their licences")
+ func installsMissing() async throws {
+ let dir = try directory("install")
+ defer { try? FileManager.default.removeItem(at: dir) }
+ let (tarball, pins) = try archive(in: dir, contents: [
+ "a.ttf": "font a", "b.ttc": "font b",
+ "source-han-sans/LICENSE.txt": "OFL", "ume/license.html": "Ume",
+ ])
+ let fonts = dir.appending(path: "fonts", directoryHint: .isDirectory)
+ try FileManager.default.createDirectory(at: fonts, withIntermediateDirectories: true)
+ #expect(CJKFonts.missing(in: fonts, pins: pins) == ["a.ttf", "b.ttc"])
+
+ try await CJKFonts.install(into: fonts, downloads: dir.appending(path: "dl"), pins: pins) { _ in tarball }
+ #expect(CJKFonts.missing(in: fonts, pins: pins).isEmpty)
+ #expect(FileManager.default.fileExists(atPath: fonts.appending(path: "source-han-sans/LICENSE.txt").path(percentEncoded: false)))
+
+ // Nothing missing: no download at all.
+ try await CJKFonts.install(into: fonts, downloads: dir, pins: pins) { _ in
+ Issue.record("downloaded although every font was there"); return tarball
+ }
+ }
+
+ @Test("A damaged download changes nothing, and nothing happens before setup")
+ func refusesDamaged() async throws {
+ let dir = try directory("damaged")
+ defer { try? FileManager.default.removeItem(at: dir) }
+ let (tarball, _) = try archive(in: dir, contents: ["a.ttf": "not the pinned font"])
+ let pins = ["a.ttf": Digest.sha256(of: Data("font a".utf8))]
+ let fonts = dir.appending(path: "fonts", directoryHint: .isDirectory)
+
+ // No fonts folder yet: Bridgeplay isn't set up, so nothing is fetched.
+ try await CJKFonts.install(into: fonts, downloads: dir, pins: pins) { _ in
+ Issue.record("downloaded before setup"); return tarball
+ }
+
+ try FileManager.default.createDirectory(at: fonts, withIntermediateDirectories: true)
+ try Data("older".utf8).write(to: fonts.appending(path: "a.ttf"))
+ await #expect(throws: StepFailure.self) {
+ try await CJKFonts.install(into: fonts, downloads: dir, pins: pins) { _ in tarball }
+ }
+ #expect(try String(contentsOf: fonts.appending(path: "a.ttf"), encoding: .utf8) == "older")
+ }
+}
diff --git a/docs/RELEASING.md b/docs/RELEASING.md
index 96a0d6d..5844416 100644
--- a/docs/RELEASING.md
+++ b/docs/RELEASING.md
@@ -230,6 +230,19 @@ import it. Without the backup, a new certificate means one more App Management g
every user. Do not change the certificate's Trust settings. The first `make app` with the
identity asks for access to its key; choose Always Allow.
+## CJK fonts
+
+The Chinese, Japanese and Korean fonts (Makefile `CJK_FONTS`, about 85 MB) are not in the app.
+`CJKFonts.swift` downloads them once the fonts folder exists, from a `fonts-cjk-<id>`
+prerelease, and checks the archive and every font against its pins. Existing installs already
+have them from earlier apps, so they download nothing. When `fonts/` changes:
+
+1. `make fonts`, then `scripts/package-fonts.sh`. The archive is reproducible, and `<id>` comes
+ from the fonts, so unchanged fonts give the same name and pins.
+2. Copy the pins it prints into `CJKFonts.swift`.
+3. `scripts/package-fonts.sh --publish` creates the release. `release-local.sh` stops while the
+ pinned archive is missing on GitHub.
+
## Compatibility reports
The app's one-tap reports go to `https://bridgeplay.dev/api/report` (bridgeplay-web,
diff --git a/scripts/package-fonts.sh b/scripts/package-fonts.sh
new file mode 100755
index 0000000..da501f9
--- /dev/null
+++ b/scripts/package-fonts.sh
@@ -0,0 +1,70 @@
+#!/bin/sh
+# Pack the Chinese, Japanese and Korean fonts (Makefile CJK_FONTS, built by `make fonts`)
+# with their licences into out/fonts-cjk-<id>.tar.xz, the archive CJKFonts.swift downloads.
+# The same fonts always give the same archive and the same id.
+#
+# scripts/package-fonts.sh pack, then print the pins for CJKFonts.swift
+# scripts/package-fonts.sh --publish also create the fonts-cjk-<id> release that hosts it
+#
+# Only needed when the fonts change; app releases reuse the published archive.
+
+set -eu
+
+die() { echo "==> $*" >&2; exit 1; }
+
+repo=$(cd "$(dirname "$0")/.." && pwd)
+cd "$repo"
+publish=0
+case "${1:-}" in
+ --publish) publish=1 ;;
+ "") ;;
+ *) die "usage: $0 [--publish]" ;;
+esac
+
+fonts=$(sed -n 's/^CJK_FONTS := //p' Makefile)
+[ -n "$fonts" ] || die "no CJK_FONTS in the Makefile"
+# msyh, msyhbd, simsun and malgun are built from Source Han Sans, msgothic from Ume.
+licences="source-han-sans/LICENSE.txt ume/license.html"
+for f in $fonts $licences; do
+ [ -f "build/fonts/$f" ] || die "missing build/fonts/$f, run: make fonts"
+done
+
+# The id names the fonts, not the archive, so it only changes when a font does.
+id=$(for f in $fonts; do shasum -a 256 "build/fonts/$f" | cut -d' ' -f1; done | shasum -a 256 | cut -c1-12)
+name=fonts-cjk-$id
+work=$(mktemp -d)
+trap 'rm -rf "$work"' EXIT
+mkdir -p "$work/stage"
+for f in $fonts $licences; do
+ mkdir -p "$work/stage/$(dirname "$f")"
+ cp "build/fonts/$f" "$work/stage/$f"
+done
+# Fixed modes, times and owners, entries in sorted order: a reproducible tarball.
+find "$work/stage" -type d -exec chmod 755 {} + -o -type f -exec chmod 644 {} +
+find "$work/stage" -exec touch -h -t 202601010000 {} +
+(cd "$work/stage" && find . -type f | LC_ALL=C sort) >"$work/list"
+mkdir -p out
+archive=out/$name.tar.xz
+(cd "$work/stage" && tar --uid 0 --gid 0 --uname root --gname wheel --no-xattrs --no-mac-metadata \
+ -cf - -T "$work/list") | xz -9e -T1 >"$archive"
+sha=$(shasum -a 256 "$archive" | cut -d' ' -f1)
+echo "==> $archive ($(du -h "$archive" | cut -f1 | tr -d ' ')), sha256 $sha"
+
+echo "==> pins for app/Sources/BridgeplayApp/Model/CJKFonts.swift:"
+echo " static let archive = \"$name.tar.xz\""
+echo " static let sha256 = \"$sha\""
+echo " release tag: $name"
+for f in $fonts; do
+ echo " \"$f\": \"$(shasum -a 256 "build/fonts/$f" | cut -d' ' -f1)\","
+done
+
+[ "$publish" -eq 1 ] || exit 0
+slug=raymondchins/Bridgeplay
+if gh release view "$name" -R "$slug" >/dev/null 2>&1; then
+ echo "==> $name is already published"
+ exit 0
+fi
+gh release create "$name" "$archive" -R "$slug" --prerelease --latest=false \
+ --title "CJK fonts $id" \
+ --notes "Chinese, Japanese and Korean fonts that Bridgeplay downloads during setup (Source Han Sans and Ume, licences inside). Built by fonts/build.sh, packed by scripts/package-fonts.sh."
+echo "==> published https://github.com/$slug/releases/tag/$name"
diff --git a/scripts/release-local.sh b/scripts/release-local.sh
index 346c2c0..71d1f66 100755
--- a/scripts/release-local.sh
+++ b/scripts/release-local.sh
@@ -116,6 +116,14 @@ if [ -z "$notes" ]; then
[ -n "$notes" ] || notes="Bridgeplay $version"
fi
+# The app downloads its CJK fonts from the release CJKFonts.swift pins (scripts/package-fonts.sh
+# --publish); a release without it would leave new installs without them.
+fonts_archive=$(sed -n 's/.*static let archive = "\(fonts-cjk-[0-9a-f]*\.tar\.xz\)".*/\1/p' app/Sources/BridgeplayApp/Model/CJKFonts.swift)
+[ -n "$fonts_archive" ] || die "no fonts archive pinned in CJKFonts.swift"
+fonts_tag=${fonts_archive%.tar.xz}
+gh release view "$fonts_tag" -R "$slug" --json assets -q '.assets[].name' 2>/dev/null | grep -qx "$fonts_archive" \
+ || check "$fonts_tag has no $fonts_archive on GitHub; run scripts/package-fonts.sh --publish"
+
sparkle=app/.build/artifacts/sparkle/Sparkle/bin
[ -x "$sparkle/generate_appcast" ] || swift build --package-path app >/dev/null
[ -x "$sparkle/generate_appcast" ] || die "no Sparkle tools at $sparkle"