Commit 4c2bd711 authored by mercury233's avatar mercury233

Merge branch 'patch-import' into 'v3'

Patch import

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