Commit 4ab3842e authored by wudizhanche1000's avatar wudizhanche1000

调整校验完整性和导入

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