             return
         }
         
-        var root : String? = "~/Library/Application Support/Ergometer".stringByStandardizingPath
+        var root : String? = "~/Library/Application Support/Ergometer/state".stringByStandardizingPath
         var errors = [String]()
         var e : NSError?
         if !NSFileManager.defaultManager().createDirectoryAtPath(root!, withIntermediateDirectories: true, attributes: nil, error: &e) {

    
    let app: App
    let name: String
    var actionCost = 0
    var actionLimit: Int
    var firstActed: NSTimeInterval?
    var timeLimit: NSTimeInterval
    var restTime: NSTimeInterval
    
    init(app: App, name: String, actionLimit: Int, timeLimit: NSTimeInterval = 0, restTime: NSTimeInterval = 0) {
        self.app = app
        self.name = name
        self.actionLimit = actionLimit
        self.timeLimit = timeLimit
        self.restTime = restTime
    }
    
    func add(i: Int, now: NSTimeInterval) {
        actionCost += i
        if timeLimit > 0 {
            firstActed = firstActed ?? now
        }
    }
    
    func rest(lastActed: NSTimeInterval, now: NSTimeInterval) -> NSTimeInterval {
        let restLeft = lastActed + restTime - now
        let restNeeded = actionCost != 0 || firstActed != nil
        if restTime > 0 && restLeft <= 0 && restNeeded {
            app.mayGo = true
            app.reset(self)
        }
        return restLeft
    }
    
    func status(lastActed: NSTimeInterval) -> Int {
        let timed = timeLimit != 0
        let activeElapsed = firstActed != nil ? lastActed - firstActed! : 0
        if actionLimit != 0 {
            var value = actionLimit - actionCost
            if timed {
                var timeCost = activeElapsed / timeLimit * Double(actionLimit)
                value -= Int(timeCost)
            }
            return value
        }
        if timed {
            return Int(timeLimit - activeElapsed)
        }
        return actionCost
    }
    
    func expire() {
        if restTime == 0 {
            app.reset(self)
        }
    }
}


    var fadeValue : CGDisplayBlendFraction = 0.5
    let restDelay = 5.0

    let clock: (() -> Double)
    var errors: [String]
    let id: String
    let state: File
