mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2025-10-27 11:52:32 +00:00
Enhancements
Fix exporting broken configuration file in some occasions. Fix directly treating not-exist ruleset file as URL. Fix group fallback not working on Quantumult X configurations. Fix typo in example profile. Add specifying default external configuration file to use when none is provided. Optimize codes.
This commit is contained in:
@@ -5,6 +5,7 @@ common:
|
||||
insert_url: []
|
||||
exclude_remarks: ["(到期|剩余流量|时间|官网|产品)"]
|
||||
include_remarks: []
|
||||
default_external_config: "" # config/example_external_config.yml
|
||||
clash_rule_base: base/all_base.tpl
|
||||
surge_rule_base: base/all_base.tpl
|
||||
surfboard_rule_base: base/all_base.tpl
|
||||
|
||||
@@ -18,6 +18,9 @@ exclude_remarks=(到期|剩余流量|时间|官网|产品)
|
||||
;Only include nodes which remarks match the following patterns. Supports regular expression.
|
||||
;include_remarks=V3.*港
|
||||
|
||||
;Setting an external config file as default when none is specified, supports local files/URL
|
||||
;default_external_config=config/example_external_config.ini
|
||||
|
||||
;Clash config base used by the generator, supports local files/URL
|
||||
clash_rule_base=base/all_base.tpl
|
||||
|
||||
|
||||
@@ -7,6 +7,6 @@
|
||||
target=clash
|
||||
url=ss://Y2hhY2hhMjAtaWV0Zi1wb2x5MTMwNTpwYXNzd29yZA@www.example.com:1080#Example
|
||||
;config=config/example_external_config.ini
|
||||
;surge_ver=3
|
||||
;ver=3
|
||||
;udp=true
|
||||
;emoji=false
|
||||
|
||||
@@ -899,17 +899,22 @@ public:
|
||||
std::string ToString()
|
||||
{
|
||||
std::string content;
|
||||
string_size strsize;
|
||||
|
||||
if(!parsed)
|
||||
return std::string();
|
||||
|
||||
for(auto &x : section_order)
|
||||
{
|
||||
string_size strsize = 0;
|
||||
content += "[" + x + "]\n";
|
||||
if(ini_content.find(x) != ini_content.end())
|
||||
{
|
||||
auto section = ini_content.at(x);
|
||||
if(section.empty())
|
||||
{
|
||||
content += "\n";
|
||||
continue;
|
||||
}
|
||||
for(auto iter = section.begin(); iter != section.end(); iter++)
|
||||
{
|
||||
if(iter->first != "{NONAME}")
|
||||
@@ -922,7 +927,7 @@ public:
|
||||
if(strsize)
|
||||
content += "\n";
|
||||
}
|
||||
return content.erase(content.size() - 2);
|
||||
return content;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include "templates.h"
|
||||
|
||||
//common settings
|
||||
std::string pref_path = "pref.ini";
|
||||
std::string pref_path = "pref.ini", def_ext_config;
|
||||
string_array def_exclude_remarks, def_include_remarks, rulesets, stream_rules, time_rules;
|
||||
std::vector<ruleset_content> ruleset_content_array;
|
||||
std::string listen_address = "127.0.0.1", default_url, insert_url, managed_config_prefix;
|
||||
@@ -445,6 +445,7 @@ void readYAMLConf(YAML::Node &node)
|
||||
section["loon_rule_base"] >> loon_rule_base;
|
||||
section["sssub_rule_base"] >> sssub_rule_base;
|
||||
|
||||
section["default_external_config"] >> def_ext_config;
|
||||
section["append_proxy_type"] >> append_proxy_type;
|
||||
section["proxy_config"] >> proxy_config;
|
||||
section["proxy_ruleset"] >> proxy_ruleset;
|
||||
@@ -659,6 +660,7 @@ void readConf()
|
||||
ini.GetIfExist("quan_rule_base", quan_rule_base);
|
||||
ini.GetIfExist("quanx_rule_base", quanx_rule_base);
|
||||
ini.GetIfExist("loon_rule_base", loon_rule_base);
|
||||
ini.GetIfExist("default_external_config", def_ext_config);
|
||||
ini.GetBoolIfExist("append_proxy_type", append_proxy_type);
|
||||
ini.GetIfExist("proxy_config", proxy_config);
|
||||
ini.GetIfExist("proxy_ruleset", proxy_ruleset);
|
||||
@@ -1090,6 +1092,8 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
|
||||
ext.managed_config_prefix = managed_config_prefix;
|
||||
|
||||
//load external configuration
|
||||
if(config.empty())
|
||||
config = def_ext_config;
|
||||
if(config.size())
|
||||
{
|
||||
//std::cerr<<"External configuration file provided. Loading...\n";
|
||||
|
||||
@@ -636,7 +636,7 @@ void rulesetToSurge(INIReader &base_rule, std::vector<ruleset_content> &ruleset_
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if(startsWith(rule_path, "https://") || startsWith(rule_path, "http://") || startsWith(rule_path, "data:"))
|
||||
{
|
||||
if(surge_ver > 2 && remote_path_prefix.size())
|
||||
{
|
||||
@@ -658,6 +658,8 @@ void rulesetToSurge(INIReader &base_rule, std::vector<ruleset_content> &ruleset_
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
continue;
|
||||
retrived_rules = x.rule_content.get();
|
||||
if(retrived_rules.empty())
|
||||
{
|
||||
@@ -1320,6 +1322,7 @@ std::string netchToSurge(std::vector<nodeInfo> &nodes, std::string &base_conf, s
|
||||
case "load-balance"_hash:
|
||||
if(surge_ver < 1)
|
||||
continue;
|
||||
[[fallthrough]];
|
||||
case "url-test"_hash:
|
||||
case "fallback"_hash:
|
||||
if(rules_upper_bound < 5)
|
||||
@@ -1910,14 +1913,14 @@ void netchToQuan(std::vector<nodeInfo> &nodes, INIReader &ini, std::vector<rules
|
||||
if(!filtered_nodelist.size())
|
||||
filtered_nodelist.emplace_back("direct");
|
||||
|
||||
if(filtered_nodelist.size() < 2) // force groups with 1 node to be static
|
||||
type = "static";
|
||||
|
||||
proxies = std::accumulate(std::next(filtered_nodelist.begin()), filtered_nodelist.end(), filtered_nodelist[0], [](std::string a, std::string b)
|
||||
{
|
||||
return std::move(a) + "\n" + std::move(b);
|
||||
});
|
||||
|
||||
if(filtered_nodelist.size() < 2) // force groups with 1 node to be static
|
||||
type = "static";
|
||||
|
||||
singlegroup = name + " : " + type;
|
||||
if(type == "static")
|
||||
singlegroup += ", " + filtered_nodelist[0];
|
||||
@@ -2120,6 +2123,9 @@ void netchToQuanX(std::vector<nodeInfo> &nodes, INIReader &ini, std::vector<rule
|
||||
if(!filtered_nodelist.size())
|
||||
filtered_nodelist.emplace_back("direct");
|
||||
|
||||
if(filtered_nodelist.size() < 2) // force groups with 1 node to be static
|
||||
type = "static";
|
||||
|
||||
auto iter = std::find_if(original_groups.begin(), original_groups.end(), [name](const string_multimap::value_type &n)
|
||||
{
|
||||
std::string groupdata = n.second;
|
||||
@@ -2139,9 +2145,6 @@ void netchToQuanX(std::vector<nodeInfo> &nodes, INIReader &ini, std::vector<rule
|
||||
}
|
||||
}
|
||||
|
||||
if(filtered_nodelist.size() < 2) // force groups with 1 node to be static
|
||||
type = "static";
|
||||
|
||||
proxies = std::accumulate(std::next(filtered_nodelist.begin()), filtered_nodelist.end(), filtered_nodelist[0], [](std::string a, std::string b)
|
||||
{
|
||||
return std::move(a) + ", " + std::move(b);
|
||||
|
||||
Reference in New Issue
Block a user