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