Commit 4ab3842e authored by wudizhanche1000's avatar wudizhanche1000

调整校验完整性和导入

parent f43539b8
......@@ -2,7 +2,7 @@
<!--应用未安装-->
<div class="actions" *ngIf="!currentApp.isInstalled()">
<button i18n type="button" class="btn btn-primary" data-toggle="modal" (click)="updateInstallOption(currentApp)" data-target="#install-modal">安装</button>
<!--<button i18n type="button" class="btn btn-secondary">导入</button>-->
<button i18n (click)="importGame(currentApp)" type="button" class="btn btn-secondary">导入</button>
</div>
<!--应用变更中-->
......@@ -76,7 +76,7 @@
</div>
<h2 i18n>本地文件</h2>
<button i18n (click)="appsService.browse(currentApp)" [disabled]="!appsService.allReady(currentApp)" type="button" class="btn btn-secondary">浏览本地文件</button>
<!--<button i18n type="button" (click)="verifyFiles(currentApp)" class="btn btn-secondary">校验完整性</button>-->
<button i18n type="button" (click)="verifyFiles(currentApp)" class="btn btn-secondary">校验完整性</button>
<button i18n (click)="uninstall(currentApp)" [disabled]="!appsService.allReady(currentApp)" type="button" class="btn btn-secondary">卸载</button>
</div>
......
......@@ -145,6 +145,11 @@ export class AppDetailComponent implements OnInit {
this.appsService.runApp(app, 'custom');
}
importGame(app: App) {
let dir = this.selectDir();
this.appsService.importApp(app, dir);
}
async verifyFiles(app: App) {
try {
await this.appsService.update(app, true);
......
......@@ -332,17 +332,23 @@ export class AppsService {
} else {
readyToUpdate = app.isReady() && mods.every((mod) => mod.isReady());
}
if (app.id === "ygopro") {
console.log(111);
}
if (readyToUpdate && (verify || app.local!.version !== app.version )) {
app.status.status = "updating";
try {
Logger.info("Checking updating: ", app);
let latestFiles = await this.getChecksumFile(app);
let localFiles: Map<string,string>;
let localFiles: Map<string,string>|undefined;
if (verify) {
localFiles = await this.verifyFiles(app, latestFiles);
await new Promise((resolve, reject) => {
this.ngZone.runOutsideAngular(async() => {
try {
localFiles = await this.verifyFiles(app, latestFiles);
resolve();
} catch (e) {
reject(e);
}
});
});
} else {
localFiles = app.local!.files;
}
......@@ -351,17 +357,22 @@ export class AppsService {
let deletedFiles: Set<string> = new Set<string>();
// 遍历寻找新增加的文件
for (let [file,checksum] of latestFiles) {
if (!localFiles.has(file) && latestFiles.get(file) !== "") {
if (checksum !== "" && !localFiles!.has(file)) {
addedFiles.add(file);
// changedFiles包含addedFiles,addedFiles仅供mod更新的时候使用。
changedFiles.add(file);
} else if (checksum === "" && file != ".") {
await this.createDirectory(path.join(app.local!.path, file));
}
}
// 遍历寻找旧版本与新版本不一样的文件和新版本比旧版少了的文件
for (let [file,checksum] of localFiles) {
for (let [file,checksum] of localFiles!) {
if (latestFiles.has(file)) {
if (latestFiles.get(file) !== checksum && latestFiles.get(file) !== "") {
let latestChecksum = latestFiles.get(file);
if (latestChecksum !== checksum && latestChecksum !== "") {
changedFiles.add(file);
} else if (latestChecksum === "") {
await this.createDirectory(path.join(app.local!.path, file));
}
} else {
deletedFiles.add(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