import fs = require("fs"); import path = require("path"); import { FileUtil } from "./tool/FileUtil"; class ResCompare { constructor() { this.getResData(); } private getResData() { let s = this; var http = require('http'); http.get('http://172.18.2.61/php/redis/db.php?type=get', function (res) { var resData = ""; res.on("data", function (data) { resData += data; }); res.on("end", function () { s.comareFiles(resData.split('|')); }); }) } private comareFiles(files: string[]) { files.forEach((value, index) => { files[index] = path.normalize(value); }); let s = this; s.loadUrls = files;//用过的资源 let resCfgStr = fs.readFileSync(path.join(__dirname, 'resource', 'default.res.json'), "utf-8"); let qufuResCfgStr = fs.readFileSync(path.join(__dirname, 'qufuResource', 'default.res.json'), "utf-8"); let reses: { url: string, name: string, type: string, subkeys?: string }[] = JSON.parse(resCfgStr).resources; let qufuReses = JSON.parse(qufuResCfgStr).resources; s.existUrls = [];//现有得资源 s.ansyRes(reses); s.ansyRes(qufuReses); s.existUrls.forEach(urlKey => { if (s.loadUrls.indexOf(urlKey) < 0) { console.log('暂未发现:' + urlKey); if (s.notFindUrls.indexOf(urlKey) < 0) s.notFindUrls.push(urlKey); } }); FileUtil.walkDir(path.join(__dirname, 'avatarres'), s.onFile, null, s); FileUtil.walkDir(path.join(__dirname, 'map'), s.onFile, null, s); fs.writeFileSync(path.join(__dirname, 'notfind.json'), JSON.stringify(s.notFindUrls), { encoding: "utf-8" }); } private onFile(url: string) { let s = this; url = url.replace(__dirname + "\\", ''); if (this.loadUrls.indexOf(url) < 0) { console.log('暂未发现:' + url); if (s.notFindUrls.indexOf(url) < 0) s.notFindUrls.push(url); } } private ansyRes(reses: { url: string, name: string, type: string, subkeys?: string }[]) { let s = this; reses.forEach(item => { if (item.type == 'sheet') { s.existUrls = s.existUrls.concat(item.subkeys.split(',')); } else { s.existUrls[s.existUrls.length] = item.name; } }); } private existUrls: string[]; private loadUrls: string[]; private notFindUrls: string[] = []; } export function run(): void { new ResCompare(); }