"use strict";
var Future = require("fibers/future");
var path = require("path");
var shelljs = require("shelljs");
var IOSSimulatorFileSystem = (function () {
    function IOSSimulatorFileSystem(iosSim, identifier, $fs, $logger) {
        this.iosSim = iosSim;
        this.identifier = identifier;
        this.$fs = $fs;
        this.$logger = $logger;
    }
    IOSSimulatorFileSystem.prototype.listFiles = function (devicePath) {
        return this.iosSim.listFiles(devicePath);
    };
    IOSSimulatorFileSystem.prototype.getFile = function (deviceFilePath) {
        return this.iosSim.getFile(deviceFilePath);
    };
    IOSSimulatorFileSystem.prototype.putFile = function (localFilePath, deviceFilePath) {
        return this.iosSim.putFile(localFilePath, deviceFilePath);
    };
    IOSSimulatorFileSystem.prototype.deleteFile = function (deviceFilePath, appIdentifier) {
        shelljs.rm("-rf", deviceFilePath);
    };
    IOSSimulatorFileSystem.prototype.transferFiles = function (deviceAppData, localToDevicePaths) {
        var _this = this;
        return (function () {
            _.each(localToDevicePaths, function (localToDevicePathData) { return _this.transferFile(localToDevicePathData.getLocalPath(), localToDevicePathData.getDevicePath()).wait(); });
        }).future()();
    };
    IOSSimulatorFileSystem.prototype.transferDirectory = function (deviceAppData, localToDevicePaths, projectFilesPath) {
        var destinationPath = deviceAppData.deviceProjectRootPath;
        this.$logger.trace("Transferring from " + projectFilesPath + " to " + destinationPath);
        return Future.fromResult(shelljs.cp("-Rf", path.join(projectFilesPath, "*"), destinationPath));
    };
    IOSSimulatorFileSystem.prototype.transferFile = function (localFilePath, deviceFilePath) {
        var _this = this;
        return (function () {
            _this.$logger.trace("Transferring from " + localFilePath + " to " + deviceFilePath);
            if (_this.$fs.getFsStats(localFilePath).wait().isDirectory()) {
                shelljs.mkdir(deviceFilePath);
            }
            else {
                shelljs.cp("-f", localFilePath, deviceFilePath);
            }
        }).future()();
    };
    return IOSSimulatorFileSystem;
})();
exports.IOSSimulatorFileSystem = IOSSimulatorFileSystem;
