fix: file path on macOS 10.13

This commit is contained in:
relikd
2026-01-28 12:43:09 +01:00
parent 05714ef69e
commit 1af81e5b4a

View File

@@ -66,17 +66,19 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
(sender.representedObject as! Entry).run()
}
// MARK: - Helper
private func resFile(_ name: String, _ ext: String?) -> URL {
// if run via .app bundle
return Bundle.main.url(forResource: name, withExtension: ext)
// if calling swift directly
?? URL(fileURLWithPath: #file + "/../../" + name + (ext == nil ? "" : ("." + ext!)))
}
// MARK: - Manage storage path
private func resolvedStorageURL() -> URL {
userStorageURL()
// if run via .app bundle
?? Bundle.main.url(forResource: "examples", withExtension: nil)
// if calling swift directly
?? URL(string: "file://" + FileManager.default.currentDirectoryPath + "/" + #file)!
.deletingLastPathComponent()
.deletingLastPathComponent()
.appendingPathComponent("examples")
userStorageURL() ?? resFile("examples", nil)
}
private func userStorageURL() -> URL? {
@@ -204,7 +206,7 @@ struct Entry {
var rv: [Entry] = []
for url
in (try? FileManager.default.contentsOfDirectory(
at: URL(string: path)!,
at: URL(fileURLWithPath: path),
includingPropertiesForKeys: [.isDirectoryKey, .isExecutableKey])) ?? []
{
if url.hasDirectoryPath || FileManager.default.isExecutableFile(atPath: url.path) {