Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.
Swift apple-siliconcustom-formathomebrewiosipaipadipadosiphonemetalnative-portnintendo-switchnxnativeromfsswitch-games
Launcher: drop Convert files
v0lumehi076c2795c21e
diff --git a/frontend-qt/nspb_qt/localization.py b/frontend-qt/nspb_qt/localization.pyindex 88feecf0..8962222a 100644--- a/frontend-qt/nspb_qt/localization.py+++ b/frontend-qt/nspb_qt/localization.py@@ -255,13 +255,6 @@ TABLE: dict[str, tuple[str, str, str, str]] = {'saves.askNote': ('请先在 %1$@ 上关闭游戏:正在运行的游戏之后会用自己的存档覆盖复制过去的存档。被替换的存档会先保存到 %2$@。', 'Close the game on %1$@ first: a running game writes its own save over the copy later. The save being replaced is kept in %2$@ first.', 'Stäng först spelet på %1$@: ett spel som körs skriver senare över kopian med sin egen sparfil. Sparfilen som ersätts sparas först i %2$@.', 'Beende das Spiel zuerst auf %1$@. Ein laufendes Spiel schreibt später seinen eigenen Spielstand über die Kopie. Der zu ersetzende Spielstand wird vorher in %2$@ gesichert.'),'saves.cancel': ('取消', 'Cancel', 'Avbryt', 'Abbrechen'),'confirm.typePrompt': ('输入「%@」以确认', 'Type “%@” to confirm', 'Skriv “%@” för att bekräfta', 'Gib „%@“ ein, um zu bestätigen'),- 'convert.title': ('转换文件', 'Convert files', 'Konvertera filer', 'Dateien konvertieren'),- 'convert.note': ('用内置的 nsz 转换:压缩包(.nsz/.xcz)解回 .nsp/.xci,普通包压成 .nsz。输出写在原文件旁边。', 'Convert with the bundled nsz: a compressed dump (.nsz/.xcz) back to .nsp/.xci, or a plain package into a compressed one. The output is written beside the input.', 'Konvertera med inbyggda nsz: ett komprimerat arkiv (.nsz/.xcz) tillbaka till .nsp/.xci, eller ett vanligt paket till ett komprimerat. Utdata skrivs bredvid indata.', 'Konvertieren mit dem mitgelieferten nsz: ein komprimiertes Archiv (.nsz/.xcz) zurück zu .nsp/.xci, oder ein normales Paket in ein komprimiertes. Die Ausgabe liegt neben der Eingabe.'),- 'convert.choose': ('选择文件…', 'Choose files…', 'Välj filer…', 'Dateien auswählen…'),- 'convert.none': ('还没有选择可以转换的文件(.nsp/.xci/.nsz/.xcz)。', 'No convertible files selected (.nsp/.xci/.nsz/.xcz).', 'Inga konverterbara filer valda (.nsp/.xci/.nsz/.xcz).', 'Keine konvertierbaren Dateien ausgewählt (.nsp/.xci/.nsz/.xcz).'),- 'convert.run': ('开始转换', 'Convert', 'Konvertera', 'Konvertieren'),- 'convert.running': ('转换中…', 'Converting…', 'Konverterar…', 'Konvertiere…'),- 'convert.ready': ('转换完成后,输出文件在原文件旁边。', 'When done, the output is beside each input.', 'När det är klart ligger utdata bredvid varje indata.', 'Wenn fertig, liegt die Ausgabe neben jeder Eingabe.'),'confirm.cancel': ('取消', 'Cancel', 'Avbryt', 'Abbrechen'),'saves.replace': ('替换', 'Replace', 'Ersätt', 'Ersetzen'),'saves.copying': ('正在复制存档…', 'Copying the save…', 'Kopierar sparfilen …', 'Spielstand wird kopiert …'),diff --git a/frontend/Sources/NSPortBuilder/ContentView.swift b/frontend/Sources/NSPortBuilder/ContentView.swiftindex 0ebbcca8..b9b2049a 100644--- a/frontend/Sources/NSPortBuilder/ContentView.swift+++ b/frontend/Sources/NSPortBuilder/ContentView.swift@@ -627,7 +627,6 @@ final class BuildModel: ObservableObject {/// Whether the "a new version is out" sheet is up: opened by the launch check and by Check for/// updates, so a user learns what changed before deciding, not after downloading.@Published var showUpdateSheet = false- @Published var showConvertSheet = false/// The uninstall row's dialog: computed when the row is pressed, run when the phrase matches.@Published var uninstallPlan: Uninstall.Plan?@Published var appStatus = ""@@ -3554,9 +3553,6 @@ struct BuilderView: View {private var tools: some View {group(m.t("section.tools"), footnote: m.repoStatus.isEmpty ? (m.repoOK ? "" : m.t("repo.firstHint")) : m.repoStatus) {- row(m.t("convert.title"), detail: m.t("convert.note")) {- Button(m.t("convert.choose")) { m.showConvertSheet = true }- }row(m.t("repo.title"),detail: m.repoOK ? m.shortPath(m.repoPath): (m.repoPath.isEmpty ? m.t("repo.notFound") : String(format: m.t("repo.notRepo"), m.shortPath(m.repoPath))),diff --git a/frontend/Sources/NSPortBuilder/ConvertView.swift b/frontend/Sources/NSPortBuilder/ConvertView.swiftdeleted file mode 100644index ded7b026..00000000--- a/frontend/Sources/NSPortBuilder/ConvertView.swift+++ /dev/null@@ -1,101 +0,0 @@-import SwiftUI--/// Convert files with the bundled nsz: a compressed dump (.nsz/.xcz) to .nsp/.xci beside it, or a plain-/// package into a compressed one. One file at a time, the build's own interpreter, the log live below.-struct ConvertView: View {- @ObservedObject var m: BuildModel- @Environment(\.dismiss) private var dismiss- @State private var paths: [String] = []- @State private var log = ""- @State private var running = false-- private var plan: [(path: String, kind: FileConvert.Kind, output: String)] { FileConvert.plan(for: paths) }-- var body: some View {- VStack(alignment: .leading, spacing: 0) {- VStack(alignment: .leading, spacing: 4) {- Text(m.t("convert.title")).font(.manrope(26, .heavy)).tracking(-0.6)- Text(m.t("convert.note")).font(.manrope(14)).foregroundStyle(.secondary)- .fixedSize(horizontal: false, vertical: true)- }- .padding(.horizontal, 30).padding(.top, 28).padding(.bottom, 14)- ScrollView {- VStack(alignment: .leading, spacing: 12) {- Button(m.t("convert.choose")) {- let panel = NSOpenPanel()- panel.canChooseFiles = true; panel.canChooseDirectories = false; panel.allowsMultipleSelection = true- panel.allowedContentTypes = [.data] // NSP/XCI/NSZ/XCZ have no registered type: pick anything, filter here- if panel.runModal() == .OK {- paths = panel.urls.map(\.path).filter { FileConvert.kind(for: $0) != nil }- }- }- .buttonStyle(LauncherSecondaryButtonStyle())- ForEach(plan, id: \.path) { item in- HStack(spacing: 12) {- Image(systemName: item.kind == .decompress ? "arrow.down.doc" : "arrow.up.doc")- .foregroundStyle(.secondary)- VStack(alignment: .leading, spacing: 2) {- Text((item.path as NSString).lastPathComponent).font(.manrope(13, .medium)).lineLimit(1)- Text("→ " + (item.output as NSString).lastPathComponent).font(.manrope(12)).foregroundStyle(.secondary)- }- Spacer(minLength: 8)- }- .padding(.horizontal, 18).padding(.vertical, 11)- .background(LauncherPalette.surface.opacity(0.75), in: RoundedRectangle(cornerRadius: 12))- }- if paths.isEmpty {- Text(m.t("convert.none")).font(.manrope(13)).foregroundStyle(.secondary)- .padding(.vertical, 6)- }- if !log.isEmpty {- Text(log).font(.system(size: 11, design: .monospaced)).foregroundStyle(.secondary)- .textSelection(.enabled).frame(maxWidth: .infinity, alignment: .leading)- .padding(12).background(Color.black.opacity(0.3), in: RoundedRectangle(cornerRadius: 10))- }- }- .padding(.horizontal, 30).padding(.bottom, 16)- }- Divider().opacity(0.3)- HStack(spacing: 14) {- Text(running ? m.t("convert.running") : m.t("convert.ready")).font(.manrope(12)).foregroundStyle(.secondary).lineLimit(1)- Spacer(minLength: 8)- Button(m.t("convert.run")) { run() }- .buttonStyle(LauncherSecondaryButtonStyle())- .disabled(plan.isEmpty || running)- Button { dismiss() } label: {- Text(m.t("launch.done")).font(.manrope(13.5, .bold)).foregroundStyle(.black)- .padding(.horizontal, 22).padding(.vertical, 9)- .background(LauncherPalette.cream, in: Capsule())- }- .buttonStyle(.plain).keyboardShortcut(.defaultAction)- }- .padding(.horizontal, 30).padding(.vertical, 16)- }- .frame(width: 620, height: 640)- .background(LauncherPalette.background)- .font(.manrope(13))- .preferredColorScheme(.dark)- .tint(LauncherPalette.cream)- }-- /// One nsz run per file, in order, each writing beside its input. The same interpreter the build- /// uses, so the bundled nsz runs and nothing new is installed.- private func run() {- let python = m.pythonPath.isEmpty ? BuildModel.findPython().path : m.pythonPath- let jobs = plan- guard !jobs.isEmpty else { return }- running = true; log = ""- DispatchQueue.global(qos: .userInitiated).async {- for job in jobs {- DispatchQueue.main.async { self.log += "$ " + FileConvert.command(python: python, kind: job.kind, path: job.path).joined(separator: " ") + "\n" }- let r = BuildModel.runQuiet(FileConvert.command(python: python, kind: job.kind, path: job.path),- env: BuildModel.gitEnv().merging(["HOME": NSHomeDirectory()]) { $1 })- DispatchQueue.main.async {- self.log += r.ok ? "✓ " + FileConvert.output(for: job.path, kind: job.kind) + "\n"- : "✗ " + r.out.suffix(400) + "\n"- }- }- DispatchQueue.main.async { self.running = false }- }- }-}diff --git a/frontend/Sources/NSPortBuilder/FileConvert.swift b/frontend/Sources/NSPortBuilder/FileConvert.swiftdeleted file mode 100644index 7dbbc117..00000000--- a/frontend/Sources/NSPortBuilder/FileConvert.swift+++ /dev/null@@ -1,44 +0,0 @@-import Foundation--/// File conversion with the bundled nsz (frontend/bundled-python/requirements.txt): a compressed dump-/// (.nsz/.xcz) decompresses to .nsp/.xci, and the other way around. LumaNX ships a whole workspace for-/// this; ours is the one thing players actually asked for, running the same tool the build runs.-enum FileConvert {- enum Kind: String, CaseIterable {- case decompress- case compress-- var flag: String { self == .decompress ? "-D" : "-C" }- }-- /// What a file can become. A compressed dump decompresses; a plain package compresses.- nonisolated static func kind(for path: String) -> Kind? {- switch (path as NSString).pathExtension.lowercased() {- case "nsz", "xcz": return .decompress- case "nsp", "xci": return .compress- default: return nil- }- }-- /// The command the build itself runs nsz with (`python -m nsz`), against the interpreter the- /// launcher builds with — so the bundled nsz is used and nothing new is installed.- nonisolated static func command(python: String, kind: Kind, path: String) -> [String] {- [python, "-m", "nsz", kind.flag, path]- }-- /// The output file nsz writes beside the input: the same stem, the other extension.- nonisolated static func output(for path: String, kind: Kind) -> String {- let base = (path as NSString).deletingPathExtension- return kind == .decompress- ? base + "." + ((path as NSString).pathExtension.lowercased() == "nsz" ? "nsp" : "xci")- : base + ".nsz"- }-- /// The files of a selection this tool can act on, in order, and what it would make of them.- nonisolated static func plan(for paths: [String]) -> [(path: String, kind: Kind, output: String)] {- paths.compactMap { path in- guard let kind = kind(for: path) else { return nil }- return (path, kind, output(for: path, kind: kind))- }- }-}diff --git a/frontend/Sources/NSPortBuilder/LauncherView.swift b/frontend/Sources/NSPortBuilder/LauncherView.swiftindex d1d0da21..8b64016c 100644--- a/frontend/Sources/NSPortBuilder/LauncherView.swift+++ b/frontend/Sources/NSPortBuilder/LauncherView.swift@@ -280,7 +280,6 @@ struct ContentView: View {}.onChange(of: freeSpaceFor) { id in padFocus.scope = id != nil ? "free" : currentPadScope }.sheet(isPresented: $m.showUpdateSheet) { UpdateSheet(m: m) }- .sheet(isPresented: $m.showConvertSheet) { ConvertView(m: m) }.typeToConfirm(isPresented: Binding(get: { m.uninstallPlan != nil }, set: { if !$0 { m.uninstallPlan = nil } }),phrase: "NX2Apple",diff --git a/frontend/Sources/NSPortBuilder/Localization.swift b/frontend/Sources/NSPortBuilder/Localization.swiftindex 6430cf2a..293b1c35 100644--- a/frontend/Sources/NSPortBuilder/Localization.swift+++ b/frontend/Sources/NSPortBuilder/Localization.swift@@ -298,13 +298,6 @@ enum L10n {"saves.askNote": ("请先在 %1$@ 上关闭游戏:正在运行的游戏之后会用自己的存档覆盖复制过去的存档。被替换的存档会先保存到 %2$@。", "Close the game on %1$@ first: a running game writes its own save over the copy later. The save being replaced is kept in %2$@ first."),"saves.cancel": ("取消", "Cancel"),"confirm.typePrompt": ("输入「%@」以确认", "Type \u{201c}%@\u{201d} to confirm"),- "convert.title": ("转换文件", "Convert files"),- "convert.note": ("用内置的 nsz 转换:压缩包(.nsz/.xcz)解回 .nsp/.xci,普通包压成 .nsz。输出写在原文件旁边。", "Convert with the bundled nsz: a compressed dump (.nsz/.xcz) back to .nsp/.xci, or a plain package into a compressed one. The output is written beside the input."),- "convert.choose": ("选择文件…", "Choose files…"),- "convert.none": ("还没有选择可以转换的文件(.nsp/.xci/.nsz/.xcz)。", "No convertible files selected (.nsp/.xci/.nsz/.xcz)."),- "convert.run": ("开始转换", "Convert"),- "convert.running": ("转换中…", "Converting…"),- "convert.ready": ("转换完成后,输出文件在原文件旁边。", "When done, the output is beside each input."),"confirm.cancel": ("取消", "Cancel"),"saves.replace": ("替换", "Replace"),"saves.copying": ("正在复制存档…", "Copying the save…"),@@ -1246,13 +1239,6 @@ enum L10n {"saves.askToMac": "Ersätt sparfilen på den här Mac-datorn med den från %@?","saves.askNote": "Stäng först spelet på %1$@: ett spel som körs skriver senare över kopian med sin egen sparfil. Sparfilen som ersätts sparas först i %2$@.","saves.cancel": "Avbryt",- "convert.title": "Konvertera filer",- "convert.note": "Konvertera med inbyggda nsz: ett komprimerat arkiv (.nsz/.xcz) tillbaka till .nsp/.xci, eller ett vanligt paket till ett komprimerat. Utdata skrivs bredvid indata.",- "convert.choose": "Välj filer…",- "convert.none": "Inga konverterbara filer valda (.nsp/.xci/.nsz/.xcz).",- "convert.run": "Konvertera",- "convert.running": "Konverterar…",- "convert.ready": "När det är klart ligger utdata bredvid varje indata.","confirm.typePrompt": "Skriv \u{201c}%@\u{201d} för att bekräfta","confirm.cancel": "Avbryt","saves.replace": "Ersätt",@@ -2072,13 +2058,6 @@ enum L10n {"saves.cancel": "Abbrechen","confirm.typePrompt": "Gib \u{201e}%@\u{201c} ein, um zu bestätigen","confirm.cancel": "Abbrechen",- "convert.title": "Dateien konvertieren",- "convert.note": "Konvertieren mit dem mitgelieferten nsz: ein komprimiertes Archiv (.nsz/.xcz) zurück zu .nsp/.xci, oder ein normales Paket in ein komprimiertes. Die Ausgabe liegt neben der Eingabe.",- "convert.choose": "Dateien auswählen…",- "convert.none": "Keine konvertierbaren Dateien ausgewählt (.nsp/.xci/.nsz/.xcz).",- "convert.run": "Konvertieren",- "convert.running": "Konvertiere…",- "convert.ready": "Wenn fertig, liegt die Ausgabe neben jeder Eingabe.","saves.replace": "Ersetzen","saves.copying": "Spielstand wird kopiert …","saves.copied": "Kopiert.",diff --git a/frontend/Tests/NSPortBuilderTests/FileConvertTests.swift b/frontend/Tests/NSPortBuilderTests/FileConvertTests.swiftdeleted file mode 100644index b8828d74..00000000--- a/frontend/Tests/NSPortBuilderTests/FileConvertTests.swift+++ /dev/null@@ -1,34 +0,0 @@-import XCTest-@testable import NSPortBuilder--/// What the converter runs for a file (FileConvert.swift): the kind by extension, the nsz command and-/// the output beside the input. The nsz run itself needs real dumps and is not tested here.-final class FileConvertTests: XCTestCase {- func testTheKindFollowsTheExtension() {- XCTAssertEqual(FileConvert.kind(for: "/g/Mario Kart 8 [0100152000022000][v0].nsz"), .decompress)- XCTAssertEqual(FileConvert.kind(for: "/g/game.xcz"), .decompress)- XCTAssertEqual(FileConvert.kind(for: "/g/game.nsp"), .compress)- XCTAssertEqual(FileConvert.kind(for: "/g/game.xci"), .compress)- XCTAssertNil(FileConvert.kind(for: "/g/game.bin"))- XCTAssertNil(FileConvert.kind(for: "/g/without-extension"))- }-- func testTheCommandIsTheBuildsOwnNszInvocation() {- XCTAssertEqual(FileConvert.command(python: "/py", kind: .decompress, path: "/g/game.nsz"),- ["/py", "-m", "nsz", "-D", "/g/game.nsz"])- XCTAssertEqual(FileConvert.command(python: "/py", kind: .compress, path: "/g/game.nsp"),- ["/py", "-m", "nsz", "-C", "/g/game.nsp"])- }-- func testTheOutputSitsBesideTheInput() {- XCTAssertEqual(FileConvert.output(for: "/g/game.nsz", kind: .decompress), "/g/game.nsp")- XCTAssertEqual(FileConvert.output(for: "/g/game.xcz", kind: .decompress), "/g/game.xci")- XCTAssertEqual(FileConvert.output(for: "/g/game.NSP", kind: .compress), "/g/game.nsz")- }-- func testThePlanSkipsWhatItCannotConvert() {- let plan = FileConvert.plan(for: ["/g/a.nsz", "/g/readme.txt", "/g/b.nsp"])- XCTAssertEqual(plan.map(\.path), ["/g/a.nsz", "/g/b.nsp"])- XCTAssertEqual(plan.map(\.kind), [.decompress, .compress])- }-}