Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_initLocalServerDir() {
if (this.localServerPath && this.localServerPath.length > 0) {
console.log("已经有本地server目录");
} else {
let zipDir = CfgUtil.getPackZipDir();
if (!fs.existsSync(zipDir)) {
fs.mkdirSync(zipDir);
}
let serverDir = path.join(zipDir, "server");
if (!fs.existsSync(serverDir)) {
fs.mkdirSync(serverDir);
}
this.localServerPath = serverDir;
}
},
// 选择项目的manifest文件目录
_resizeImage(imgPath) {
if (!imgPath) {
this._addLog("图片路径有误: " + imgPath);
return;
}
let sharpPath = Editor.url('unpack://utils/sharp');
let sharp = require(sharpPath);
// 创建相应尺寸的目录
let desDir = this._getTempDir();
if (!fs.existsSync(desDir)) {
fs.mkdirSync(desDir);
}
let pixDir = path.join(desDir, this.sizeWidth + "x" + this.sizeHeight);
if (!fs.existsSync(pixDir)) {
fs.mkdirSync(pixDir);
}
let fileName = path.basename(imgPath);
let desFilePath = path.join(pixDir, fileName);
sharp(imgPath).resize(this.sizeWidth, this.sizeHeight).toFile(desFilePath, function (err, info) {
if (err) {
this._addLog("裁剪失败!" + imgPath);
// Editor.warn("error:"+err);
console.log("error:" + err);
console.log("info: " + info);
} else {
_compressMp3(fileDataArray) {
// 设置lame路径
let lamePath = this._getLamePath();
if (!fs.existsSync(lamePath)) {
this._addLog("文件不存在: " + lamePath);
return;
}
console.log("压缩");
co(function* () {
// 处理要压缩的音频文件
for (let i = 0; i < fileDataArray.length; i++) {
let voiceFile = fileDataArray[i].path;
let voiceFileUrl = fileDataArray[i].url;
if (!fs.existsSync(voiceFile)) {
this._addLog("声音文件不存在: " + voiceFile);
return;
}
if (path.extname(voiceFile) === ".mp3") {
// 检测临时缓存目录
_compressMp3(fileDataArray) {
// 设置lame路径
let lamePath = this._getLamePath();
if (!fs.existsSync(lamePath)) {
this._addLog("文件不存在: " + lamePath);
return;
}
console.log("压缩");
co(function* () {
// 处理要压缩的音频文件
for (let i = 0; i < fileDataArray.length; i++) {
let voiceFile = fileDataArray[i].path;
let voiceFileUrl = fileDataArray[i].url;
if (!fs.existsSync(voiceFile)) {
this._addLog("声音文件不存在: " + voiceFile);
return;
}
if (path.extname(voiceFile) === ".mp3") {
// 检测临时缓存目录
results.forEach(function (result) {
// 删除临时目录的文件
// console.log("type: " + result.type);
if (result.type = "audio-clip") {
console.log("del: " + result.path);
if (fs.existsSync(newNamePath)) {
fs.unlinkSync(newNamePath);// 删除临时文件
}
}
});
}.bind(this));
results.forEach(function (result) {
// 删除临时目录的文件
// console.log("type: " + result.type);
if (result.type = "audio-clip") {
console.log("del: " + result.path);
if (fs.existsSync(newNamePath)) {
fs.unlinkSync(newNamePath);// 删除临时文件
}
}
});
}.bind(this));
onOpenBuglySymbol() {
if (!FS.existsSync(this.outPutFilePath)) {
return;
}
Electron.shell.showItemInFolder(this.outPutFilePath);
Electron.shell.beep();
},
// 上传符号表文件
_importJsonCfg(typeDir) {
if (!fs.existsSync(this.importProjectCfgPath)) {
this._addLog("导入项目路径不存在:" + this.importProjectCfgPath);
return;
}
if (!this.isExportJson) {
this._addLog("[Warning] 您未勾选导出Json配置,可能导入的配置时上个版本的!");
}
let importPath = Editor.assetdb.remote.fspathToUrl(this.importProjectCfgPath);
if (importPath.indexOf("db://assets") >= 0) {
// 检索所有的json配置
let clientDir = path.join(this.jsonSavePath, typeDir);
if (!fs.existsSync(clientDir)) {
this._addLog("配置目录不存在:" + clientDir);
return;
}
onBtnClickJsonAllCfgFile() {
let saveFileFullPath1 = path.join(this.jsonSavePath, dirClientName, this.jsonAllCfgFileName + ".json");
let saveFileFullPath2 = path.join(this.jsonSavePath, dirServerName, this.jsonAllCfgFileName + ".json");
if (fs.existsSync(saveFileFullPath1)) {
Electron.shell.openItem(saveFileFullPath1);
Electron.shell.beep();
} else if (fs.existsSync(saveFileFullPath2)) {
Electron.shell.openItem(saveFileFullPath2);
Electron.shell.beep();
} else {
// this._addLog("目录不存在:" + this.resourceRootDir);
this._addLog("目录不存在:" + saveFileFullPath1 + ' or:' + saveFileFullPath2);
return;
}
},
checkJsonAllCfgFileExist() {
onBtnClickJsonAllCfgFile() {
let saveFileFullPath1 = path.join(this.jsonSavePath, dirClientName, this.jsonAllCfgFileName + ".json");
let saveFileFullPath2 = path.join(this.jsonSavePath, dirServerName, this.jsonAllCfgFileName + ".json");
if (fs.existsSync(saveFileFullPath1)) {
Electron.shell.openItem(saveFileFullPath1);
Electron.shell.beep();
} else if (fs.existsSync(saveFileFullPath2)) {
Electron.shell.openItem(saveFileFullPath2);
Electron.shell.beep();
} else {
// this._addLog("目录不存在:" + this.resourceRootDir);
this._addLog("目录不存在:" + saveFileFullPath1 + ' or:' + saveFileFullPath2);
return;
}
},
checkJsonAllCfgFileExist() {