Skip to content

Commit 230ed90

Browse files
committedMay 16, 2016
Merge pull request #326 from DustinCampbell/fix-omnisharp-download
No longer download OmniSharp from GitHub releases
2 parents 08a0cd4 + 4b48c62 commit 230ed90

File tree

2 files changed

+33
-41
lines changed

2 files changed

+33
-41
lines changed
 

‎package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "csharp",
33
"publisher": "ms-vscode",
4-
"version": "1.0.8",
4+
"version": "1.0.9",
55
"description": "C# for Visual Studio Code (powered by OmniSharp).",
66
"displayName": "C#",
77
"author": "Microsoft Corporation",
@@ -21,7 +21,6 @@
2121
"decompress": "^3.0.0",
2222
"del": "^2.0.2",
2323
"fs-extra-promise": "^0.3.1",
24-
"github-releases": "^0.3.0",
2524
"run-in-terminal": "*",
2625
"semver": "*",
2726
"vscode-debugprotocol": "^1.6.1",

‎src/omnisharpDownload.ts

+32-39
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77

88
import * as fs from 'fs-extra-promise';
99
import * as path from 'path';
10+
import * as https from 'https';
11+
import * as stream from 'stream';
1012
import * as tmp from 'tmp';
13+
import {parse} from 'url';
1114
import {SupportedPlatform, getSupportedPlatform} from './utils';
1215

1316
const Decompress = require('decompress');
14-
const Github = require('github-releases');
1517

16-
const OmnisharpRepo = 'OmniSharp/omnisharp-roslyn';
17-
const OmnisharpVersion = 'v1.9-alpha14';
18+
const BaseDownloadUrl = 'https://vscodeoscon.blob.core.windows.net/ext';
1819
const DefaultInstallLocation = path.join(__dirname, '../.omnisharp');
1920
const ApiToken = '18a6f5ecea711220d4f433d4fd41062d479fda1d';
2021

@@ -45,46 +46,39 @@ function getOmnisharpAssetName(): string {
4546
}
4647
}
4748

49+
function download(urlString: string): Promise<stream.Readable> {
50+
let url = parse(urlString);
51+
let options: https.RequestOptions = {
52+
host: url.host,
53+
path: url.path,
54+
}
55+
56+
return new Promise<stream.Readable>((resolve, reject) => {
57+
return https.get(options, res => {
58+
// handle redirection
59+
if (res.statusCode === 302) {
60+
return download(res.headers.location);
61+
}
62+
else if (res.statusCode !== 200) {
63+
return reject(Error(`Download failed with code ${res.statusCode}.`));
64+
}
65+
66+
return resolve(res);
67+
});
68+
});
69+
}
70+
4871
export function downloadOmnisharp(): Promise<boolean> {
4972
return new Promise<boolean>((resolve, reject) => {
5073
console.log(`[OmniSharp]: Installing to ${DefaultInstallLocation}`);
5174

52-
const repo = new Github({ repo: OmnisharpRepo, token: ApiToken });
5375
const assetName = getOmnisharpAssetName();
76+
const urlString = `${BaseDownloadUrl}/${assetName}`;
5477

55-
console.log(`[OmniSharp] Looking for ${OmnisharpVersion}, ${assetName}...`);
56-
57-
repo.getReleases({ tag_name: OmnisharpVersion }, (err, releases) => {
58-
if (err) {
59-
return reject(err);
60-
}
61-
62-
if (!releases.length) {
63-
return reject(new Error(`OmniSharp release ${OmnisharpVersion} not found.`));
64-
}
65-
66-
// Note: there should only be a single release, but use the first one
67-
// if there are ever multiple results. Same thing for assets.
68-
let foundAsset = null;
69-
70-
for (var asset of releases[0].assets) {
71-
if (asset.name === assetName) {
72-
foundAsset = asset;
73-
break;
74-
}
75-
}
76-
77-
if (!foundAsset) {
78-
return reject(new Error(`OmniSharp release ${OmnisharpVersion} asset, ${assetName} not found.`));
79-
}
80-
81-
console.log(`[OmniSharp] Found it!`);
82-
83-
repo.downloadAsset(foundAsset, (err, inStream) => {
84-
if (err) {
85-
return reject(err);
86-
}
87-
78+
console.log(`[OmniSharp] Attempting to download ${assetName}...`);
79+
80+
return download(urlString)
81+
.then(inStream => {
8882
tmp.file((err, tmpPath, fd, cleanupCallback) => {
8983
if (err) {
9084
return reject(err);
@@ -106,7 +100,7 @@ export function downloadOmnisharp(): Promise<boolean> {
106100
.src(tmpPath)
107101
.dest(DefaultInstallLocation);
108102

109-
if (path.extname(foundAsset.name).toLowerCase() === '.zip') {
103+
if (path.extname(assetName).toLowerCase() === '.zip') {
110104
decompress = decompress.use(Decompress.zip());
111105
console.log(`[OmniSharp] Unzipping...`);
112106
}
@@ -129,6 +123,5 @@ export function downloadOmnisharp(): Promise<boolean> {
129123
inStream.pipe(outStream);
130124
});
131125
});
132-
});
133126
});
134127
}

0 commit comments

Comments
 (0)