Commit 64ac26ca authored by 神楽坂玲奈's avatar 神楽坂玲奈

Merge branch 'v3' of github.com:mycard/mycard into v3

parents fad06ea8 a6b26d36
...@@ -313,18 +313,22 @@ export class AppsService { ...@@ -313,18 +313,22 @@ export class AppsService {
app.status.status = "updating"; app.status.status = "updating";
let checksumFiles = await this.getChecksumFile(app); let checksumFiles = await this.getChecksumFile(app);
await this.createDirectory(option.installDir); await this.createDirectory(option.installDir);
let sortedFiles = Array.from(checksumFiles.entries()).sort((a: string[], b: string[]): number => {
if (a[0] > b[0]) {
return 1;
} else if (a[0] < b[0]) {
return -1;
} else {
return 0;
}
});
app.status.total = sortedFiles.length;
// 刷新进度
let interval = setInterval(() => {
}, 500);
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
this.ngZone.runOutsideAngular(async() => { this.ngZone.runOutsideAngular(async() => {
try { try {
let sortedFiles = Array.from(checksumFiles.entries()).sort((a: string[], b: string[]): number => {
if (a[0] > b[0]) {
return 1;
} else if (a[0] < b[0]) {
return -1;
} else {
return 0;
}
});
for (let [file, checksum] of sortedFiles) { for (let [file, checksum] of sortedFiles) {
let src = path.join(appPath, file); let src = path.join(appPath, file);
let dst = path.join(option.installDir, file); let dst = path.join(option.installDir, file);
...@@ -334,6 +338,9 @@ export class AppsService { ...@@ -334,6 +338,9 @@ export class AppsService {
try { try {
await this.copyFile(src, dst); await this.copyFile(src, dst);
} catch (e) { } catch (e) {
} finally {
app.status.progress += 1;
} }
} }
} }
...@@ -343,6 +350,7 @@ export class AppsService { ...@@ -343,6 +350,7 @@ export class AppsService {
} }
}); });
}); });
clearInterval(interval);
app.local = new AppLocal(); app.local = new AppLocal();
app.local.path = option.installDir; app.local.path = option.installDir;
app.status.status = "ready"; app.status.status = "ready";
...@@ -371,7 +379,7 @@ export class AppsService { ...@@ -371,7 +379,7 @@ export class AppsService {
}); });
} }
async verifyFiles(app: App, checksumFiles: Map<string,string>): Promise<Map<string,string>> { async verifyFiles(app: App, checksumFiles: Map<string,string>, callback: () => void): Promise<Map<string,string>> {
let result = new Map<string,string>(); let result = new Map<string,string>();
for (let [file, checksum] of checksumFiles) { for (let [file, checksum] of checksumFiles) {
let filePath = path.join(app.local!.path, file); let filePath = path.join(app.local!.path, file);
...@@ -386,6 +394,7 @@ export class AppsService { ...@@ -386,6 +394,7 @@ export class AppsService {
let sha256sum = await this.sha256sum(filePath); let sha256sum = await this.sha256sum(filePath);
result.set(file, sha256sum); result.set(file, sha256sum);
} }
callback();
resolve(); resolve();
}); });
}); });
...@@ -413,16 +422,23 @@ export class AppsService { ...@@ -413,16 +422,23 @@ export class AppsService {
let latestFiles = await this.getChecksumFile(app); let latestFiles = await this.getChecksumFile(app);
let localFiles: Map<string,string>|undefined; let localFiles: Map<string,string>|undefined;
if (verify) { if (verify) {
//刷新进度条
let interval = setInterval(() => {
}, 500);
app.status.total = latestFiles.size;
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
this.ngZone.runOutsideAngular(async() => { this.ngZone.runOutsideAngular(async() => {
try { try {
localFiles = await this.verifyFiles(app, latestFiles); localFiles = await this.verifyFiles(app, latestFiles, () => {
app.status.progress += 1;
});
resolve(); resolve();
} catch (e) { } catch (e) {
reject(e); reject(e);
} }
}); });
}); });
clearInterval(interval);
} else { } else {
localFiles = app.local!.files; localFiles = app.local!.files;
} }
......
...@@ -185,9 +185,7 @@ export class YGOProComponent implements OnInit { ...@@ -185,9 +185,7 @@ export class YGOProComponent implements OnInit {
async get_font(files: string[]): Promise<string | undefined> { async get_font(files: string[]): Promise<string | undefined> {
for (let file of files) { for (let file of files) {
console.log(file);
let found = await new Promise((resolve) => fs.access(file, fs.constants.R_OK, error => resolve(!error))); let found = await new Promise((resolve) => fs.access(file, fs.constants.R_OK, error => resolve(!error)));
console.log(found);
if (found) { if (found) {
return file; return file;
} }
......
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