mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2026-11-04 10:42:04 +00:00
Add update-interval option to exported Surge RULE-SET
Optimize codes.
This commit is contained in:
3 files changed
+24
-17
No files matched your search
+1
-1
@@ -1240,7 +1240,7 @@ int loadExternalConfig(std::string &path, ExternalConfig &ext)
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
YAML::Node yaml = YAML::Load(base_content);
|
YAML::Node yaml = YAML::Load(base_content);
|
||||||
if(yaml.size() && yaml["custom"])
|
if(yaml.size() && yaml["custom"].IsDefined())
|
||||||
return loadExternalYAML(yaml, ext);
|
return loadExternalYAML(yaml, ext);
|
||||||
}
|
}
|
||||||
catch (YAML::Exception &e)
|
catch (YAML::Exception &e)
|
||||||
|
|||||||
+18
-16
@@ -155,7 +155,7 @@ class tribool
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
int _M_VALUE = -1;
|
char _M_VALUE = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -179,14 +179,15 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator bool() const { return _M_VALUE == 1; }
|
operator bool() const { return _M_VALUE == 3; }
|
||||||
|
|
||||||
bool is_undef() { return _M_VALUE == -1; }
|
bool is_undef() { return _M_VALUE <= 1; }
|
||||||
|
|
||||||
template <typename T> void define(const T &value)
|
template <typename T> tribool define(const T &value)
|
||||||
{
|
{
|
||||||
if(_M_VALUE == -1)
|
if(_M_VALUE <= 1)
|
||||||
*this = value;
|
*this = value;
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> tribool read(const T &value)
|
template <typename T> tribool read(const T &value)
|
||||||
@@ -197,13 +198,14 @@ public:
|
|||||||
|
|
||||||
tribool reverse()
|
tribool reverse()
|
||||||
{
|
{
|
||||||
_M_VALUE = _M_VALUE == -1 ? -1 : (_M_VALUE == 0 ? 1 : 0);
|
if(_M_VALUE > 1)
|
||||||
|
_M_VALUE = _M_VALUE > 2 ? 2 : 3;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get(const bool &def_value = false)
|
bool get(const bool &def_value = false)
|
||||||
{
|
{
|
||||||
if(_M_VALUE == -1)
|
if(_M_VALUE <= 1)
|
||||||
return def_value;
|
return def_value;
|
||||||
return _M_VALUE;
|
return _M_VALUE;
|
||||||
}
|
}
|
||||||
@@ -212,9 +214,9 @@ public:
|
|||||||
{
|
{
|
||||||
switch(_M_VALUE)
|
switch(_M_VALUE)
|
||||||
{
|
{
|
||||||
case 0:
|
case 2:
|
||||||
return "false";
|
return "false";
|
||||||
case 1:
|
case 3:
|
||||||
return "true";
|
return "true";
|
||||||
}
|
}
|
||||||
return "undef";
|
return "undef";
|
||||||
@@ -222,8 +224,8 @@ public:
|
|||||||
|
|
||||||
template <typename T> bool set(const T &value)
|
template <typename T> bool set(const T &value)
|
||||||
{
|
{
|
||||||
_M_VALUE = value;
|
_M_VALUE = (bool)value + 2;
|
||||||
return _M_VALUE;
|
return _M_VALUE > 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool set(const std::string &str)
|
bool set(const std::string &str)
|
||||||
@@ -232,23 +234,23 @@ public:
|
|||||||
{
|
{
|
||||||
case "true"_hash:
|
case "true"_hash:
|
||||||
case "1"_hash:
|
case "1"_hash:
|
||||||
_M_VALUE = 1;
|
_M_VALUE = 3;
|
||||||
break;
|
break;
|
||||||
case "false"_hash:
|
case "false"_hash:
|
||||||
case "0"_hash:
|
case "0"_hash:
|
||||||
_M_VALUE = 0;
|
_M_VALUE = 2;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if(to_int(str, 0) > 1)
|
if(to_int(str, 0) > 1)
|
||||||
_M_VALUE = 1;
|
_M_VALUE = 3;
|
||||||
else
|
else
|
||||||
_M_VALUE = -1;
|
_M_VALUE = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return _M_VALUE;
|
return _M_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear() { _M_VALUE = -1; }
|
void clear() { _M_VALUE = 0; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef HAVE_TO_STRING
|
#ifndef HAVE_TO_STRING
|
||||||
|
|||||||
@@ -868,6 +868,8 @@ void rulesetToSurge(INIReader &base_rule, std::vector<ruleset_content> &ruleset_
|
|||||||
if(surge_ver > 2 && remote_path_prefix.size())
|
if(surge_ver > 2 && remote_path_prefix.size())
|
||||||
{
|
{
|
||||||
strLine = "RULE-SET," + remote_path_prefix + "/getruleset?type=1&url=" + urlsafe_base64_encode(rule_path_typed) + "," + rule_group;
|
strLine = "RULE-SET," + remote_path_prefix + "/getruleset?type=1&url=" + urlsafe_base64_encode(rule_path_typed) + "," + rule_group;
|
||||||
|
if(x.update_interval)
|
||||||
|
strLine += ",update-interval=" + std::to_string(x.update_interval);
|
||||||
allRules.emplace_back(std::move(strLine));
|
allRules.emplace_back(std::move(strLine));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -899,6 +901,9 @@ void rulesetToSurge(INIReader &base_rule, std::vector<ruleset_content> &ruleset_
|
|||||||
else
|
else
|
||||||
strLine = "RULE-SET," + rule_path + "," + rule_group;
|
strLine = "RULE-SET," + rule_path + "," + rule_group;
|
||||||
|
|
||||||
|
if(x.update_interval)
|
||||||
|
strLine += ",update-interval=" + std::to_string(x.update_interval);
|
||||||
|
|
||||||
allRules.emplace_back(std::move(strLine));
|
allRules.emplace_back(std::move(strLine));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user