fix: file path on macOS 10.13
This commit is contained in:
@@ -66,17 +66,19 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|||||||
(sender.representedObject as! Entry).run()
|
(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
|
// MARK: - Manage storage path
|
||||||
|
|
||||||
private func resolvedStorageURL() -> URL {
|
private func resolvedStorageURL() -> URL {
|
||||||
userStorageURL()
|
userStorageURL() ?? resFile("examples", nil)
|
||||||
// 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")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func userStorageURL() -> URL? {
|
private func userStorageURL() -> URL? {
|
||||||
@@ -204,7 +206,7 @@ struct Entry {
|
|||||||
var rv: [Entry] = []
|
var rv: [Entry] = []
|
||||||
for url
|
for url
|
||||||
in (try? FileManager.default.contentsOfDirectory(
|
in (try? FileManager.default.contentsOfDirectory(
|
||||||
at: URL(string: path)!,
|
at: URL(fileURLWithPath: path),
|
||||||
includingPropertiesForKeys: [.isDirectoryKey, .isExecutableKey])) ?? []
|
includingPropertiesForKeys: [.isDirectoryKey, .isExecutableKey])) ?? []
|
||||||
{
|
{
|
||||||
if url.hasDirectoryPath || FileManager.default.isExecutableFile(atPath: url.path) {
|
if url.hasDirectoryPath || FileManager.default.isExecutableFile(atPath: url.path) {
|
||||||
|
|||||||
Reference in New Issue
Block a user