helperBinary.ts 1.21 KB
Newer Older
1 2 3 4 5
import { Store } from "./store";

import * as path from "path";
import * as fs from "fs-extra";
import * as https from "https";
6
import { getWorkspaceOrShowError } from "./storeHelper";
7

8 9 10 11 12 13
export function getHelperPath(store: Store): string {
	if (getWorkspaceOrShowError(store).settings.helper.useManagedHelper) {
		return path.join(store.soicodeExtensionDataPath, "helper");
	} else {
		return getWorkspaceOrShowError(store).settings.helper.manualHelperPath;
	}
14 15 16
}

export async function downloadHelperBinary(store: Store) {
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
	let platform = "";
	// also look at process.arch
	switch (process.platform) {
		case "darwin":
			platform = "darwin-amd64";
		case "win32":
			platform = "windows-amd64";
		case "linux":
			platform = "linux-amd64";
	}
	console.log("Fetching Helper binary for platform " + platform);
	try {
		await fs.mkdir(store.soicodeExtensionDataPath);
	} catch (err) {
		if (err.code !== "EEXIST") {
			throw err;
		}
	}
	let file = fs.createWriteStream(
		path.join(store.soicodeExtensionDataPath, "helper"),
		{ mode: parseInt("755", 8) }
	);
	https.get(
		"https://blob.dolansoft.org/soicode/helper-" + platform,
		response => {
			response.pipe(file);
			file.on("finish", () => {
				file.close();
			});
		}
	);
}