//
// Utilities-macOS.swift
// No specific project, used throuhgout
// This version last modified on Feb 24. 2017
//
// Now works (hopefully) for all versions of mac OS
// To Do:
//
// Fix alerts for macOS
//
import Foundation
public let dfm = FileManager.default
public func homeURL() -> URL {
if #available(macOS 10.12, *) {
return dfm.homeDirectoryForCurrentUser
}
else {
return dfm.urls(for: FileManager.SearchPathDirectory.userDirectory,
in: FileManager.SearchPathDomainMask.userDomainMask).first!
}
}
public func homePath() -> String {
return homeURL().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.urls(for: FileManager.SearchPathDirectory.documentDirectory,
in: FileManager.SearchPathDomainMask.userDomainMask).first!
}
public func documentsPath() -> String {
return documentsURL().path
}
public func libraryURL() -> URL {
return dfm.urls(for: FileManager.SearchPathDirectory.libraryDirectory,
in: FileManager.SearchPathDomainMask.userDomainMask).first!
}
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]
}