From f01b7b6d2dff8bbb0f422cdab5f96706618a5efa Mon Sep 17 00:00:00 2001 From: Tindy X <49061470+tindy2013@users.noreply.github.com> Date: Sun, 23 Feb 2020 20:36:16 +0800 Subject: [PATCH] Bug fixes Fix a bug that some groups are missing in the exported Quantumult X/Mellow configurations. Optimize codes. --- src/subexport.cpp | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/subexport.cpp b/src/subexport.cpp index 2ccb267..a3cbe4e 100644 --- a/src/subexport.cpp +++ b/src/subexport.cpp @@ -789,20 +789,23 @@ void netchToClash(std::vector &nodes, YAML::Node &yamlnode, string_arr singlegroup["name"] = vArray[0]; singlegroup["type"] = vArray[1]; - if(vArray[1] == "select") + rules_upper_bound = vArray.size(); + switch(hash_(vArray[1])) { - rules_upper_bound = vArray.size(); - } - else if(vArray[1] == "url-test" || vArray[1] == "fallback" || vArray[1] == "load-balance") - { - if(vArray.size() < 5) + case "select"_hash: + break; + case "url-test"_hash: + case "fallback"_hash: + case "load-balance"_hash: + if(rules_upper_bound < 5) continue; - rules_upper_bound = vArray.size() - 2; - singlegroup["url"] = vArray[vArray.size() - 2]; - singlegroup["interval"] = to_int(vArray[vArray.size() - 1]); - } - else + rules_upper_bound -= 2; + singlegroup["url"] = vArray[rules_upper_bound]; + singlegroup["interval"] = to_int(vArray[rules_upper_bound + 1]); + break; + default: continue; + } for(unsigned int i = 2; i < rules_upper_bound; i++) groupGenerate(vArray[i], nodelist, filtered_nodelist, true); @@ -1043,14 +1046,14 @@ std::string netchToSurge(std::vector &nodes, std::string &base_conf, s break; case "url-test"_hash: case "fallback"_hash: - if(vArray.size() < 5) + if(rules_upper_bound < 5) continue; rules_upper_bound -= 2; url = vArray[rules_upper_bound]; interval = to_int(vArray[rules_upper_bound + 1]); break; case "ssid"_hash: - if(vArray.size() < 4) + if(rules_upper_bound < 4) continue; proxy = vArray[1] + ",default=" + vArray[2] + ","; proxy += std::accumulate(vArray.begin() + 4, vArray.end(), vArray[3], [](std::string a, std::string b) @@ -1058,7 +1061,6 @@ std::string netchToSurge(std::vector &nodes, std::string &base_conf, s return std::move(a) + "," + std::move(b); }); ini.Set("{NONAME}", vArray[0] + " = " + proxy); //insert order - continue; default: continue; } @@ -1728,9 +1730,10 @@ void netchToQuanX(std::vector &nodes, INIReader &ini, std::vector &nodes, INIReader &ini, std::vector &nodes, std::string &base_conf, st return std::move(a) + "," + std::move(b); }); ini.Set("{NONAME}", vArray[0] + " = " + proxy); //insert order - continue; default: continue; }