mirror of
https://github.com/2dust/v2rayN.git
synced 2025-08-29 22:36:20 +00:00
server filter add regex support
This commit is contained in:
parent
8a3eb41314
commit
05ff7341bb
3 changed files with 61 additions and 2 deletions
|
@ -1,5 +1,8 @@
|
|||
using SQLite;
|
||||
using SQLitePCL;
|
||||
using System.Collections;
|
||||
using System.Drawing;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace v2rayN
|
||||
{
|
||||
|
@ -17,6 +20,20 @@ namespace v2rayN
|
|||
_connstr = Utils.GetConfigPath(Global.ConfigDB);
|
||||
_db = new SQLiteConnection(_connstr, false);
|
||||
_dbAsync = new SQLiteAsyncConnection(_connstr, false);
|
||||
SQLitePCL.raw.sqlite3_create_function(_db.Handle, "REGEXP", 2, null, MatchRegex);
|
||||
SQLitePCL.raw.sqlite3_create_function(_dbAsync.GetConnection().Handle, "REGEXP", 2, null, MatchRegex);
|
||||
}
|
||||
|
||||
private void MatchRegex(sqlite3_context ctx, object user_data, sqlite3_value[] args)
|
||||
{
|
||||
lock (objLock)
|
||||
{
|
||||
bool isMatched = System.Text.RegularExpressions.Regex.IsMatch(SQLitePCL.raw.sqlite3_value_text(args[1]).utf8_to_string(), SQLitePCL.raw.sqlite3_value_text(args[0]).utf8_to_string(), RegexOptions.IgnoreCase);
|
||||
if (isMatched)
|
||||
SQLitePCL.raw.sqlite3_result_int(ctx, 1);
|
||||
else
|
||||
SQLitePCL.raw.sqlite3_result_int(ctx, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public CreateTableResult CreateTable<T>()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Runtime.Intrinsics.X86;
|
||||
using v2rayN.Base;
|
||||
using v2rayN.Mode;
|
||||
|
||||
namespace v2rayN.Handler
|
||||
|
@ -73,6 +73,19 @@ namespace v2rayN.Handler
|
|||
return SqliteHelper.Instance.Table<SubItem>().FirstOrDefault(t => t.id == subid);
|
||||
}
|
||||
|
||||
public List<SubItem> SubItemIndexs(string filterreg)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(filterreg))
|
||||
{
|
||||
return SqliteHelper.Instance.Table<SubItem>().ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
var sql = String.Format("SELECT * FROM SubItem WHERE remarks REGEXP '{0}'",filterreg);
|
||||
return SqliteHelper.Instance.Query<SubItem>(sql);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ProfileItem> ProfileItems(string subid)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(subid))
|
||||
|
@ -120,6 +133,35 @@ namespace v2rayN.Handler
|
|||
return SqliteHelper.Instance.Query<ProfileItemModel>(sql).ToList();
|
||||
}
|
||||
|
||||
public List<ProfileItemModel> ProfileItemsReg(string subidfilter, string profilefilter)
|
||||
{
|
||||
var sql = @$"SELECT * FROM ProfileItem";
|
||||
|
||||
if (!Utils.IsNullOrEmpty(profilefilter))
|
||||
{
|
||||
if (profilefilter[0] != '^' && profilefilter[0] != '.')
|
||||
profilefilter = @".*" + profilefilter;
|
||||
if (profilefilter[profilefilter.Length - 1] != '$' && profilefilter[profilefilter.Length - 1] != '*')
|
||||
profilefilter = profilefilter + @".*";
|
||||
|
||||
sql += String.Format(" WHERE remarks REGEXP '{0}'", profilefilter);
|
||||
}
|
||||
|
||||
if (!Utils.IsNullOrEmpty(subidfilter))
|
||||
{
|
||||
//if (subidfilter[0] != '^' && subidfilter[0] != '.')
|
||||
// subidfilter = @".*" + subidfilter;
|
||||
//if (subidfilter[subidfilter.Length-1] != '$' && subidfilter[subidfilter.Length - 1] != '*')
|
||||
// subidfilter =subidfilter+@".*";
|
||||
if (!Utils.IsNullOrEmpty(profilefilter))
|
||||
sql += String.Format(" AND subid REGEXP '{0}'", subidfilter);
|
||||
else
|
||||
sql += String.Format(" WHERE subid REGEXP '{0}'", subidfilter);
|
||||
}
|
||||
|
||||
return SqliteHelper.Instance.Query<ProfileItemModel>(sql).ToList();
|
||||
}
|
||||
|
||||
public ProfileItem? GetProfileItem(string indexId)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(indexId))
|
||||
|
|
|
@ -800,7 +800,7 @@ namespace v2rayN.ViewModels
|
|||
|
||||
public void RefreshServers()
|
||||
{
|
||||
List<ProfileItemModel> lstModel = LazyConfig.Instance.ProfileItems(_subId, _serverFilter);
|
||||
List<ProfileItemModel> lstModel = LazyConfig.Instance.ProfileItemsReg(_subId, _serverFilter);
|
||||
|
||||
ConfigHandler.SetDefaultServer(_config, lstModel);
|
||||
|
||||
|
|
Loading…
Reference in a new issue