One project had four root folders. The shell's history is kept, paths now point inside this repo, and the boundary stays: src/ imports nothing from the shell, which only speaks the contract. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
57 lines
2.9 KiB
Swift
57 lines
2.9 KiB
Swift
import Foundation
|
|
|
|
/// Wo die Huelle liegt und welche Dateien der Vertrag mit dem Bot sind (sicht/scratch/).
|
|
enum Orte {
|
|
/// Reihenfolge: POKERFREAK_SHELL, der beim Bauen eingetragene Pfad (Info.plist), sonst der
|
|
/// Quellbaum, aus dem diese Datei kompiliert wurde (swift run).
|
|
static let shell: URL = {
|
|
if let p = ProcessInfo.processInfo.environment["POKERFREAK_SHELL"], !p.isEmpty {
|
|
return URL(filePath: p, directoryHint: .isDirectory)
|
|
}
|
|
if let p = Bundle.main.object(forInfoDictionaryKey: "PokerfreakShell") as? String, !p.isEmpty {
|
|
return URL(filePath: p, directoryHint: .isDirectory)
|
|
}
|
|
return URL(filePath: #filePath).deletingLastPathComponent() // Sources/Cockpit
|
|
.deletingLastPathComponent().deletingLastPathComponent() // mac
|
|
.deletingLastPathComponent() // pokerfreak
|
|
}()
|
|
|
|
static let scratch = shell.appending(path: "sicht/scratch", directoryHint: .isDirectory)
|
|
static let startSkript = shell.appending(path: "sicht/start.py")
|
|
/// Rahmen des Panels fuer hand/act.py (Klickschutz) und sicht/tische.py (Anordnen).
|
|
static let cockpitRahmen = scratch.appending(path: "cockpit.json")
|
|
/// hand/act.py legt sie an, bevor ein Bot-Klick unter dem Panel landet.
|
|
static let ausweichen = scratch.appending(path: "ausweichen")
|
|
/// Du hast Maus oder Tastatur benutzt (nicht der Bot): der Läufer lässt dir den Vortritt.
|
|
static let eingriff = scratch.appending(path: "eingriff")
|
|
/// hand/dialog.py legt sie an, bevor der Bot selbst ESC drueckt.
|
|
static let eigeneTaste = scratch.appending(path: "eigene_taste")
|
|
|
|
/// Alter einer Datei in Sekunden, nil wenn es sie nicht gibt.
|
|
static func alter(_ url: URL, jetzt: Date = Date()) -> Double? {
|
|
guard let a = try? FileManager.default.attributesOfItem(atPath: url.path(percentEncoded: false)),
|
|
let m = a[.modificationDate] as? Date else { return nil }
|
|
return jetzt.timeIntervalSince(m)
|
|
}
|
|
}
|
|
|
|
/// Was schiefging, fuer die Fehlersuche: stderr (sichtbar bei `swift run Cockpit`) und das Systemprotokoll.
|
|
/// Was geschah, fuer die Fehlersuche: stderr (sichtbar bei `swift run Cockpit`) und
|
|
/// sicht/scratch/cockpit.log (auch fuer die installierte App).
|
|
enum Protokoll {
|
|
static let datei = Orte.scratch.appending(path: "cockpit.log")
|
|
|
|
static func schreiben(_ text: String) {
|
|
let zeile = "\(Date().formatted(.iso8601)) \(text)\n"
|
|
FileHandle.standardError.write(Data(("Cockpit: " + text + "\n").utf8))
|
|
if let h = try? FileHandle(forWritingTo: datei) {
|
|
_ = try? h.seekToEnd()
|
|
h.write(Data(zeile.utf8))
|
|
try? h.close()
|
|
} else {
|
|
try? FileManager.default.createDirectory(at: Orte.scratch, withIntermediateDirectories: true)
|
|
try? Data(zeile.utf8).write(to: datei)
|
|
}
|
|
}
|
|
}
|