mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Merge from master
This commit is contained in:
@@ -3,8 +3,6 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as pfs from 'vs/base/node/pfs';
|
||||
@@ -13,7 +11,6 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
|
||||
import { ILifecycleService } from 'vs/platform/lifecycle/electron-main/lifecycleMain';
|
||||
import { IRequestService } from 'vs/platform/request/node/request';
|
||||
import product from 'vs/platform/node/product';
|
||||
import { TPromise, Promise } from 'vs/base/common/winjs.base';
|
||||
import { State, IUpdate, StateType, AvailableForDownload, UpdateType } from 'vs/platform/update/common/update';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
@@ -24,19 +21,13 @@ import { checksum } from 'vs/base/node/crypto';
|
||||
import { tmpdir } from 'os';
|
||||
import { spawn } from 'child_process';
|
||||
import { shell } from 'electron';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { timeout } from 'vs/base/common/async';
|
||||
|
||||
function pollUntil(fn: () => boolean, timeout = 1000): TPromise<void> {
|
||||
return new TPromise<void>(c => {
|
||||
const poll = () => {
|
||||
if (fn()) {
|
||||
c(null);
|
||||
} else {
|
||||
setTimeout(poll, timeout);
|
||||
}
|
||||
};
|
||||
|
||||
poll();
|
||||
});
|
||||
async function pollUntil(fn: () => boolean, millis = 1000): Promise<void> {
|
||||
while (!fn()) {
|
||||
await timeout(millis);
|
||||
}
|
||||
}
|
||||
|
||||
interface IAvailableUpdate {
|
||||
@@ -62,7 +53,7 @@ export class Win32UpdateService extends AbstractUpdateService {
|
||||
private availableUpdate: IAvailableUpdate | undefined;
|
||||
|
||||
@memoize
|
||||
get cachePath(): TPromise<string> {
|
||||
get cachePath(): Thenable<string> {
|
||||
// {{SQL CARBON EDIT}}
|
||||
const result = path.join(tmpdir(), `sqlops-update-${product.target}-${process.arch}`);
|
||||
return pfs.mkdirp(result, null).then(() => result);
|
||||
@@ -116,7 +107,7 @@ export class Win32UpdateService extends AbstractUpdateService {
|
||||
|
||||
this.setState(State.CheckingForUpdates(context));
|
||||
|
||||
this.requestService.request({ url: this.url })
|
||||
this.requestService.request({ url: this.url }, CancellationToken.None)
|
||||
.then<IUpdate>(asJson)
|
||||
.then(update => {
|
||||
const updateType = getUpdateType();
|
||||
@@ -130,12 +121,12 @@ export class Win32UpdateService extends AbstractUpdateService {
|
||||
this.telemetryService.publicLog('update:notAvailable', { explicit: !!context });
|
||||
|
||||
this.setState(State.Idle(updateType));
|
||||
return TPromise.as(null);
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
if (updateType === UpdateType.Archive) {
|
||||
this.setState(State.AvailableForDownload(update));
|
||||
return TPromise.as(null);
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
this.setState(State.Downloading(update));
|
||||
@@ -144,14 +135,14 @@ export class Win32UpdateService extends AbstractUpdateService {
|
||||
return this.getUpdatePackagePath(update.version).then(updatePackagePath => {
|
||||
return pfs.exists(updatePackagePath).then(exists => {
|
||||
if (exists) {
|
||||
return TPromise.as(updatePackagePath);
|
||||
return Promise.resolve(updatePackagePath);
|
||||
}
|
||||
|
||||
const url = update.url;
|
||||
const hash = update.hash;
|
||||
const downloadPath = `${updatePackagePath}.tmp`;
|
||||
|
||||
return this.requestService.request({ url })
|
||||
return this.requestService.request({ url }, CancellationToken.None)
|
||||
.then(context => download(downloadPath, context))
|
||||
.then(hash ? () => checksum(downloadPath, update.hash) : () => null)
|
||||
.then(() => pfs.rename(downloadPath, updatePackagePath))
|
||||
@@ -182,68 +173,75 @@ export class Win32UpdateService extends AbstractUpdateService {
|
||||
}
|
||||
*/
|
||||
this.telemetryService.publicLog('update:notAvailable', { explicit: !!context });
|
||||
this.setState(State.Idle(getUpdateType()));
|
||||
|
||||
// only show message when explicitly checking for updates
|
||||
const message: string | undefined = !!context ? (err.message || err) : undefined;
|
||||
this.setState(State.Idle(getUpdateType(), message));
|
||||
});
|
||||
}
|
||||
|
||||
protected doDownloadUpdate(state: AvailableForDownload): TPromise<void> {
|
||||
protected async doDownloadUpdate(state: AvailableForDownload): Promise<void> {
|
||||
shell.openExternal(state.update.url);
|
||||
this.setState(State.Idle(getUpdateType()));
|
||||
return TPromise.as(null);
|
||||
}
|
||||
|
||||
private getUpdatePackagePath(version: string): TPromise<string> {
|
||||
private async getUpdatePackagePath(version: string): Promise<string> {
|
||||
const cachePath = await this.cachePath;
|
||||
// {{SQL CARBON EDIT}}
|
||||
return this.cachePath.then(cachePath => path.join(cachePath, `AzureDataStudioSetup-${product.quality}-${version}.exe`));
|
||||
return path.join(cachePath, `AzureDataStudioSetup-${product.quality}-${version}.exe`);
|
||||
}
|
||||
|
||||
private cleanup(exceptVersion: string = null): Promise {
|
||||
private async cleanup(exceptVersion: string | null = null): Promise<any> {
|
||||
const filter = exceptVersion ? one => !(new RegExp(`${product.quality}-${exceptVersion}\\.exe$`).test(one)) : () => true;
|
||||
|
||||
return this.cachePath
|
||||
.then(cachePath => pfs.readdir(cachePath)
|
||||
.then(all => Promise.join(all
|
||||
.filter(filter)
|
||||
.map(one => pfs.unlink(path.join(cachePath, one)).then(null, () => null))
|
||||
))
|
||||
);
|
||||
const cachePath = await this.cachePath;
|
||||
const versions = await pfs.readdir(cachePath);
|
||||
|
||||
const promises = versions.filter(filter).map(async one => {
|
||||
try {
|
||||
await pfs.unlink(path.join(cachePath, one));
|
||||
} catch (err) {
|
||||
// ignore
|
||||
}
|
||||
});
|
||||
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
||||
protected doApplyUpdate(): TPromise<void> {
|
||||
protected async doApplyUpdate(): Promise<void> {
|
||||
if (this.state.type !== StateType.Downloaded && this.state.type !== StateType.Downloading) {
|
||||
return TPromise.as(null);
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
if (!this.availableUpdate) {
|
||||
return TPromise.as(null);
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
const update = this.state.update;
|
||||
this.setState(State.Updating(update));
|
||||
|
||||
return this.cachePath.then(cachePath => {
|
||||
this.availableUpdate.updateFilePath = path.join(cachePath, `CodeSetup-${product.quality}-${update.version}.flag`);
|
||||
const cachePath = await this.cachePath;
|
||||
|
||||
return pfs.writeFile(this.availableUpdate.updateFilePath, 'flag').then(() => {
|
||||
const child = spawn(this.availableUpdate.packagePath, ['/verysilent', `/update="${this.availableUpdate.updateFilePath}"`, '/nocloseapplications', '/mergetasks=runcode,!desktopicon,!quicklaunchicon'], {
|
||||
detached: true,
|
||||
stdio: ['ignore', 'ignore', 'ignore'],
|
||||
windowsVerbatimArguments: true
|
||||
});
|
||||
this.availableUpdate.updateFilePath = path.join(cachePath, `CodeSetup-${product.quality}-${update.version}.flag`);
|
||||
|
||||
child.once('exit', () => {
|
||||
this.availableUpdate = undefined;
|
||||
this.setState(State.Idle(getUpdateType()));
|
||||
});
|
||||
|
||||
const readyMutexName = `${product.win32MutexName}-ready`;
|
||||
const isActive = (require.__$__nodeRequire('windows-mutex') as any).isActive;
|
||||
|
||||
// poll for mutex-ready
|
||||
pollUntil(() => isActive(readyMutexName))
|
||||
.then(() => this.setState(State.Ready(update)));
|
||||
});
|
||||
await pfs.writeFile(this.availableUpdate.updateFilePath, 'flag');
|
||||
const child = spawn(this.availableUpdate.packagePath, ['/verysilent', `/update="${this.availableUpdate.updateFilePath}"`, '/nocloseapplications', '/mergetasks=runcode,!desktopicon,!quicklaunchicon'], {
|
||||
detached: true,
|
||||
stdio: ['ignore', 'ignore', 'ignore'],
|
||||
windowsVerbatimArguments: true
|
||||
});
|
||||
|
||||
child.once('exit', () => {
|
||||
this.availableUpdate = undefined;
|
||||
this.setState(State.Idle(getUpdateType()));
|
||||
});
|
||||
|
||||
const readyMutexName = `${product.win32MutexName}-ready`;
|
||||
const isActive = (require.__$__nodeRequire('windows-mutex') as any).isActive;
|
||||
|
||||
// poll for mutex-ready
|
||||
pollUntil(() => isActive(readyMutexName))
|
||||
.then(() => this.setState(State.Ready(update)));
|
||||
}
|
||||
|
||||
protected doQuitAndInstall(): void {
|
||||
|
||||
Reference in New Issue
Block a user