Commit 6ee42d78 authored by nanahira's avatar nanahira

buffer things

parent 69014ef8
...@@ -214,6 +214,7 @@ ...@@ -214,6 +214,7 @@
<h4 i18n>快捷方式</h4> <h4 i18n>快捷方式</h4>
<div class="checkbox"> <div class="checkbox">
<input id="create_application_shortcut" type="checkbox" name="application" [(ngModel)]="installOption.createShortcut"> <input id="create_application_shortcut" type="checkbox" name="application" [(ngModel)]="installOption.createShortcut">
<label i18n *ngIf="platform == 'linux'" for="create_application_shortcut">创建启动菜单快捷方式</label>
<label i18n *ngIf="platform == 'darwin'" for="create_application_shortcut">创建 LaunchPad 快捷方式</label> <label i18n *ngIf="platform == 'darwin'" for="create_application_shortcut">创建 LaunchPad 快捷方式</label>
<label i18n *ngIf="platform == 'win32'" for="create_application_shortcut">创建开始菜单快捷方式</label> <label i18n *ngIf="platform == 'win32'" for="create_application_shortcut">创建开始菜单快捷方式</label>
</div> </div>
...@@ -362,4 +363,4 @@ ...@@ -362,4 +363,4 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div>
\ No newline at end of file
import { ApplicationRef, EventEmitter, Injectable, NgZone } from '@angular/core'; import {ApplicationRef, EventEmitter, Injectable, NgZone} from '@angular/core';
import { Http } from '@angular/http'; import {Http} from '@angular/http';
import * as child_process from 'child_process'; import * as child_process from 'child_process';
import { ChildProcess } from 'child_process'; import {ChildProcess} from 'child_process';
import * as crypto from 'crypto'; import * as crypto from 'crypto';
import { remote } from 'electron'; import {remote} from 'electron';
import * as sudo from 'electron-sudo'; import * as sudo from 'electron-sudo';
import * as fs from 'fs'; import * as fs from 'fs';
import * as glob from 'glob'; import * as glob from 'glob';
...@@ -11,16 +11,17 @@ import * as ini from 'ini'; ...@@ -11,16 +11,17 @@ import * as ini from 'ini';
import * as path from 'path'; import * as path from 'path';
import * as readline from 'readline'; import * as readline from 'readline';
import 'rxjs/Rx'; import 'rxjs/Rx';
import { Observable, Observer } from 'rxjs/Rx'; import {Observable, Observer} from 'rxjs/Rx';
import { Action, App, AppStatus } from './app'; import {Action, App, AppStatus} from './app';
import { AppLocal } from './app-local'; import {AppLocal} from './app-local';
import { DownloadService, DownloadStatus } from './download.service'; import {DownloadService, DownloadStatus} from './download.service';
import { InstallOption } from './install-option'; import {InstallOption} from './install-option';
import { LoginService } from './login.service'; import {LoginService} from './login.service';
import { SettingsService } from './settings.sevices'; import {SettingsService} from './settings.sevices';
import { ComparableSet } from './shared/ComparableSet'; import {ComparableSet} from './shared/ComparableSet';
import Timer = NodeJS.Timer; import Timer = NodeJS.Timer;
import ReadableStream = NodeJS.ReadableStream; import ReadableStream = NodeJS.ReadableStream;
const Logger = { const Logger = {
info: (...message: any[]) => { info: (...message: any[]) => {
console.log('AppService [INFO]: ', ...message); console.log('AppService [INFO]: ', ...message);
...@@ -29,16 +30,19 @@ const Logger = { ...@@ -29,16 +30,19 @@ const Logger = {
console.error('AppService [ERROR]: ', ...message); console.error('AppService [ERROR]: ', ...message);
} }
}; };
interface InstallTask { interface InstallTask {
app: App; app: App;
option: InstallOption; option: InstallOption;
} }
interface InstallStatus { interface InstallStatus {
status: string; status: string;
progress: number; progress: number;
total: number; total: number;
lastItem: string; lastItem: string;
} }
interface Connection { interface Connection {
connection: WebSocket; connection: WebSocket;
address: string | null; address: string | null;
...@@ -49,16 +53,14 @@ declare const System: any; ...@@ -49,16 +53,14 @@ declare const System: any;
@Injectable() @Injectable()
export class AppsService { export class AppsService {
private apps: Map<string, App>;
eventEmitter = new EventEmitter<void>(); eventEmitter = new EventEmitter<void>();
map: Map<string, string> = new Map(); map: Map<string, string> = new Map();
connections = new Map<App, Connection>(); connections = new Map<App, Connection>();
maotama: Promise<ChildProcess>; maotama: Promise<ChildProcess>;
readonly tarPath = process.platform === 'win32' ? readonly tarPath = process.platform === 'win32' ?
path.join(process.env['NODE_ENV'] === 'production' ? process.resourcesPath! : '', 'bin', 'bsdtar.exe') path.join(process.env['NODE_ENV'] === 'production' ? process.resourcesPath! : '', 'bin', 'bsdtar.exe')
: 'bsdtar'; : 'bsdtar';
private apps: Map<string, App>;
constructor(private http: Http, private settingsService: SettingsService, private ref: ApplicationRef, constructor(private http: Http, private settingsService: SettingsService, private ref: ApplicationRef,
private downloadService: DownloadService, private ngZone: NgZone, private loginService: LoginService) { private downloadService: DownloadService, private ngZone: NgZone, private loginService: LoginService) {
...@@ -264,6 +266,8 @@ export class AppsService { ...@@ -264,6 +266,8 @@ export class AppsService {
if (app[key]) { if (app[key]) {
if (app[key][platform]) { if (app[key][platform]) {
app[key] = app[key][platform]; app[key] = app[key][platform];
} else if (platform === 'linux' && app[key].darwin) {
app[key] = app[key].darwin;
} else { } else {
app[key] = null; app[key] = null;
} }
...@@ -475,7 +479,7 @@ export class AppsService { ...@@ -475,7 +479,7 @@ export class AppsService {
} else { } else {
readyToUpdate = app.isReady() && mods.every((mod) => mod.isReady()); readyToUpdate = app.isReady() && mods.every((mod) => mod.isReady());
} }
if (readyToUpdate && (verify || app.local!.version !== app.version )) { if (readyToUpdate && (verify || app.local!.version !== app.version)) {
app.status.status = 'updating'; app.status.status = 'updating';
try { try {
Logger.info('Checking updating: ', app); Logger.info('Checking updating: ', app);
...@@ -1026,8 +1030,7 @@ export class AppsService { ...@@ -1026,8 +1030,7 @@ export class AppsService {
} catch (e) { } catch (e) {
console.log('exception in doInstall', e); console.log('exception in doInstall', e);
throw e; throw e;
} } finally {
finally {
this.eventEmitter.emit(); this.eventEmitter.emit();
} }
......
...@@ -199,7 +199,7 @@ export class DownloadService { ...@@ -199,7 +199,7 @@ export class DownloadService {
} }
async addMetalink (metalink: string, library: string): Promise<string> { async addMetalink (metalink: string, library: string): Promise<string> {
let encodedMeta4 = new Buffer((metalink)).toString('base64'); let encodedMeta4 = Buffer.from((metalink)).toString('base64');
let gidList = await this.aria2.addMetalink(encodedMeta4, {dir: library}); let gidList = await this.aria2.addMetalink(encodedMeta4, {dir: library});
let taskId = this.createId(); let taskId = this.createId();
this.taskMap.set(taskId, gidList); this.taskMap.set(taskId, gidList);
......
...@@ -611,7 +611,7 @@ export class YGOProComponent implements OnInit, OnDestroy { ...@@ -611,7 +611,7 @@ export class YGOProComponent implements OnInit, OnDestroy {
}; };
create_room(room: Room) { create_room(room: Room) {
let options_buffer = new Buffer(6); let options_buffer = Buffer.alloc(6);
// 建主密码 https://docs.google.com/document/d/1rvrCGIONua2KeRaYNjKBLqyG9uybs9ZI-AmzZKNftOI/edit // 建主密码 https://docs.google.com/document/d/1rvrCGIONua2KeRaYNjKBLqyG9uybs9ZI-AmzZKNftOI/edit
options_buffer.writeUInt8((room.private ? 2 : 1) << 4, 1); options_buffer.writeUInt8((room.private ? 2 : 1) << 4, 1);
options_buffer.writeUInt8( options_buffer.writeUInt8(
...@@ -655,7 +655,7 @@ export class YGOProComponent implements OnInit, OnDestroy { ...@@ -655,7 +655,7 @@ export class YGOProComponent implements OnInit, OnDestroy {
} }
join_room(room: Room) { join_room(room: Room) {
let options_buffer = new Buffer(6); let options_buffer = Buffer.alloc(6);
options_buffer.writeUInt8(3 << 4, 1); options_buffer.writeUInt8(3 << 4, 1);
let checksum = 0; let checksum = 0;
for (let i = 1; i < options_buffer.length; i++) { for (let i = 1; i < options_buffer.length; i++) {
...@@ -675,7 +675,7 @@ export class YGOProComponent implements OnInit, OnDestroy { ...@@ -675,7 +675,7 @@ export class YGOProComponent implements OnInit, OnDestroy {
} }
join_private(password: string) { join_private(password: string) {
let options_buffer = new Buffer(6); let options_buffer = Buffer.alloc(6);
options_buffer.writeUInt8(5 << 4, 1); options_buffer.writeUInt8(5 << 4, 1);
let checksum = 0; let checksum = 0;
for (let i = 1; i < options_buffer.length; i++) { for (let i = 1; i < options_buffer.length; i++) {
......
...@@ -12,7 +12,7 @@ function handleElevate() { ...@@ -12,7 +12,7 @@ function handleElevate() {
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
require('electron').app.dock.hide(); require('electron').app.dock.hide();
} }
let elevate = JSON.parse(new Buffer(process.argv[2], 'base64').toString()); let elevate = JSON.parse(Buffer.from(process.argv[2], 'base64').toString());
require('net').connect(elevate['ipc'], function () { require('net').connect(elevate['ipc'], function () {
process.send = (message, sendHandle, options, callback) => this.write(JSON.stringify(message) + require('os').EOL, callback); process.send = (message, sendHandle, options, callback) => this.write(JSON.stringify(message) + require('os').EOL, callback);
this.on('end', () => process.emit('disconnect')); this.on('end', () => process.emit('disconnect'));
......
...@@ -2,7 +2,7 @@ const raw = require("raw-socket"); ...@@ -2,7 +2,7 @@ const raw = require("raw-socket");
let socket = raw.createSocket({protocol: raw.Protocol.UDP}); let socket = raw.createSocket({protocol: raw.Protocol.UDP});
let connect = (local_port, remote_port, remote_address)=> { let connect = (local_port, remote_port, remote_address)=> {
let buffer = new Buffer(9); let buffer = Buffer.alloc(9);
buffer.writeUInt16BE(local_port, 0); buffer.writeUInt16BE(local_port, 0);
buffer.writeUInt16BE(remote_port, 2); buffer.writeUInt16BE(remote_port, 2);
buffer.writeUInt16BE(buffer.length, 4); buffer.writeUInt16BE(buffer.length, 4);
...@@ -21,4 +21,4 @@ process.on('message', (message)=> { ...@@ -21,4 +21,4 @@ process.on('message', (message)=> {
process.on('disconnect', process.exit); process.on('disconnect', process.exit);
process.send('initialized'); process.send('initialized');
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment