Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

Mac launcher: show and set a game's cloud saves folder, and the last sync (#499)

v0lumehi7891bc96fe37
diff --git a/frontend/Sources/NX2Apple/CloudSavesCard.swift b/frontend/Sources/NX2Apple/CloudSavesCard.swift
new file mode 100644
index 00000000..210492e2
--- /dev/null
+++ b/frontend/Sources/NX2Apple/CloudSavesCard.swift
@@ -0,0 +1,199 @@
+import AppKit
+import SwiftUI
+import NXCore
+import NXModel
+import NXLauncher
+
+/// The Cloud saves section of a game's settings (#499): the folder the game syncs through and where that was set, Choose
+/// folder and Turn off, a notice when the folder cannot be the one another device uses, and what the last session's log says
+/// about the sync, with the time of that session. The state is only what the log says: the launcher does not watch a running game.
+struct CloudSavesCard: View {
+ let game: LibraryGame
+ /// Visual QA: a store with example values and a last session, read instead of the files.
+ var saves: GameCloudSaves?
+ var preview: (check: CloudSaveSync.FolderCheck?, last: (state: CloudSaveSync.LogState?, date: Date?)?)?
+ var chooseFolder: (URL?) -> URL? = CloudSavesCard.openPanel
+ var home = NSHomeDirectory()
+ @EnvironmentObject var loc: Localizer
+ @State private var revision = 0
+ @State private var last: (state: CloudSaveSync.LogState?, date: Date?)?? = nil
+ @State private var problem: String?
+
+ private var store: GameCloudSaves { saves ?? GameCloudSaves(titleID: game.titleID, appPath: game.appPath) }
+ static let attention = Color(red: 1, green: 0.78, blue: 0.24)
+
+ var body: some View {
+ let _ = revision
+ let setting = store.setting
+ let check = preview?.check ?? setting.folder.map { CloudSaveSync.check(folder: $0, titleID: game.titleID) }
+ VStack(alignment: .leading, spacing: 10) {
+ Text(loc.t("cloud.title")).font(.manrope(15, .semibold)).foregroundStyle(.secondary).padding(.leading, 2)
+ VStack(alignment: .leading, spacing: 0) {
+ folderRow(setting)
+ if let check, let notice = notice(check) {
+ Divider().opacity(0.25).padding(.leading, 18)
+ notice
+ }
+ Divider().opacity(0.25).padding(.leading, 18)
+ lastRow
+ }
+ .background(LauncherPalette.surface.opacity(0.75), in: RoundedRectangle(cornerRadius: 14))
+ .overlay(RoundedRectangle(cornerRadius: 14).strokeBorder(Color.white.opacity(0.06)))
+ Text(problem ?? loc.t(setting.isOn ? "cloud.applies" : "cloud.offNote")).font(.manrope(12))
+ .foregroundStyle(problem == nil ? .secondary : Self.attention)
+ .padding(.leading, 2).fixedSize(horizontal: false, vertical: true)
+ }
+ .onAppear(perform: readLog)
+ }
+
+ // ---- the folder ----
+
+ private func folderRow(_ setting: CloudSaveSync.Setting) -> some View {
+ HStack(alignment: .center, spacing: 14) {
+ Image(systemName: setting.isOn ? "icloud" : "icloud.slash").font(.system(size: 17, weight: .medium))
+ .foregroundStyle(setting.isOn ? LauncherPalette.cream : .secondary).frame(width: 22)
+ VStack(alignment: .leading, spacing: 3) {
+ Text(setting.folder.map(Self.name) ?? loc.t("cloud.off")).font(.manrope(14, .medium)).lineLimit(1)
+ if let folder = setting.folder {
+ Text(Self.shown(folder, home: home)).font(.manrope(11.5)).foregroundStyle(.secondary).lineLimit(1).truncationMode(.middle)
+ .help(folder)
+ }
+ if let source = sourceText(setting) { Text(source).font(.manrope(11.5)).foregroundStyle(.tertiary) }
+ }
+ Spacer(minLength: 12)
+ if setting.isOn {
+ Button(loc.t("cloud.turnOff")) { change { try store.turnOff() } }
+ .padTarget("cloud.off", scope: "launch") { change { try store.turnOff() } }
+ }
+ Button(loc.t("cloud.choose")) { choose(from: setting.folder) }
+ .padTarget("cloud.choose", scope: "launch") { choose(from: setting.folder) }
+ }
+ .buttonStyle(LauncherSecondaryButtonStyle())
+ .padding(.horizontal, 18).padding(.vertical, 13).frame(minHeight: 56)
+ }
+
+ private func sourceText(_ setting: CloudSaveSync.Setting) -> String? {
+ switch setting.source {
+ case .playerEnv: return loc.t("cloud.fromPlayerEnv")
+ case .appEnv: return loc.t("cloud.fromAppEnv")
+ case .preference, .none: return nil
+ }
+ }
+
+ /// iCloud Drive's own folders by their name in the Finder, anything else by its last part.
+ static func name(_ folder: String) -> String { (folder as NSString).lastPathComponent }
+
+ static func shown(_ folder: String, home: String = NSHomeDirectory()) -> String {
+ let drive = home + "/Library/Mobile Documents/com~apple~CloudDocs"
+ if folder == drive { return "iCloud Drive" }
+ if folder.hasPrefix(drive + "/") { return "iCloud Drive › " + folder.dropFirst(drive.count + 1).replacingOccurrences(of: "/", with: " › ") }
+ return (folder as NSString).abbreviatingWithTildeInPath
+ }
+
+ // ---- what the folder holds ----
+
+ private func notice(_ check: CloudSaveSync.FolderCheck) -> AnyView? {
+ switch check {
+ case .missing: return AnyView(noticeRow("exclamationmark.triangle", loc.t("cloud.missing"), Self.attention))
+ case .noSave: return AnyView(noticeRow("exclamationmark.triangle", loc.t("cloud.noSave"), Self.attention))
+ case .hasSave(let date):
+ guard let date else { return nil }
+ return AnyView(noticeRow("checkmark.icloud", String(format: loc.t("cloud.hasSave"), when(date)), .secondary))
+ }
+ }
+
+ private func noticeRow(_ symbol: String, _ text: String, _ tint: Color) -> some View {
+ HStack(alignment: .firstTextBaseline, spacing: 14) {
+ Image(systemName: symbol).font(.system(size: 13, weight: .medium)).foregroundStyle(tint).frame(width: 22)
+ Text(text).font(.manrope(12.5)).foregroundStyle(tint == .secondary ? .secondary : .primary)
+ .fixedSize(horizontal: false, vertical: true)
+ Spacer(minLength: 0)
+ }
+ .padding(.horizontal, 18).padding(.vertical, 11)
+ }
+
+ // ---- the last session ----
+
+ @ViewBuilder private var lastRow: some View {
+ let shown = preview?.last ?? last ?? nil
+ HStack(alignment: .firstTextBaseline, spacing: 14) {
+ Circle().fill(color(shown?.state)).frame(width: 8, height: 8).frame(width: 22)
+ VStack(alignment: .leading, spacing: 3) {
+ Text(stateText(shown)).font(.manrope(13.5, .medium)).fixedSize(horizontal: false, vertical: true)
+ if let date = shown?.date {
+ Text(String(format: loc.t("cloud.lastSession"), when(date))).font(.manrope(11.5)).foregroundStyle(.secondary)
+ }
+ }
+ Spacer(minLength: 0)
+ }
+ .padding(.horizontal, 18).padding(.vertical, 12)
+ }
+
+ private func stateText(_ last: (state: CloudSaveSync.LogState?, date: Date?)?) -> String {
+ guard let last else { return loc.t("cloud.state.notPlayed") }
+ switch last.state {
+ case nil: return loc.t("cloud.state.none")
+ case .inStep: return loc.t("cloud.state.inStep")
+ case .sent: return loc.t("cloud.state.sent")
+ case .broughtIn(let device): return String(format: loc.t("cloud.state.broughtIn"), device)
+ case .waitingToSend: return loc.t("cloud.state.waiting")
+ case .offline: return loc.t("cloud.state.offline")
+ case .nothingYet: return loc.t("cloud.state.nothingYet")
+ case .off(let why): return String(format: loc.t("cloud.state.off"), why)
+ case .failed(let why): return String(format: loc.t("cloud.state.failed"), why)
+ }
+ }
+
+ private func color(_ state: CloudSaveSync.LogState?) -> Color {
+ switch state {
+ case .inStep, .sent, .broughtIn: return Color(red: 0.25, green: 0.84, blue: 0.47)
+ case .waitingToSend, .offline, .off: return Self.attention
+ case .failed: return Color(red: 1, green: 0.42, blue: 0.40)
+ case .nothingYet, nil: return Color.white.opacity(0.3)
+ }
+ }
+
+ /// In the launcher's language, not the Mac's.
+ private func when(_ date: Date) -> String {
+ let f = DateFormatter()
+ f.locale = Locale(identifier: loc.lang.code)
+ f.dateStyle = .medium
+ f.timeStyle = .short
+ f.doesRelativeDateFormatting = true
+ return f.string(from: date)
+ }
+
+ // ---- changes ----
+
+ private func choose(from folder: String?) {
+ let start = folder.map { URL(fileURLWithPath: $0) }
+ ?? URL(fileURLWithPath: NSHomeDirectory() + "/Library/Mobile Documents/com~apple~CloudDocs")
+ guard let url = chooseFolder(start) else { return }
+ change { try store.choose(url.path) }
+ }
+
+ private func change(_ body: () throws -> Void) {
+ do { try body(); problem = nil } catch { problem = String(format: loc.t("cloud.failed"), error.localizedDescription) }
+ revision += 1
+ }
+
+ private func readLog() {
+ guard preview == nil else { return }
+ let store = store
+ DispatchQueue.global(qos: .utility).async {
+ let result = store.lastSession()
+ DispatchQueue.main.async { last = .some(result) }
+ }
+ }
+
+ /// The folder panel, opened at the current folder or iCloud Drive.
+ static func openPanel(_ start: URL?) -> URL? {
+ let panel = NSOpenPanel()
+ panel.canChooseDirectories = true
+ panel.canChooseFiles = false
+ panel.canCreateDirectories = true
+ panel.allowsMultipleSelection = false
+ panel.directoryURL = start
+ return panel.runModal() == .OK ? panel.url : nil
+ }
+}
diff --git a/frontend/Sources/NX2Apple/GameCloudSaves.swift b/frontend/Sources/NX2Apple/GameCloudSaves.swift
new file mode 100644
index 00000000..8ce46691
--- /dev/null
+++ b/frontend/Sources/NX2Apple/GameCloudSaves.swift
@@ -0,0 +1,65 @@
+import Foundation
+import NXCore
+
+/// One Mac game's cloud saves folder on disk (#499): read where dm/mac/launcher.c reads it (CloudSaveSync), changed where it
+/// counts, and the last session's sync from the game's log.
+///
+/// A change goes to the place the engine reads first among those that set the folder: the player's env.txt when it or the
+/// app's own env.txt has a `DM_SAVE_SYNC` line (the app's is inside the signed app and is not changed, the player's wins over
+/// it), else `cloudSaves.folder` in the app's preferences domain, as the app's own settings window does.
+struct GameCloudSaves {
+ let titleID: String
+ let appPath: String
+ var home = NSHomeDirectory()
+ var support = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0]
+ var readPreference: () -> String?
+ var writePreference: (String?) -> Void
+
+ init(titleID: String, appPath: String) {
+ self.titleID = titleID
+ self.appPath = appPath
+ let domain = SavedChoices.domain(app: appPath, titleID: titleID) as CFString
+ let key = CloudSaveSync.preferenceKey as CFString
+ readPreference = { CFPreferencesCopyAppValue(key, domain) as? String }
+ writePreference = { value in
+ CFPreferencesSetAppValue(key, value as CFString?, domain)
+ CFPreferencesAppSynchronize(domain)
+ }
+ }
+
+ var playerEnv: URL { support.appendingPathComponent("nxnative").appendingPathComponent(titleID).appendingPathComponent("env.txt") }
+ var appEnv: URL { URL(fileURLWithPath: appPath).appendingPathComponent("Contents/Resources/dm/env.txt") }
+
+ private static func text(_ url: URL) -> String? { (try? Data(contentsOf: url)).map { String(decoding: $0, as: UTF8.self) } }
+
+ var setting: CloudSaveSync.Setting {
+ CloudSaveSync.resolve(playerEnv: Self.text(playerEnv), appEnv: appPath.isEmpty ? nil : Self.text(appEnv),
+ preference: readPreference(), home: home)
+ }
+
+ /// Whether a line of an env.txt sets the folder: then the player's env.txt is where a change counts.
+ private var envDecides: Bool { [.playerEnv, .appEnv].contains(setting.source) }
+
+ /// Syncs through `folder` from the game's next start.
+ func choose(_ folder: String) throws { try set(folder) }
+
+ /// Turns cloud saves off from the game's next start. An env.txt line becomes `DM_SAVE_SYNC=0`, so the app's own line
+ /// cannot turn them on again.
+ func turnOff() throws { try set(nil) }
+
+ private func set(_ folder: String?) throws {
+ if envDecides {
+ try FileManager.default.createDirectory(at: playerEnv.deletingLastPathComponent(), withIntermediateDirectories: true)
+ try Data(CloudSaveSync.settingEnv(Self.text(playerEnv), to: folder ?? "0").utf8).write(to: playerEnv, options: .atomic)
+ }
+ writePreference(folder)
+ }
+
+ /// The last session's sync and when that session's log was last written, nil when the game has no log yet.
+ func lastSession() -> (state: CloudSaveSync.LogState?, date: Date?)? {
+ guard let log = GameLog.latest(titleID: titleID, appPath: appPath, home: home) else { return nil }
+ let date = (try? FileManager.default.attributesOfItem(atPath: log.path))?[.modificationDate] as? Date
+ let text = (try? Data(contentsOf: log)).map { String(decoding: $0, as: UTF8.self) } ?? ""
+ return (CloudSaveSync.state(fromLog: text), date)
+ }
+}
diff --git a/frontend/Sources/NX2Apple/LaunchOptionsView.swift b/frontend/Sources/NX2Apple/LaunchOptionsView.swift
index 3cf74550..d903a926 100644
--- a/frontend/Sources/NX2Apple/LaunchOptionsView.swift
+++ b/frontend/Sources/NX2Apple/LaunchOptionsView.swift
@@ -55,6 +55,7 @@ struct LaunchOptionsView: View {
groups(settings.filter(\.isBasic), game, all: settings)
modsSection(game)
frameTimesSection(game)
+ CloudSavesCard(game: game)
let advanced = settings.filter { !$0.isBasic }
if !advanced.isEmpty {
card {
diff --git a/frontend/Sources/NXCore/CloudSaveSync.swift b/frontend/Sources/NXCore/CloudSaveSync.swift
new file mode 100644
index 00000000..8bc68361
--- /dev/null
+++ b/frontend/Sources/NXCore/CloudSaveSync.swift
@@ -0,0 +1,131 @@
+import Foundation
+
+/// A Mac game's cloud saves as the engine reads them (#499), and what its last session's log says about the sync.
+///
+/// Where the folder comes from, in dm/mac/launcher.c's order (docs/frontends.md, "The cloud saves folder"): the first
+/// `DM_SAVE_SYNC` line of `~/Library/Application Support/nxnative/<title ID>/env.txt`, then of the app's own
+/// `Contents/Resources/dm/env.txt`, then `cloudSaves.folder` in the app's preferences domain. `icloud` is iCloud Drive ›
+/// nxnative Saves, `0` or an empty value is off. The save is `<folder>/<TITLE ID>/save.dmsync`, or `<folder>/save.dmsync` for a
+/// folder that is already the game's own (dm/host/save_sync.c, cloud_file).
+package enum CloudSaveSync {
+ package static let key = "DM_SAVE_SYNC"
+ /// The key in the app's preferences domain (dm/mac/launcher.c, cloud_saves_folder).
+ package static let preferenceKey = "cloudSaves.folder"
+ package static let icloudFolder = "nxnative Saves"
+
+ /// Where the folder that counts was set.
+ package enum Source: Equatable { case playerEnv, appEnv, preference, none }
+
+ /// The folder setting that counts, as the engine resolves it.
+ package struct Setting: Equatable {
+ package var source: Source
+ /// The value as written (`icloud`, a path, `0`), nil when nothing sets it.
+ package var value: String?
+ /// The folder it means, nil when cloud saves are off.
+ package var folder: String?
+ package init(source: Source, value: String?, folder: String?) { self.source = source; self.value = value; self.folder = folder }
+ package var isOn: Bool { folder != nil }
+ }
+
+ /// The first `DM_SAVE_SYNC` value of an env.txt, read as launcher.c's env_file does: `KEY=VALUE` lines, `#` starts a comment,
+ /// spaces around the key and at the end of the value are dropped, the first line for a key wins.
+ package static func envValue(_ text: String) -> String? { envLine(text)?.value }
+
+ private static func envLine(_ text: String) -> (index: Int, value: String, ending: String)? {
+ for (i, raw) in text.components(separatedBy: "\n").enumerated() {
+ let line = raw.drop(while: { $0 == " " || $0 == "\t" })
+ guard !line.hasPrefix("#"), let eq = line.firstIndex(of: "="), eq != line.startIndex,
+ line[..<eq].trimmingCharacters(in: .whitespaces) == key else { continue }
+ var value = String(line[line.index(after: eq)...])
+ var ending = ""
+ while let last = value.last, last == "\r" || last == " " || last == "\t" { ending = String(last) + ending; value.removeLast() }
+ return (i, value, ending)
+ }
+ return nil
+ }
+
+ /// The folder a value means: nil for off (`0`, empty), iCloud Drive › nxnative Saves for `icloud`, else the path as written
+ /// without a trailing slash.
+ package static func folder(for value: String?, home: String = NSHomeDirectory()) -> String? {
+ guard let value, !value.isEmpty, value != "0" else { return nil }
+ if value == "icloud" { return home + "/Library/Mobile Documents/com~apple~CloudDocs/" + icloudFolder }
+ var path = (value as NSString).expandingTildeInPath
+ while path.count > 1 && path.hasSuffix("/") { path.removeLast() }
+ return path
+ }
+
+ /// The setting that counts, from the two env.txt texts (nil when the file is missing) and the preference.
+ package static func resolve(playerEnv: String?, appEnv: String?, preference: String?, home: String = NSHomeDirectory()) -> Setting {
+ if let v = playerEnv.flatMap(envValue) { return Setting(source: .playerEnv, value: v, folder: folder(for: v, home: home)) }
+ if let v = appEnv.flatMap(envValue) { return Setting(source: .appEnv, value: v, folder: folder(for: v, home: home)) }
+ if let v = preference, !v.isEmpty { return Setting(source: .preference, value: v, folder: folder(for: v, home: home)) }
+ return Setting(source: .none, value: nil, folder: nil)
+ }
+
+ /// `<folder>/<TITLE ID>/save.dmsync`, or `<folder>/save.dmsync` when the folder is the game's own.
+ package static func saveFile(folder: String, titleID: String) -> String {
+ let id = titleID.uppercased()
+ return (folder as NSString).lastPathComponent.uppercased() == id ? folder + "/save.dmsync" : folder + "/" + id + "/save.dmsync"
+ }
+
+ /// The player's env.txt with its first `DM_SAVE_SYNC` line set to `value`, or the line added at the end when it has none.
+ /// Comments and every other line stay as they are.
+ package static func settingEnv(_ text: String?, to value: String) -> String {
+ let text = text ?? ""
+ var lines = text.components(separatedBy: "\n")
+ if let line = envLine(text) {
+ lines[line.index] = "\(key)=\(value)\(line.ending)"
+ return lines.joined(separator: "\n")
+ }
+ let body = text.isEmpty || text.hasSuffix("\n") ? text : text + "\n"
+ return body + "\(key)=\(value)\n"
+ }
+
+ /// What the folder holds for the game: a notice before the first play, so a wrong folder shows (#490).
+ package enum FolderCheck: Equatable { case missing, noSave, hasSave(Date?) }
+
+ package static func check(folder: String, titleID: String, fm: FileManager = .default) -> FolderCheck {
+ var isDir: ObjCBool = false
+ guard fm.fileExists(atPath: folder, isDirectory: &isDir), isDir.boolValue else { return .missing }
+ let file = saveFile(folder: folder, titleID: titleID)
+ guard fm.fileExists(atPath: file) else { return .noSave }
+ return .hasSave((try? fm.attributesOfItem(atPath: file))?[.modificationDate] as? Date)
+ }
+
+ /// What the last session's log says about the sync: the last result of the `save sync:` lines (dm/host/save_sync.c).
+ package enum LogState: Equatable {
+ case off(String) // "off: <why>"
+ case inStep // the save here and the cloud's are the same
+ case broughtIn(String) // a newer save came from the cloud, from the device named
+ case waitingToSend // this device's save is newer and goes to the cloud, and no send followed in this log
+ case sent(String) // "sent: <n> files, saved <time>, to <file>": the part before ", to"
+ case offline // the cloud's save could not be read in time: sent later
+ case nothingYet // no save here or in the cloud yet
+ case failed(String) // a [RED] line, its text
+ }
+
+ /// The state the log ends with, nil when the session did not sync (cloud saves off, or the game never mounted its save).
+ package static func state(fromLog text: String) -> LogState? {
+ var state: LogState?
+ for raw in text.split(separator: "\n", omittingEmptySubsequences: true) {
+ let line = String(raw)
+ guard let at = line.range(of: "save sync: ") else { continue }
+ let message = String(line[at.upperBound...]).trimmingCharacters(in: .whitespacesAndNewlines)
+ if line.contains("[RED] save sync:") { state = .failed(message); continue }
+ if message.hasPrefix("off: ") { state = .off(String(message.dropFirst(5))) }
+ else if message.hasPrefix("sent: ") {
+ let detail = message.dropFirst(6)
+ state = .sent(String(detail.range(of: ", to ").map { detail[..<$0.lowerBound] } ?? detail))
+ }
+ else if message == "in step with the cloud" { state = .inStep }
+ else if message.hasPrefix("brought in the cloud's save") {
+ let from = message.range(of: "(from ").flatMap { r in message[r.upperBound...].range(of: ", saved ").map { String(message[r.upperBound..<$0.lowerBound]) } }
+ state = .broughtIn(from ?? "")
+ }
+ else if message.hasPrefix("this device's save") && message.hasSuffix("it goes to the cloud") { state = .waitingToSend }
+ else if message.hasSuffix("cannot be read now; sending later") || message.hasPrefix("the cloud's save did not come within") { state = .offline }
+ else if message == "no save here or in the cloud yet" { state = .nothingYet }
+ }
+ return state
+ }
+}
diff --git a/frontend/Tests/NX2AppleTests/GameCloudSavesTests.swift b/frontend/Tests/NX2AppleTests/GameCloudSavesTests.swift
new file mode 100644
index 00000000..6d270e05
--- /dev/null
+++ b/frontend/Tests/NX2AppleTests/GameCloudSavesTests.swift
@@ -0,0 +1,137 @@
+import AppKit
+import SwiftUI
+import XCTest
+@testable import NX2Apple
+@testable import NXCore
+@testable import NXLauncher
+
+/// #499: the Mac launcher shows and sets a game's cloud saves folder where dm/mac/launcher.c reads it, and reads the last
+/// session's sync from the game's log.
+final class GameCloudSavesTests: XCTestCase {
+ private var root: URL!
+ private let titleID = "0100535012974000"
+ private var preference: String?
+
+ override func setUpWithError() throws {
+ root = FileManager.default.temporaryDirectory.appendingPathComponent("nxnative-cloud-" + UUID().uuidString)
+ try FileManager.default.createDirectory(at: root, withIntermediateDirectories: true)
+ preference = nil
+ }
+
+ override func tearDownWithError() throws { try FileManager.default.removeItem(at: root) }
+
+ private func write(_ text: String, _ relative: String) throws {
+ let url = root.appendingPathComponent(relative)
+ try FileManager.default.createDirectory(at: url.deletingLastPathComponent(), withIntermediateDirectories: true)
+ try Data(text.utf8).write(to: url)
+ }
+ private func read(_ relative: String) -> String? { try? String(contentsOf: root.appendingPathComponent(relative), encoding: .utf8) }
+
+ /// The game's app in a library folder, ~/Library and the preference standing in, nothing of the real ones touched.
+ private func saves() -> GameCloudSaves {
+ var s = GameCloudSaves(titleID: titleID, appPath: root.path + "/lib/Hades.app")
+ s.home = root.path + "/home"
+ s.support = root.appendingPathComponent("support")
+ s.readPreference = { [unowned self] in preference }
+ s.writePreference = { [unowned self] in preference = $0 }
+ return s
+ }
+ private var env: String { "support/nxnative/\(titleID)/env.txt" }
+
+ func testWithoutAnyLineThePreferenceIsWhatChanges() throws {
+ let s = saves()
+ XCTAssertFalse(s.setting.isOn)
+ try s.choose("/Cloud/Saves")
+ XCTAssertEqual(preference, "/Cloud/Saves")
+ XCTAssertNil(read(env), "no env.txt is made for it")
+ XCTAssertEqual(s.setting, .init(source: .preference, value: "/Cloud/Saves", folder: "/Cloud/Saves"))
+ try s.turnOff()
+ XCTAssertNil(preference)
+ XCTAssertFalse(s.setting.isOn)
+ }
+
+ /// #490: an env.txt line from an older version wins over the preference, so the change goes into that line.
+ func testAnOldEnvLineIsChangedWhereItIs() throws {
+ try write("# my settings\nDM_SAVE_SYNC=icloud\nDM_FPS_TARGET=60\n", env)
+ let s = saves()
+ XCTAssertEqual(s.setting.source, .playerEnv)
+ XCTAssertEqual(s.setting.folder, root.path + "/home/Library/Mobile Documents/com~apple~CloudDocs/nxnative Saves")
+ try s.choose("/Cloud/Shared")
+ XCTAssertEqual(read(env), "# my settings\nDM_SAVE_SYNC=/Cloud/Shared\nDM_FPS_TARGET=60\n")
+ XCTAssertEqual(s.setting.folder, "/Cloud/Shared")
+ try s.turnOff()
+ XCTAssertEqual(read(env), "# my settings\nDM_SAVE_SYNC=0\nDM_FPS_TARGET=60\n")
+ XCTAssertFalse(s.setting.isOn)
+ }
+
+ /// The app's own env.txt is inside the signed app: a change goes into the player's env.txt, which wins over it.
+ func testTheAppsEnvLineIsOverriddenNotEdited() throws {
+ try write("DM_SAVE_SYNC=icloud\n", "lib/Hades.app/Contents/Resources/dm/env.txt")
+ try write("DM_FPS_TARGET=30", env)
+ let s = saves()
+ XCTAssertEqual(s.setting.source, .appEnv)
+ try s.turnOff()
+ XCTAssertEqual(read(env), "DM_FPS_TARGET=30\nDM_SAVE_SYNC=0\n")
+ XCTAssertEqual(read("lib/Hades.app/Contents/Resources/dm/env.txt"), "DM_SAVE_SYNC=icloud\n")
+ XCTAssertFalse(s.setting.isOn)
+ }
+
+ func testTheLastSessionComesFromTheNewestLog() throws {
+ try write("", "lib/.nx2apple-library")
+ try write("[dm] save sync: on: /c\n[dm] save sync: in step with the cloud\n", "lib/log/\(titleID).prev.log")
+ let s = saves()
+ XCTAssertEqual(s.lastSession()?.state, .inStep)
+ try write("[dm] save sync: on: /c\n[dm] [RED] save sync: sending to /c failed (errno=1)\n", "lib/log/\(titleID).log")
+ XCTAssertEqual(s.lastSession()?.state, .failed("sending to /c failed (errno=1)"))
+ XCTAssertNotNil(s.lastSession()?.date)
+ }
+
+ func testNoLogMeansNotPlayed() {
+ XCTAssertNil(saves().lastSession())
+ }
+
+ func testTheFolderIsShownByItsNameInICloudDrive() {
+ let drive = "/Users/jo/Library/Mobile Documents/com~apple~CloudDocs"
+ XCTAssertEqual(CloudSavesCard.shown(drive + "/nxnative Saves", home: "/Users/jo"), "iCloud Drive › nxnative Saves")
+ XCTAssertEqual(CloudSavesCard.shown(drive + "/Games/Saves", home: "/Users/jo"), "iCloud Drive › Games › Saves")
+ XCTAssertEqual(CloudSavesCard.name(drive + "/nxnative Saves"), "nxnative Saves")
+ }
+
+ /// The Cloud saves section for visual QA (`NX_LAUNCHER_CAPTURE_DIR`, `NX_CAPTURE_LANG`): off, on with a save in the folder and
+ /// the last session sent, a folder without the game's save (#490), and an env.txt line with a failed sync.
+ @MainActor func testRenderCloudSavesForVisualQA() throws {
+ guard let directory = ProcessInfo.processInfo.environment["NX_LAUNCHER_CAPTURE_DIR"] else { throw XCTSkip("Set NX_LAUNCHER_CAPTURE_DIR to capture native views") }
+ let output = URL(fileURLWithPath: directory)
+ try FileManager.default.createDirectory(at: output, withIntermediateDirectories: true)
+ NSApplication.shared.setActivationPolicy(.accessory)
+ let localizer = LauncherStores().localizer
+ localizer.lang = CaptureLanguage.current(.en)
+ let game = LibraryGame(titleID: titleID, name: "Hades")
+ let drive = "/Users/jo/Library/Mobile Documents/com~apple~CloudDocs"
+ let date = Date(timeIntervalSinceNow: -3600)
+ let cases: [(String, String?, String?, CloudSaveSync.FolderCheck?, (state: CloudSaveSync.LogState?, date: Date?)?)] = [
+ ("cloud-off", nil, nil, nil, (nil, date)),
+ ("cloud-sent", drive + "/nxnative Saves", nil, .hasSave(date), (.sent("3 files"), date)),
+ ("cloud-no-save", drive + "/NX2Apple Saves", nil, .noSave, (.inStep, date)),
+ ("cloud-env-failed", nil, "DM_SAVE_SYNC=" + drive + "/Old Saves\n", .missing, (.failed("sending to \(drive)/Old Saves/\(titleID)/save.dmsync failed (errno=13)"), date)),
+ ]
+ for (name, pref, envText, check, last) in cases {
+ if let envText { try write(envText, env) } else { try? FileManager.default.removeItem(at: root.appendingPathComponent(env)) }
+ preference = pref
+ let card = CloudSavesCard(game: game, saves: saves(), preview: (check, last), home: "/Users/jo")
+ .environmentObject(localizer).environmentObject(PadFocus()).padding(30).frame(width: 600).background(LauncherPalette.background)
+ .font(.manrope(13)).preferredColorScheme(.dark)
+ let host = NSHostingView(rootView: card)
+ host.frame = NSRect(origin: .zero, size: host.fittingSize)
+ let window = OffscreenWindow(size: host.frame.size)
+ window.contentView = host
+ window.orderFront(nil)
+ RunLoop.main.run(until: Date().addingTimeInterval(0.4))
+ host.layoutSubtreeIfNeeded()
+ let rep = try XCTUnwrap(host.bitmapImageRepForCachingDisplay(in: host.bounds))
+ host.cacheDisplay(in: host.bounds, to: rep)
+ try XCTUnwrap(rep.representation(using: .png, properties: [:])).write(to: output.appendingPathComponent("\(name)-\(localizer.lang.code).png"))
+ window.orderOut(nil)
+ }
+ }
+}
diff --git a/frontend/Tests/NXCoreTests/CloudSaveSyncTests.swift b/frontend/Tests/NXCoreTests/CloudSaveSyncTests.swift
new file mode 100644
index 00000000..a00b21e7
--- /dev/null
+++ b/frontend/Tests/NXCoreTests/CloudSaveSyncTests.swift
@@ -0,0 +1,96 @@
+import XCTest
+@testable import NXCore
+
+/// #499: the cloud saves folder a Mac game uses, read as dm/mac/launcher.c reads it, and the sync state of its last session's log.
+final class CloudSaveSyncTests: XCTestCase {
+ private let home = "/Users/jo"
+ private let drive = "/Users/jo/Library/Mobile Documents/com~apple~CloudDocs"
+ private let id = "0100535012974000"
+
+ // ---- env.txt files as older versions and players wrote them ----
+
+ /// What CloudSavesMigration wrote in v0.9 for a game on the old keyword: its comment, then the path.
+ func testTheMigrationsPinnedPathCounts() {
+ let text = CloudSavesMigration.comment + "\nDM_SAVE_SYNC=\(drive)/NX2Apple Saves\nDM_FPS_TARGET=60\n"
+ let s = CloudSaveSync.resolve(playerEnv: text, appEnv: nil, preference: "/Elsewhere", home: home)
+ XCTAssertEqual(s, .init(source: .playerEnv, value: "\(drive)/NX2Apple Saves", folder: "\(drive)/NX2Apple Saves"))
+ }
+
+ /// The keyword a player wrote by hand, with Windows line ends (#490 had one like it).
+ func testTheIcloudKeywordIsNxnativeSaves() {
+ let s = CloudSaveSync.resolve(playerEnv: "DM_SAVE_SYNC=icloud\r\n", appEnv: nil, preference: nil, home: home)
+ XCTAssertEqual(s.folder, "\(drive)/nxnative Saves")
+ XCTAssertEqual(s.value, "icloud")
+ }
+
+ func testCommentsSpacesAndTheFirstLineRule() {
+ XCTAssertNil(CloudSaveSync.envValue("# DM_SAVE_SYNC=/old\n #DM_SAVE_SYNC=/older\n"))
+ XCTAssertEqual(CloudSaveSync.envValue(" DM_SAVE_SYNC =/a folder/ \t\nDM_SAVE_SYNC=/second\n"), "/a folder/")
+ XCTAssertEqual(CloudSaveSync.envValue("DM_SAVE_SYNC= /x\n"), " /x", "launcher.c keeps what follows the = as it is")
+ XCTAssertEqual(CloudSaveSync.folder(for: "/a folder/"), "/a folder")
+ XCTAssertNil(CloudSaveSync.envValue("DM_SAVE_SYNCX=/no\n=nothing\n"))
+ }
+
+ func testOffWinsOverLaterPlaces() {
+ let s = CloudSaveSync.resolve(playerEnv: "DM_SAVE_SYNC=0\n", appEnv: "DM_SAVE_SYNC=icloud\n", preference: "/P", home: home)
+ XCTAssertEqual(s.source, .playerEnv)
+ XCTAssertFalse(s.isOn)
+ }
+
+ func testTheOrderIsPlayerEnvThenAppEnvThenThePreference() {
+ XCTAssertEqual(CloudSaveSync.resolve(playerEnv: "DM_FPS_TARGET=30\n", appEnv: "DM_SAVE_SYNC=/App\n", preference: "/P").source, .appEnv)
+ XCTAssertEqual(CloudSaveSync.resolve(playerEnv: nil, appEnv: nil, preference: "/P"), .init(source: .preference, value: "/P", folder: "/P"))
+ XCTAssertEqual(CloudSaveSync.resolve(playerEnv: nil, appEnv: nil, preference: ""), .init(source: .none, value: nil, folder: nil))
+ }
+
+ func testSettingTheLineKeepsEverythingElse() {
+ let old = CloudSavesMigration.comment + "\r\nDM_SAVE_SYNC=icloud\r\nDM_FPS_TARGET=60\r\n"
+ XCTAssertEqual(CloudSaveSync.settingEnv(old, to: "/New"), CloudSavesMigration.comment + "\r\nDM_SAVE_SYNC=/New\r\nDM_FPS_TARGET=60\r\n")
+ XCTAssertEqual(CloudSaveSync.settingEnv("DM_FPS_TARGET=60", to: "0"), "DM_FPS_TARGET=60\nDM_SAVE_SYNC=0\n")
+ XCTAssertEqual(CloudSaveSync.settingEnv(nil, to: "/New"), "DM_SAVE_SYNC=/New\n")
+ }
+
+ func testTheSaveFileFollowsCloudFile() {
+ XCTAssertEqual(CloudSaveSync.saveFile(folder: "/C/Saves", titleID: id.lowercased()), "/C/Saves/\(id)/save.dmsync")
+ XCTAssertEqual(CloudSaveSync.saveFile(folder: "/C/Saves/\(id.lowercased())", titleID: id), "/C/Saves/\(id.lowercased())/save.dmsync",
+ "the game's own folder is not given a second title ID")
+ }
+
+ func testTheFolderCheckSeesAWrongFolder() throws {
+ let root = FileManager.default.temporaryDirectory.appendingPathComponent("cloud-check-" + UUID().uuidString)
+ defer { try? FileManager.default.removeItem(at: root) }
+ XCTAssertEqual(CloudSaveSync.check(folder: root.path, titleID: id), .missing)
+ try FileManager.default.createDirectory(at: root.appendingPathComponent(id), withIntermediateDirectories: true)
+ XCTAssertEqual(CloudSaveSync.check(folder: root.path, titleID: id), .noSave, "a folder nobody else writes this game to")
+ try Data("DMSYNC1\n".utf8).write(to: root.appendingPathComponent("\(id)/save.dmsync"))
+ guard case .hasSave(let date) = CloudSaveSync.check(folder: root.path, titleID: id) else { return XCTFail("the save is there") }
+ XCTAssertNotNil(date)
+ }
+
+ // ---- the log ----
+
+ func testTheLastResultOfTheLogCounts() {
+ let log = """
+ launcher: cloud saves through \(drive)/nxnative Saves
+ [dm] save sync: on: \(drive)/nxnative Saves/\(id)/save.dmsync
+ [dm] save sync: in step with the cloud
+ [dm] save sync: this device's save (saved 2026-11-02 21:14:03) changed since the last sync: it goes to the cloud
+ [dm] save sync: sent: 3 files, saved 2026-11-02 21:14:03, to \(drive)/nxnative Saves/\(id)/save.dmsync
+ """
+ XCTAssertEqual(CloudSaveSync.state(fromLog: log), .sent("3 files, saved 2026-11-02 21:14:03"))
+ }
+
+ func testEachResult() {
+ func state(_ line: String) -> CloudSaveSync.LogState? { CloudSaveSync.state(fromLog: "[dm] save sync: on: /x\n[dm] " + line + "\n") }
+ XCTAssertEqual(state("save sync: in step with the cloud"), .inStep)
+ XCTAssertEqual(state("save sync: brought in the cloud's save (from iPhone17,1, saved 2026-11-02 08:00:00); this device's is kept in /s-backups/x"), .broughtIn("iPhone17,1"))
+ XCTAssertEqual(state("save sync: this device's save (saved 2026-11-02 08:00:00) is not in the cloud yet: it goes to the cloud"), .waitingToSend)
+ XCTAssertEqual(state("save sync: the cloud's save /x/save.dmsync cannot be read now; sending later"), .offline)
+ XCTAssertEqual(state("save sync: the cloud's save did not come within 8 s"), .offline)
+ XCTAssertEqual(state("save sync: no save here or in the cloud yet"), .nothingYet)
+ XCTAssertEqual(state("save sync: off: iCloud Drive is not on for this Mac (no /Users/jo/Library/Mobile Documents/com~apple~CloudDocs)"),
+ .off("iCloud Drive is not on for this Mac (no /Users/jo/Library/Mobile Documents/com~apple~CloudDocs)"))
+ XCTAssertEqual(state("[RED] save sync: sending to /x/save.dmsync failed (errno=13)"), .failed("sending to /x/save.dmsync failed (errno=13)"))
+ XCTAssertNil(CloudSaveSync.state(fromLog: "launcher: saves /s\nfork patches: none\n"), "a session without cloud saves")
+ }
+}
diff --git a/frontend/l10n/de.json b/frontend/l10n/de.json
index 85f0fde9..f65a5f62 100644
--- a/frontend/l10n/de.json
+++ b/frontend/l10n/de.json
@@ -92,6 +92,29 @@
"cheats.title": "Cheats",
"cheats.toDevice": "Auf %@ kopieren",
"cheats.writeFailed": "Schreiben nicht möglich: %@",
+ "cloud.applies": "Eine Änderung gilt ab dem nächsten Start des Spiels. Nimm auf deinem iPhone oder iPad denselben Ordner.",
+ "cloud.choose": "Ordner wählen …",
+ "cloud.failed": "Der Ordner konnte nicht gesetzt werden: %@",
+ "cloud.fromAppEnv": "In der env.txt der App gesetzt",
+ "cloud.fromPlayerEnv": "In der env.txt dieses Spiels gesetzt",
+ "cloud.hasSave": "Der Ordner hat einen Spielstand dieses Spiels von %@.",
+ "cloud.lastSession": "Letzte Sitzung: %@",
+ "cloud.missing": "Diesen Ordner gibt es auf diesem Mac nicht.",
+ "cloud.noSave": "In diesem Ordner liegt noch kein Spielstand dieses Spiels. Wenn du es auf einem anderen Gerät spielst, wähle den Ordner, den dieses Gerät nutzt.",
+ "cloud.off": "Aus",
+ "cloud.offNote": "Wähle denselben Ordner wie auf deinem iPhone oder iPad. Eine Änderung gilt ab dem nächsten Start des Spiels.",
+ "cloud.state.broughtIn": "Ein neuerer Spielstand kam aus der Cloud (von %@)",
+ "cloud.state.failed": "Synchronisierung fehlgeschlagen: %@",
+ "cloud.state.inStep": "Gleich mit der Cloud",
+ "cloud.state.none": "Die letzte Sitzung hat nicht synchronisiert",
+ "cloud.state.notPlayed": "Auf diesem Mac noch nicht gespielt",
+ "cloud.state.nothingYet": "Noch kein Spielstand hier oder in der Cloud",
+ "cloud.state.off": "In dieser Sitzung aus: %@",
+ "cloud.state.offline": "Die Cloud war nicht erreichbar. Der Spielstand geht beim nächsten Start.",
+ "cloud.state.sent": "Spielstand an die Cloud gesendet",
+ "cloud.state.waiting": "Ein neuerer Spielstand wurde noch nicht gesendet. Er geht beim nächsten Start.",
+ "cloud.title": "Cloud-Spielstände",
+ "cloud.turnOff": "Ausschalten",
"console.adjustHint": "Mit links oder rechts anpassen.",
"console.assign": "Spieler zuweisen",
"console.assignCancelled": "Spielerzuweisung abgebrochen.",
diff --git a/frontend/l10n/en.json b/frontend/l10n/en.json
index c90f93be..c18d9e6e 100644
--- a/frontend/l10n/en.json
+++ b/frontend/l10n/en.json
@@ -90,6 +90,29 @@
"cheats.title": "Cheats",
"cheats.toDevice": "Copy to %@",
"cheats.writeFailed": "Could not write: %@",
+ "cloud.applies": "A change counts from the game’s next start. Use the same folder on your iPhone or iPad.",
+ "cloud.choose": "Choose folder…",
+ "cloud.failed": "The folder could not be set: %@",
+ "cloud.fromAppEnv": "Set in the app’s env.txt",
+ "cloud.fromPlayerEnv": "Set in this game’s env.txt",
+ "cloud.hasSave": "The folder holds a save of this game from %@.",
+ "cloud.lastSession": "Last session, %@",
+ "cloud.missing": "This folder does not exist on this Mac.",
+ "cloud.noSave": "No save of this game is in this folder yet. If you play it on another device, choose the folder that device uses.",
+ "cloud.off": "Off",
+ "cloud.offNote": "Choose the same folder you use on your iPhone or iPad. A change counts from the game’s next start.",
+ "cloud.state.broughtIn": "A newer save came from the cloud (from %@)",
+ "cloud.state.failed": "Sync failed: %@",
+ "cloud.state.inStep": "In step with the cloud",
+ "cloud.state.none": "The last session did not sync",
+ "cloud.state.notPlayed": "Not played on this Mac yet",
+ "cloud.state.nothingYet": "No save here or in the cloud yet",
+ "cloud.state.off": "Off in that session: %@",
+ "cloud.state.offline": "The cloud could not be reached. The save goes at the next start.",
+ "cloud.state.sent": "Save sent to the cloud",
+ "cloud.state.waiting": "A newer save was not sent yet. It goes at the next start.",
+ "cloud.title": "Cloud saves",
+ "cloud.turnOff": "Turn off",
"console.adjustHint": "Use left or right to adjust.",
"console.assign": "Assign player",
"console.assignCancelled": "Player assignment cancelled.",
diff --git a/frontend/l10n/fr.json b/frontend/l10n/fr.json
index 111d6e82..48164583 100644
--- a/frontend/l10n/fr.json
+++ b/frontend/l10n/fr.json
@@ -91,6 +91,29 @@
"cheats.title": "Codes de triche",
"cheats.toDevice": "Copier sur %@",
"cheats.writeFailed": "Écriture impossible : %@",
+ "cloud.applies": "Un changement compte au prochain lancement du jeu. Utilisez le même dossier sur votre iPhone ou iPad.",
+ "cloud.choose": "Choisir un dossier…",
+ "cloud.failed": "Le dossier n’a pas pu être défini : %@",
+ "cloud.fromAppEnv": "Défini dans le env.txt de l’app",
+ "cloud.fromPlayerEnv": "Défini dans le env.txt de ce jeu",
+ "cloud.hasSave": "Le dossier contient une sauvegarde de ce jeu du %@.",
+ "cloud.lastSession": "Dernière session : %@",
+ "cloud.missing": "Ce dossier n’existe pas sur ce Mac.",
+ "cloud.noSave": "Ce dossier ne contient pas encore de sauvegarde de ce jeu. Si vous y jouez sur un autre appareil, choisissez le dossier qu’il utilise.",
+ "cloud.off": "Désactivé",
+ "cloud.offNote": "Choisissez le même dossier que sur votre iPhone ou iPad. Un changement compte au prochain lancement du jeu.",
+ "cloud.state.broughtIn": "Une sauvegarde plus récente est venue du cloud (de %@)",
+ "cloud.state.failed": "Échec de la synchronisation : %@",
+ "cloud.state.inStep": "À jour avec le cloud",
+ "cloud.state.none": "La dernière session n’a pas synchronisé",
+ "cloud.state.notPlayed": "Pas encore joué sur ce Mac",
+ "cloud.state.nothingYet": "Pas encore de sauvegarde ici ni dans le cloud",
+ "cloud.state.off": "Désactivé pendant cette session : %@",
+ "cloud.state.offline": "Le cloud était injoignable. La sauvegarde part au prochain lancement.",
+ "cloud.state.sent": "Sauvegarde envoyée dans le cloud",
+ "cloud.state.waiting": "Une sauvegarde plus récente n’a pas encore été envoyée. Elle part au prochain lancement.",
+ "cloud.title": "Sauvegardes dans le cloud",
+ "cloud.turnOff": "Désactiver",
"console.adjustHint": "Utilisez gauche ou droite pour ajuster.",
"console.assign": "Attribuer un joueur",
"console.assignCancelled": "Attribution du joueur annulée.",
diff --git a/frontend/l10n/it.json b/frontend/l10n/it.json
index b659139a..f5fd17bf 100644
--- a/frontend/l10n/it.json
+++ b/frontend/l10n/it.json
@@ -91,6 +91,29 @@
"cheats.title": "Trucchi",
"cheats.toDevice": "Copia su %@",
"cheats.writeFailed": "Impossibile scrivere: %@",
+ "cloud.applies": "Una modifica vale dal prossimo avvio del gioco. Usa la stessa cartella su iPhone o iPad.",
+ "cloud.choose": "Scegli cartella…",
+ "cloud.failed": "Impossibile impostare la cartella: %@",
+ "cloud.fromAppEnv": "Impostata nel env.txt dell’app",
+ "cloud.fromPlayerEnv": "Impostata nel env.txt di questo gioco",
+ "cloud.hasSave": "La cartella ha un salvataggio di questo gioco del %@.",
+ "cloud.lastSession": "Ultima sessione: %@",
+ "cloud.missing": "Questa cartella non esiste su questo Mac.",
+ "cloud.noSave": "Questa cartella non ha ancora un salvataggio di questo gioco. Se ci giochi su un altro dispositivo, scegli la cartella che usa quel dispositivo.",
+ "cloud.off": "Disattivati",
+ "cloud.offNote": "Scegli la stessa cartella che usi su iPhone o iPad. Una modifica vale dal prossimo avvio del gioco.",
+ "cloud.state.broughtIn": "Un salvataggio più recente è arrivato dal cloud (da %@)",
+ "cloud.state.failed": "Sincronizzazione non riuscita: %@",
+ "cloud.state.inStep": "Allineato con il cloud",
+ "cloud.state.none": "L’ultima sessione non ha sincronizzato",
+ "cloud.state.notPlayed": "Non ancora giocato su questo Mac",
+ "cloud.state.nothingYet": "Ancora nessun salvataggio qui o nel cloud",
+ "cloud.state.off": "Disattivati in quella sessione: %@",
+ "cloud.state.offline": "Il cloud non era raggiungibile. Il salvataggio parte al prossimo avvio.",
+ "cloud.state.sent": "Salvataggio inviato al cloud",
+ "cloud.state.waiting": "Un salvataggio più recente non è stato ancora inviato. Parte al prossimo avvio.",
+ "cloud.title": "Salvataggi nel cloud",
+ "cloud.turnOff": "Disattiva",
"console.adjustHint": "Usa sinistra o destra per regolare.",
"console.assign": "Assegna giocatore",
"console.assignCancelled": "Assegnazione del giocatore annullata.",
diff --git a/frontend/l10n/sv.json b/frontend/l10n/sv.json
index 04ecc273..f27c3a9a 100644
--- a/frontend/l10n/sv.json
+++ b/frontend/l10n/sv.json
@@ -91,6 +91,29 @@
"cheats.title": "Fusk",
"cheats.toDevice": "Kopiera till %@",
"cheats.writeFailed": "Kunde inte skriva: %@",
+ "cloud.applies": "En ändring gäller från spelets nästa start. Använd samma mapp på din iPhone eller iPad.",
+ "cloud.choose": "Välj mapp …",
+ "cloud.failed": "Mappen kunde inte ställas in: %@",
+ "cloud.fromAppEnv": "Satt i appens env.txt",
+ "cloud.fromPlayerEnv": "Satt i spelets env.txt",
+ "cloud.hasSave": "Mappen har en sparfil för det här spelet från %@.",
+ "cloud.lastSession": "Senaste spelpass: %@",
+ "cloud.missing": "Den här mappen finns inte på den här Macen.",
+ "cloud.noSave": "Mappen har ingen sparfil för det här spelet än. Om du spelar det på en annan enhet, välj mappen som den enheten använder.",
+ "cloud.off": "Av",
+ "cloud.offNote": "Välj samma mapp som på din iPhone eller iPad. En ändring gäller från spelets nästa start.",
+ "cloud.state.broughtIn": "En nyare sparfil kom från molnet (från %@)",
+ "cloud.state.failed": "Synkningen misslyckades: %@",
+ "cloud.state.inStep": "I takt med molnet",
+ "cloud.state.none": "Senaste spelpasset synkade inte",
+ "cloud.state.notPlayed": "Inte spelat på den här Macen än",
+ "cloud.state.nothingYet": "Ingen sparfil här eller i molnet än",
+ "cloud.state.off": "Av under det spelpasset: %@",
+ "cloud.state.offline": "Molnet gick inte att nå. Sparfilen skickas vid nästa start.",
+ "cloud.state.sent": "Sparfilen skickades till molnet",
+ "cloud.state.waiting": "En nyare sparfil har inte skickats än. Den skickas vid nästa start.",
+ "cloud.title": "Molnsparfiler",
+ "cloud.turnOff": "Stäng av",
"controls.applied": "Tillämpas nästa gång du väljer Spela här. Äldre byggen ignorerar det.",
"controls.changes": "%d ändringar",
"controls.clear": "Ingen tangent",
diff --git a/frontend/l10n/zh.json b/frontend/l10n/zh.json
index cf2ba75b..9ed3eaa0 100644
--- a/frontend/l10n/zh.json
+++ b/frontend/l10n/zh.json
@@ -91,6 +91,29 @@
"cheats.title": "金手指",
"cheats.toDevice": "复制到 %@",
"cheats.writeFailed": "无法写入:%@",
+ "cloud.applies": "更改从游戏下次启动时生效。请在 iPhone 或 iPad 上使用同一个文件夹。",
+ "cloud.choose": "选择文件夹…",
+ "cloud.failed": "无法设置文件夹:%@",
+ "cloud.fromAppEnv": "在应用的 env.txt 中设置",
+ "cloud.fromPlayerEnv": "在这个游戏的 env.txt 中设置",
+ "cloud.hasSave": "文件夹里有这个游戏 %@ 的存档。",
+ "cloud.lastSession": "上次游戏:%@",
+ "cloud.missing": "这个文件夹在这台 Mac 上不存在。",
+ "cloud.noSave": "这个文件夹里还没有这个游戏的存档。如果你在另一台设备上玩,请选择那台设备使用的文件夹。",
+ "cloud.off": "关闭",
+ "cloud.offNote": "选择你在 iPhone 或 iPad 上使用的同一个文件夹。更改从游戏下次启动时生效。",
+ "cloud.state.broughtIn": "从云端取回了较新的存档(来自 %@)",
+ "cloud.state.failed": "同步失败:%@",
+ "cloud.state.inStep": "与云端一致",
+ "cloud.state.none": "上次游戏没有同步",
+ "cloud.state.notPlayed": "还没有在这台 Mac 上玩过",
+ "cloud.state.nothingYet": "这里和云端都还没有存档",
+ "cloud.state.off": "那次游戏中已关闭:%@",
+ "cloud.state.offline": "无法连接云端,存档将在下次启动时发送。",
+ "cloud.state.sent": "存档已发送到云端",
+ "cloud.state.waiting": "较新的存档尚未发送,将在下次启动时发送。",
+ "cloud.title": "云存档",
+ "cloud.turnOff": "关闭",
"console.adjustHint": "使用左右方向键调整。",
"console.assign": "分配玩家",
"console.assignCancelled": "已取消分配玩家。",