Commit d4240a4e authored by mercury233's avatar mercury233

Patch import

parent 4eb628be
...@@ -264,4 +264,8 @@ table.expansions tr:last-child td:last-child{ ...@@ -264,4 +264,8 @@ table.expansions tr:last-child td:last-child{
font-size: 1rem; font-size: 1rem;
margin-bottom: 0; margin-bottom: 0;
margin-top: .5rem; margin-top: .5rem;
}
.custom-file-control:lang(zh)::before {
content: "打开...";
} }
\ No newline at end of file
...@@ -252,13 +252,13 @@ ...@@ -252,13 +252,13 @@
</button> </button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<p><strong i18n>请注意,导入功能只适用于下载并解压的MyCard提供的完整包,无法正常导入其他渠道提供的版本。用于导入的完整包请从社区或者反馈群等处获取,导入其他的版本将极易导致无法预知的错误。在下载功能出现故障无法使用时,导入功能也将无法使用。</strong></p> <p i18n>请注意!!导入功能只适用于手动下载的<strong class="text-primary">MyCard提供的</strong>完整包,<strong class="text-danger">无法正常导入其他渠道提供的版本</strong>。用于导入的完整包请从社区或者反馈群等处获取,导入其他的版本将极易导致无法预知的错误。<strong class="text-primary">在下载功能出现故障无法使用时,导入功能也可能无法使用</strong></p>
<p i18n>选择主程序 {{currentApp.actions.get('main').execute}}</p> <p i18n>选择主程序 {{currentApp.actions.get('main').execute}} 或者完整包</p>
<label class="custom-file" lang="en"> <label class="custom-file" lang="zh">
<input (click)="$event.preventDefault();selectImport(currentApp)" type="file" id="file" class="custom-file-input"> <input (click)="$event.preventDefault();selectImport(currentApp)" type="file" id="file" class="custom-file-input">
<span class="custom-file-control">{{import_path || currentApp.actions.get('main').execute}}</span> <span class="custom-file-control">{{import_path}}</span>
</label> </label>
<hr>
<h4 i18n>导入到</h4> <h4 i18n>导入到</h4>
<div class="form-group"> <div class="form-group">
<select class="form-control" name="installPath" (change)="selectLibrary()" [(ngModel)]="installOption.installLibrary" title="path"> <select class="form-control" name="installPath" (change)="selectLibrary()" [(ngModel)]="installOption.installLibrary" title="path">
......
...@@ -213,6 +213,31 @@ export class AppDetailComponent implements OnInit, OnChanges { ...@@ -213,6 +213,31 @@ export class AppDetailComponent implements OnInit, OnChanges {
async importGame(targetApp: App, option: InstallOption, referencesInstall: { [id: string]: boolean }) { async importGame(targetApp: App, option: InstallOption, referencesInstall: { [id: string]: boolean }) {
$('#import-modal').modal('hide'); $('#import-modal').modal('hide');
let dir = path.dirname(this.import_path); let dir = path.dirname(this.import_path);
let ext = path.extname(this.import_path);
if (ext === '.zst') {
try {
console.log('extracting import file');
await new Promise((resolve, reject) => {
targetApp.status.status = 'installing';
this.appsService.extract(this.import_path, option.installDir).subscribe(
(lastItem: string) => {
targetApp.status.progressMessage = lastItem;
},
(error) => {
reject(error);
},
() => {
resolve(null);
});
});
dir = option.installDir;
targetApp.status.status = 'init';
}
catch (e) {
console.error(e);
new Notification(targetApp.name, {body: '导入时解压失败' + e.message});
}
}
// TODO: 执行依赖和references安装 // TODO: 执行依赖和references安装
try { try {
await this.appsService.importApp(targetApp, dir, option); await this.appsService.importApp(targetApp, dir, option);
...@@ -263,7 +288,7 @@ export class AppDetailComponent implements OnInit, OnChanges { ...@@ -263,7 +288,7 @@ export class AppDetailComponent implements OnInit, OnChanges {
// let remote = require('electron').remote // let remote = require('electron').remote
let filePaths = await new Promise<string[]>((resolve, reject) => { let filePaths = await new Promise<string[]>((resolve, reject) => {
remote.dialog.showOpenDialog({ remote.dialog.showOpenDialog({
filters: [{name: filename, extensions: [extname]}], filters: [{name: filename, extensions: [extname, 'zst']}],
properties: ['openFile'] properties: ['openFile']
}, resolve); }, resolve);
}); });
......
...@@ -382,7 +382,7 @@ export class AppsService { ...@@ -382,7 +382,7 @@ export class AppsService {
async importApp(app: App, appPath: string, option: InstallOption) { async importApp(app: App, appPath: string, option: InstallOption) {
if (!app.isInstalled()) { if (!app.isInstalled()) {
app.status.status = 'updating'; app.status.status = 'installing';
let checksumFiles = await this.getChecksumFile(app); let checksumFiles = await this.getChecksumFile(app);
for (let [pattern, fileOption] of app.files) { for (let [pattern, fileOption] of app.files) {
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
...@@ -411,30 +411,31 @@ export class AppsService { ...@@ -411,30 +411,31 @@ export class AppsService {
// 刷新进度 // 刷新进度
let interval = setInterval(() => { let interval = setInterval(() => {
}, 500); }, 500);
await new Promise((resolve, reject) => { if (path.resolve(appPath) !== path.resolve(option.installDir)) {
this.ngZone.runOutsideAngular(async () => { await new Promise((resolve, reject) => {
try { this.ngZone.runOutsideAngular(async () => {
for (let [file, checksum] of sortedFiles) { try {
let src = path.join(appPath, file); for (let [file, checksum] of sortedFiles) {
let dst = path.join(option.installDir, file); let src = path.join(appPath, file);
if (checksum === '') { let dst = path.join(option.installDir, file);
await this.createDirectory(dst); if (checksum === '') {
} else { await this.createDirectory(dst);
try { } else {
await this.copyFile(src, dst); try {
} catch (e) { await this.copyFile(src, dst);
} finally { } catch (e) {
app.status.progress += 1; } finally {
app.status.progress += 1;
}
} }
} }
resolve(null);
} catch (e) {
reject(e);
} }
resolve(null); });
} catch (e) {
reject(e);
}
}); });
}); }
clearInterval(interval); clearInterval(interval);
app.local = new AppLocal(); app.local = new AppLocal();
app.local.path = option.installDir; app.local.path = option.installDir;
......
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