Skip to content

Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.

A chosen data location: engines and environments on any APFS folder or drive (#24, #68)

Gauthier Piarrette51d6258a575e
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index d7dc869..892d606 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -361,6 +361,60 @@ final class AppState {
}
let paths = HighballPaths()
+ /// The chosen data location whose drive is not connected (#24): shown instead of the library,
+ /// never as a first run, so nothing gets reinstalled onto the internal disk by mistake.
+ var homeUnavailable: URL? { paths.unavailableConfiguredHome }
+ /// A location chosen in Settings, waiting for the move to be confirmed.
+ var pendingHome: URL?
+
+ /// Settings › Environments › Change…: a folder on any APFS volume, checked before anything moves.
+ func chooseHome() {
+ let panel = NSOpenPanel()
+ panel.canChooseDirectories = true; panel.canChooseFiles = false; panel.canCreateDirectories = true
+ panel.prompt = L("Use this folder")
+ panel.message = L("Highball will keep its engines and environments in this folder. It must be on an APFS volume (external drives formatted as exFAT cannot hold a Windows environment).")
+ guard panel.runModal() == .OK, let url = panel.url else { return }
+ if let why = HighballPaths.locationProblem(url) { errorMessage = why; return }
+ if url.standardizedFileURL == paths.home.standardizedFileURL { return }
+ pendingHome = url
+ }
+
+ /// Moves everything, records the location, then relaunches: the running app keeps its old paths.
+ func moveHome(to target: URL) {
+ pendingHome = nil
+ let source = paths.home
+ runBusy(String(format: L("Moving Highball's data to %@"), target.lastPathComponent),
+ expected: L("as long as copying your games takes; nothing is removed until the copy checks out"),
+ done: DoneState(title: L("Moved. Highball needs a relaunch to use the new location."), ctaTitle: L("Relaunch"), cta: { Self.relaunch() })) { [self] in
+ try await Task.detached {
+ try HomeMove.move(from: source, to: target) { name in
+ Task { @MainActor in self.stage = String(format: L("Copying %@…"), name) }
+ }
+ try HighballPaths.setConfiguredHome(target)
+ }.value
+ await MainActor.run { self.appendLog("data moved to \(target.path)") }
+ }
+ }
+
+ /// Back to the default location, with the data, from the unavailable-drive screen or Settings.
+ func useDefaultHome() {
+ let target = HighballPaths.defaultHome
+ if paths.home.standardizedFileURL == target.standardizedFileURL || !paths.hasData {
+ try? HighballPaths.setConfiguredHome(nil); Self.relaunch(); return
+ }
+ pendingHome = nil
+ runBusy(L("Moving Highball's data back to the default location"), done: DoneState(title: L("Moved. Highball needs a relaunch."), ctaTitle: L("Relaunch"), cta: { Self.relaunch() })) { [self] in
+ try await Task.detached { try HomeMove.move(from: self.paths.home, to: target); try HighballPaths.setConfiguredHome(nil) }.value
+ }
+ }
+
+ static func relaunch() {
+ let bundle = Bundle.main.bundleURL.path
+ let p = Process(); p.executableURL = URL(fileURLWithPath: "/bin/sh")
+ p.arguments = ["-c", "sleep 1; /usr/bin/open -n \"\(bundle)\""]
+ try? p.run()
+ NSApp.terminate(nil)
+ }
/// This Mac's chip, read once: the game page compares it with the chip a verdict was taken on.
let machineChip = Machine.chip()
var engineStore: EngineStore { EngineStore(paths: paths) }
@@ -413,7 +467,7 @@ final class AppState {
engines = (try? engineStore.installedEngines()) ?? []
bottles = (try? bottleStore.list()) ?? []
damagedBottles = (try? bottleStore.damaged()) ?? []
- needsOnboarding = engines.isEmpty
+ needsOnboarding = engines.isEmpty && homeUnavailable == nil // an unplugged drive is not a first run
rosettaInstalled = FileManager.default.fileExists(atPath: "/Library/Apple/usr/share/rosetta/rosetta")
// Drop a selection whose bottle is gone, not merely a nil one: a delete that threw after
// the bottle had in fact been removed (the losing side of a race) left the selection
diff --git a/Sources/HighballApp/HighballApp.swift b/Sources/HighballApp/HighballApp.swift
index 0a6a3d8..c56d38c 100644
--- a/Sources/HighballApp/HighballApp.swift
+++ b/Sources/HighballApp/HighballApp.swift
@@ -159,7 +159,18 @@ struct ContentView: View {
var body: some View {
@Bindable var state = state
Group {
- if state.needsOnboarding {
+ if let missing = state.homeUnavailable {
+ VStack(spacing: 14) {
+ Image(systemName: "externaldrive.badge.questionmark").font(.system(size: 44)).foregroundStyle(.secondary)
+ Text(L("Your Highball folder is not connected")).font(.title2.bold())
+ Text(String(format: L("Highball keeps its engines and environments in %@, and that location is not available right now. Connect the drive and relaunch, or go back to the default location on this Mac."), missing.path))
+ .multilineTextAlignment(.center).foregroundStyle(.secondary).frame(maxWidth: 520)
+ HStack {
+ Button(L("Relaunch")) { AppState.relaunch() }.buttonStyle(.borderedProminent)
+ Button(L("Use the default location")) { state.useDefaultHome() }
+ }
+ }.frame(maxWidth: .infinity, maxHeight: .infinity).padding(40)
+ } else if state.needsOnboarding {
OnboardingView()
} else {
// One library, full width (UX plan Phase 1): no sidebar, no bottles in the way.
@@ -265,6 +276,14 @@ struct ContentView: View {
} message: { trial in
Text(String(format: L("It ran with %@. Another mode often suits a game better on this Mac, and old DirectX 9 games in particular do badly on Wine's own Direct3D. This changes the mode for this game only; the environment keeps its own. Undo it any time under Advanced on the game's page."), GamePageCopy.plainName(trial.current)))
}
+ .alert(state.pendingHome.map { String(format: L("Move Highball's data to %@?"), $0.lastPathComponent) } ?? "",
+ isPresented: .init(get: { state.pendingHome != nil }, set: { if !$0 { state.pendingHome = nil } }),
+ presenting: state.pendingHome) { target in
+ Button(L("Move now")) { state.moveHome(to: target) }
+ Button(L("Cancel"), role: .cancel) { state.pendingHome = nil }
+ } message: { target in
+ Text(String(format: L("Engines, environments and downloads copy to %@, get checked, and are then removed from %@. Highball relaunches when it is done. Nothing is removed until the copy checks out."), target.path, state.paths.home.path))
+ }
.sheet(isPresented: $state.showEpicSignIn) { EpicSignInSheet() }
// A partial delete succeeded — the bottle is gone and the name is free — so framing it as
// a failure, with an invitation to file a bug, misreads what happened. Same alert, honest
diff --git a/Sources/HighballApp/L10n.swift b/Sources/HighballApp/L10n.swift
index 796e3e5..aca4a66 100644
--- a/Sources/HighballApp/L10n.swift
+++ b/Sources/HighballApp/L10n.swift
@@ -116,6 +116,25 @@ enum L10n {
"D3DMetal — D3D11/12, Apple": "D3DMetal — D3D11/12, Apple",
"DXVK — D3D9/10/11 → Vulkan": "DXVK — D3D9/10/11 → Vulkan",
"Get beta builds": "Recevoir les versions bêta",
+ "Kept in %@": "Stocké dans %@",
+ "Change…": "Changer…",
+ "Default": "Par défaut",
+ "Use this folder": "Utiliser ce dossier",
+ "Move now": "Déplacer maintenant",
+ "Move Highball's data to %@?": "Déplacer les données de Highball vers %@ ?",
+ "Moving Highball's data to %@": "Déplacement des données de Highball vers %@",
+ "Copying %@…": "Copie de %@…",
+ "Relaunch": "Relancer",
+ "Use the default location": "Utiliser l'emplacement par défaut",
+ "Your Highball folder is not connected": "Votre dossier Highball n'est pas connecté",
+ "Moved. Highball needs a relaunch to use the new location.": "Déplacé. Highball doit être relancé pour utiliser le nouvel emplacement.",
+ "Moved. Highball needs a relaunch.": "Déplacé. Highball doit être relancé.",
+ "Moving Highball's data back to the default location": "Retour des données de Highball à l'emplacement par défaut",
+ "Back to ~/Library/Application Support/Highball, with the data": "Retour dans ~/Library/Application Support/Highball, avec les données",
+ "as long as copying your games takes; nothing is removed until the copy checks out": "le temps de copier vos jeux, rien n'est supprimé avant vérification de la copie",
+ "Highball will keep its engines and environments in this folder. It must be on an APFS volume (external drives formatted as exFAT cannot hold a Windows environment).": "Highball gardera ses moteurs et environnements dans ce dossier. Il doit être sur un volume APFS (un disque externe en exFAT ne peut pas contenir un environnement Windows).",
+ "Highball keeps its engines and environments in %@, and that location is not available right now. Connect the drive and relaunch, or go back to the default location on this Mac.": "Highball garde ses moteurs et environnements dans %@, et cet emplacement n'est pas disponible pour le moment. Branchez le disque et relancez, ou revenez à l'emplacement par défaut sur ce Mac.",
+ "Engines, environments and downloads copy to %@, get checked, and are then removed from %@. Highball relaunches when it is done. Nothing is removed until the copy checks out.": "Les moteurs, environnements et téléchargements sont copiés vers %@, vérifiés, puis supprimés de %@. Highball se relance ensuite. Rien n'est supprimé avant vérification de la copie.",
"Mode for this game": "Mode pour ce jeu",
"Environment's mode": "Mode de l'environnement",
"Use %@ for this game": "Utiliser %@ pour ce jeu",
diff --git a/Sources/HighballApp/SettingsView.swift b/Sources/HighballApp/SettingsView.swift
index 09a5197..9b2b102 100644
--- a/Sources/HighballApp/SettingsView.swift
+++ b/Sources/HighballApp/SettingsView.swift
@@ -95,6 +95,15 @@ struct EnvironmentsPane: View {
Spacer(minLength: 0)
HStack(spacing: 10) {
Button(L("New environment…")) { showCreate = true }.disabled(state.busy)
+ Spacer()
+ // Where it all lives (#24, #68): games are big and internal disks are small.
+ Text(String(format: L("Kept in %@"), state.paths.home.path)).font(.caption).foregroundStyle(.secondary).lineLimit(1).truncationMode(.middle)
+ .help(state.paths.home.path)
+ Button(L("Change…")) { state.chooseHome() }.controlSize(.small).disabled(state.busy)
+ if HighballPaths.configuredHome() != nil {
+ Button(L("Default")) { state.useDefaultHome() }.controlSize(.small).disabled(state.busy)
+ .help(L("Back to ~/Library/Application Support/Highball, with the data"))
+ }
if let b = selected {
Button(L("Repair")) { state.repairBottle(b) }.disabled(state.busy)
Button(L("Full page…")) { openName = b.name }
diff --git a/Sources/HighballKit/Paths.swift b/Sources/HighballKit/Paths.swift
index 6b0c6c7..de9fc19 100644
--- a/Sources/HighballKit/Paths.swift
+++ b/Sources/HighballKit/Paths.swift
@@ -7,15 +7,73 @@ public let reportRepo = "gauthierpiarrette/highball-db"
/// `~/Library/Application Support/Gin`, overridable with `HIGHBALL_HOME` for tests.
public struct HighballPaths: Sendable {
public let home: URL
+ /// A location the user chose that is not there right now (its drive unplugged, #24): the app
+ /// runs on the default home for the moment, says so, and never treats it as a first run.
+ public let unavailableConfiguredHome: URL?
+
+ /// `~/Library/Application Support/Highball`, the home unless one is chosen.
+ public static var defaultHome: URL {
+ FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0]
+ .appending(path: "Highball", directoryHint: .isDirectory)
+ }
+ /// The pointer to a chosen location, at the fixed default home so the app and the CLI read the
+ /// same one (UserDefaults is per bundle). `{"home": "/Volumes/Games/Highball"}`.
+ public static var configFile: URL { defaultHome.appending(path: "config.json") }
public init(home: URL? = nil) {
- if let home { self.home = home; return }
- if let env = ProcessInfo.processInfo.environment["HIGHBALL_HOME"] {
- self.home = URL(fileURLWithPath: env, isDirectory: true)
+ let env = ProcessInfo.processInfo.environment["HIGHBALL_HOME"].map { URL(fileURLWithPath: $0, isDirectory: true) }
+ let chosen = Self.configuredHome()
+ let r = Self.resolve(explicit: home, env: env, configured: chosen,
+ reachable: chosen.map { FileManager.default.fileExists(atPath: $0.path) } ?? false,
+ defaultHome: Self.defaultHome)
+ self.home = r.home; self.unavailableConfiguredHome = r.unavailable
+ }
+
+ /// Precedence, most explicit first: the caller's, `HIGHBALL_HOME`, the chosen location when its
+ /// folder is there, else the default (with the chosen one reported as unavailable).
+ public static func resolve(explicit: URL?, env: URL?, configured: URL?, reachable: Bool, defaultHome: URL) -> (home: URL, unavailable: URL?) {
+ if let explicit { return (explicit, nil) }
+ if let env { return (env, nil) }
+ if let configured { return reachable ? (configured, nil) : (defaultHome, configured) }
+ return (defaultHome, nil)
+ }
+
+ public static func configuredHome(from file: URL = configFile) -> URL? {
+ guard let data = try? Data(contentsOf: file),
+ let obj = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
+ let path = obj["home"] as? String, !path.isEmpty else { return nil }
+ return URL(fileURLWithPath: path, isDirectory: true)
+ }
+
+ /// Records a chosen location, or with nil goes back to the default.
+ public static func setConfiguredHome(_ url: URL?, file: URL = configFile) throws {
+ if let url {
+ try FileManager.default.createDirectory(at: file.deletingLastPathComponent(), withIntermediateDirectories: true)
+ let data = try JSONSerialization.data(withJSONObject: ["home": url.standardizedFileURL.path], options: [.prettyPrinted])
+ try data.write(to: file, options: .atomic)
} else {
- let support = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0]
- self.home = support.appending(path: "Highball", directoryHint: .isDirectory)
+ try? FileManager.default.removeItem(at: file)
+ }
+ }
+
+ /// Why a folder cannot hold Highball's data, or nil when it can. Wine builds an environment's
+ /// drive letters out of symbolic links, so a volume without them (exFAT, FAT) cannot hold one;
+ /// the folder must exist and be writable; and it must not sit inside the default home, which
+ /// would move the data into itself.
+ public static func locationProblem(_ url: URL, defaultHome: URL = defaultHome) -> String? {
+ let fm = FileManager.default
+ var isDir: ObjCBool = false
+ guard fm.fileExists(atPath: url.path, isDirectory: &isDir), isDir.boolValue else { return "That folder does not exist." }
+ guard fm.isWritableFile(atPath: url.path) else { return "Highball cannot write in that folder." }
+ let target = url.standardizedFileURL.path + "/", base = defaultHome.standardizedFileURL.path + "/"
+ if target.hasPrefix(base) || base.hasPrefix(target) { return "Pick a folder outside Highball's own data folder." }
+ if let values = try? url.resourceValues(forKeys: [.volumeSupportsSymbolicLinksKey, .volumeIsReadOnlyKey]) {
+ if values.volumeIsReadOnly == true { return "That volume is read only." }
+ if values.volumeSupportsSymbolicLinks == false {
+ return "That drive's format (exFAT or FAT) cannot hold a Windows environment: Wine needs symbolic links. Format it as APFS, or pick another drive."
+ }
}
+ return nil
}
public var downloads: URL { home.appending(path: "downloads", directoryHint: .isDirectory) }
@@ -37,6 +95,51 @@ public struct HighballPaths: Sendable {
try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
}
}
+
+ /// Whether this home holds anything worth moving.
+ public var hasData: Bool {
+ let fm = FileManager.default
+ return [engines, bottles].contains { (try? fm.contentsOfDirectory(atPath: $0.path))?.contains { !$0.hasPrefix(".") } == true }
+ }
+}
+
+/// Moves Highball's data between homes (#24, #68): every top-level entry except the pointer file
+/// and the trash is copied, checked file by file for count and bytes, and only then removed at
+/// the source, so a failure part way leaves the old home intact. Symbolic links are copied as
+/// links; the engine's absolute ones are re-made by the engine on its next use.
+public enum HomeMove {
+ public static let skipped: Set<String> = ["config.json", ".trash", ".DS_Store"]
+
+ public static func move(from source: URL, to target: URL, progress: (String) -> Void = { _ in }) throws {
+ let fm = FileManager.default
+ try fm.createDirectory(at: target, withIntermediateDirectories: true)
+ let entries = try fm.contentsOfDirectory(atPath: source.path).filter { !skipped.contains($0) }.sorted()
+ for name in entries {
+ let from = source.appending(path: name), to = target.appending(path: name)
+ progress(name)
+ if fm.fileExists(atPath: to.path) { try fm.removeItem(at: to) }
+ try fm.copyItem(at: from, to: to)
+ let a = try tally(from), b = try tally(to)
+ guard a == b else { throw HighballError.failed("'\(name)' did not copy completely (\(a.files) files, \(a.bytes) bytes at the source, \(b.files) files, \(b.bytes) bytes at the destination); nothing was removed") }
+ }
+ for name in entries { try fm.removeItem(at: source.appending(path: name)) }
+ }
+
+ /// File count and byte total under a path, links counted as themselves and not followed.
+ public static func tally(_ root: URL) throws -> (files: Int, bytes: Int64) {
+ let fm = FileManager.default
+ var files = 0, bytes: Int64 = 0
+ let keys: [URLResourceKey] = [.isRegularFileKey, .isSymbolicLinkKey, .fileSizeKey]
+ guard let rootValues = try? root.resourceValues(forKeys: Set(keys + [.isDirectoryKey])) else { return (0, 0) }
+ if rootValues.isDirectory != true { return (1, Int64(rootValues.fileSize ?? 0)) }
+ guard let e = fm.enumerator(at: root, includingPropertiesForKeys: keys, options: []) else { return (0, 0) }
+ for case let url as URL in e {
+ let v = try url.resourceValues(forKeys: Set(keys))
+ if v.isSymbolicLink == true { files += 1; continue }
+ if v.isRegularFile == true { files += 1; bytes += Int64(v.fileSize ?? 0) }
+ }
+ return (files, bytes)
+ }
}
/// Builds a pre-filled GitHub bug-report URL: system info and a digest of the most relevant
diff --git a/Sources/highball/main.swift b/Sources/highball/main.swift
index 7529e1c..58890aa 100644
--- a/Sources/highball/main.swift
+++ b/Sources/highball/main.swift
@@ -7,7 +7,7 @@ struct Highball: AsyncParsableCommand {
static let configuration = CommandConfiguration(
commandName: "highball",
abstract: "Highball — run Windows games on Apple Silicon. Free, open, engine-agnostic.",
- subcommands: [Engine.self, Bottle.self, Run.self, PinCommand.self, Recipe.self, Tricks.self, Env.self, Epic.self, Report.self, BugReportCommand.self, Verify.self],
+ subcommands: [Config.self, Engine.self, Bottle.self, Run.self, PinCommand.self, Recipe.self, Tricks.self, Env.self, Epic.self, Report.self, BugReportCommand.self, Verify.self],
defaultSubcommand: nil
)
}
@@ -631,3 +631,37 @@ struct BugReportCommand: AsyncParsableCommand {
}
extension HighballKit.Renderer: ExpressibleByArgument {}
+
+
+struct Config: AsyncParsableCommand {
+ static let configuration = CommandConfiguration(abstract: "Where Highball keeps engines and environments (#24): `config` shows it, `config home <folder>` moves there, `config home --default` goes back.")
+ @Argument(help: "'home' to change the location.") var setting: String?
+ @Argument(help: "A folder on any APFS volume, or --default.") var value: String?
+ @Flag(name: .customLong("default"), help: "Back to ~/Library/Application Support/Highball.") var useDefault = false
+
+ func run() async throws {
+ let paths = HighballPaths()
+ guard let setting else {
+ print("home: \(paths.home.path)\(HighballPaths.configuredHome() == nil ? " (default)" : " (chosen)")")
+ if let missing = paths.unavailableConfiguredHome { print("chosen location not available right now: \(missing.path); running on the default meanwhile") }
+ return
+ }
+ guard setting == "home" else { throw ValidationError("unknown setting \(setting); only 'home'") }
+ if useDefault {
+ let target = HighballPaths.defaultHome
+ if paths.home.standardizedFileURL != target.standardizedFileURL, paths.hasData {
+ print("moving data back to \(target.path)…"); try HomeMove.move(from: paths.home, to: target) { print(" \($0)") }
+ }
+ try HighballPaths.setConfiguredHome(nil); print("home: \(target.path) (default)"); return
+ }
+ guard let value else { throw ValidationError("usage: highball config home <folder> | --default") }
+ let target = URL(fileURLWithPath: value, isDirectory: true)
+ if let why = HighballPaths.locationProblem(target) { throw ValidationError(why) }
+ if paths.hasData, target.standardizedFileURL != paths.home.standardizedFileURL {
+ print("moving engines, environments and downloads to \(target.path)…")
+ try HomeMove.move(from: paths.home, to: target) { print(" \($0)") }
+ }
+ try HighballPaths.setConfiguredHome(target)
+ print("home: \(target.path). Relaunch the Highball app to use it.")
+ }
+}
diff --git a/Tests/HighballKitTests/HomeLocationTests.swift b/Tests/HighballKitTests/HomeLocationTests.swift
new file mode 100644
index 0000000..56fda78
--- /dev/null
+++ b/Tests/HighballKitTests/HomeLocationTests.swift
@@ -0,0 +1,72 @@
+import XCTest
+@testable import HighballKit
+
+/// A chosen data location (#24, #68): the resolver's precedence, the preflight on a folder, the
+/// pointer file, and the mover that copies and checks before it removes anything.
+final class HomeLocationTests: XCTestCase {
+ private var tmp: URL!
+ override func setUpWithError() throws {
+ tmp = FileManager.default.temporaryDirectory.appending(path: "hb-home-\(UUID().uuidString)")
+ try FileManager.default.createDirectory(at: tmp, withIntermediateDirectories: true)
+ }
+ override func tearDownWithError() throws { try? FileManager.default.removeItem(at: tmp) }
+
+ func testPrecedenceExplicitThenEnvThenChosenThenDefault() {
+ let d = URL(fileURLWithPath: "/d"), e = URL(fileURLWithPath: "/e"), c = URL(fileURLWithPath: "/c"), x = URL(fileURLWithPath: "/x")
+ XCTAssertEqual(HighballPaths.resolve(explicit: x, env: e, configured: c, reachable: true, defaultHome: d).home, x)
+ XCTAssertEqual(HighballPaths.resolve(explicit: nil, env: e, configured: c, reachable: true, defaultHome: d).home, e)
+ XCTAssertEqual(HighballPaths.resolve(explicit: nil, env: nil, configured: c, reachable: true, defaultHome: d).home, c)
+ let unplugged = HighballPaths.resolve(explicit: nil, env: nil, configured: c, reachable: false, defaultHome: d)
+ XCTAssertEqual(unplugged.home, d, "an unplugged drive falls back to the default")
+ XCTAssertEqual(unplugged.unavailable, c, "and says which location is missing")
+ XCTAssertEqual(HighballPaths.resolve(explicit: nil, env: nil, configured: nil, reachable: false, defaultHome: d).home, d)
+ }
+
+ func testPointerFileRoundTrip() throws {
+ let file = tmp.appending(path: "config.json")
+ XCTAssertNil(HighballPaths.configuredHome(from: file))
+ try HighballPaths.setConfiguredHome(URL(fileURLWithPath: "/Volumes/Games/Highball"), file: file)
+ XCTAssertEqual(HighballPaths.configuredHome(from: file)?.path, "/Volumes/Games/Highball")
+ try HighballPaths.setConfiguredHome(nil, file: file)
+ XCTAssertNil(HighballPaths.configuredHome(from: file))
+ }
+
+ func testLocationPreflight() throws {
+ let def = tmp.appending(path: "default"), good = tmp.appending(path: "good"), inside = def.appending(path: "inner")
+ try FileManager.default.createDirectory(at: good, withIntermediateDirectories: true)
+ try FileManager.default.createDirectory(at: inside, withIntermediateDirectories: true)
+ XCTAssertNil(HighballPaths.locationProblem(good, defaultHome: def))
+ XCTAssertNotNil(HighballPaths.locationProblem(tmp.appending(path: "missing"), defaultHome: def))
+ XCTAssertNotNil(HighballPaths.locationProblem(inside, defaultHome: def), "inside the default home would move the data into itself")
+ XCTAssertNotNil(HighballPaths.locationProblem(tmp, defaultHome: tmp.appending(path: "default")), "the default's own parent is refused too")
+ }
+
+ func testMoveCopiesChecksThenRemovesAndKeepsLinks() throws {
+ let src = tmp.appending(path: "src"), dst = tmp.appending(path: "dst")
+ let fm = FileManager.default
+ try fm.createDirectory(at: src.appending(path: "bottles/Games/dosdevices"), withIntermediateDirectories: true)
+ try fm.createDirectory(at: src.appending(path: "engines/e/wine"), withIntermediateDirectories: true)
+ try Data(repeating: 7, count: 5000).write(to: src.appending(path: "bottles/Games/system.reg"))
+ try Data("x".utf8).write(to: src.appending(path: "engines/e/wine/w"))
+ try Data("{}".utf8).write(to: src.appending(path: "library.json"))
+ try Data("{\"home\":\"/x\"}".utf8).write(to: src.appending(path: "config.json"))
+ try fm.createSymbolicLink(atPath: src.appending(path: "bottles/Games/dosdevices/c:").path, withDestinationPath: "../drive_c")
+ let before = try HomeMove.tally(src.appending(path: "bottles"))
+ var seen: [String] = []
+ try HomeMove.move(from: src, to: dst) { seen.append($0) }
+ XCTAssertEqual(seen, ["bottles", "engines", "library.json"], "the pointer file is not data")
+ XCTAssertTrue(fm.fileExists(atPath: dst.appending(path: "bottles/Games/system.reg").path))
+ let after = try HomeMove.tally(dst.appending(path: "bottles"))
+ XCTAssertEqual(after.files, before.files); XCTAssertEqual(after.bytes, before.bytes)
+ XCTAssertEqual(try fm.destinationOfSymbolicLink(atPath: dst.appending(path: "bottles/Games/dosdevices/c:").path), "../drive_c", "links travel as links")
+ XCTAssertFalse(fm.fileExists(atPath: src.appending(path: "bottles").path), "removed at the source only after the check")
+ XCTAssertTrue(fm.fileExists(atPath: src.appending(path: "config.json").path), "the pointer stays put")
+ }
+
+ func testHasData() throws {
+ let p = HighballPaths(home: tmp)
+ XCTAssertFalse(p.hasData)
+ try FileManager.default.createDirectory(at: p.bottles.appending(path: "Games"), withIntermediateDirectories: true)
+ XCTAssertTrue(p.hasData)
+ }
+}