//
// Utilities-tools.swift
// No specific project, used throuhgout
// This version last modified on Feb 24. 2017
//
// This version last modified März 15. 2017, dfm.tempDirectory
// is only available form macOS 10.12 onwards
//
// April 4th 2017
// Rewritten in order to use FileManager's attributes
//
import Foundation
public let dfm = FileManager.default
public func homeURL() -> URL {
return dfm.homeDirectoryForCurrentUser
}
public func desktopURL() -> URL {
return dfm.homeDirectoryForCurrentUser.appendingPathComponent("Desktop")
}
public func homePath() -> String {
return dfm.homeDirectoryForCurrentUser.path
}
public func tmpURL() -> URL {
if #available(macOS 10.12, *) {
return dfm.temporaryDirectory
} else {
// Fallback on earlier versions
return URL(string: NSTemporaryDirectory())!
}
}
public func tmpPath() -> String{
return tmpURL().path
}
public func documentsURL() -> URL {
return dfm.homeDirectoryForCurrentUser.appendingPathComponent("Documents")
}
public func documentsPath() -> String {
return documentsURL().path
}
public func libraryURL() -> URL {
return dfm.homeDirectoryForCurrentUser.appendingPathComponent("Library")
}
public func libraryPath() -> String {
return libraryURL().path
}
public func splitIntoNameAndExtension(total:String) -> [String]? {
let parts = total.components(separatedBy: ".")
guard
parts.count == 2,
let name = parts.first,
!name.isEmpty,
let ext = parts.last,
!ext.isEmpty
else
{ return nil }
return [name, ext]
}