Commit 95f65352 authored by wudizhanche1000's avatar wudizhanche1000

Merge remote-tracking branch 'origin/v3' into v3

# Conflicts:
#	app/apps.service.ts
#	index.js
parents 05e831bd 783a2327
......@@ -8,10 +8,10 @@
<!--应用变更中-->
<div class="actions" *ngIf="currentApp.isInstalled() && !currentApp.isReady()">
<div>
<span *ngIf="currentApp.isDownloading()">正在下载</span>
<span *ngIf="currentApp.isInstalling()">正在安装...</span>
<span *ngIf="currentApp.isUninstalling()">正在卸载...</span>
<span *ngIf="currentApp.isWaiting()">等待安装...</span>
<span i18n *ngIf="currentApp.isDownloading()">正在下载</span>
<span i18n *ngIf="currentApp.isInstalling()">正在安装...</span>
<span i18n *ngIf="currentApp.isUninstalling()">正在卸载...</span>
<span i18n *ngIf="currentApp.isWaiting()">等待安装...</span>
<span *ngIf="currentApp.status.total">{{(currentApp.status.progress/currentApp.status.total * 100).toFixed()}}%</span>
<span>{{currentApp.progressMessage()}}</span>
</div>
......
......@@ -74,7 +74,7 @@ export class AppDetailComponent implements OnInit {
async installMod(mod: App) {
let option = new InstallOption(mod, path.dirname(mod.parent.local!.path));
let option = new InstallOption(mod, path.dirname(mod.parent!.local!.path));
await this.install(mod, option, {});
}
......
......@@ -52,7 +52,7 @@ export class App {
author: string; // English Only
homepage: string;
category: Category;
parent: App;
parent?: App;
get download(): string {
let downloadUrl = "https://thief.mycard.moe/metalinks/";
......
import {Injectable, ApplicationRef, EventEmitter} from "@angular/core";
import {Http} from "@angular/http";
import {App, AppStatus, Action} from "./app";
import {App, AppStatus, Action, Category} from "./app";
import {SettingsService} from "./settings.sevices";
import * as fs from "fs";
import * as path from "path";
......@@ -54,14 +54,37 @@ export class AppsService {
private downloadService: DownloadService) {
}
loadApps() {
return this.http.get('./apps.json')
.toPromise()
.then((response) => {
let data = response.json();
this.apps = this.loadAppsList(data);
return this.apps;
});
async loadApps() {
let data = await this.http.get('./apps.json').map((response) => response.json()).toPromise();
this.apps = this.loadAppsList(data);
return this.apps;
}
async migrate() {
await this.migrate_v2_ygopro();
await this.migreate_library();
}
async migrate_v2_ygopro() {
// 导入萌卡 v2 的 YGOPRO
try {
const legacy_ygopro_path = require(path.join('db.json')).local.ygopro.path;
if (legacy_ygopro_path) {
// 导入YGOPRO
}
} catch (error) {
}
}
async migreate_library() {
let libraries = this.settingsService.getLibraries();
for (let library of libraries) {
if (library.path == path.join(remote.app.getPath("appData"), "library")) {
library.path = path.join(remote.app.getPath("appData"), "MyCardLibrary")
}
}
localStorage.setItem(SettingsService.SETTING_LIBRARY, JSON.stringify(libraries));
}
loadAppsList = (data: any): Map<string,App> => {
......@@ -84,12 +107,14 @@ export class AppsService {
}
// 去除无关语言
for (let key of ['name', 'description']) {
let value = app[key][locale];
if (!value) {
value = app[key]["zh-CN"];
for (let key of ['name', 'description', 'news']) {
if (app[key]) {
let value = app[key][locale];
if (!value) {
value = app[key]["zh-CN"];
}
app[key] = value;
}
app[key] = value;
}
// 去除平台无关的内容
......@@ -108,8 +133,9 @@ export class AppsService {
}
// 设置App关系
for (let [id] of apps) {
let temp = apps.get(id)!.actions;
for (let [id,app] of apps) {
let temp=app.actions;
let map = new Map<string,any>();
for (let action of Object.keys(temp)) {
let openId = temp[action]["open"];
......@@ -118,10 +144,9 @@ export class AppsService {
}
map.set(action, temp[action]);
}
apps.get(id)!.actions = map;
app.actions = map;
for (let key of ['dependencies', 'references', 'parent']) {
let app = apps.get(id)!;
let value = app[key];
if (value) {
if (Array.isArray(value)) {
......@@ -135,6 +160,26 @@ export class AppsService {
}
}
}
// 为语言包置一个默认的名字
// 这里简易做个 i18n 的 hack
const lang = {
'en-US': {
'en-US': 'English',
'zh-CN': 'Simplified Chinese',
'zh-TW': 'Traditional Chinese',
'language_pack': 'Language'
},
'zh-CN': {
'en-US': '英文',
'zh-CN': '简体中文',
'zh-TW': '繁体中文',
'language_pack': '语言包'
}
};
if (!app.name && app.category == Category.module && app.tags.includes('language') && app.parent) {
app.name = `${app.parent.name} ${lang[locale].language_pack} (${app.locales.map((l) => lang[locale][l]).join(', ')})`
}
}
return apps;
};
......@@ -332,18 +377,9 @@ export class AppsService {
remote.getCurrentWindow().minimize();
}
// 如果有actions.main.execuate, 定位那个execuate的顶层路径
// 如果没有,定位目录里面任意一个顶级文件
browse(app: App) {
if (app.local) {
let appPath = app.local.path;
fs.readdir(appPath, (err, files) => {
if (!err) {
remote.shell.showItemInFolder(appPath + "/.");
} else {
Logger.error("Browser Window Error:", appPath, err);
}
});
remote.shell.showItemInFolder(app.local.path + "/.");
}
}
......@@ -371,7 +407,6 @@ export class AppsService {
if (connection) {
connection.connection.close();
}
console.log(server.url);
connection = {connection: new WebSocket(server.url), address: null};
let id: Timer | null;
this.connections.set(app, connection);
......
......@@ -2,7 +2,7 @@
<div id="main">
<div id="apps" *ngIf="apps">
<span *ngIf="grouped_apps.installed">已安装</span>
<span i18n *ngIf="grouped_apps.installed">已安装</span>
<ul *ngIf="grouped_apps.installed" class="nav nav-sidebar">
<li *ngFor="let app of grouped_apps.installed" [class.active]="app===currentApp">
<i *ngIf="!app.isReady() && !app.status.total" class="spin fa fa-circle-o-notch fa-spin fa-fw"></i>
......@@ -17,13 +17,13 @@
</li>
</ul>
<span *ngIf="grouped_apps.recommend">推荐</span>
<span i18n *ngIf="grouped_apps.recommend">推荐</span>
<ul *ngIf="grouped_apps.recommend" class="nav nav-sidebar">
<li *ngFor="let app of grouped_apps.recommend" [class.active]="app===currentApp">
<a (click)="chooseApp(app)" href="#">{{app.name}}</a>
</li>
</ul>
<span *ngIf="grouped_apps.mysterious">迷之物体</span>
<span i18n *ngIf="grouped_apps.mysterious">迷之物体</span>
<ul *ngIf="grouped_apps.mysterious" class="nav nav-sidebar">
<li *ngFor="let app of grouped_apps.mysterious" [class.active]="app===currentApp">
<a (click)="chooseApp(app)" href="#">{{app.name}}</a>
......@@ -33,7 +33,7 @@
max="{{app.status.total}}"></progress>
</li>
</ul>
<span *ngIf="grouped_apps.touhou">东方 Project</span>
<span i18n *ngIf="grouped_apps.touhou">东方 Project</span>
<ul *ngIf="grouped_apps.touhou" class="nav nav-sidebar">
<li *ngFor="let app of grouped_apps.touhou" [class.active]="app===currentApp">
<a (click)="chooseApp(app)" href="#">{{app.name}}</a>
......@@ -43,13 +43,13 @@
max="{{app.status.total}}"></progress>
</li>
</ul>
<span *ngIf="grouped_apps.touhou_pc98">东方旧作</span>
<span i18n *ngIf="grouped_apps.touhou_pc98">东方旧作</span>
<ul *ngIf="grouped_apps.touhou_pc98" class="nav nav-sidebar">
<li *ngFor="let app of grouped_apps.touhou_pc98" [class.active]="app===currentApp">
<a (click)="chooseApp(app)" href="#">{{app.name}}</a>
</li>
</ul>
<span *ngIf="grouped_apps.runtime_installed">已安装的运行库</span>
<span i18n *ngIf="grouped_apps.runtime_installed">已安装的运行库</span>
<ul *ngIf="grouped_apps.runtime_installed" class="nav nav-sidebar">
<li *ngFor="let app of grouped_apps.runtime_installed" [class.active]="app===currentApp">
<a (click)="chooseApp(app)" href="#">{{app.name}}</a>
......
......@@ -29,6 +29,7 @@ export class LobbyComponent implements OnInit {
async ngOnInit() {
this.apps = await this.appsService.loadApps();
await this.appsService.migrate();
this.chooseApp(Array.from(this.apps.values()).find(app => app.isInstalled()) || this.apps.get("ygopro")!);
// 初始化聊天室
......
......@@ -14,7 +14,7 @@ declare const $: any;
export class MyCardComponent implements OnInit {
currentPage: string = "lobby";
update_status: string | undefined;
update_status: string | undefined = remote.getGlobal('update_status');
update_error: string | undefined;
currentWindow = remote.getCurrentWindow();
window = window;
......
......@@ -2,7 +2,6 @@
* Created by zh99998 on 16/9/2.
*/
import {Component, OnInit, ChangeDetectorRef, Input} from "@angular/core";
import {AppsService} from "./apps.service";
import * as fs from "fs";
import * as path from "path";
import * as crypto from "crypto";
......@@ -15,7 +14,7 @@ import {App} from "./app";
import {Http, Headers, URLSearchParams} from "@angular/http";
import "rxjs/Rx";
import {ISubscription} from "rxjs/Subscription";
import {AppLocal} from "./app-local";
import {SettingsService} from "./settings.sevices";
declare const $: any;
......@@ -109,7 +108,7 @@ export class YGOProComponent implements OnInit {
connections: WebSocket[] = [];
constructor(private http: Http, private appsService: AppsService, private loginService: LoginService, private ref: ChangeDetectorRef) {
constructor(private http: Http, private settingsService: SettingsService, private loginService: LoginService, private ref: ChangeDetectorRef) {
switch (process.platform) {
case 'darwin':
this.numfont = ['/System/Library/Fonts/SFNSTextCondensed-Bold.otf'];
......@@ -117,7 +116,7 @@ export class YGOProComponent implements OnInit {
break;
case 'win32':
this.numfont = [path.join(process.env['SystemRoot'], 'Fonts', 'arialbd.ttf')];
this.textfont = [path.join(process.env['SystemRoot'], 'Fonts', 'simsun.ttc')];
this.textfont = [path.join(process.env['SystemRoot'], 'Fonts', 'msyh.ttc'), path.join(process.env['SystemRoot'], 'Fonts', 'msyh.ttf'), path.join(process.env['SystemRoot'], 'Fonts', 'simsun.ttc')];
break;
}
}
......@@ -208,7 +207,7 @@ export class YGOProComponent implements OnInit {
}
}
if (!await this.get_font([data.textfont.split(' ', 2)[0]])) {
if (data.textfont == 'c:/windows/fonts/simsun.ttc 14' || !await this.get_font([data.textfont.split(' ', 2)[0]])) {
let font = await this.get_font(this.textfont);
if (font) {
data['textfont'] = `${font} 14`
......@@ -258,10 +257,51 @@ export class YGOProComponent implements OnInit {
return this.join('AI#' + name, this.servers[0])
}
start_game(args: string[]) {
async start_game(args: string[]) {
let win = remote.getCurrentWindow();
win.minimize();
console.log(path.join(this.app.local!.path, this.app.actions.get('main')!.execute), args, {cwd: this.app.local!.path});
let locale = this.settingsService.getLocale();
if (localStorage.getItem('ygopro-locale') != locale) {
console.log(`try convert ygopro locale to ${locale}`)
try {
await new Promise((resolve, reject) => {
let source = fs.createReadStream(path.join(this.app.local!.path, 'locales', locale, 'strings.conf'));
source.on('open', (error: Error) => {
let destination = fs.createWriteStream(path.join(this.app.local!.path, 'strings.conf'));
source.pipe(destination);
destination.on('error', (error: Error) => {
reject(error)
});
destination.on('close', () => {
resolve()
})
});
source.on('error', (error: Error) => {
reject(error)
});
});
await new Promise((resolve, reject) => {
let source = fs.createReadStream(path.join(this.app.local!.path, 'locales', locale, 'cards.cdb'));
source.on('open', (error: Error) => {
let destination = fs.createWriteStream(path.join(this.app.local!.path, 'cards.cdb'));
source.pipe(destination);
destination.on('error', (error: Error) => {
reject(error)
});
destination.on('close', () => {
resolve()
})
});
source.on('error', (error: Error) => {
reject(error)
});
});
localStorage.setItem('ygopro-locale', locale)
console.log(`convert ygopro locale to ${locale} success`)
} catch (error) {
console.error(`convert ygopro locale to ${locale} failed`, error)
}
}
return new Promise((resolve, reject) => {
let child = child_process.spawn(path.join(this.app.local!.path, this.app.actions.get('main')!.execute), args, {
cwd: this.app.local!.path,
......
This diff is collapsed.
......@@ -16,6 +16,36 @@
<source>切换账号</source>
<target>Change Account</target>
</trans-unit>
<trans-unit datatype="html" id="1761e51e36b01ae1e0012914bd58aa2a741d0401">
<source>已安装</source>
<target>Installed</target>
</trans-unit>
<trans-unit datatype="html" id="69f3fab778e92fcec3a8c38d53d771a36e6d5230">
<source>推荐</source>
<target>Recommend</target>
</trans-unit>
<trans-unit datatype="html" id="fc570ecca13755cb4a92e7513fbd55c2d412f23c">
<source>迷之物体</source>
<target>Something</target>
</trans-unit>
<trans-unit datatype="html" id="0873cd6df2d1f1016e02526aa9ba32415c1a11d8">
<source>东方 Project</source>
<target>Touhou Project</target>
</trans-unit>
<trans-unit datatype="html" id="785db32107cc0b47564b05381a1d782021d77c67">
<source>东方旧作</source>
<target>Touhou old series</target>
</trans-unit>
<trans-unit datatype="html" id="817376261844eb7eb0c035ed0e3fce744a96b6d9">
<source>已安装的运行库</source>
<target>Installed Runtime Library</target>
</trans-unit>
<trans-unit datatype="html" id="a8cae935472a05e1c8c9be436bb7b1bdea96a54a">
<source>安装</source>
......@@ -26,11 +56,21 @@
<source>导入</source>
<target>Import</target>
</trans-unit>
<trans-unit datatype="html" id="8bb533b37ee18bf8d09df19b4d7234b38f134909">
<source>正在下载</source>
<target>Downloading...</target>
</trans-unit>
<trans-unit datatype="html" id="2fe99d94b20d6f8aba7814d8657037ec9d69d36c">
<source>正在安装...</source>
<target>Installing...</target>
</trans-unit>
<trans-unit datatype="html" id="bea72fe35b7b9933e126b6ee3a6828c307ccc3d4">
<source>正在卸载...</source>
<target>UnInstalling...</target>
</trans-unit>
<trans-unit datatype="html" id="e5ee7e692c816893b6fd2f9375e6d8303cd794cd">
<source>等待安装...</source>
......@@ -103,12 +143,18 @@
</trans-unit>
<trans-unit datatype="html" id="4809edca33b1a07d7d6e8905287d3825e676f2c8">
<source>安装 <x id="INTERPOLATION"/></source>
<target>Install <x id="INTERPOLATION"/></target>
<source>安装
<x id="INTERPOLATION"/>
</source>
<target>Install
<x id="INTERPOLATION"/>
</target>
</trans-unit>
<trans-unit datatype="html" id="f8e60167c7a0871ccf40ed2a0750311411dfd665">
<source>即将开始安装 <x id="INTERPOLATION"/></source>
<source>即将开始安装
<x id="INTERPOLATION"/>
</source>
<target>Preparing Installation
<x id="INTERPOLATION"/>
</target>
......@@ -138,11 +184,6 @@
<source>创建桌面快捷方式</source>
<target>Create Desktop Shortcut</target>
</trans-unit>
<trans-unit datatype="html" id="2af1068491573803bc4756c4f94a689155370d9c">
<source>扩展内容</source>
<target>Expansion</target>
</trans-unit>
<trans-unit datatype="html" id="2ba33dd61b1ac70666322680f248e5336b3ee69a">
<source>依赖:</source>
......@@ -310,7 +351,10 @@
</trans-unit>
<trans-unit datatype="html" id="4baa1360b4d635000fc5e14a6e7376f46ace0bd9">
<source><x id="INTERPOLATION"/> LP</source>
<source>
<x id="INTERPOLATION"/>
LP
</source>
<target>
<x id="INTERPOLATION"/>
LP
......@@ -318,7 +362,10 @@
</trans-unit>
<trans-unit datatype="html" id="1939517ea2b4ff337ce2847302fbcc6f1217d269">
<source><x id="INTERPOLATION"/> 初始</source>
<source>
<x id="INTERPOLATION"/>
初始
</source>
<target>
<x id="INTERPOLATION"/>
Starting
......@@ -326,7 +373,10 @@
</trans-unit>
<trans-unit datatype="html" id="a19d6d5a2c74d9df73936a17b5c71b2069051b49">
<source><x id="INTERPOLATION"/> 抽卡</source>
<source>
<x id="INTERPOLATION"/>
抽卡
</source>
<target>
<x id="INTERPOLATION"/>
Draw
......
{
"name": "mycard",
"version": "3.0.0-dev.14",
"version": "3.0.0-dev.17",
"description": "mycard",
"keywords": [],
"author": "zh99998 <zh99998@gmail.com>",
......
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