Add update-interval option to exported Surge RULE-SET

Optimize codes.
This commit is contained in:
Tindy X committed 2020-07-22 23:55:17 +08:00
1 parent 4f039bd726
commit e34c60af6a
3 files changed
+24 -17

No files matched your search

+1 -1
View File
@@ -1240,7 +1240,7 @@ int loadExternalConfig(std::string &path, ExternalConfig &ext)
try
{
YAML::Node yaml = YAML::Load(base_content);
if(yaml.size() && yaml["custom"])
if(yaml.size() && yaml["custom"].IsDefined())
return loadExternalYAML(yaml, ext);
}
catch (YAML::Exception &e)
+18 -16
View File
@@ -155,7 +155,7 @@ class tribool
{
private:
int _M_VALUE = -1;
char _M_VALUE = 0;
public:
@@ -179,14 +179,15 @@ public:
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;
return *this;
}
template <typename T> tribool read(const T &value)
@@ -197,13 +198,14 @@ public:
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;
}
bool get(const bool &def_value = false)
{
if(_M_VALUE == -1)
if(_M_VALUE <= 1)
return def_value;
return _M_VALUE;
}
@@ -212,9 +214,9 @@ public:
{
switch(_M_VALUE)
{
case 0:
case 2:
return "false";
case 1:
case 3:
return "true";
}
return "undef";
@@ -222,8 +224,8 @@ public:
template <typename T> bool set(const T &value)
{
_M_VALUE = value;
return _M_VALUE;
_M_VALUE = (bool)value + 2;
return _M_VALUE > 2;
}
bool set(const std::string &str)
@@ -232,23 +234,23 @@ public:
{
case "true"_hash:
case "1"_hash:
_M_VALUE = 1;
_M_VALUE = 3;
break;
case "false"_hash:
case "0"_hash:
_M_VALUE = 0;
_M_VALUE = 2;
break;
default:
if(to_int(str, 0) > 1)
_M_VALUE = 1;
_M_VALUE = 3;
else
_M_VALUE = -1;
_M_VALUE = 0;
break;
}
return _M_VALUE;
}
void clear() { _M_VALUE = -1; }
void clear() { _M_VALUE = 0; }
};
#ifndef HAVE_TO_STRING
+5
View File
@@ -868,6 +868,8 @@ void rulesetToSurge(INIReader &base_rule, std::vector<ruleset_content> &ruleset_
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;
if(x.update_interval)
strLine += ",update-interval=" + std::to_string(x.update_interval);
allRules.emplace_back(std::move(strLine));
continue;
}
@@ -899,6 +901,9 @@ void rulesetToSurge(INIReader &base_rule, std::vector<ruleset_content> &ruleset_
else
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));
continue;
}