text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
      value: true
  });
  exports.ParallelsVmManager = exports.parseVmList = undefined;
  
  var _bluebirdLst;
  
  function _load_bluebirdLst() {
      return _bluebirdLst = require("bluebird-lst");
  }
  
  /** @internal */
  let parseVmList = exports.parseVmList = (() => {
      var _ref = (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* (debugLogger) {
          // do not log output if debug - it is huge, logged using debugLogger
          let rawList = yield (0, (_builderUtil || _load_builderUtil()).exec)("prlctl", ["list", "-i", "-s", "name"], undefined, false);
          debugLogger.add("parallels.list", rawList);
          rawList = rawList.substring(rawList.indexOf("ID:"));
          // let match: Array<string> | null
          const result = [];
          for (const info of rawList.split("\n\n").map(function (it) {
              return it.trim();
          }).filter(function (it) {
              return it.length > 0;
          })) {
              const vm = {};
              for (const line of info.split("\n")) {
                  const meta = /^([^:("]+): (.*)$/.exec(line);
                  if (meta == null) {
                      continue;
                  }
                  const key = meta[1].toLowerCase();
                  if (key === "id" || key === "os" || key === "name" || key === "state" || key === "name") {
                      vm[key] = meta[2].trim();
                  }
              }
              result.push(vm);
          }
          return result;
      });
  
      return function parseVmList(_x) {
          return _ref.apply(this, arguments);
      };
  })();
  /** @internal */
  
  
  exports.macPathToParallelsWindows = macPathToParallelsWindows;
  
  var _builderUtil;
  
  function _load_builderUtil() {
      return _builderUtil = require("builder-util");
  }
  
  var _child_process;
  
  function _load_child_process() {
      return _child_process = require("child_process");
  }
  
  var _vm;
  
  function _load_vm() {
      return _vm = require("./vm");
  }
  
  class ParallelsVmManager extends (_vm || _load_vm()).VmManager {
      constructor(vm) {
          super();
          this.vm = vm;
          this.isExitHookAdded = false;
          this.startPromise = this.doStartVm();
      }
      get pathSep() {
          return "/";
      }
      handleExecuteError(error) {
          if (error.message.includes("Unable to open new session in this virtual machine")) {
              throw new Error(`Please ensure that your are logged in "${this.vm.name}" parallels virtual machine. In the future please do not stop VM, but suspend.\n\n${error.message}`);
          }
          throw error;
      }
      exec(file, args, options) {
          var _this = this;
  
          return (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* () {
              yield _this.ensureThatVmStarted();
              // it is important to use "--current-user" to execute command under logged in user - to access certs.
              return yield (0, (_builderUtil || _load_builderUtil()).exec)("prlctl", ["exec", _this.vm.id, "--current-user", file.startsWith("/") ? macPathToParallelsWindows(file) : file].concat(args), options).catch(function (error) {
                  return _this.handleExecuteError(error);
              });
          })();
      }
      spawn(file, args, options, extraOptions) {
          var _this2 = this;
  
          return (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* () {
              yield _this2.ensureThatVmStarted();
              return yield (0, (_builderUtil || _load_builderUtil()).spawn)("prlctl", ["exec", _this2.vm.id, file].concat(args), options, extraOptions).catch(function (error) {
                  return _this2.handleExecuteError(error);
              });
          })();
      }
      doStartVm() {
          var _this3 = this;
  
          return (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* () {
              const vmId = _this3.vm.id;
              const state = _this3.vm.state;
              if (state === "running") {
                  return;
              }
              if (!_this3.isExitHookAdded) {
                  _this3.isExitHookAdded = true;
                  require("async-exit-hook")(function (callback) {
                      const stopArgs = ["suspend", vmId];
                      if (callback == null) {
                          (0, (_child_process || _load_child_process()).execFileSync)("prlctl", stopArgs);
                      } else {
                          (0, (_builderUtil || _load_builderUtil()).exec)("prlctl", stopArgs).then(callback).catch(callback);
                      }
                  });
              }
              yield (0, (_builderUtil || _load_builderUtil()).exec)("prlctl", ["start", vmId]);
          })();
      }
      ensureThatVmStarted() {
          let startPromise = this.startPromise;
          if (startPromise == null) {
              startPromise = this.doStartVm();
              this.startPromise = startPromise;
          }
          return startPromise;
      }
      toVmFile(file) {
          // https://stackoverflow.com/questions/4742992/cannot-access-network-drive-in-powershell-running-as-administrator
          return macPathToParallelsWindows(file);
      }
  }
  exports.ParallelsVmManager = ParallelsVmManager;
  function macPathToParallelsWindows(file) {
      if (file.startsWith("C:\\")) {
          return file;
      }
      return "\\\\Mac\\Host\\" + file.replace(/\//g, "\\");
  }
  //# sourceMappingURL=ParallelsVm.js.map