提交 be413a0e 编写于 作者: J João Moreno 提交者: GitHub

Merge pull request #31120 from Microsoft/joao/win32-bump64

Windows: 32 to 64bit migration
......@@ -5,7 +5,9 @@
'use strict';
import { localize } from 'vs/nls';
import * as path from 'path';
import * as fs from 'fs';
import * as pfs from 'vs/base/node/pfs';
import { checksum } from 'vs/base/node/crypto';
import { EventEmitter } from 'events';
......@@ -18,6 +20,9 @@ import { download, asJson } from 'vs/base/node/request';
import { IRequestService } from 'vs/platform/request/node/request';
import { IAutoUpdater } from 'vs/platform/update/common/update';
import product from 'vs/platform/node/product';
import { IStorageService } from 'vs/platform/storage/node/storage';
import { dialog } from 'electron';
import { getUpdateFeedUrl, Win32UninstallPath } from './updateFeedUrl';
interface IUpdate {
url: string;
......@@ -28,20 +33,51 @@ interface IUpdate {
hash: string;
}
const eventNames = [
'checking-for-update',
'update-not-available',
'update-available',
'update-downloaded',
'update-not-available',
'error'
];
function forwardEvent(eventName: string, source: EventEmitter, target: EventEmitter): void {
source.on(eventName, (...args) => target.emit(eventName, ...args));
}
export class Win32AutoUpdaterImpl extends EventEmitter implements IAutoUpdater {
private autoUpdater64: Win32AutoUpdaterImpl = null;
private url: string = null;
private currentRequest: Promise = null;
private updatePackagePath: string = null;
constructor(
@IRequestService private requestService: IRequestService
private arch: string,
private channel: string,
@IRequestService private requestService: IRequestService,
@IStorageService private storageService: IStorageService
) {
super();
if (arch === 'ia32') {
if (this.storageService.getItem('autoUpdateWin32Prefer64Bits', false)) {
this.autoUpdater64 = this.create64BitAutoUpdater();
}
}
}
get cachePath(): TPromise<string> {
const result = path.join(tmpdir(), `vscode-update-${process.arch}`);
private create64BitAutoUpdater(): Win32AutoUpdaterImpl {
const result = new Win32AutoUpdaterImpl('x64', this.channel, this.requestService, this.storageService);
result.setFeedURL(getUpdateFeedUrl(this.channel, 'x64'));
eventNames.forEach(e => forwardEvent(e, result, this));
return result;
}
private get cachePath(): TPromise<string> {
const result = path.join(tmpdir(), `vscode-update-${this.arch}`);
return new TPromise<string>((c, e) => mkdirp(result, null, err => err ? e(err) : c(result)));
}
......@@ -50,6 +86,10 @@ export class Win32AutoUpdaterImpl extends EventEmitter implements IAutoUpdater {
}
checkForUpdates(): void {
if (this.autoUpdater64) {
return this.autoUpdater64.checkForUpdates();
}
if (!this.url) {
throw new Error('No feed url set.');
}
......@@ -58,6 +98,27 @@ export class Win32AutoUpdaterImpl extends EventEmitter implements IAutoUpdater {
return;
}
const shouldPromptToMoveTo64Bits = this.arch === 'ia32' && this.storageService.getItem('autoUpdateWin32Propose64bits', true);
if (shouldPromptToMoveTo64Bits) {
const result = dialog.showMessageBox({
title: product.nameLong,
type: 'question',
message: localize('propose64', "{0} 64 bits for Windows is now available! Would you like to upgrade to the 64 bit version?", product.nameShort),
buttons: [localize('yes', "Yes"), localize('no', "No"), localize('neverAgain', "Never Ask Again")],
noLink: true
});
if (result === 2) {
this.storageService.setItem('autoUpdateWin32Propose64bits', false);
} else if (result === 0) {
this.storageService.setItem('autoUpdateWin32Prefer64Bits', true);
this.autoUpdater64 = this.create64BitAutoUpdater();
return this.autoUpdater64.checkForUpdates();
}
}
this.emit('checking-for-update');
this.currentRequest = this.requestService.request({ url: this.url })
......@@ -128,10 +189,26 @@ export class Win32AutoUpdaterImpl extends EventEmitter implements IAutoUpdater {
}
quitAndInstall(): void {
if (this.autoUpdater64) {
return this.autoUpdater64.quitAndInstall();
}
if (!this.updatePackagePath) {
return;
}
if (process.arch === 'ia32' && this.arch === 'x64') {
const updatePackageContents = `@echo off\r\n"${Win32UninstallPath}" /silent\r\nstart /b "" "${this.updatePackagePath}" /silent /mergetasks=runcode,!desktopicon,!quicklaunchicon\r\n`;
const updatePackagePath = path.join(tmpdir(), 'vscode-update-32-to-64.bat');
fs.writeFileSync(updatePackagePath, updatePackageContents);
spawn('cmd', ['/c', 'call', updatePackagePath], {
detached: true
});
return;
}
spawn(this.updatePackagePath, ['/silent', '/mergetasks=runcode,!desktopicon,!quicklaunchicon'], {
detached: true,
stdio: ['ignore', 'ignore', 'ignore']
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as fs from 'original-fs';
import * as path from 'path';
import product from 'vs/platform/node/product';
export const Win32UninstallPath = path.join(path.dirname(process.execPath), 'unins000.exe');
export function getUpdateFeedUrl(channel: string, arch: string = process.arch): string {
if (!channel) {
return null;
}
if (process.platform === 'win32' && !fs.existsSync(Win32UninstallPath)) {
return null;
}
if (!product.updateUrl || !product.commit) {
return null;
}
const platform = getUpdatePlatform(arch);
return `${product.updateUrl}/api/update/${platform}/${channel}/${product.commit}`;
}
function getUpdatePlatform(arch: string): string {
if (process.platform === 'linux') {
return `linux-${arch}`;
}
if (process.platform === 'win32' && arch === 'x64') {
return 'win32-x64';
}
return process.platform;
}
\ No newline at end of file
......@@ -5,8 +5,6 @@
'use strict';
import * as fs from 'original-fs';
import * as path from 'path';
import * as electron from 'electron';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import Event, { Emitter, once, filterEvent } from 'vs/base/common/event';
......@@ -22,6 +20,8 @@ import product from 'vs/platform/node/product';
import { TPromise } from 'vs/base/common/winjs.base';
import { IUpdateService, State, IAutoUpdater, IUpdate, IRawUpdate } from 'vs/platform/update/common/update';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { getUpdateFeedUrl } from './updateFeedUrl';
import { IStorageService } from 'vs/platform/storage/node/storage';
export class UpdateService implements IUpdateService {
......@@ -87,10 +87,13 @@ export class UpdateService implements IUpdateService {
@IRequestService requestService: IRequestService,
@ILifecycleService private lifecycleService: ILifecycleService,
@IConfigurationService private configurationService: IConfigurationService,
@ITelemetryService private telemetryService: ITelemetryService
@ITelemetryService private telemetryService: ITelemetryService,
@IStorageService private storageService: IStorageService
) {
const channel = this.getUpdateChannel();
if (process.platform === 'win32') {
this.raw = new Win32AutoUpdaterImpl(requestService);
this.raw = new Win32AutoUpdaterImpl(process.arch, channel, requestService, storageService);
} else if (process.platform === 'linux') {
this.raw = new LinuxAutoUpdaterImpl(requestService);
} else if (process.platform === 'darwin') {
......@@ -99,8 +102,7 @@ export class UpdateService implements IUpdateService {
return;
}
const channel = this.getUpdateChannel();
const feedUrl = this.getUpdateFeedUrl(channel);
const feedUrl = getUpdateFeedUrl(channel);
if (!feedUrl) {
return; // updates not available
......@@ -208,36 +210,6 @@ export class UpdateService implements IUpdateService {
return channel === 'none' ? null : product.quality;
}
private getUpdateFeedUrl(channel: string): string {
if (!channel) {
return null;
}
if (process.platform === 'win32' && !fs.existsSync(path.join(path.dirname(process.execPath), 'unins000.exe'))) {
return null;
}
if (!product.updateUrl || !product.commit) {
return null;
}
const platform = this.getUpdatePlatform();
return `${product.updateUrl}/api/update/${platform}/${channel}/${product.commit}`;
}
private getUpdatePlatform(): string {
if (process.platform === 'linux') {
return `linux-${process.arch}`;
}
if (process.platform === 'win32' && process.arch === 'x64') {
return 'win32-x64';
}
return process.platform;
}
quitAndInstall(): TPromise<void> {
if (!this._availableUpdate) {
return TPromise.as(null);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册