From a9a9f3fc7aae9b8d2abba2fa31111d6ea3991f63 Mon Sep 17 00:00:00 2001 From: Guillaume Kotulski Date: Thu, 14 Dec 2023 17:18:24 +0100 Subject: [PATCH] Tool4D decompress uses tar --- .vscode/launch.json | 9 +++++++ editor/src/config.ts | 3 +-- editor/src/ctx.ts | 56 +++++++++++++++++++++++++------------------- 3 files changed, 42 insertions(+), 26 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index d055b78..a7923b9 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -28,6 +28,15 @@ "ANALYZER_4D_DEBUG":"true" } }, + { + "name": "Launch Extension Debug Tool4D", + "type": "extensionHost", + "request": "launch", + "runtimeExecutable": "${execPath}", + "args": ["--extensionDevelopmentPath=${workspaceFolder}/editor"], + "env": { + } + }, { "name": "Launch Extension", "type": "extensionHost", diff --git a/editor/src/config.ts b/editor/src/config.ts index d347228..2858cd0 100644 --- a/editor/src/config.ts +++ b/editor/src/config.ts @@ -40,7 +40,6 @@ export class Config { public shouldPrepareTool4D() :boolean { const p = this._serverPathFromSettings; - if(!p) return true; return false; @@ -108,7 +107,7 @@ export class Config { opt => event.affectsConfiguration(opt) ); - if(this._ctx.client) { + if(this._ctx?.client) { await this._ctx.client.sendNotification(lc.DidChangeConfigurationNotification.type, { settings: this.cfg, }); diff --git a/editor/src/ctx.ts b/editor/src/ctx.ts index dfb6bca..895b7ca 100644 --- a/editor/src/ctx.ts +++ b/editor/src/ctx.ts @@ -50,12 +50,11 @@ export class Ctx private _getServerPath(config : Config, isDebug : boolean) : string { let serverPath : string = this._config.serverPath; - - if(process.env.ANALYZER_4D_PATH) - { + + if(process.env.ANALYZER_4D_PATH) { serverPath = process.env.ANALYZER_4D_PATH; } - + if(isDebug) { serverPath = '';//debug } @@ -162,27 +161,36 @@ export class Ctx { url+="win/tool4d_v20.0_win.tar.xz" } + console.log("Download", url) return url; } - private async _decompress(input : string, output : string) : Promise { + private async _decompress(input : string, inDirectory : string) : Promise { return new Promise(async (resolve, reject)=> { if(!existsSync(input)) reject(); + console.log("Untar", input) + const childProcess = child_process.spawn("tar", [ + '-xf', input, '-C', inDirectory + ]); + + childProcess.stderr.on('data', (chunk: Buffer) => { + //const str = chunk.toString(); + //console.log('4D Language Server:', str); + //this._client.outputChannel.appendLine(str); + }); - const bz2 = require('unbzip2-stream'); - const tarfs = require('tar-fs'); - //TODO improve to know which tool4D to download - fs.createReadStream(input).pipe(bz2()).pipe(tarfs.extract(output)) - .on("finish", async ()=> { - resolve(); - }) - .on("error", async ()=> { - reject(); - }) - .on("close", async ()=> { - resolve(); + childProcess.on('exit', (code, signal) => { + if(code == 0) + { + resolve() + } + else + { + reject() + } }); + }); } @@ -195,13 +203,13 @@ export class Ctx if (!existsSync(globalStoragePath)) { mkdirSync(globalStoragePath); } - const zipPath = path.join(globalStoragePath, "tool4D.tar.xz") - const tool4D = path.join(globalStoragePath, "tool4D") + const zipPath = path.join(globalStoragePath, "tool4d.tar.xz") + const tool4D = path.join(globalStoragePath, "tool4d") let tool4DExecutable = ""; const osType = os.type(); if(osType === "Windows_NT") { - tool4DExecutable = path.join(tool4D, "tool4d", "tool4d.exe"); + tool4DExecutable = path.join(tool4D, "tool4d.exe"); } else if(osType == "Darwin") { @@ -209,9 +217,9 @@ export class Ctx } else { - tool4DExecutable = path.join(tool4D, "tool4d", "tool4d"); + tool4DExecutable = path.join(tool4D, "tool4d"); } - + if(!existsSync(tool4D)) { const url : string = this._getURLTool4D(); @@ -225,7 +233,7 @@ export class Ctx } } - this._decompress(zipPath, tool4D).then(()=> { + this._decompress(zipPath, globalStoragePath).then(()=> { resolve(tool4DExecutable); }) .catch(()=> { @@ -240,7 +248,6 @@ export class Ctx } private _launch4D() { - const client = this._client; this._config.checkSettings(); let isDebug : boolean; isDebug = false; @@ -341,6 +348,7 @@ export class Ctx this._config = new Config(this._extensionContext); if(this._config.shouldPrepareTool4D()) { this.prepareTool4D().then(path => { + console.log("Tool4D path", path) this._config.setTool4DPath(path); this._launch4D(); })