mirror of
https://gitlab.com/YuukiPS/GC-Proto.git
synced 2024-12-25 07:59:24 +03:00
add clean_proto_gen
This commit is contained in:
parent
238dd43a77
commit
302d35f51a
1487
gc_needed.json
Normal file
1487
gc_needed.json
Normal file
File diff suppressed because it is too large
Load Diff
174
op.js
174
op.js
@ -9,6 +9,7 @@ const read_cmdid_output = "cmdid.json";
|
||||
const read_cmdid_output_gc = "cmdid_gc.json";
|
||||
const read_cmdid_output_gc_update = "cmdid_gc_update.json";
|
||||
const read_cmdid_output_gc_nofound = "cmdid_gc_nofound.json";
|
||||
const file_gc_needed = "gc_needed.json";
|
||||
|
||||
const write_op = "PacketOpcodes.java";
|
||||
|
||||
@ -213,6 +214,10 @@ function update_cmdid_gc() {
|
||||
save_json(data_gc_cmdid_nofound, read_cmdid_output_gc_nofound);
|
||||
}
|
||||
|
||||
function read_json(file) {
|
||||
return JSON.parse(fs.readFileSync(file));
|
||||
}
|
||||
|
||||
// save json
|
||||
function save_json(raw, file) {
|
||||
var j = JSON.stringify(raw, null, 4);
|
||||
@ -257,43 +262,33 @@ var index_file_packet_nofound = 0;
|
||||
var index_file_packet_rename = 0;
|
||||
var index_file_packet_norename = 0;
|
||||
var index_file_packet_renamemulti = 0;
|
||||
function fix_packet(p = "recv", saveit = false) {
|
||||
var path = folder_packet_gc + p;
|
||||
fs.readdir(path, function (err, files) {
|
||||
//handling error
|
||||
if (err) {
|
||||
return console.log("Unable to scan directory: " + err);
|
||||
}
|
||||
var file_gc_need = [];
|
||||
function fix_packet(saveit = false) {
|
||||
const files = getAllFiles(folder_packet_gc);
|
||||
|
||||
const cmd_last = fs.readFileSync(read_cmdid_output);
|
||||
const cmd_old = fs.readFileSync(read_cmdid_output_gc);
|
||||
const cmdidfix_raw = fs.readFileSync(read_cmdid_output_gc_update);
|
||||
const json_cmdid_last = JSON.parse(cmd_last);
|
||||
const json_cmdid_old = JSON.parse(cmd_old);
|
||||
const json_cmdidfix_raw = JSON.parse(cmdidfix_raw);
|
||||
const json_cmdid_last = read_json(read_cmdid_output);
|
||||
const json_cmdid_old = read_json(read_cmdid_output_gc);
|
||||
const json_cmdidfix_raw = read_json(read_cmdid_output_gc_update);
|
||||
|
||||
files.forEach(function (file) {
|
||||
var f = path + "/" + file;
|
||||
const read = fs.readFileSync(f);
|
||||
//var f = path + "/" + file;
|
||||
const read = fs.readFileSync(file);
|
||||
var real = read.toString();
|
||||
var r = real.match(/\(.*?\)/g).map((x) => x.replace(/[()]/g, ""));
|
||||
|
||||
var name;
|
||||
r.forEach(function (s, index) {
|
||||
if (s.match("PacketOpcodes.")) {
|
||||
name = s.split("PacketOpcodes.")[1];
|
||||
if (name.match(",")) {
|
||||
name = name.split(",")[0];
|
||||
}
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
var name = getPacketOpcodes(real);
|
||||
if (!name) {
|
||||
console.log("no found");
|
||||
return;
|
||||
}
|
||||
|
||||
if (name === "NONE") {
|
||||
return;
|
||||
}
|
||||
|
||||
var subdata = new Object();
|
||||
subdata["name"] = name;
|
||||
file_gc_need.push(subdata);
|
||||
|
||||
//var name = c[1];
|
||||
|
||||
//console.log(r);
|
||||
@ -371,6 +366,7 @@ function fix_packet(p = "recv", saveit = false) {
|
||||
//return;
|
||||
index_file_packet++;
|
||||
});
|
||||
save_json(file_gc_need, file_gc_needed);
|
||||
console.log(
|
||||
"Index file: " +
|
||||
index_file_packet +
|
||||
@ -383,15 +379,133 @@ function fix_packet(p = "recv", saveit = false) {
|
||||
" | NoRename " +
|
||||
index_file_packet_norename
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function isBlank(str) {
|
||||
return !!!str || /^\s*$/.test(str);
|
||||
}
|
||||
|
||||
fix_packet("send", false);
|
||||
//fix_packet("recv");
|
||||
function getAllFiles(dirPath, arrayOfFiles) {
|
||||
files = fs.readdirSync(dirPath);
|
||||
|
||||
arrayOfFiles = arrayOfFiles || [];
|
||||
|
||||
files.forEach(function (file) {
|
||||
if (fs.statSync(dirPath + "/" + file).isDirectory()) {
|
||||
arrayOfFiles = getAllFiles(dirPath + "/" + file, arrayOfFiles);
|
||||
} else {
|
||||
arrayOfFiles.push(path.join(__dirname, dirPath, "/", file));
|
||||
}
|
||||
});
|
||||
|
||||
return arrayOfFiles;
|
||||
}
|
||||
|
||||
function getPacketOpcodes(raw) {
|
||||
var r = raw.match(/\(.*?\)/g).map((x) => x.replace(/[()]/g, ""));
|
||||
var name;
|
||||
r.forEach(function (s, index) {
|
||||
if (s.match("PacketOpcodes.")) {
|
||||
name = s.split("PacketOpcodes.")[1];
|
||||
if (name.match(",")) {
|
||||
name = name.split(",")[0];
|
||||
}
|
||||
return;
|
||||
}
|
||||
});
|
||||
return name;
|
||||
}
|
||||
|
||||
var file_toclean = [];
|
||||
var file_toaddmore = [];
|
||||
var found_noclean = 0;
|
||||
var found_needclean = 0;
|
||||
var found_maybe_related = 0;
|
||||
function clean_proto_gen() {
|
||||
//const files = getAllFiles(folder_proto_gc_gen);
|
||||
const files = getAllFiles("./proto");
|
||||
|
||||
const json_gc_needed = read_json(file_gc_needed);
|
||||
const json_gc_now = read_json(read_cmdid_output_gc);
|
||||
const json_gc_update = read_json(read_cmdid_output_gc_update);
|
||||
//console.log(json_gc_needed);
|
||||
|
||||
console.log(
|
||||
"File proto: " + files.length + " | Need " + json_gc_needed.length
|
||||
);
|
||||
|
||||
const regex = /\import "(.*?)\.proto"/g;
|
||||
|
||||
// find all file import
|
||||
files.forEach(function (file) {
|
||||
var found = json_gc_needed.find((j) => file.match(j.name));
|
||||
if (found) {
|
||||
// read file
|
||||
const read = fs.readFileSync(file);
|
||||
var rd = read.toString();
|
||||
// find import
|
||||
while ((m = regex.exec(rd)) !== null) {
|
||||
// This is necessary to avoid infinite loops with zero-width matches
|
||||
if (m.index === regex.lastIndex) {
|
||||
regex.lastIndex++;
|
||||
}
|
||||
// The result can be accessed through the `m`-variable.
|
||||
m.forEach((match, groupIndex) => {
|
||||
// only index 1 grup
|
||||
if (groupIndex == 1) {
|
||||
var found_rt = file_toaddmore.find((j) => j.name === match);
|
||||
if (found_rt) {
|
||||
//found_maybe_related++;
|
||||
//console.log(`Skip ${match}`);
|
||||
} else {
|
||||
var subdata = new Object();
|
||||
subdata["name"] = match;
|
||||
file_toaddmore.push(subdata);
|
||||
found_maybe_related++;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// all
|
||||
files.forEach(function (file) {
|
||||
// main file
|
||||
var found = json_gc_needed.find((j) => file.match(j.name));
|
||||
if (found) {
|
||||
found_noclean++;
|
||||
} else {
|
||||
var found1 = file_toaddmore.find((j) => file.match(j.name));
|
||||
if (found1) {
|
||||
found_noclean++;
|
||||
//console.log("Files sub are required: "+file);
|
||||
} else {
|
||||
found_needclean++;
|
||||
try {
|
||||
fs.unlinkSync(file);
|
||||
//file removed
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//console.log(file_toaddmore);
|
||||
|
||||
console.log(
|
||||
"No clean: " +
|
||||
found_noclean +
|
||||
" | Need to clean: " +
|
||||
found_needclean +
|
||||
" | Related " +
|
||||
found_maybe_related
|
||||
);
|
||||
}
|
||||
|
||||
clean_proto_gen();
|
||||
//fix_packet(false);
|
||||
//cmdid_to_op();
|
||||
//update_cmdid_gc();
|
||||
//get_cmdid_gc();
|
||||
|
Loading…
Reference in New Issue
Block a user