Bug fixes

Fix a bug that some groups are missing in the exported Quantumult X/Mellow configurations.
Optimize codes.
This commit is contained in:
Tindy X committed 2020-02-23 20:36:16 +08:00
1 parent 9bf13e792b
commit f01b7b6d2d
1 file changed
+19 -16
+19 -16
View File
@@ -789,20 +789,23 @@ void netchToClash(std::vector<nodeInfo> &nodes, YAML::Node &yamlnode, string_arr
singlegroup["name"] = vArray[0]; singlegroup["name"] = vArray[0];
singlegroup["type"] = vArray[1]; singlegroup["type"] = vArray[1];
if(vArray[1] == "select") rules_upper_bound = vArray.size();
switch(hash_(vArray[1]))
{ {
rules_upper_bound = vArray.size(); case "select"_hash:
} break;
else if(vArray[1] == "url-test" || vArray[1] == "fallback" || vArray[1] == "load-balance") case "url-test"_hash:
{ case "fallback"_hash:
if(vArray.size() < 5) case "load-balance"_hash:
if(rules_upper_bound < 5)
continue; continue;
rules_upper_bound = vArray.size() - 2; rules_upper_bound -= 2;
singlegroup["url"] = vArray[vArray.size() - 2]; singlegroup["url"] = vArray[rules_upper_bound];
singlegroup["interval"] = to_int(vArray[vArray.size() - 1]); singlegroup["interval"] = to_int(vArray[rules_upper_bound + 1]);
} break;
else default:
continue; continue;
}
for(unsigned int i = 2; i < rules_upper_bound; i++) for(unsigned int i = 2; i < rules_upper_bound; i++)
groupGenerate(vArray[i], nodelist, filtered_nodelist, true); groupGenerate(vArray[i], nodelist, filtered_nodelist, true);
@@ -1043,14 +1046,14 @@ std::string netchToSurge(std::vector<nodeInfo> &nodes, std::string &base_conf, s
break; break;
case "url-test"_hash: case "url-test"_hash:
case "fallback"_hash: case "fallback"_hash:
if(vArray.size() < 5) if(rules_upper_bound < 5)
continue; continue;
rules_upper_bound -= 2; rules_upper_bound -= 2;
url = vArray[rules_upper_bound]; url = vArray[rules_upper_bound];
interval = to_int(vArray[rules_upper_bound + 1]); interval = to_int(vArray[rules_upper_bound + 1]);
break; break;
case "ssid"_hash: case "ssid"_hash:
if(vArray.size() < 4) if(rules_upper_bound < 4)
continue; continue;
proxy = vArray[1] + ",default=" + vArray[2] + ","; proxy = vArray[1] + ",default=" + vArray[2] + ",";
proxy += std::accumulate(vArray.begin() + 4, vArray.end(), vArray[3], [](std::string a, std::string b) 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<nodeInfo> &nodes, std::string &base_conf, s
return std::move(a) + "," + std::move(b); return std::move(a) + "," + std::move(b);
}); });
ini.Set("{NONAME}", vArray[0] + " = " + proxy); //insert order ini.Set("{NONAME}", vArray[0] + " = " + proxy); //insert order
continue;
default: default:
continue; continue;
} }
@@ -1728,9 +1730,10 @@ void netchToQuanX(std::vector<nodeInfo> &nodes, INIReader &ini, std::vector<rule
type = "available"; type = "available";
case "load-balance"_hash: case "load-balance"_hash:
type = "round-robin"; type = "round-robin";
if(vArray.size() < 5) if(rules_upper_bound < 5)
continue; continue;
rules_upper_bound -= 2; rules_upper_bound -= 2;
break;
default: default:
continue; continue;
} }
@@ -2091,6 +2094,7 @@ void netchToMellow(std::vector<nodeInfo> &nodes, INIReader &ini, std::vector<rul
continue; continue;
rules_upper_bound -= 2; rules_upper_bound -= 2;
url = vArray[vArray.size() - 2]; url = vArray[vArray.size() - 2];
break;
default: default:
continue; continue;
} }
@@ -2314,7 +2318,6 @@ std::string netchToLoon(std::vector<nodeInfo> &nodes, std::string &base_conf, st
return std::move(a) + "," + std::move(b); return std::move(a) + "," + std::move(b);
}); });
ini.Set("{NONAME}", vArray[0] + " = " + proxy); //insert order ini.Set("{NONAME}", vArray[0] + " = " + proxy); //insert order
continue;
default: default:
continue; continue;
} }