mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2025-10-26 19:32:55 +00:00
Enhancements
Fix compiler warnings. Add group type fallback when only one node is found for an auto group in Quantumult(X) configuration. Tweak default Emoji rules. Optimize codes.
This commit is contained in:
@@ -33,7 +33,7 @@ EU,🇪🇺
|
||||
(SG|Singapore|新加坡|狮城|[^-]新),🇸🇬
|
||||
(TH|Thailand|泰国|曼谷),🇹🇭
|
||||
(TR|Turkey|土耳其|伊斯坦布尔),🇹🇷
|
||||
(?i:US|America|United.*?States|美国|[^-]美|波特兰|达拉斯|俄勒冈|凤凰城|费利蒙|硅谷|拉斯维加斯|洛杉矶|圣何塞|圣克拉拉|西雅图|芝加哥),🇺🇲
|
||||
(?i:US|America|United.*?States|美国|[^-]美|波特兰|达拉斯|俄勒冈|凤凰城|费利蒙|硅谷|拉斯维加斯|洛杉矶|圣何塞|圣克拉拉|西雅图|芝加哥),🇺🇸
|
||||
(VN|越南),🇻🇳
|
||||
(ZA|南非),🇿🇦
|
||||
(?i:TW|Taiwan|新北|彰化|CHT|台湾|[^-]台|HINET),🇨🇳
|
||||
|
||||
42
src/misc.cpp
42
src/misc.cpp
@@ -431,11 +431,15 @@ std::string getSystemProxy()
|
||||
//return 0;
|
||||
return std::string();
|
||||
#else
|
||||
char* proxy = getenv("ALL_PROXY");
|
||||
if(proxy != NULL)
|
||||
return std::string(proxy);
|
||||
else
|
||||
return std::string();
|
||||
string_array proxy_env = {"all_proxy", "ALL_PROXY", "http_proxy", "HTTP_PROXY", "https_proxy", "HTTPS_PROXY"};
|
||||
char* proxy;
|
||||
for(std::string &x : proxy_env)
|
||||
{
|
||||
proxy = getenv(x.c_str());
|
||||
if(proxy != NULL)
|
||||
return std::string(proxy);
|
||||
}
|
||||
return std::string();
|
||||
#endif // _WIN32
|
||||
}
|
||||
|
||||
@@ -728,6 +732,7 @@ std::string fileGet(const std::string &path, bool scope_limit)
|
||||
{
|
||||
std::fseek(fp, 0, SEEK_END);
|
||||
long tot = std::ftell(fp);
|
||||
/*
|
||||
char *data = new char[tot + 1];
|
||||
data[tot] = '\0';
|
||||
std::rewind(fp);
|
||||
@@ -735,6 +740,11 @@ std::string fileGet(const std::string &path, bool scope_limit)
|
||||
std::fclose(fp);
|
||||
content.assign(data, tot);
|
||||
delete[] data;
|
||||
*/
|
||||
content.resize(tot);
|
||||
std::rewind(fp);
|
||||
std::fread(&content[0], 1, tot, fp);
|
||||
std::fclose(fp);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -793,6 +803,7 @@ std::string fileGetMD5(const std::string &filepath)
|
||||
|
||||
int fileWrite(const std::string &path, const std::string &content, bool overwrite)
|
||||
{
|
||||
/*
|
||||
std::fstream outfile;
|
||||
std::ios_base::openmode mode = overwrite ? std::ios_base::out : std::ios_base::app;
|
||||
mode |= std::ios_base::binary;
|
||||
@@ -800,6 +811,12 @@ int fileWrite(const std::string &path, const std::string &content, bool overwrit
|
||||
outfile << content;
|
||||
outfile.close();
|
||||
return 0;
|
||||
*/
|
||||
const char *mode = overwrite ? "wb" : "ab";
|
||||
std::FILE *fp = std::fopen(path.c_str(), mode);
|
||||
std::fwrite(content.c_str(), 1, content.size(), fp);
|
||||
std::fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool isIPv4(const std::string &address)
|
||||
@@ -845,20 +862,23 @@ std::string rand_str(const int len)
|
||||
void urlParse(std::string &url, std::string &host, std::string &path, int &port, bool &isTLS)
|
||||
{
|
||||
std::vector<std::string> args;
|
||||
string_size pos;
|
||||
|
||||
if(regMatch(url, "^https://(.*)"))
|
||||
isTLS = true;
|
||||
url = regReplace(url, "^(http|https)://", "");
|
||||
if(url.find("/") == url.npos)
|
||||
pos = url.find("/");
|
||||
if(pos == url.npos)
|
||||
{
|
||||
host = url;
|
||||
path = "/";
|
||||
}
|
||||
else
|
||||
{
|
||||
host = url.substr(0, url.find("/"));
|
||||
path = url.substr(url.find("/"));
|
||||
host = url.substr(0, pos);
|
||||
path = url.substr(pos);
|
||||
}
|
||||
pos = host.rfind(":");
|
||||
if(regFind(host, "\\[(.*)\\]")) //IPv6
|
||||
{
|
||||
args = split(regReplace(host, "\\[(.*)\\](.*)", "$1,$2"), ",");
|
||||
@@ -866,10 +886,10 @@ void urlParse(std::string &url, std::string &host, std::string &path, int &port,
|
||||
port = to_int(args[1].substr(1));
|
||||
host = args[0];
|
||||
}
|
||||
else if(strFind(host, ":"))
|
||||
else if(pos != host.npos)
|
||||
{
|
||||
port = to_int(host.substr(host.rfind(":") + 1));
|
||||
host = host.substr(0, host.rfind(":"));
|
||||
port = to_int(host.substr(pos + 1));
|
||||
host = host.substr(0, pos);
|
||||
}
|
||||
if(port == 0)
|
||||
{
|
||||
|
||||
@@ -1236,6 +1236,7 @@ std::string netchToSurge(std::vector<nodeInfo> &nodes, std::string &base_conf, s
|
||||
return std::move(a) + "," + std::move(b);
|
||||
});
|
||||
ini.Set("{NONAME}", vArray[0] + " = " + proxy); //insert order
|
||||
continue;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
@@ -1681,6 +1682,9 @@ void netchToQuan(std::vector<nodeInfo> &nodes, INIReader &ini, std::vector<rules
|
||||
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];
|
||||
@@ -1897,6 +1901,9 @@ 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);
|
||||
@@ -2399,6 +2406,7 @@ std::string netchToLoon(std::vector<nodeInfo> &nodes, std::string &base_conf, st
|
||||
return std::move(a) + "," + std::move(b);
|
||||
});
|
||||
ini.Set("{NONAME}", vArray[0] + " = " + proxy); //insert order
|
||||
continue;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user