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