Skip to content

Commit

Permalink
Tool4D decompress uses tar
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-kotulski committed Dec 14, 2023
1 parent d3aeee8 commit a9a9f3f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 26 deletions.
9 changes: 9 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions editor/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export class Config {

public shouldPrepareTool4D() :boolean {
const p = this._serverPathFromSettings;

if(!p)
return true;
return false;
Expand Down Expand Up @@ -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,
});
Expand Down
56 changes: 32 additions & 24 deletions editor/src/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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<void> {
private async _decompress(input : string, inDirectory : string) : Promise<void> {
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()
}
});

});
}

Expand All @@ -195,23 +203,23 @@ 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")
{
tool4DExecutable = path.join(tool4D, "tool4d.app");
}
else
{
tool4DExecutable = path.join(tool4D, "tool4d", "tool4d");
tool4DExecutable = path.join(tool4D, "tool4d");
}

if(!existsSync(tool4D))
{
const url : string = this._getURLTool4D();
Expand All @@ -225,7 +233,7 @@ export class Ctx
}
}

this._decompress(zipPath, tool4D).then(()=> {
this._decompress(zipPath, globalStoragePath).then(()=> {
resolve(tool4DExecutable);
})
.catch(()=> {
Expand All @@ -240,7 +248,6 @@ export class Ctx
}

private _launch4D() {
const client = this._client;
this._config.checkSettings();
let isDebug : boolean;
isDebug = false;
Expand Down Expand Up @@ -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();
})
Expand Down

0 comments on commit a9a9f3f

Please sign in to comment.