33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6+ import * as fs from 'async-file' ;
67import { MessageItem , vscode } from '../vscodeAdapter' ;
7- import { BaseEvent , OmnisharpServerOnError , OmnisharpServerMsBuildProjectDiagnostics } from "../omnisharp/loggingEvents" ;
8+ import { BaseEvent , OmnisharpServerOnError , OmnisharpServerMsBuildProjectDiagnostics , ZipFileError } from "../omnisharp/loggingEvents" ;
89import { Scheduler } from 'rxjs/Scheduler' ;
910import { Subject } from 'rxjs/Subject' ;
1011import 'rxjs/add/operator/debounceTime' ;
12+ import { CreateTmpFile } from '../CreateTmpAsset' ;
13+ import * as vscode1 from 'vscode' ;
1114
1215export interface MessageItemWithCommand extends MessageItem {
1316 command : string ;
@@ -23,17 +26,12 @@ export class WarningMessageObserver {
2326 let value : MessageItemWithCommand ;
2427 try {
2528 value = await this . vscode . window . showWarningMessage < MessageItemWithCommand > ( message , { title : "Show Output" , command : 'o.showOutput' } ) ;
26- }
27- catch ( err ) {
28- console . log ( err ) ;
29- }
30- if ( value ) {
31- try {
29+ if ( value ) {
3230 await this . vscode . commands . executeCommand < string > ( value . command ) ;
3331 }
34- catch ( err ) {
35- console . log ( err ) ;
36- }
32+ }
33+ catch ( err ) {
34+ console . log ( err ) ;
3735 }
3836 } ) ;
3937 }
@@ -46,6 +44,9 @@ export class WarningMessageObserver {
4644 case OmnisharpServerMsBuildProjectDiagnostics . name :
4745 this . handleOmnisharpServerMsBuildProjectDiagnostics ( < OmnisharpServerMsBuildProjectDiagnostics > event ) ;
4846 break ;
47+ case ZipFileError . name :
48+ this . handleZipFileError ( < ZipFileError > event ) ;
49+ break ;
4950 }
5051 }
5152
@@ -54,4 +55,27 @@ export class WarningMessageObserver {
5455 this . warningMessageDebouncer . next ( event ) ;
5556 }
5657 }
58+
59+ private async handleZipFileError ( event : ZipFileError ) {
60+ let tmpFile = await CreateTmpFile ( ) ;
61+ let writestream = fs . createWriteStream ( tmpFile . name ) ;
62+ writestream . write ( event . content ) ;
63+ //once we have written to the file show a warning message to open it
64+ let value : MessageItemWithCommand ;
65+ let message = " The downloaded file is not a zip. Please review your proxy settings or view the downloaded file below." ;
66+ try {
67+ //let file = "C:\\Users\\akagarw\\AppData\\Local\\Temp\\package-32592bbSNWBM3SWGP";
68+ let file = vscode1 . Uri . file ( tmpFile . name ) ;
69+ value = await this . vscode . window . showWarningMessage < MessageItemWithCommand > ( message , { title : "View downloaded file" , command : 'vscode.open' } ) ;
70+ if ( value ) {
71+ await this . vscode . commands . executeCommand < string > ( value . command , file ) ;
72+ }
73+ }
74+ catch ( err ) {
75+ console . log ( err ) ;
76+ }
77+ finally {
78+ tmpFile . dispose ( ) ;
79+ }
80+ }
5781}
0 commit comments