Skip to content

Commit 88d9bbd

Browse files
committed
optimize binaries updater
1 parent 06e54e5 commit 88d9bbd

File tree

1 file changed

+57
-48
lines changed

1 file changed

+57
-48
lines changed

src/extension.ts

Lines changed: 57 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -377,45 +377,42 @@ async function checkAndInstallBinaries(forceInstall?: boolean): Promise<boolean>
377377
// if binaries is installed, we try check update from remote repo after x sec delay
378378
else if (checkBinFolder(binFolder)) {
379379

380-
// 5sec delay
381-
setTimeout(async () => {
382-
383-
let localVersion: string | undefined;
384-
385-
// get local binary version from disk
386-
// check binaries Main_Ver (<Main_Ver>.xx.xx <=> <Main_Ver>.xx.xx)
387-
const verFile = File.fromArray([binFolder.path, 'VERSION']);
388-
if (verFile.IsFile()) {
389-
const cont = verFile.Read().trim();
390-
if (utility.isVersionString(cont)) {
391-
localVersion = cont;
392-
const mainLocalVersion = parseInt(localVersion.split('.')[0]);
393-
const mainMinReqVersion = parseInt(minReqVersion.split('.')[0]);
394-
if (mainMinReqVersion != mainLocalVersion) { // local Main verson != min Main version
395-
localVersion = undefined; // local binaries is invalid, force update
396-
}
380+
let localVersion: string | undefined;
381+
382+
// get local binary version from disk
383+
// check binaries Main_Ver (<Main_Ver>.xx.xx <=> <Main_Ver>.xx.xx)
384+
const verFile = File.fromArray([binFolder.path, 'VERSION']);
385+
if (verFile.IsFile()) {
386+
const cont = verFile.Read().trim();
387+
if (utility.isVersionString(cont)) {
388+
localVersion = cont;
389+
const mainLocalVersion = parseInt(localVersion.split('.')[0]);
390+
const mainMinReqVersion = parseInt(minReqVersion.split('.')[0]);
391+
if (mainMinReqVersion != mainLocalVersion) { // local Main verson != min Main version
392+
localVersion = undefined; // local binaries is invalid, force update
397393
}
398394
}
395+
}
399396

400-
// try update
401-
if (localVersion) {
402-
const done = await tryUpdateBinaries(binFolder, localVersion);
397+
// try fetch update after 5sec delay
398+
if (localVersion) {
399+
setTimeout(async (curLocalVersion: string) => {
400+
const done = await tryUpdateBinaries(binFolder, curLocalVersion);
403401
if (!done) {
404-
const msg = `Update eide-binaries failed, please restart vscode !`;
402+
const msg = `Update eide-binaries failed, please restart vscode to try again !`;
405403
const sel = await vscode.window.showErrorMessage(msg, 'Restart', 'Cancel');
406404
if (sel == 'Restart') {
407405
vscode.commands.executeCommand('workbench.action.reloadWindow');
408406
}
409407
}
410-
}
411-
412-
// binaries folder is existed, but can not get local binaries version,
413-
// we need to force install it
414-
else {
415-
checkAndInstallBinaries(true);
416-
}
408+
}, 5 * 1000, localVersion);
409+
}
417410

418-
}, 5 * 1000);
411+
// binaries folder is existed, but can not get local binaries version,
412+
// the binaries maybe damaged, we need to force reinstall it
413+
else {
414+
checkAndInstallBinaries(true);
415+
}
419416

420417
return true;
421418
}
@@ -642,6 +639,11 @@ async function tryInstallBinaries(binFolder: File, binVersion: string): Promise<
642639
platform.DeleteDir(binFolder);
643640
}
644641

642+
// chmod executable's permission
643+
if (installedDone) {
644+
initBinariesExecutablePermission();
645+
}
646+
645647
return installedDone;
646648
}
647649

@@ -661,6 +663,7 @@ function exportEnvToSysPath() {
661663
const defEnvPath: string[] = [
662664
NodePath.normalize(`${builderFolder.path}/bin`), // builder bin folder
663665
NodePath.normalize(`${builderFolder.path}/utils`), // utils tool folder
666+
NodePath.normalize(`${builderFolder.dir}/scripts`),
664667
];
665668

666669
//
@@ -735,8 +738,9 @@ async function checkAndInstallRuntime() {
735738
//
736739
try {
737740
GlobalEvent.emit('globalLog', newMessage('Info', 'Checking .NET6 Runtime ...'));
738-
const dotnetInfo = ChildProcess.execSync(`dotnet --info`).toString().trim();
739-
GlobalEvent.emit('globalLog', newMessage('Info', dotnetInfo));
741+
const chkCmd = `dotnet --info`;
742+
const dotnetInfo = ChildProcess.execSync(chkCmd).toString().trim();
743+
GlobalEvent.emit('globalLog', newMessage('Info', `${chkCmd}:\n${dotnetInfo}`));
740744
if (!/Version: (?:6|7)\./.test(dotnetInfo)) { throw new Error(`Not found .NET6 Runtime`); }
741745
GlobalEvent.emit('globalLog', newMessage('Info', '.NET6 Runtime Found !'));
742746
} catch (error) {
@@ -806,24 +810,9 @@ async function checkAndInstallRuntime() {
806810
}
807811
}
808812

809-
async function InitComponents(context: vscode.ExtensionContext): Promise<boolean | undefined> {
810-
811-
// init managers
812-
const resManager = ResManager.GetInstance(context);
813-
const settingManager = SettingManager.GetInstance(context);
814-
815-
// chmod +x for 7za
816-
if (os.platform() != 'win32') {
817-
try {
818-
ChildProcess.execSync(`chmod +x "${resManager.Get7za().path}"`);
819-
} catch (error) {
820-
GlobalEvent.emit('msg', ExceptionToMessage(error, 'Error'));
821-
}
822-
}
813+
function initBinariesExecutablePermission() {
823814

824-
/* check binaries, if not found, install it ! */
825-
const done = await checkAndInstallBinaries();
826-
if (!done) { return false; } /* exit if failed */
815+
const resManager = ResManager.GetInstance();
827816

828817
// chmod +x for other executable files
829818
if (os.platform() != 'win32') {
@@ -859,6 +848,26 @@ async function InitComponents(context: vscode.ExtensionContext): Promise<boolean
859848
}
860849
}
861850
}
851+
}
852+
853+
async function InitComponents(context: vscode.ExtensionContext): Promise<boolean | undefined> {
854+
855+
// init managers
856+
const resManager = ResManager.GetInstance(context);
857+
const settingManager = SettingManager.GetInstance(context);
858+
859+
// chmod +x for 7za
860+
if (os.platform() != 'win32') {
861+
try {
862+
ChildProcess.execSync(`chmod +x "${resManager.Get7za().path}"`);
863+
} catch (error) {
864+
GlobalEvent.emit('msg', ExceptionToMessage(error, 'Error'));
865+
}
866+
}
867+
868+
/* check binaries, if not found, install it ! */
869+
const done = await checkAndInstallBinaries();
870+
if (!done) { return false; } /* exit if failed */
862871

863872
// check and install .NET6 runtime
864873
await checkAndInstallRuntime();

0 commit comments

Comments
 (0)