//
// FileHandling.swift
// DocHub
//
// Created by Tristan Juricek on 6/19/14.
// Copyright (c) 2014 Perforce. All rights reserved.
//
import Foundation
struct FileHandling {
static func applicationSupportDir() -> String {
return "\(NSHomeDirectory())/Application Support"
}
// Will create the Application Support directory in this applications home
// directory. This blindly assumes this application is sandboxed, otherwise,
// you'll just end up with ~/Application Support. Not the worst thing to
// happen.
//
// This will raise an NSException if we can't create this directory, which
// should probably not be handled by your application.
static func initApplicationSupportDir() -> String {
let appDir = applicationSupportDir()
initDir(appDir)
return appDir
}
static func initDir(dir:String) {
let manager = NSFileManager.defaultManager()
if !manager.fileExistsAtPath(dir) {
var err: NSError? = nil
manager.createDirectoryAtPath(dir, withIntermediateDirectories: false,
attributes: nil, error: &err)
if let error = err {
NSException(name: "InitializationException",
reason: err!.localizedDescription, userInfo: nil)
}
}
}
}