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

np2

parent f3ae14ac
...@@ -20,6 +20,12 @@ export enum Category { ...@@ -20,6 +20,12 @@ export enum Category {
// uninstalling, // uninstalling,
// waiting, // waiting,
// } // }
export interface Action {
execute: string;
args: string[];
env: {};
open?: App
}
export class AppStatus { export class AppStatus {
progress: number; progress: number;
...@@ -42,7 +48,7 @@ export class App { ...@@ -42,7 +48,7 @@ export class App {
homepage: string; homepage: string;
category: Category; category: Category;
parent: App; parent: App;
actions: Map<string,{execute: string, args: string[], env: {}, open: App}>; actions: Map<string,Action>;
references: Map<string,App>; references: Map<string,App>;
dependencies: Map<string,App>; dependencies: Map<string,App>;
locales: string[]; locales: string[];
...@@ -82,7 +88,7 @@ export class App { ...@@ -82,7 +88,7 @@ export class App {
let set = new Set(); let set = new Set();
for (let dependency of this.dependencies.values()) { for (let dependency of this.dependencies.values()) {
dependency.findDependencies() dependency.findDependencies()
.forEach((value)=> { .forEach((value) => {
set.add(value); set.add(value);
}); });
set.add(dependency); set.add(dependency);
......
import {Injectable, ApplicationRef} from "@angular/core"; import {Injectable, ApplicationRef} from "@angular/core";
import {Http} from "@angular/http"; import {Http} from "@angular/http";
import {App, AppStatus} from "./app"; import {App, AppStatus, Action} from "./app";
import {SettingsService} from "./settings.sevices"; import {SettingsService} from "./settings.sevices";
import * as fs from "fs";
import * as path from "path"; import * as path from "path";
import * as child_process from "child_process"; import * as child_process from "child_process";
import {remote} from "electron"; import {remote} from "electron";
import "rxjs/Rx"; import "rxjs/Rx";
import {AppLocal} from "./app-local"; import {AppLocal} from "./app-local";
import * as ini from "ini";
const Aria2 = require('aria2'); const Aria2 = require('aria2');
const sudo = require('electron-sudo'); const sudo = require('electron-sudo');
...@@ -120,23 +121,46 @@ export class AppsService { ...@@ -120,23 +121,46 @@ export class AppsService {
return children; return children;
} }
runApp(app: App) { async runApp(app: App) {
let children = this.findChildren(app); let children = this.findChildren(app);
let cwd = (<AppLocal>app.local).path; let cwd = (<AppLocal>app.local).path;
let action: any = app.actions.get('main'); let action: Action = <Action>app.actions.get('main');
let args: string[] = []; let args: string[] = [];
let env = {}; let env = {};
for (let child of children) { for (let child of children) {
if(child.isInstalled()) { if (child.isInstalled()) {
action = child.actions.get('main'); let _action = child.actions.get('main');
if (_action) {
action = _action
}
} }
} }
let execute = path.join(cwd, action.execute); let execute = path.join(cwd, action.execute);
if (action.open) { if (action.open) {
let openAction = action.open.actions.get('main'); if (action.open.id == 'np2fmgen') {
const config_file = path.join((<AppLocal>(<App>action.open).local).path, 'np21nt.ini');
let config = await new Promise((resolve, reject) => {
let config = fs.readFile(config_file, {encoding: 'utf-8'}, (error, data) => {
if (error) return reject(error);
resolve(ini.parse(data));
});
});
config['NekoProject21']['HDD1FILE'] = path.win32.join("Z:", (<AppLocal>app.local).path, action.execute);
await new Promise((resolve, reject) => {
fs.writeFile(config_file, ini.stringify(config), (error) => {
if (error) {
reject(error)
} else {
resolve()
}
})
});
}
let openAction = <Action>action.open.actions.get('main');
args = args.concat(openAction.args); args = args.concat(openAction.args);
args.push(action.execute); args.push(action.execute);
execute = path.join(action.open.local.path, openAction.execute); execute = path.join((<AppLocal>action.open.local).path, openAction.execute);
env = Object.assign(env, openAction.env); env = Object.assign(env, openAction.env);
} }
args = args.concat(action.args); args = args.concat(action.args);
......
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