Commit 14eeca64 authored by wudizhanche1000's avatar wudizhanche1000

卸载进度,依赖安装

parent 0fafee68
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
<div> <div>
<span *ngIf="currentApp.isDownloading()">正在下载</span> <span *ngIf="currentApp.isDownloading()">正在下载</span>
<span *ngIf="currentApp.isInstalling()">正在安装...</span> <span *ngIf="currentApp.isInstalling()">正在安装...</span>
<span *ngIf="currentApp.isUninstalling()">正在卸载...</span>
<span *ngIf="currentApp.isWaiting()">等待安装...</span> <span *ngIf="currentApp.isWaiting()">等待安装...</span>
<span *ngIf="currentApp.status.total">{{(currentApp.status.progress/currentApp.status.total * 100).toFixed()}}%</span> <span *ngIf="currentApp.status.total">{{(currentApp.status.progress/currentApp.status.total * 100).toFixed()}}%</span>
<span>{{currentApp.progressMessage()}}</span> <span>{{currentApp.progressMessage()}}</span>
...@@ -64,8 +65,10 @@ ...@@ -64,8 +65,10 @@
</td> </td>
<td *ngIf="!mod.isInstalled()"> <td *ngIf="!mod.isInstalled()">
<button i18n (click)="installMod(mod)" type="button" *ngIf="!mod.isInstalled()" class="btn btn-primary btn-sm">安装</button> <button i18n (click)="installMod(mod)" type="button" *ngIf="!mod.isInstalled()" class="btn btn-primary btn-sm">安装</button>
<progress *ngIf="mod.isDownloading()" class="progress progress-striped progress-animated" value="{{mod.status.progress}}" max="{{mod.status.total}}"></progress> </td>
<div i18n *ngIf="mod.isWaiting()">等待安装...</div> <td *ngIf="mod.isInstalled()&&!mod.isReady()">
<progress class="progress progress-striped progress-animated" value="{{mod.status.progress}}" max="{{mod.status.total}}"></progress>
<!--<div i18n *ngIf="mod.isWaiting()">等待安装...</div>-->
</td> </td>
</tr> </tr>
</tbody> </tbody>
...@@ -104,10 +107,10 @@ ...@@ -104,10 +107,10 @@
<input id="create_desktop_shortcut" type="checkbox" name="desktop" [(ngModel)]="installOption.createDesktopShortcut"> <input id="create_desktop_shortcut" type="checkbox" name="desktop" [(ngModel)]="installOption.createDesktopShortcut">
<label i18n for="create_desktop_shortcut">创建桌面快捷方式</label> <label i18n for="create_desktop_shortcut">创建桌面快捷方式</label>
</div> </div>
<!--<h4 *ngIf="installOption.references.length">扩展内容</h4>--> <h4 *ngIf="references.length>0">扩展内容</h4>
<!--<div *ngFor="let reference of installOption.references"><label>--> <div *ngFor="let reference of references"><label>
<!--<input type="checkbox" [(ngModel)]="reference.install" name="references" value="{{reference.app.id}}"> {{reference.app.name}}--> <input type="checkbox" [(ngModel)]="referencesInstall[reference.id]" name="references"> {{reference.name}}
<!--</label></div>--> </label></div>
<div *ngIf="currentApp.findDependencies().length"> <div *ngIf="currentApp.findDependencies().length">
<span i18n>依赖:</span> <span i18n>依赖:</span>
<span class="dependency" *ngFor="let dependency of currentApp.findDependencies()">{{dependency.name}}</span> <span class="dependency" *ngFor="let dependency of currentApp.findDependencies()">{{dependency.name}}</span>
......
...@@ -24,6 +24,9 @@ export class AppDetailComponent implements OnInit { ...@@ -24,6 +24,9 @@ export class AppDetailComponent implements OnInit {
installOption: InstallOption; installOption: InstallOption;
references: App[];
referencesInstall: {[id: string]: boolean};
constructor(private appsService: AppsService, private settingsService: SettingsService, constructor(private appsService: AppsService, private settingsService: SettingsService,
private downloadService: DownloadService, private installService: InstallService, private downloadService: DownloadService, private installService: InstallService,
private ref: ChangeDetectorRef) { private ref: ChangeDetectorRef) {
...@@ -35,10 +38,12 @@ export class AppDetailComponent implements OnInit { ...@@ -35,10 +38,12 @@ export class AppDetailComponent implements OnInit {
updateInstallOption(app: App) { updateInstallOption(app: App) {
this.installOption = new InstallOption(app); this.installOption = new InstallOption(app);
this.installOption.installLibrary = this.settingsService.getDefaultLibrary().path; this.installOption.installLibrary = this.settingsService.getDefaultLibrary().path;
// this.installOption.references = []; this.references = Array.from(app.references.values());
// for (let reference of app.references.values()) { console.log(this.references);
// this.installOption.references.push(new InstallOption(reference)) this.referencesInstall = {};
// } for (let reference of this.references) {
this.referencesInstall[reference.id] = true;
}
} }
get libraries(): string[] { get libraries(): string[] {
...@@ -73,6 +78,14 @@ export class AppDetailComponent implements OnInit { ...@@ -73,6 +78,14 @@ export class AppDetailComponent implements OnInit {
try { try {
await this.appsService.install(targetApp, options); await this.appsService.install(targetApp, options);
if (this.references.length > 0) {
for (let [id,isInstalled] of Object.entries(this.referencesInstall)) {
if (isInstalled) {
let reference = targetApp.references.get(id)!;
await this.appsService.install(reference, options);
}
}
}
} catch (e) { } catch (e) {
console.error(e); console.error(e);
new Notification(targetApp.name, {body: "下载失败"}); new Notification(targetApp.name, {body: "下载失败"});
......
...@@ -100,6 +100,9 @@ export class App { ...@@ -100,6 +100,9 @@ export class App {
isDownloading(): boolean { isDownloading(): boolean {
return this.status.status === "downloading"; return this.status.status === "downloading";
} }
isUninstalling():boolean{
return this.status.status==="uninstalling";
}
runable(): boolean { runable(): boolean {
return [Category.game].includes(this.category); return [Category.game].includes(this.category);
......
...@@ -215,27 +215,30 @@ export class AppsService { ...@@ -215,27 +215,30 @@ export class AppsService {
}) })
}); });
}; };
try { if (!app.isInstalled()) {
let apps: App[] = []; try {
let dependencies = app.findDependencies().filter((dependency) => { let apps: App[] = [];
return !dependency.isInstalled(); let dependencies = app.findDependencies().filter((dependency) => {
}); return !dependency.isInstalled();
apps.push(...dependencies, app); });
let downloadPath = path.join(option.installLibrary, 'downloading'); apps.push(...dependencies, app);
let tasks: Promise<any>[] = []; let downloadPath = path.join(option.installLibrary, 'downloading');
for (let a of apps) { let tasks: Promise<any>[] = [];
tasks.push(addDownloadTask(a, downloadPath)); for (let a of apps) {
} tasks.push(addDownloadTask(a, downloadPath));
let downloadResults = await Promise.all(tasks); }
for (let result of downloadResults) { let downloadResults = await Promise.all(tasks);
console.log(result); for (let result of downloadResults) {
let o = new InstallOption(result.app, option.installLibrary); console.log(result);
o.downloadFiles = result.files; let o = new InstallOption(result.app, option.installLibrary);
this.installService.push({app: result.app, option: o}); o.downloadFiles = result.files;
this.installService.push({app: result.app, option: o});
}
} catch (e) {
app.status.status = 'init';
console.log(e);
throw e;
} }
} catch (e) {
console.log(e);
throw e;
} }
} }
...@@ -288,12 +291,12 @@ export class AppsService { ...@@ -288,12 +291,12 @@ export class AppsService {
} }
if (action.open) { if (action.open) {
let np2 = <App>action.open; let np2 = action.open;
let openAction: Action; let openAction: Action;
openAction = <Action>np2.actions.get('main'); openAction = np2.actions.get('main')!;
let openPath = (<AppLocal>np2.local).path; let openPath = np2.local!.path;
if (action.open.id == 'np2fmgen') { if (action.open.id == 'np2fmgen') {
const config_file = path.join((<AppLocal>(<App>action.open).local).path, 'np21nt.ini'); const config_file = path.join(action.open!.local!.path, 'np21nt.ini');
let config = await new Promise((resolve, reject) => { let config = await new Promise((resolve, reject) => {
fs.readFile(config_file, {encoding: 'utf-8'}, (error, data) => { fs.readFile(config_file, {encoding: 'utf-8'}, (error, data) => {
if (error) return reject(error); if (error) return reject(error);
...@@ -309,7 +312,7 @@ export class AppsService { ...@@ -309,7 +312,7 @@ export class AppsService {
windtype: '0' windtype: '0'
}; };
config['NekoProject21'] = Object.assign({}, default_config, config['NekoProject21']); config['NekoProject21'] = Object.assign({}, default_config, config['NekoProject21']);
config['NekoProject21']['HDD1FILE'] = path.win32.join(process.platform == 'win32' ? '' : 'Z:', (<AppLocal>app.local).path, action.execute); config['NekoProject21']['HDD1FILE'] = path.win32.join(process.platform == 'win32' ? '' : 'Z:', app.local!.path, action.execute);
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
fs.writeFile(config_file, ini.stringify(config), (error) => { fs.writeFile(config_file, ini.stringify(config), (error) => {
if (error) { if (error) {
...@@ -319,12 +322,15 @@ export class AppsService { ...@@ -319,12 +322,15 @@ export class AppsService {
} }
}) })
}); });
args.push(openAction.execute);
args = args.concat(openAction.args); if (process.platform != 'win32') {
let wine = <App>openAction.open; args.push(openAction.execute);
openPath = (<AppLocal>wine.local).path; args = args.concat(openAction.args);
openAction = <Action>(<App>openAction.open).actions.get('main'); let wine = openAction.open!;
cwd = (<AppLocal>np2.local).path; openPath = wine.local!.path;
openAction = openAction!.open!.actions.get('main')!;
}
cwd = np2.local!.path;
} }
args = args.concat(openAction.args); args = args.concat(openAction.args);
args.push(action.execute); args.push(action.execute);
......
...@@ -83,10 +83,12 @@ export class DownloadService { ...@@ -83,10 +83,12 @@ export class DownloadService {
let newDownloadSpeed = 0; let newDownloadSpeed = 0;
for (let [index,gid] of gidList.entries()) { for (let [index,gid] of gidList.entries()) {
let task = this.taskList.get(gid)!; let task = this.taskList.get(gid)!;
statusList[index] = task.status; if (task) {
newCompletedLength += parseInt(task.completedLength); statusList[index] = task.status;
newTotalLength += parseInt(task.totalLength); newCompletedLength += parseInt(task.completedLength);
newDownloadSpeed += parseInt(task.downloadSpeed); newTotalLength += parseInt(task.totalLength);
newDownloadSpeed += parseInt(task.downloadSpeed);
}
} }
if (newCompletedLength !== completedLength || newTotalLength !== totalLength) { if (newCompletedLength !== completedLength || newTotalLength !== totalLength) {
completedLength = newCompletedLength; completedLength = newCompletedLength;
......
...@@ -293,11 +293,15 @@ export class InstallService { ...@@ -293,11 +293,15 @@ export class InstallService {
async uninstall(app: App) { async uninstall(app: App) {
if (app.isReady()) { if (app.isReady()) {
app.status.status = "uninstalling";
let appDir = app.local!.path; let appDir = app.local!.path;
let files = Array.from(app.local!.files.keys()).sort().reverse(); let files = Array.from(app.local!.files.keys()).sort().reverse();
app.status.total = files.length;
for (let file of files) { for (let file of files) {
this.deleteFile(path.join(appDir, file)); app.status.progress += 1;
await this.deleteFile(path.join(appDir, file));
} }
if (app.parent) { if (app.parent) {
......
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