#publish ..

main
xian18 3 years ago
parent da2c3fa167
commit 819f483885

@ -335,14 +335,11 @@ var SF_Plugins = SF_Plugins || {};
this._updateFileList = []; this._updateFileList = [];
this._updateFileIndex = 0; this._updateFileIndex = 0;
this._updateFileCount = 0; this._updateFileCount = 0;
this._updateFileName = ""; this._updateFile = {};
this._updateSuccess = false; this._updateSuccess = false;
this._deleteFileList = []; 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", "delete file", "update file" this._job = ""; // "fetch remote file info", "compare file info", "delete file", "update file"
@ -443,17 +440,9 @@ var SF_Plugins = SF_Plugins || {};
Scene_AutoUpdate.prototype.deleteFile = function () { Scene_AutoUpdate.prototype.deleteFile = function () {
UpdateUtils.startUpdateFiles(); UpdateUtils.startUpdateFiles();
var update_set = new Set(this._updateFileList);
var delete_list = [];
this._deleteFileList.forEach(function (file_name) { this._deleteFileList.forEach(function (file_info) {
if (!update_set.has(file_name)) { FileUtils.delete(file_info.file_name)
delete_list.push(file_name);
}
});
delete_list.forEach(function (file_name) {
FileUtils.delete(file_name);
}); });
this._status = "completed"; this._status = "completed";
@ -466,7 +455,7 @@ var SF_Plugins = SF_Plugins || {};
this._status = "completed"; this._status = "completed";
return; return;
} }
this._updateFileName = this._updateFileList[this._updateFileIndex]; this._updateFile = this._updateFileList[this._updateFileIndex];
this.updateFileNext(); this.updateFileNext();
} }
@ -477,7 +466,7 @@ var SF_Plugins = SF_Plugins || {};
this._status = "completed"; this._status = "completed";
this._updateSuccess = true; this._updateSuccess = true;
} else { } else {
this._updateFileName = this._updateFileList[this._updateFileIndex]; this._updateFile = this._updateFileList[this._updateFileIndex];
this.updateFileNext(); this.updateFileNext();
} }
}).bind(this); }).bind(this);
@ -488,8 +477,14 @@ var SF_Plugins = SF_Plugins || {};
this._updateSuccess = false; this._updateSuccess = false;
}).bind(this); }).bind(this);
if (!FileUtils.exists(FileUtils.getParent(this._updateFileName))) { var file = this._updateFile;
FileUtils.mkdirs(FileUtils.getParent(this._updateFileName)); if (file.is_dir) {
success();
return;
}
if (!FileUtils.exists(FileUtils.getParent(file.file_name))) {
FileUtils.mkdirs(FileUtils.getParent(file.file_name));
} }
UpdateUtils.downloadRelativeUrl( UpdateUtils.downloadRelativeUrl(

@ -1,37 +1,44 @@
onmessage = function (e) { onmessage = function (e) {
var request = e.data; var request = e.data;
var delete_list = [];
var update_list = [];
switch (request.command) { switch (request.command) {
case 'compare': case 'compare':
compare_file_info(request.local_file_info, request.remote_file_info); compare_file_info(request.local_file_info, request.remote_file_info, delete_list, update_list);
send_command('delete', delete_list);
send_command('update', update_list);
send_command('finish', []); send_command('finish', []);
break; break;
case 'finish': case 'finish':
send_command('finish'); send_command('finish');
break; break;
case 'delete':
} }
} }
function compare_file_info(local_file_info, remote_file_info) { function compare_file_info(local_file_info, remote_file_info, delete_list, update_list) {
if (!remote_file_info || local_file_info.is_dir !== remote_file_info.is_dir) { if (!remote_file_info) {
send_command('delete', generate_file_list(local_file_info)); delete_list = delete_list.concat(generate_file_list(local_file_info));
send_command('update', generate_file_list(remote_file_info)); } else if (!local_file_info) {
update_list = update_list.concat(generate_file_list(remote_file_info));
} else if (local_file_info.is_dir !== remote_file_info.is_dir) {
delete_list = delete_list.concat(generate_file_list(local_file_info));
update_list = update_list.concat(generate_file_list(remote_file_info));
} else if (local_file_info.sha_512 !== remote_file_info.sha_512) { } else if (local_file_info.sha_512 !== remote_file_info.sha_512) {
if (local_file_info.is_dir) { if (local_file_info.is_dir) {
var visited_children = new Set(); var visited_children = new Set();
for (var i in local_file_info.children) { for (var i in local_file_info.children) {
compare_file_info(local_file_info.children[i], remote_file_info.children[i]); compare_file_info(local_file_info.children[i], remote_file_info.children[i], delete_list, update_list);
visited_children.add(i); visited_children.add(i);
} }
for (var i in remote_file_info.children) { for (var i in remote_file_info.children) {
if (!visited_children.has(i)) { if (!visited_children.has(i)) {
send_command('update', generate_file_list(remote_file_info.children[i])); update_list = update_list.concat(generate_file_list(remote_file_info.children[i]));
} }
} }
} else { } else {
send_command('update', generate_file_list(remote_file_info)); update_list = update_list.concat(generate_file_list(remote_file_info));
} }
} }
} }
@ -46,7 +53,12 @@ function generate_file_list(file_info) {
file_list = file_list.concat(generate_file_list(file_info.children[i])); file_list = file_list.concat(generate_file_list(file_info.children[i]));
} }
} }
file_list.push(file_info.file_name); file_list.push({
"file_name": file_info.file_name,
"is_dir": file_info.is_dir,
"is_file": file_info.is_file,
"sha_512": file_info.sha_512
});
return file_list; return file_list;
} }
@ -57,8 +69,4 @@ function send_command(command, file_list) {
file_list: file_list file_list: file_list
}; };
postMessage(command_data); postMessage(command_data);
}
function delete_file(file_name) {
} }
Loading…
Cancel
Save