Commit bb825989 authored by 神楽坂玲奈's avatar 神楽坂玲奈

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

parents 14834cc8 35158c17
...@@ -13,7 +13,7 @@ const Aria2 = require('aria2'); ...@@ -13,7 +13,7 @@ const Aria2 = require('aria2');
@Injectable() @Injectable()
export class DownloadService { export class DownloadService {
aria2 = new Aria2(); aria2 = new Aria2();
baseURL = 'http://thief.mycard.moe/metalinks/' baseURL = 'https://thief.mycard.moe/metalinks/';
appGidMap = new Map<App,string>(); appGidMap = new Map<App,string>();
gidAppMap = new Map<string,App>(); gidAppMap = new Map<string,App>();
eventEmitter = new EventEmitter(); eventEmitter = new EventEmitter();
...@@ -107,6 +107,9 @@ export class DownloadService { ...@@ -107,6 +107,9 @@ export class DownloadService {
return app; return app;
} else { } else {
let meta4link = `${this.baseURL}${id}.meta4`; let meta4link = `${this.baseURL}${id}.meta4`;
if (id === "ygopro") {
meta4link = `${this.baseURL}${id}-${process.platform}.meta4`
}
let response = await this.http.get(meta4link).toPromise(); let response = await this.http.get(meta4link).toPromise();
let meta4 = btoa(response.text()); let meta4 = btoa(response.text());
let gid = (await this.aria2.addMetalink(meta4, {dir: path}))[0]; let gid = (await this.aria2.addMetalink(meta4, {dir: path}))[0];
......
...@@ -24,41 +24,41 @@ export class InstallService { ...@@ -24,41 +24,41 @@ export class InstallService {
installingQueue: Set<App> = new Set(); installingQueue: Set<App> = new Set();
checksumUri = "http://thief.mycard.moe/checksums/"; checksumUri = "https://thief.mycard.moe/checksums/";
constructor(private http: Http, private appsService: AppsService) { constructor(private http: Http, private appsService: AppsService) {
if (process.platform === "win32") { if (process.platform === "win32") {
this.tarPath = path.join(process.resourcesPath, 'bin/tar.exe'); this.tarPath = path.join(process.resourcesPath, 'bin', 'bsdtar.exe');
} else { } else {
this.tarPath = "tar" this.tarPath = "bsdtar"
} }
} }
createDirectory(dir: string) { createDirectory(dir: string) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject)=> {
mkdirp(dir, resolve); mkdirp(dir, resolve);
}) })
} }
getComplete(app: App): Promise<App> { getComplete(app: App): Promise<App> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject)=> {
this.eventEmitter.once(app.id, (complete) => { this.eventEmitter.once(app.id, (complete)=> {
resolve(); resolve();
}); });
}); });
} }
extract(file: string, destPath: string) { extract(file: string, destPath: string) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject)=> {
let tarProcess = child_process.spawn(this.tarPath, ['xvf', file, '-C', destPath]); let tarProcess = child_process.spawn(this.tarPath, ['xvf', file, '-C', destPath]);
let rl = readline.createInterface({ let rl = readline.createInterface({
input: <ReadableStream>tarProcess.stderr, input: <ReadableStream>tarProcess.stderr,
}); });
rl.on('line', (input) => { rl.on('line', (input)=> {
console.log(input); console.log(input);
}); });
tarProcess.on('exit', (code) => { tarProcess.on('exit', (code)=> {
if (code === 0) { if (code === 0) {
resolve(); resolve();
} else { } else {
...@@ -72,26 +72,26 @@ export class InstallService { ...@@ -72,26 +72,26 @@ export class InstallService {
let action = app.actions.get('install'); let action = app.actions.get('install');
if (action) { if (action) {
let env = Object.assign({}, action.env); let env = Object.assign({}, action.env);
let command: string[] = []; let command:string[] = [];
command.push(path.join(appPath, action.execute)); command.push(path.join(appPath, action.execute));
command.push(...action.args); command.push(...action.args);
let open = action.open; let open = action.open;
if (open) { if (open) {
let openAction: any = open.actions.get("main"); let openAction:any = open.actions.get("main");
env = Object.assign(env, openAction.env); env = Object.assign(env, openAction.env);
command.unshift(...openAction.args); command.unshift(...openAction.args);
command.unshift(path.join((<AppLocal>open.local).path, openAction.execute)); command.unshift(path.join((<AppLocal>open.local).path, openAction.execute));
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject)=> {
let child = child_process.spawn(<string>command.shift(), command, { let child = child_process.spawn(<string>command.shift(), command, {
env: env, env: env,
stdio: 'inherit', stdio: 'inherit',
shell: true, shell: true,
}); });
child.on('error', (error) => { child.on('error', (error)=> {
console.log(error); console.log(error);
}); });
child.on('exit', (code) => { child.on('exit', (code)=> {
if (code === 0) { if (code === 0) {
resolve(); resolve();
} else { } else {
...@@ -112,7 +112,7 @@ export class InstallService { ...@@ -112,7 +112,7 @@ export class InstallService {
let backupPath = path.join((<AppLocal>app.local).path, "backup"); let backupPath = path.join((<AppLocal>app.local).path, "backup");
await this.createDirectory(backupPath); await this.createDirectory(backupPath);
for (let file of files) { for (let file of files) {
await new Promise((resolve, reject) => { await new Promise((resolve, reject)=> {
let oldPath = path.join((<AppLocal>app.local).path, file); let oldPath = path.join((<AppLocal>app.local).path, file);
let newPath = path.join(backupPath, file); let newPath = path.join(backupPath, file);
fs.rename(oldPath, newPath, resolve); fs.rename(oldPath, newPath, resolve);
...@@ -121,8 +121,12 @@ export class InstallService { ...@@ -121,8 +121,12 @@ export class InstallService {
} }
async getChecksumFile(app: App): Promise<Map<string,string> > { async getChecksumFile(app: App): Promise<Map<string,string> > {
let checksumMap: Map<string,string> = await this.http.get(this.checksumUri + app.id) let checksumUrl = this.checksumUri + app.id;
.map((response) => { if (app.id === "ygopro") {
checksumUrl = this.checksumUri + app.id + "-" + process.platform;
}
let checksumMap: Map<string,string> = await this.http.get(checksumUrl)
.map((response)=> {
let map = new Map<string,string>(); let map = new Map<string,string>();
for (let line of response.text().split('\n')) { for (let line of response.text().split('\n')) {
if (line !== "") { if (line !== "") {
...@@ -138,12 +142,15 @@ export class InstallService { ...@@ -138,12 +142,15 @@ export class InstallService {
async doInstall() { async doInstall() {
for (let app of this.installQueue.keys()) { for (let app of this.installQueue.keys()) {
let depInstalled = app.findDependencies() let depInstalled = app.findDependencies()
.every((dependency) => dependency.isInstalled()); .every((dependency)=>dependency.isInstalled());
if (depInstalled && !this.installingQueue.has(app)) { if (depInstalled && !this.installingQueue.has(app)) {
this.installingQueue.add(app); this.installingQueue.add(app);
let options = <InstallConfig>this.installQueue.get(app); let options = <InstallConfig>this.installQueue.get(app);
let checksumMap = await this.getChecksumFile(app); let checksumMap = await this.getChecksumFile(app);
let packagePath = path.join(options.installLibrary, 'downloading', `${app.id}.tar.xz`); let packagePath = path.join(options.installLibrary, 'downloading', `${app.id}.tar.xz`);
if (app.id === "ygopro") {
packagePath = path.join(options.installLibrary, 'downloading', `${app.id}-${process.platform}.tar.xz`);
}
let destPath: string; let destPath: string;
if (app.parent) { if (app.parent) {
let differenceSet = new Set<string>(); let differenceSet = new Set<string>();
...@@ -187,15 +194,15 @@ export class InstallService { ...@@ -187,15 +194,15 @@ export class InstallService {
} }
deleteFile(file: string): Promise<string> { deleteFile(file: string): Promise<string> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject)=> {
fs.lstat(file, (err, stats) => { fs.lstat(file, (err, stats)=> {
if (err) return resolve(path); if (err) return resolve(path);
if (stats.isDirectory()) { if (stats.isDirectory()) {
fs.rmdir(file, (err) => { fs.rmdir(file, (err)=> {
resolve(file); resolve(file);
}); });
} else { } else {
fs.unlink(file, (err) => { fs.unlink(file, (err)=> {
resolve(file); resolve(file);
}); });
} }
...@@ -222,7 +229,7 @@ export class InstallService { ...@@ -222,7 +229,7 @@ export class InstallService {
await this.deleteFile(oldFile); await this.deleteFile(oldFile);
if (app.parent) { if (app.parent) {
let backFile = path.join((<AppLocal>app.local).path, "backup", file); let backFile = path.join((<AppLocal>app.local).path, "backup", file);
await new Promise((resolve, reject) => { await new Promise((resolve, reject)=> {
fs.rename(backFile, oldFile, resolve); fs.rename(backFile, oldFile, resolve);
}); });
} }
......
...@@ -39,8 +39,8 @@ export class LobbyComponent implements OnInit { ...@@ -39,8 +39,8 @@ export class LobbyComponent implements OnInit {
} }
async updateApp() { async updateApp() {
let updateServer = "http://thief.mycard.moe/update/metalinks/"; let updateServer = "https://thief.mycard.moe/update/metalinks/";
let checksumServer = "http://thief.mycard.moe/checksums/"; let checksumServer = "https://thief.mycard.moe/checksums/";
for (let app of this.apps.values()) { for (let app of this.apps.values()) {
if (app.isInstalled() && app.version != (<AppLocal>app.local).version) { if (app.isInstalled() && app.version != (<AppLocal>app.local).version) {
let checksumMap = await this.installService.getChecksumFile(app); let checksumMap = await this.installService.getChecksumFile(app);
......
...@@ -46,7 +46,7 @@ interface SystemConf { ...@@ -46,7 +46,7 @@ interface SystemConf {
} }
interface Server { interface Server {
id: string id?: string
url: string url: string
address: string address: string
port: number port: number
...@@ -76,8 +76,7 @@ export class YGOProComponent implements OnInit { ...@@ -76,8 +76,7 @@ export class YGOProComponent implements OnInit {
app: App; app: App;
decks: string[] = []; decks: string[] = [];
current_deck: string; current_deck: string;
system_conf;
system_conf = path.join((<AppLocal>this.app.local).path, 'system.conf');
numfont = {'darwin': ['/System/Library/Fonts/PingFang.ttc']}; numfont = {'darwin': ['/System/Library/Fonts/PingFang.ttc']};
textfont = {'darwin': ['/System/Library/Fonts/PingFang.ttc']}; textfont = {'darwin': ['/System/Library/Fonts/PingFang.ttc']};
...@@ -109,10 +108,12 @@ export class YGOProComponent implements OnInit { ...@@ -109,10 +108,12 @@ export class YGOProComponent implements OnInit {
connections: WebSocket[] = []; connections: WebSocket[] = [];
constructor(private http: Http, private appsService: AppsService, private loginService: LoginService, private ref: ChangeDetectorRef) { constructor(private http: Http, private appsService: AppsService, private loginService: LoginService, private ref: ChangeDetectorRef) {
this.refresh();
} }
ngOnInit() { ngOnInit() {
this.system_conf = path.join((<AppLocal>this.app.local).path, 'system.conf');
this.refresh();
let modal = $('#game-list-modal'); let modal = $('#game-list-modal');
modal.on('show.bs.modal', (event) => { modal.on('show.bs.modal', (event) => {
......
This diff is collapsed.
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