Initial Commit

This commit is contained in:
Mark Gregory
2026-09-08 14:12:59 +01:00
commit 3b95f53a25
46 changed files with 4334 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
import AppKit
@MainActor
enum FilePicker {
static func chooseDirectory() -> String? {
let panel = NSOpenPanel()
panel.canChooseDirectories = true
panel.canChooseFiles = false
panel.allowsMultipleSelection = false
panel.canCreateDirectories = true
return panel.runModal() == .OK ? panel.url?.path : nil
}
static func chooseFile() -> String? {
let panel = NSOpenPanel()
panel.canChooseDirectories = false
panel.canChooseFiles = true
panel.allowsMultipleSelection = false
return panel.runModal() == .OK ? panel.url?.path : nil
}
}
@@ -0,0 +1,41 @@
import Foundation
import Security
enum KeychainStore {
private static let service = "net.absdev.RsyncManager"
static func string(for account: String) -> String {
let query: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrService as String: service,
kSecAttrAccount as String: account,
kSecReturnData as String: true,
kSecMatchLimit as String: kSecMatchLimitOne
]
var item: CFTypeRef?
guard SecItemCopyMatching(query as CFDictionary, &item) == errSecSuccess,
let data = item as? Data,
let value = String(data: data, encoding: .utf8) else { return "" }
return value
}
static func set(_ value: String, for account: String) {
let base: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrService as String: service,
kSecAttrAccount as String: account
]
if value.isEmpty {
SecItemDelete(base as CFDictionary)
return
}
let data = Data(value.utf8)
let update: [String: Any] = [kSecValueData as String: data]
if SecItemUpdate(base as CFDictionary, update as CFDictionary) == errSecItemNotFound {
var add = base
add[kSecValueData as String] = data
add[kSecAttrAccessible as String] = kSecAttrAccessibleAfterFirstUnlock
SecItemAdd(add as CFDictionary, nil)
}
}
}