#publish 测试自动更新

main
xian18 3 years ago
parent ca25285d2a
commit 5e426908c6

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 71 KiB

After

Width:  |  Height:  |  Size: 302 KiB

@ -70,6 +70,7 @@ var SF_Plugins = SF_Plugins || {};
* public void evaluateJavascript(String script) * public void evaluateJavascript(String script)
* public void downloadFullUrl(String fileName, String urlString, String success, String fail) * public void downloadFullUrl(String fileName, String urlString, String success, String fail)
* public void downloadRelativeUrl(String fileName, String urlString, String success, String fail) * public void downloadRelativeUrl(String fileName, String urlString, String success, String fail)
* public void startUpdateFiles()
* public void updateFileCompleted(boolean bool) * public void updateFileCompleted(boolean bool)
* public String getHashInfoJson() * public String getHashInfoJson()
* public void updateFile(String fileName, String success, String fail) * public void updateFile(String fileName, String success, String fail)
@ -86,7 +87,9 @@ var SF_Plugins = SF_Plugins || {};
SF_AutoUpdate.localFileInfoName = "file_info_local.json"; SF_AutoUpdate.localFileInfoName = "file_info_local.json";
SF_AutoUpdate.remoteFileInfoUrl = "https://ycrpg.xyzzgame.com/ycrpg2/file_info_remote.json"; SF_AutoUpdate.remoteFileInfoUrl = "https://ycrpg.xyzzgame.com/ycrpg2/file_info_remote.json";
SF_AutoUpdate.remoteUrlRoot = "https://ycrpg.xyzzgame.com/YCrpg2/"; SF_AutoUpdate.remoteUrlRoot = "https://ycrpg.xyzzgame.com/YCrpg2/";
SF_AutoUpdate.emptyFileInfoStr = `{"is_file":false,"is_dir":"true","files":[],"dirs":[],"sha_512":""}`; SF_AutoUpdate.emptyFileInfoStr = `{"is_file":false,"is_dir":"true","children":[],"sha_512":""}`;
SF_AutoUpdate.workerFileName = "js/plugins/SF_AutoUpdateWorker.js";
SF_AutoUpdate.localStorageKey = "SF_AutoUpdate_UpdateFileCompleted";
SF_AutoUpdate.enableAutoUpdate = false; SF_AutoUpdate.enableAutoUpdate = false;
@ -103,7 +106,7 @@ var SF_Plugins = SF_Plugins || {};
} }
SF_AutoUpdate.isSupported = function () { SF_AutoUpdate.isSupported = function () {
return SF_AutoUpdate.enableAutoUpdate && (SF_AutoUpdate.isAndroid() || SF_AutoUpdate.isPC()); return SF_AutoUpdate.enableAutoUpdate && (SF_AutoUpdate.isAndroid() || SF_AutoUpdate.isPC()) && !Utils.isOptionValid('test');
} }
if (!SF_AutoUpdate.isSupported()) { return; } if (!SF_AutoUpdate.isSupported()) { return; }
@ -285,8 +288,12 @@ var SF_Plugins = SF_Plugins || {};
SF_AutoUpdate.UpdateUtils.downloadFullUrl(fileName, SF_AutoUpdate.remoteUrlRoot + url, success, fail); SF_AutoUpdate.UpdateUtils.downloadFullUrl(fileName, SF_AutoUpdate.remoteUrlRoot + url, success, fail);
} }
SF_AutoUpdate.UpdateUtils.updateFileCompleted = function (result) { SF_AutoUpdate.UpdateUtils.updateFileCompleted = function (isSuccess) {
// todo localStorage.setItem(SF_AutoUpdate.localStorageKey, JsonEx.stringify(isSuccess));
if (isSuccess) {
nw.Window.open(`chrome-extension://${chrome.runtime.id}/index.html`);
nw.Window.get().close();
}
} }
SF_AutoUpdate.UpdateUtils.getHashInfoJson = function () { SF_AutoUpdate.UpdateUtils.getHashInfoJson = function () {
@ -300,6 +307,11 @@ var SF_Plugins = SF_Plugins || {};
SF_AutoUpdate.UpdateUtils.updateFile = function (fileName, success, fail) { SF_AutoUpdate.UpdateUtils.updateFile = function (fileName, success, fail) {
SF_AutoUpdate.UpdateUtils.downloadRelativeUrl(fileName, fileName, success, fail); SF_AutoUpdate.UpdateUtils.downloadRelativeUrl(fileName, fileName, success, fail);
} }
SF_AutoUpdate.UpdateUtils.startUpdateFiles = function () {
localStorage.setItem(SF_AutoUpdate.localStorageKey, 'false');
}
} }
//============================================================================= //=============================================================================
@ -319,14 +331,25 @@ var SF_Plugins = SF_Plugins || {};
Scene_Base.prototype.initialize.call(this); Scene_Base.prototype.initialize.call(this);
this._localFileInfo = JsonEx.parse(UpdateUtils.readTextFile(SF_AutoUpdate.localFileInfoName)); this._localFileInfo = JsonEx.parse(UpdateUtils.readTextFile(SF_AutoUpdate.localFileInfoName));
this._remoteFileInfo = {}; this._remoteFileInfo = {};
this._updateFileList = []; this._updateFileList = [];
this._updateFileIndex = 0; this._updateFileIndex = 0;
this._updateFileCount = 0; this._updateFileCount = 0;
this._updateFileName = ""; this._updateFileName = "";
this._updateSuccess = false;
this._deleteFileList = [];
this._deleteFileIndex = 0;
this._deleteFileCount = 0;
this._deleteFileName = "";
this._status = "completed"; // "working", "completed" this._status = "completed"; // "working", "completed"
this._job = ""; // "fetch remote file info", "compare file info", "update file" this._job = ""; // "fetch remote file info", "compare file info", "delete file", "update file"
this._nextJob = "fetched remote file info"; this._nextJob = "fetched remote file info";
this._compareWorker = new Worker(SF_AutoUpdate.workerFileName);
this._compareWorker.onmessage = this._onCompareWorkerMessage.bind(this);
}; };
Scene_AutoUpdate.prototype.create = function () { Scene_AutoUpdate.prototype.create = function () {
@ -361,11 +384,21 @@ var SF_Plugins = SF_Plugins || {};
break; break;
case "compare file info": case "compare file info":
this.compareFileInfo(); this.compareFileInfo();
this._nextJob = "delete file";
break;
case "delete file":
this.deleteFile();
this._nextJob = "update file"; this._nextJob = "update file";
break; break;
case "update file": case "update file":
this.updateFile(); this.updateFile();
this._nextJob = "update completed";
break;
case "update completed":
this._status = "completed";
this._nextJob = ""; this._nextJob = "";
FileUtils.writeTextFile(SF_AutoUpdate.localFileInfoName, JsonEx.stringify(this._remoteFileInfo));
UpdateUtils.updateFileCompleted(this._updateSuccess);
break; break;
} }
} }
@ -391,7 +424,79 @@ var SF_Plugins = SF_Plugins || {};
} }
Scene_AutoUpdate.prototype.compareFileInfo = function () { Scene_AutoUpdate.prototype.compareFileInfo = function () {
this._compareWorker.postMessage({
"type": "compare",
"localFileInfo": this._localFileInfo,
"remoteFileInfo": this._remoteFileInfo
});
}
Scene_AutoUpdate.prototype._onCompareWorkerMessage = function (e) {
var result = e.data;
if (result.command === 'delete') {
this._deleteFileList.concat(result.file_list);
} else if (result.command === 'update') {
this._updateFileList.concat(result.file_list);
} else {
this._status = "completed";
}
}
Scene_AutoUpdate.prototype.deleteFile = function () {
UpdateUtils.startUpdateFiles();
var update_set = new Set(this._updateFileList);
var delete_list = [];
this._deleteFileList.forEach(function (file_name) {
if (!update_set.has(file_name)) {
delete_list.push(file_name);
}
});
delete_list.forEach(function (file_name) {
FileUtils.delete(file_name);
});
this._status = "completed";
}
Scene_AutoUpdate.prototype.updateFile = function () {
this._updateFileIndex = 0;
this._updateFileCount = this._updateFileList.length;
if (this._updateFileCount === 0) {
this._status = "completed";
this._nextJob = "";
return;
}
this._updateFileName = this._updateFileList[this._updateFileIndex];
this.updateFileNext();
}
Scene_AutoUpdate.prototype.updateFileNext = function () {
var success = (function () {
this._updateFileIndex++;
if (this._updateFileIndex >= this._updateFileCount) {
this._status = "completed";
this._nextJob = "";
this._updateSuccess = true;
} else {
this._updateFileName = this._updateFileList[this._updateFileIndex];
this.updateFileNext();
}
}).bind(this);
var fail = (function () {
this._status = "completed";
this._nextJob = "";
this._updateSuccess = false;
}).bind(this);
UpdateUtils.downloadRelativeUrl(
this._updateFileName,
this._updateFileName,
CallBack.registerOneTime(success),
CallBack.registerOneTime(fail)
);
} }
//============================================================================= //=============================================================================
// SceneManager // SceneManager
@ -403,6 +508,4 @@ var SF_Plugins = SF_Plugins || {};
this.addSceneBefore(Scene_AutoUpdate, Scene_Title); this.addSceneBefore(Scene_AutoUpdate, Scene_Title);
} }
})(); })();

@ -0,0 +1,64 @@
onmessage = function (e) {
var request = e.data;
switch (request.command) {
case 'compare':
compare_file_info(request.local_file_info, request.remote_file_info);
send_command('finish', []);
break;
case 'finish':
send_command('finish');
break;
case 'delete':
}
}
function compare_file_info(local_file_info, remote_file_info) {
if (!remote_file_info || local_file_info.is_dir !== remote_file_info.is_dir) {
send_command('delete', generate_file_list(local_file_info));
send_command('update', generate_file_list(remote_file_info));
} else if (local_file_info.sha_512 !== remote_file_info.sha_512) {
if (local_file_info.is_dir) {
var visited_children = new Set();
for (var i in local_file_info.children) {
compare_file_info(local_file_info.children[i], remote_file_info.children[i]);
visited_children.add(i);
}
for (var i in remote_file_info.children) {
if (!visited_children.has(i)) {
send_command('update', generate_file_list(remote_file_info.children[i]));
}
}
} else {
send_command('update', generate_file_list(remote_file_info));
}
}
}
function generate_file_list(file_info) {
if (!file_info) { return []; }
var file_list = [];
if (file_info.is_dir) {
for (var i in file_info.children) {
file_list = file_list.concat(generate_file_list(file_info.children[i]));
}
}
file_list.push(file_info.file_name);
return file_list;
}
// command: delete, update, finish
function send_command(command, file_list) {
var command_data = {
command: command,
file_list: file_list
};
postMessage(command_data);
}
function delete_file(file_name) {
}

@ -1,24 +0,0 @@
onmessage = function (e) {
var local_file_info = e.data[0];
var remote_file_info = e.data[1];
local_file_info.is_dir = local_file_info.is_dir || false;
remote_file_info.is_dir = remote_file_info.is_dir || false;
}
function compare_file_info(local_file_info, remote_file_info) {
}
function compare_file_file(local_file_info, remote_file_info) {
console.assert(local_file_info.is_file === remote_file_info.is_file);
}
function generate_delete_file_list(file_info) {
var delete_file_list = [];
if (file_info.is_dir) {
for (var i = 0; i < file_info.children.length; i++) {
delete_file_list = delete_file_list.concat(generate_delete_file_list(file_info.children[i]));
}
}
}

@ -324,7 +324,7 @@ var $gameMapsExt = null;
// Try To Export Extra Event to MapExt json // Try To Export Extra Event to MapExt json
//============================================================================= //=============================================================================
if (Utils.isNwjs() && SF_ExtraEvent.ExportMapExtraEvent) { if (Utils.isNwjs() && Utils.isOptionValid('test') && SF_ExtraEvent.ExportMapExtraEvent) {
var fs = require('fs'); var fs = require('fs');
var path = require('path'); var path = require('path');
var note_reg = new RegExp(/<SF_EXTRA_EVENT:\s*(\d*)>/i); var note_reg = new RegExp(/<SF_EXTRA_EVENT:\s*(\d*)>/i);

@ -1,12 +1,17 @@
{ {
"name": "", "name": "ycrpg",
"main": "index.html", "main": "index.html",
"js-flags": "--expose-gc", "js-flags": "--expose-gc",
"window": { "window": {
"title": "", "title": "异常生物见闻录",
"toolbar": false, "toolbar": true,
"width": 816, "width": 1024,
"height": 624, "height": 560,
"icon": "icon/icon.png" "icon": "icon/icon.png"
} },
} "chromium-args": "--enable-node-worker",
"node-remote": "<all_urls>",
"web_accessible_resources": [
"*"
]
}

@ -1,3 +0,0 @@
onmessage = function (e) {
debugger
}
Loading…
Cancel
Save