From 3989b7ee5e1b322bec5fd25f655b8b3ab513a3da Mon Sep 17 00:00:00 2001 From: Tindy X <49061470+tindy2013@users.noreply.github.com> Date: Tue, 14 Jul 2020 03:04:48 +0800 Subject: [PATCH] Add fallback support for different names of Shadowsocks plugins Fix compatibility problem with some non-standard v2rayN subscription. Fix running program from directory other than program folder may cause not using pref.yml as default. Optimize codes. --- src/main.cpp | 8 ++++---- src/misc.cpp | 14 ++++++++++++++ src/misc.h | 1 + src/speedtestutil.cpp | 1 + src/subexport.cpp | 2 ++ 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 2e028ef..0efbbeb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -99,6 +99,10 @@ void signal_handler(int sig) int main(int argc, char *argv[]) { +#ifndef _DEBUG + std::string prgpath = argv[0]; + setcd(prgpath); //first switch to program directory +#endif // _DEBUG if(fileExist("pref.yml")) pref_path = "pref.yml"; chkArg(argc, argv); @@ -125,10 +129,6 @@ int main(int argc, char *argv[]) signal(SIGINT, signal_handler); SetConsoleTitle("SubConverter " VERSION); -#ifndef _DEBUG - std::string prgpath = argv[0]; - setcd(prgpath); //first switch to program directory -#endif // _DEBUG readConf(); if(!update_ruleset_on_request) refreshRulesets(rulesets, ruleset_content_array); diff --git a/src/misc.cpp b/src/misc.cpp index ec80884..851d167 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -451,6 +451,20 @@ std::string getSystemProxy() #endif // _WIN32 } +void trim_self_of(std::string &str, char target, bool before, bool after) +{ + if (!before && !after) + return; + std::string::size_type pos = str.size() - 1; + if (after) + pos = str.find_last_not_of(target); + if (pos != std::string::npos) + str.erase(pos + 1); + if (before) + pos = str.find_first_not_of(target); + str.erase(0, pos); +} + std::string trim_of(const std::string& str, char target, bool before, bool after) { if (!before && !after) diff --git a/src/misc.h b/src/misc.h index a723932..0958068 100644 --- a/src/misc.h +++ b/src/misc.h @@ -55,6 +55,7 @@ std::string ACPToUTF8(const std::string &str_src); std::string trim_of(const std::string& str, char target, bool before = true, bool after = true); std::string trim(const std::string& str, bool before = true, bool after = true); std::string trim_quote(const std::string &str, bool before = true, bool after = true); +void trim_self_of(std::string &str, char target, bool before = true, bool after = true); std::string getSystemProxy(); std::string rand_str(const int len); bool is_str_utf8(const std::string &data); diff --git a/src/speedtestutil.cpp b/src/speedtestutil.cpp index 3bebf47..d42f808 100644 --- a/src/speedtestutil.cpp +++ b/src/speedtestutil.cpp @@ -85,6 +85,7 @@ void explodeVmess(std::string vmess, const std::string &custom_port, nodeInfo &n break; } + add = trim(add); node.linkType = SPEEDTEST_MESSAGE_FOUNDVMESS; node.group = V2RAY_DEFAULT_GROUP; node.remarks = ps; diff --git a/src/subexport.cpp b/src/subexport.cpp index 9801a22..63ef75d 100644 --- a/src/subexport.cpp +++ b/src/subexport.cpp @@ -1548,6 +1548,7 @@ std::string netchToSurge(std::vector &nodes, const std::string &base_c switch(hash_(plugin)) { case "simple-obfs"_hash: + case "obfs-local"_hash: if(pluginopts.size()) proxy += "," + replace_all_distinct(pluginopts, ";", ","); break; @@ -2299,6 +2300,7 @@ void netchToQuanX(std::vector &nodes, INIReader &ini, std::vector