Commit 8396d6d0 authored by 神楽坂玲奈's avatar 神楽坂玲奈

Merge branch 'v3' of github.com:mycard/mycard into v3

parents f54873eb 3602ddb6
......@@ -21,12 +21,18 @@ export class DownloadService {
open = this.aria2.open();
constructor(private ngZone: NgZone, private http: Http) {
this.aria2.onDownloadComplete = (gid)=> {
let app = this.gidAppMap.get(gid.gid);
this.aria2.onDownloadComplete = (result)=> {
let app = this.gidAppMap.get(result.gid);
if (app) {
this.appGidMap.delete(app);
this.gidAppMap.delete(gid.gid);
this.gidAppMap.delete(result.gid);
this.eventEmitter.emit(app.id, 'complete');
//
}
if (this.map.get(result.gid)) {
this.map.get(result.gid).complete();
this.map.delete(result.gid);
}
}
}
......@@ -73,6 +79,26 @@ export class DownloadService {
return tasks;
}
map: Map<string,any> = new Map();
async addMetalink(metalink: string, library: string) {
let meta4 = btoa(metalink);
let gid = ( await this.aria2.addMetalink(meta4, {dir: library}))[0];
return Observable.create((observer)=> {
this.map.set(gid, observer);
let interval;
this.ngZone.runOutsideAngular(()=> {
interval = setInterval(async()=> {
let status = await this.aria2.tellStatus(gid);
this.map.get(gid).next(status);
}, 1000)
});
return ()=> {
clearInterval(interval);
}
});
}
async addUri(app: App, path: string): Promise<App> {
let id = app.id;
await this.open;
......
......@@ -56,6 +56,7 @@ export class InstallService {
input: <ReadableStream>tarProcess.stderr,
});
rl.on('line', (input)=> {
console.log(input);
});
tarProcess.on('exit', (code)=> {
if (code === 0) {
......@@ -119,14 +120,8 @@ export class InstallService {
}
}
async doInstall() {
for (let app of this.installQueue.keys()) {
let depInstalled = app.findDependencies()
.every((dependency)=>dependency.isInstalled());
if (depInstalled && !this.installingQueue.has(app)) {
this.installingQueue.add(app);
let options = this.installQueue.get(app);
let checksumMap: Map<string,string> = await this.http.get(`${this.checksumUri}${app.id}`)
async getChecksumFile(app: App): Promise<Map<string,string> > {
let checksumMap: Map<string,string> = await this.http.get(this.checksumUri + app.id)
.map((response)=> {
let map = new Map<string,string>();
for (let line of response.text().split('\n')) {
......@@ -137,7 +132,17 @@ export class InstallService {
}
return map;
}).toPromise();
return checksumMap;
}
async doInstall() {
for (let app of this.installQueue.keys()) {
let depInstalled = app.findDependencies()
.every((dependency)=>dependency.isInstalled());
if (depInstalled && !this.installingQueue.has(app)) {
this.installingQueue.add(app);
let options = this.installQueue.get(app);
let checksumMap = await this.getChecksumFile(app);
let packagePath = path.join(options.installLibrary, 'downloading', `${app.id}.tar.xz`);
let destPath: string;
if (app.parent) {
......@@ -198,22 +203,22 @@ export class InstallService {
})
}
async uninstall(app: App) {
async uninstall(app: App, restore = true) {
if (!app.parent) {
let children = this.appsService.findChildren(app);
for (let child of children) {
if(child.isInstalled()) {
if (child.isInstalled()) {
await this.uninstall(child);
}
}
}
let files = Array.from(app.local.files.keys()).sort().reverse();
console.log(files);
for (let file of files) {
let oldFile = file;
if (!path.isAbsolute(file)) {
oldFile = path.join(app.local.path, file);
}
if (restore) {
await this.deleteFile(oldFile);
if (app.parent) {
let backFile = path.join(app.local.path, "backup", file);
......@@ -222,6 +227,7 @@ export class InstallService {
});
}
}
}
if (app.parent) {
await this.deleteFile(path.join(app.local.path, "backup"));
......
......@@ -6,6 +6,11 @@ import {AppsService} from "./apps.service";
import {LoginService} from "./login.service";
import {App, Category} from "./app";
import {DownloadService} from "./download.service";
import {InstallService} from "./install.service";
import {Http} from "@angular/http";
import * as path from 'path';
import {InstallConfig} from "./install-config";
@Component({
selector: 'lobby',
templateUrl: 'app/lobby.component.html',
......@@ -17,7 +22,8 @@ export class LobbyComponent implements OnInit {
currentApp: App;
private apps: Map<string,App>;
constructor(private appsService: AppsService, private loginService: LoginService,private downloadService:DownloadService) {
constructor(private appsService: AppsService, private loginService: LoginService, private downloadService: DownloadService,
private installService: InstallService, private http: Http) {
this.candy_url = './candy/index.html?jid=' + this.loginService.user.username + '@mycard.moe&password=' + this.loginService.user.external_id + '&nickname=' + this.loginService.user.username + '&autojoin=ygopro_china_north@conference.mycard.moe'
}
......@@ -26,7 +32,70 @@ export class LobbyComponent implements OnInit {
.then((apps)=> {
this.apps = apps;
this.currentApp = this.apps.get("th06");
this.updateApp();
})
}
async updateApp() {
let updateServer = "http://thief.mycard.moe/update/metalinks/";
let checksumServer = "http://thief.mycard.moe/checksums/";
for (let app of this.apps.values()) {
if (app.isInstalled() && app.version != app.local.version) {
let checksumMap = await this.installService.getChecksumFile(app);
let filesMap = app.local.files;
let deleteList = [];
let addList = [];
let changeList = [];
for (let [file,checksum] of filesMap) {
let t = checksumMap.get(file);
if (!t) {
deleteList.push(file);
} else if (t !== checksum) {
changeList.push(file);
}
}
for (let file of checksumMap.keys()) {
if (!filesMap.has(file)) {
changeList.push(file);
}
}
let metalink = await this.http.post(updateServer + app.id, changeList).map((response)=>response.text())
.toPromise();
let meta = new DOMParser().parseFromString(metalink, "text/xml");
let filename = meta.getElementsByTagName('file')[0].getAttribute('name');
let dir = path.join(path.dirname(app.local.path), "downloading");
let a = await this.downloadService.addMetalink(metalink, dir);
await new Promise((resolve, reject)=> {
a.subscribe((status)=> {
console.log(status);
}, (err)=> {
reject()
}, ()=> {
resolve();
});
});
for (let file of deleteList) {
await this.installService.deleteFile(file);
}
app.local.version=app.version;
app.local.files = checksumMap;
localStorage.setItem(app.id, JSON.stringify(app.local));
await this.installService.extract(path.join(dir, filename), app.local.path);
let children = this.appsService.findChildren(app);
for (let child of children) {
if (child.isInstalled()) {
await this.installService.uninstall(child, false);
this.installService.add(child, new InstallConfig(child, path.dirname((app.local.path))));
await this.installService.getComplete(child);
console.log("282828")
}
}
}
}
}
chooseApp(app: App) {
......
import {Component, Renderer, ChangeDetectorRef} from "@angular/core";
import {Component, Renderer, ChangeDetectorRef, OnInit} from "@angular/core";
import {TranslateService} from "ng2-translate";
import {remote} from "electron";
import {LoginService} from "./login.service";
......@@ -11,13 +11,17 @@ import {LoginService} from "./login.service";
})
export class MyCardComponent {
export class MyCardComponent implements OnInit {
currentPage: string = "lobby";
platform = process.platform;
currentWindow = remote.getCurrentWindow();
window = window;
ngOnInit() {
}
constructor(private renderer: Renderer, private translate: TranslateService, private loginService: LoginService, private ref: ChangeDetectorRef) {
renderer.listenGlobal('window', 'message', (event) => {
console.log(event);
......
/**
* Created by weijian on 2016/11/6.
*/
export class Task {
downloadUrl: string;
}
......@@ -62,6 +62,7 @@
]
},
"version": {
"win32": "1.09",
"darwin": "1.06"
},
"download": {
......
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