Skip to content

Commit 65cc67c

Browse files
committed
allow install offline .net runtime in vsix pkg
1 parent 31d1516 commit 65cc67c

File tree

1 file changed

+42
-26
lines changed

1 file changed

+42
-26
lines changed

src/extension.ts

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -782,43 +782,59 @@ async function checkAndInstallRuntime() {
782782

783783
// win32, we can auto install it
784784
else {
785-
const tmpFile = File.fromArray([os.tmpdir(), 'dotnet-runtime-6.0.5-win-x64.exe']);
785+
const defPkgName = 'dotnet-runtime-6.0.5-win-x64.exe';
786786

787-
try {
788-
if (tmpFile.IsFile()) { fs.unlinkSync(tmpFile.path) }
789-
} catch (error) {
790-
// do nothing
787+
let pkgReady: boolean;
788+
let pkgFile: File;
789+
790+
// if found local installer pkg, use it
791+
const localPkg = File.fromArray([ResManager.GetInstance().getAppRootFolder().path, defPkgName]);
792+
if (localPkg.IsFile()) {
793+
pkgReady = true;
794+
pkgFile = localPkg;
791795
}
792796

793-
const downloadUrl = `https://download.visualstudio.microsoft.com/download/pr/b395fa18-c53b-4f7f-bf91-6b2d3c43fedb/d83a318111da9e15f5ecebfd2d190e89/dotnet-runtime-6.0.5-win-x64.exe`;
797+
// if not found local installer pkg, download it
798+
else {
794799

795-
const done = await vscode.window.withProgress({
796-
location: vscode.ProgressLocation.Notification,
797-
title: 'Downloading .NET6 runtime installer',
798-
cancellable: false
799-
}, async (progress, token): Promise<boolean> => {
800+
pkgFile = File.fromArray([os.tmpdir(), defPkgName]);
801+
802+
try {
803+
if (pkgFile.IsFile()) { fs.unlinkSync(pkgFile.path) }
804+
} catch (error) {
805+
// do nothing
806+
}
807+
808+
const downloadUrl = `https://download.visualstudio.microsoft.com/download/pr/b395fa18-c53b-4f7f-bf91-6b2d3c43fedb/d83a318111da9e15f5ecebfd2d190e89/dotnet-runtime-6.0.5-win-x64.exe`;
800809

801-
const res = await utility.downloadFileWithProgress(downloadUrl, tmpFile.name, progress, token);
810+
pkgReady = await vscode.window.withProgress({
811+
location: vscode.ProgressLocation.Notification,
812+
title: 'Downloading .NET6 runtime installer',
813+
cancellable: false
814+
}, async (progress, token): Promise<boolean> => {
802815

803-
if (res instanceof Buffer) {
804-
try {
805-
fs.writeFileSync(tmpFile.path, res);
806-
return true;
807-
} catch (error) {
808-
return false;
816+
const res = await utility.downloadFileWithProgress(downloadUrl, pkgFile.name, progress, token);
817+
818+
if (res instanceof Buffer) {
819+
try {
820+
fs.writeFileSync(pkgFile.path, res);
821+
return true;
822+
} catch (error) {
823+
return false;
824+
}
809825
}
810-
}
811826

812-
if (res instanceof Error) {
813-
GlobalEvent.emit('error', res);
814-
}
827+
if (res instanceof Error) {
828+
GlobalEvent.emit('error', res);
829+
}
815830

816-
return false;
817-
});
831+
return false;
832+
});
833+
}
818834

819-
if (done && tmpFile.IsFile()) {
835+
if (pkgReady && pkgFile.IsFile()) {
820836
try {
821-
ChildProcess.execFileSync(tmpFile.path);
837+
ChildProcess.execFileSync(pkgFile.path);
822838
const sel = await vscode.window.showInformationMessage(`Ok ! Now you need relaunch VsCode !`, txt_yes);
823839
if (sel) {
824840
vscode.commands.executeCommand('workbench.action.reloadWindow');

0 commit comments

Comments
 (0)