This commit is contained in:
539943419 committed 2023-10-11 21:41:05 +08:00
1 parent 229f87c942
commit 38c4ef43ed
1 file changed
+36 -31
+36 -31
View File
@@ -58,33 +58,36 @@ game.import("extension", function (lib, game, ui, get, ai, _status) {
alert("下载成功"); alert("下载成功");
//电脑端node.js环境下 //电脑端node.js环境下
if (lib.node && lib.node.fs) { if (lib.node && lib.node.fs) {
//原谅我Promise写不好
path = __dirname + path; path = __dirname + path;
path_bak = __dirname + path_bak; path_bak = __dirname + path_bak;
// return alert(path) // return alert(path)
const fs = lib.node.fs; const fs = lib.node.fs;
//创建备份文件 //创建备份文件
try { try {
fs.readFile(path, function read(err, data) { fs.readFile(path, function read(err, data1) {
if (err) { if (err) {
throw err; throw err;
} }
if(text_download == data){ if(text_download == data1){
alert('本地和下载的一模一样喵') alert('本地和下载的一模一样喵')
}else{ }else{
fs.appendFile(path_bak, data, function (err) { fs.appendFile(path_bak, data1, function (err) {
if (err) throw err; if (err) throw err;
// 更新文件
try {
fs.writeFileSync(path, text_download);
} catch (e) {
return alert("更新extension.js时:" + e);
}
}); });
} }
}); });
} catch (e) { } catch (e) {
return alert("备份时:" + e); return alert("备份时:" + e);
} }
//更新文件
try {
fs.writeFileSync(path, text_download);
} catch (e) {
return alert("更新extension.js时:" + e);
}
} }
//移动端 //移动端
else { else {
@@ -109,7 +112,7 @@ game.import("extension", function (lib, game, ui, get, ai, _status) {
} }
//备份文件 //检查是否需要更新文件
game.readFileAsText( game.readFileAsText(
"extension/" + extName + "/extension.js", "extension/" + extName + "/extension.js",
e => { e => {
@@ -128,6 +131,26 @@ game.import("extension", function (lib, game, ui, get, ai, _status) {
//写入文件 //写入文件
// alert(oldt); // alert(oldt);
writeFile(fileEntry, dataObj); writeFile(fileEntry, dataObj);
//更新extension.js
window.resolveLocalFileSystemURL(
lib.assetURL + "extension/" + extName,
function (root) {
root.getFile(
"extension.js",
{ create: true },
function (fileEntry) {
var dataObj = new Blob([text_download], { type: "text/plain" });
//写入文件
writeFile(fileEntry, dataObj);
},
function (err) {
alert("创建失败!");
}
);
},
function (err) {}
);
}, },
function (err) { function (err) {
alert("创建失败!"); alert("创建失败!");
@@ -142,25 +165,7 @@ game.import("extension", function (lib, game, ui, get, ai, _status) {
() => {} () => {}
); );
//更新extension.js
window.resolveLocalFileSystemURL(
lib.assetURL + "extension/" + extName,
function (root) {
root.getFile(
"extension.js",
{ create: true },
function (fileEntry) {
var dataObj = new Blob([text_download], { type: "text/plain" });
//写入文件
writeFile(fileEntry, dataObj);
},
function (err) {
alert("创建失败!");
}
);
},
function (err) {}
);
} }
} }
// function miaoFetch(url) { // function miaoFetch(url) {
@@ -1537,7 +1542,7 @@ game.import("extension", function (lib, game, ui, get, ai, _status) {
}, },
updateMiao4: { updateMiao4: {
name: "<button>更新喵喵喵喵</button>", name: "<button>更新喵喵喵喵</button>",
intro: "这还用说????", intro: "更新喵喵喵喵",
clear: true, clear: true,
onclick: async function () { onclick: async function () {
if (!game.getExtensionConfig("喵喵喵喵", "enable")) { if (!game.getExtensionConfig("喵喵喵喵", "enable")) {
@@ -1558,7 +1563,7 @@ game.import("extension", function (lib, game, ui, get, ai, _status) {
updateSelf: { updateSelf: {
name: "<button>更新喵喵配件</button>", name: "<button>更新喵喵配件</button>",
intro: "这还用说????", intro: "更新喵喵配件",
clear: true, clear: true,
onclick: async function () { onclick: async function () {
if (this.innerHTML != "<span><button>更新喵喵配件</button></span>") { if (this.innerHTML != "<span><button>更新喵喵配件</button></span>") {