forked from quoid/userscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilities.swift
More file actions
43 lines (39 loc) · 1.15 KB
/
Copy pathUtilities.swift
File metadata and controls
43 lines (39 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import SwiftUI
import os.log
func USLogger(_ category: String) -> Logger? {
let subsystem = Bundle.main.bundleIdentifier!
#if DEBUG // Always enable logger in DEBUG builds
return Logger(subsystem: subsystem, category: category)
#else
if Preferences.enableLogger {
return Logger(subsystem: subsystem, category: category)
}
return nil
#endif
}
func getDocumentsDirectory() -> URL {
let fm = FileManager.default
let paths = fm.urls(for: .documentDirectory, in: .userDomainMask)
let documentsDirectory = paths[0]
return documentsDirectory
}
func directoryExists(path: String) -> Bool {
var isDirectory = ObjCBool(true)
let exists = FileManager.default.fileExists(atPath: path, isDirectory: &isDirectory)
let inTrash = path.contains(".Trash") ? false : true
return exists && inTrash && isDirectory.boolValue
}
func getPlatform() -> String {
var platform:String
#if os(iOS)
if UIDevice.current.userInterfaceIdiom == .pad {
platform = "ipados"
}
else {
platform = "ios"
}
#elseif os(macOS)
platform = "macos"
#endif
return platform
}