"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DevicePathProvider = void 0;
const helpers_1 = require("./common/helpers");
const constants_1 = require("./constants");
const constants_2 = require("./common/constants");
const path = require("path");
const yok_1 = require("./common/yok");
class DevicePathProvider {
    constructor($mobileHelper, $iOSSimResolver, $errors) {
        this.$mobileHelper = $mobileHelper;
        this.$iOSSimResolver = $iOSSimResolver;
        this.$errors = $errors;
    }
    getDeviceProjectRootPath(device, options) {
        return __awaiter(this, void 0, void 0, function* () {
            let projectRoot = "";
            if (this.$mobileHelper.isiOSPlatform(device.deviceInfo.platform)) {
                projectRoot = device.isEmulator
                    ? yield this.$iOSSimResolver.iOSSim.getApplicationPath(device.deviceInfo.identifier, options.appIdentifier)
                    : constants_2.LiveSyncPaths.IOS_DEVICE_PROJECT_ROOT_PATH;
                if (!projectRoot) {
                    this.$errors.fail("Unable to get application path on device.");
                }
                if (!options.getDirname) {
                    projectRoot = path.join(projectRoot, constants_1.APP_FOLDER_NAME);
                }
            }
            else if (this.$mobileHelper.isAndroidPlatform(device.deviceInfo.platform)) {
                projectRoot = `${constants_2.LiveSyncPaths.ANDROID_TMP_DIR_NAME}/${options.appIdentifier}`;
                if (!options.getDirname) {
                    const hashService = (device).fileSystem.getDeviceHashService(options.appIdentifier);
                    const hashFile = yield hashService.doesShasumFileExistsOnDevice();
                    const syncFolderName = options.watch || hashFile
                        ? constants_2.LiveSyncPaths.SYNC_DIR_NAME
                        : constants_2.LiveSyncPaths.FULLSYNC_DIR_NAME;
                    projectRoot = path.join(projectRoot, syncFolderName);
                }
            }
            return (0, helpers_1.fromWindowsRelativePathToUnix)(projectRoot);
        });
    }
    getDeviceSyncZipPath(device) {
        return this.$mobileHelper.isiOSPlatform(device.deviceInfo.platform) &&
            !device.isEmulator
            ? constants_2.LiveSyncPaths.IOS_DEVICE_SYNC_ZIP_PATH
            : undefined;
    }
}
exports.DevicePathProvider = DevicePathProvider;
yok_1.injector.register("devicePathProvider", DevicePathProvider);
//# sourceMappingURL=device-path-provider.js.map