Commit 5fd9ee15 authored by wudizhanche1000's avatar wudizhanche1000

添加FileOptions功能

导入时可以复制存档,校验时可以忽略
parent 59127a72
...@@ -26,6 +26,10 @@ export interface Action { ...@@ -26,6 +26,10 @@ export interface Action {
env: {}; env: {};
open?: App open?: App
} }
export class FileOptions {
sync: boolean;
ignore: boolean;
}
export class AppStatus { export class AppStatus {
progress: number; progress: number;
...@@ -80,6 +84,7 @@ export class App { ...@@ -80,6 +84,7 @@ export class App {
local: AppLocal | null; local: AppLocal | null;
status: AppStatus; status: AppStatus;
conference: string | undefined; conference: string | undefined;
files: Map<string,FileOptions>;
isLanguage() { isLanguage() {
return this.category == Category.module && this.tags.includes('language'); return this.category == Category.module && this.tags.includes('language');
...@@ -114,6 +119,7 @@ export class App { ...@@ -114,6 +119,7 @@ export class App {
isUninstalling(): boolean { isUninstalling(): boolean {
return this.status.status === "uninstalling"; return this.status.status === "uninstalling";
} }
isUpdating(): boolean { isUpdating(): boolean {
return this.status.status === "updating"; return this.status.status === "updating";
} }
...@@ -143,6 +149,7 @@ export class App { ...@@ -143,6 +149,7 @@ export class App {
this.tags = app.tags; this.tags = app.tags;
this.version = app.version; this.version = app.version;
this.conference = app.conference; this.conference = app.conference;
this.files = app.files;
} }
findDependencies(): App[] { findDependencies(): App[] {
......
import {Injectable, ApplicationRef, EventEmitter, NgZone} from "@angular/core"; import {Injectable, ApplicationRef, EventEmitter, NgZone} from "@angular/core";
import {Http} from "@angular/http"; import {Http} from "@angular/http";
import * as crypto from "crypto"; import * as crypto from "crypto";
import {App, AppStatus, Action} from "./app"; import {App, AppStatus, Action, FileOptions} from "./app";
import {SettingsService} from "./settings.sevices"; import {SettingsService} from "./settings.sevices";
import * as fs from "fs"; import * as fs from "fs";
import {createReadStream, createWriteStream} from "fs"; import {createReadStream, createWriteStream} from "fs";
...@@ -12,6 +12,7 @@ import {remote} from "electron"; ...@@ -12,6 +12,7 @@ import {remote} from "electron";
import "rxjs/Rx"; import "rxjs/Rx";
import * as readline from "readline"; import * as readline from "readline";
import {AppLocal} from "./app-local"; import {AppLocal} from "./app-local";
import * as glob from "glob";
import * as ini from "ini"; import * as ini from "ini";
import {DownloadService, DownloadStatus} from "./download.service"; import {DownloadService, DownloadStatus} from "./download.service";
import {InstallOption} from "./install-option"; import {InstallOption} from "./install-option";
...@@ -202,6 +203,13 @@ export class AppsService { ...@@ -202,6 +203,13 @@ export class AppsService {
for (let item of data) { for (let item of data) {
let app = new App(item); let app = new App(item);
let local = localStorage.getItem(app.id); let local = localStorage.getItem(app.id);
if (item.files) {
app.files = new Map(Object.entries(item.files))
} else {
app.files = new Map();
}
if (local) { if (local) {
app.local = new AppLocal(); app.local = new AppLocal();
app.local.update(JSON.parse(local)); app.local.update(JSON.parse(local));
...@@ -314,6 +322,19 @@ export class AppsService { ...@@ -314,6 +322,19 @@ export class AppsService {
if (!app.isInstalled()) { if (!app.isInstalled()) {
app.status.status = "updating"; app.status.status = "updating";
let checksumFiles = await this.getChecksumFile(app); let checksumFiles = await this.getChecksumFile(app);
for (let [pattern, fileOption] of app.files) {
await new Promise((resolve, reject) => {
new glob.Glob(pattern, {cwd: appPath}, (err, files) => {
for (let file of files) {
// 避免被当做文件夹
if (fileOption.sync) {
checksumFiles.set(file, "DO_NOT_CARE_HASH");
}
}
resolve();
});
})
}
await this.createDirectory(option.installDir); await this.createDirectory(option.installDir);
let sortedFiles = Array.from(checksumFiles.entries()).sort((a: string[], b: string[]): number => { let sortedFiles = Array.from(checksumFiles.entries()).sort((a: string[], b: string[]): number => {
if (a[0] > b[0]) { if (a[0] > b[0]) {
...@@ -457,11 +478,26 @@ export class AppsService { ...@@ -457,11 +478,26 @@ export class AppsService {
await this.createDirectory(path.join(app.local!.path, file)); await this.createDirectory(path.join(app.local!.path, file));
} }
} }
let ignoreFiles: Set<string> = new Set();
for (let [pattern, fileOption] of app.files) {
await new Promise((resolve, reject) => {
new glob.Glob(pattern, {cwd: app.local!.path}, (err, files) => {
for (let file of files) {
if (fileOption.ignore) {
ignoreFiles.add(file);
}
}
resolve();
});
});
}
// 遍历寻找旧版本与新版本不一样的文件和新版本比旧版少了的文件 // 遍历寻找旧版本与新版本不一样的文件和新版本比旧版少了的文件
// ignoreFiles里的文件不作处理
for (let [file, checksum] of localFiles!) { for (let [file, checksum] of localFiles!) {
if (latestFiles.has(file)) { if (latestFiles.has(file)) {
let latestChecksum = latestFiles.get(file); let latestChecksum = latestFiles.get(file);
if (latestChecksum !== checksum && latestChecksum !== "") { if (!ignoreFiles.has(file) && latestChecksum !== checksum && latestChecksum !== "") {
changedFiles.add(file); changedFiles.add(file);
} else if (latestChecksum === "") { } else if (latestChecksum === "") {
await this.createDirectory(path.join(app.local!.path, file)); await this.createDirectory(path.join(app.local!.path, file));
......
...@@ -2057,6 +2057,21 @@ ...@@ -2057,6 +2057,21 @@
"win32": "1.033.C-15", "win32": "1.033.C-15",
"darwin": "1.033.C-15" "darwin": "1.033.C-15"
}, },
"files": {
"deck/*.ydk": {
"sync": true,
"ignore": true
},
"single/*.lua": {
"sync": true
},
"replay/*.yrp": {
"sync": true
},
"system.conf": {
"ignore": true
}
},
"news": { "news": {
"zh-CN": [ "zh-CN": [
{ {
......
...@@ -49,6 +49,7 @@ System.config({ ...@@ -49,6 +49,7 @@ System.config({
"url": "@node/url", "url": "@node/url",
"dns": "@node/dns", "dns": "@node/dns",
"net": "@node/net", "net": "@node/net",
"glob": "@node/glob",
"dgram": "@node/dgram", "dgram": "@node/dgram",
"fs": "@node/fs", "fs": "@node/fs",
"path": "@node/path", "path": "@node/path",
......
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