mirror of
https://github.com/2dust/v2rayN.git
synced 2025-10-27 10:40:08 +00:00
Compare commits
17 commits
d99daac318
...
5d8ff38be6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d8ff38be6 | ||
|
|
2a7095aa1e | ||
|
|
531bdc522d | ||
|
|
6ff6f58129 | ||
|
|
f8fb492bc5 | ||
|
|
73c2a203de | ||
|
|
00ed1edf92 | ||
|
|
76f39ccac4 | ||
|
|
5b073927d2 | ||
|
|
5452341b60 | ||
|
|
d8a658037d | ||
|
|
91eb1846fb | ||
|
|
e1bb6abfdf | ||
|
|
1b9e5eca3e | ||
|
|
d0c177643c | ||
|
|
352490c165 | ||
|
|
2d29a4596a |
7 changed files with 27 additions and 132 deletions
|
|
@ -331,32 +331,6 @@ public class Utils
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Dictionary<string, List<string>> ParseHostsToDictionary(string hostsContent)
|
|
||||||
{
|
|
||||||
var userHostsMap = hostsContent
|
|
||||||
.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
|
|
||||||
.Select(line => line.Trim())
|
|
||||||
// skip full-line comments
|
|
||||||
.Where(line => !string.IsNullOrWhiteSpace(line) && !line.StartsWith("#"))
|
|
||||||
// strip inline comments (truncate at '#')
|
|
||||||
.Select(line =>
|
|
||||||
{
|
|
||||||
var index = line.IndexOf('#');
|
|
||||||
return index >= 0 ? line.Substring(0, index).Trim() : line;
|
|
||||||
})
|
|
||||||
// ensure line still contains valid parts
|
|
||||||
.Where(line => !string.IsNullOrWhiteSpace(line) && line.Contains(' '))
|
|
||||||
.Select(line => line.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries))
|
|
||||||
.Where(parts => parts.Length >= 2)
|
|
||||||
.GroupBy(parts => parts[0])
|
|
||||||
.ToDictionary(
|
|
||||||
group => group.Key,
|
|
||||||
group => group.SelectMany(parts => parts.Skip(1)).ToList()
|
|
||||||
);
|
|
||||||
|
|
||||||
return userHostsMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion 转换函数
|
#endregion 转换函数
|
||||||
|
|
||||||
#region 数据检查
|
#region 数据检查
|
||||||
|
|
@ -883,55 +857,6 @@ public class Utils
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsPackagedInstall()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (IsWindows() || IsOSX())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("APPIMAGE")))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
var exePath = GetExePath();
|
|
||||||
var baseDir = string.IsNullOrEmpty(exePath) ? StartupPath() : Path.GetDirectoryName(exePath) ?? "";
|
|
||||||
var p = baseDir.Replace('\\', '/');
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(p))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p.Contains("/.mount_", StringComparison.Ordinal))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p.StartsWith("/opt/v2rayN", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p.StartsWith("/usr/lib/v2rayN", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p.StartsWith("/usr/share/v2rayN", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async Task<string?> GetLinuxUserId()
|
private static async Task<string?> GetLinuxUserId()
|
||||||
{
|
{
|
||||||
var arg = new List<string>() { "-c", "id -u" };
|
var arg = new List<string>() { "-c", "id -u" };
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,17 @@ public partial class CoreConfigSingboxService
|
||||||
|
|
||||||
if (!simpleDNSItem.Hosts.IsNullOrEmpty())
|
if (!simpleDNSItem.Hosts.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
var userHostsMap = Utils.ParseHostsToDictionary(simpleDNSItem.Hosts);
|
var userHostsMap = simpleDNSItem.Hosts
|
||||||
|
.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
|
||||||
|
.Select(line => line.Trim())
|
||||||
|
.Where(line => !string.IsNullOrWhiteSpace(line) && line.Contains(' '))
|
||||||
|
.Select(line => line.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries))
|
||||||
|
.Where(parts => parts.Length >= 2)
|
||||||
|
.GroupBy(parts => parts[0])
|
||||||
|
.ToDictionary(
|
||||||
|
group => group.Key,
|
||||||
|
group => group.SelectMany(parts => parts.Skip(1)).ToList()
|
||||||
|
);
|
||||||
|
|
||||||
foreach (var kvp in userHostsMap)
|
foreach (var kvp in userHostsMap)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -71,31 +71,6 @@ public partial class CoreConfigSingboxService
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var hostsDomains = new List<string>();
|
|
||||||
var systemHostsMap = Utils.GetSystemHosts();
|
|
||||||
foreach (var kvp in systemHostsMap)
|
|
||||||
{
|
|
||||||
hostsDomains.Add(kvp.Key);
|
|
||||||
}
|
|
||||||
var dnsItem = await AppManager.Instance.GetDNSItem(ECoreType.sing_box);
|
|
||||||
if (dnsItem == null || dnsItem.Enabled == false)
|
|
||||||
{
|
|
||||||
var simpleDNSItem = _config.SimpleDNSItem;
|
|
||||||
if (!simpleDNSItem.Hosts.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
var userHostsMap = Utils.ParseHostsToDictionary(simpleDNSItem.Hosts);
|
|
||||||
foreach (var kvp in userHostsMap)
|
|
||||||
{
|
|
||||||
hostsDomains.Add(kvp.Key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
singboxConfig.route.rules.Add(new()
|
|
||||||
{
|
|
||||||
action = "resolve",
|
|
||||||
domain = hostsDomains,
|
|
||||||
});
|
|
||||||
|
|
||||||
singboxConfig.route.rules.Add(new()
|
singboxConfig.route.rules.Add(new()
|
||||||
{
|
{
|
||||||
outbound = Global.DirectTag,
|
outbound = Global.DirectTag,
|
||||||
|
|
|
||||||
|
|
@ -261,7 +261,17 @@ public partial class CoreConfigV2rayService
|
||||||
|
|
||||||
if (!simpleDNSItem.Hosts.IsNullOrEmpty())
|
if (!simpleDNSItem.Hosts.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
var userHostsMap = Utils.ParseHostsToDictionary(simpleDNSItem.Hosts);
|
var userHostsMap = simpleDNSItem.Hosts
|
||||||
|
.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
|
||||||
|
.Select(line => line.Trim())
|
||||||
|
.Where(line => !string.IsNullOrWhiteSpace(line) && line.Contains(' '))
|
||||||
|
.Select(line => line.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries))
|
||||||
|
.Where(parts => parts.Length >= 2)
|
||||||
|
.GroupBy(parts => parts[0])
|
||||||
|
.ToDictionary(
|
||||||
|
group => group.Key,
|
||||||
|
group => group.SelectMany(parts => parts.Skip(1)).ToList()
|
||||||
|
);
|
||||||
|
|
||||||
foreach (var kvp in userHostsMap)
|
foreach (var kvp in userHostsMap)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -39,30 +39,26 @@ public class AddGroupServerViewModel : MyReactiveObject
|
||||||
_config = AppManager.Instance.Config;
|
_config = AppManager.Instance.Config;
|
||||||
_updateView = updateView;
|
_updateView = updateView;
|
||||||
|
|
||||||
var canEditRemove = this.WhenAnyValue(
|
|
||||||
x => x.SelectedChild,
|
|
||||||
SelectedChild => SelectedChild != null && !SelectedChild.Remarks.IsNullOrEmpty());
|
|
||||||
|
|
||||||
RemoveCmd = ReactiveCommand.CreateFromTask(async () =>
|
RemoveCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||||
{
|
{
|
||||||
await ChildRemoveAsync();
|
await ChildRemoveAsync();
|
||||||
}, canEditRemove);
|
});
|
||||||
MoveTopCmd = ReactiveCommand.CreateFromTask(async () =>
|
MoveTopCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||||
{
|
{
|
||||||
await MoveServer(EMove.Top);
|
await MoveServer(EMove.Top);
|
||||||
}, canEditRemove);
|
});
|
||||||
MoveUpCmd = ReactiveCommand.CreateFromTask(async () =>
|
MoveUpCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||||
{
|
{
|
||||||
await MoveServer(EMove.Up);
|
await MoveServer(EMove.Up);
|
||||||
}, canEditRemove);
|
});
|
||||||
MoveDownCmd = ReactiveCommand.CreateFromTask(async () =>
|
MoveDownCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||||
{
|
{
|
||||||
await MoveServer(EMove.Down);
|
await MoveServer(EMove.Down);
|
||||||
}, canEditRemove);
|
});
|
||||||
MoveBottomCmd = ReactiveCommand.CreateFromTask(async () =>
|
MoveBottomCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||||
{
|
{
|
||||||
await MoveServer(EMove.Bottom);
|
await MoveServer(EMove.Bottom);
|
||||||
}, canEditRemove);
|
});
|
||||||
SaveCmd = ReactiveCommand.CreateFromTask(async () =>
|
SaveCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||||
{
|
{
|
||||||
await SaveServerAsync();
|
await SaveServerAsync();
|
||||||
|
|
|
||||||
|
|
@ -63,16 +63,6 @@ public class CheckUpdateViewModel : MyReactiveObject
|
||||||
|
|
||||||
private CheckUpdateModel GetCheckUpdateModel(string coreType)
|
private CheckUpdateModel GetCheckUpdateModel(string coreType)
|
||||||
{
|
{
|
||||||
if (coreType == _v2rayN && Utils.IsPackagedInstall())
|
|
||||||
{
|
|
||||||
return new()
|
|
||||||
{
|
|
||||||
IsSelected = false,
|
|
||||||
CoreType = coreType,
|
|
||||||
Remarks = ResUI.menuCheckUpdate + " (Not Support)",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return new()
|
return new()
|
||||||
{
|
{
|
||||||
IsSelected = _config.CheckUpdateItem.SelectedCoreTypes?.Contains(coreType) ?? true,
|
IsSelected = _config.CheckUpdateItem.SelectedCoreTypes?.Contains(coreType) ?? true,
|
||||||
|
|
@ -114,11 +104,6 @@ public class CheckUpdateViewModel : MyReactiveObject
|
||||||
}
|
}
|
||||||
else if (item.CoreType == _v2rayN)
|
else if (item.CoreType == _v2rayN)
|
||||||
{
|
{
|
||||||
if (Utils.IsPackagedInstall())
|
|
||||||
{
|
|
||||||
await UpdateView(_v2rayN, "Not Support");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
await CheckUpdateN(EnableCheckPreReleaseUpdate);
|
await CheckUpdateN(EnableCheckPreReleaseUpdate);
|
||||||
}
|
}
|
||||||
else if (item.CoreType == ECoreType.Xray.ToString())
|
else if (item.CoreType == ECoreType.Xray.ToString())
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ public partial class AddGroupServerWindow
|
||||||
this.Loaded += Window_Loaded;
|
this.Loaded += Window_Loaded;
|
||||||
this.PreviewKeyDown += AddGroupServerWindow_PreviewKeyDown;
|
this.PreviewKeyDown += AddGroupServerWindow_PreviewKeyDown;
|
||||||
lstChild.SelectionChanged += LstChild_SelectionChanged;
|
lstChild.SelectionChanged += LstChild_SelectionChanged;
|
||||||
menuSelectAllChild.Click += MenuSelectAllChild_Click;
|
|
||||||
|
|
||||||
ViewModel = new AddGroupServerViewModel(profileItem, UpdateViewHandler);
|
ViewModel = new AddGroupServerViewModel(profileItem, UpdateViewHandler);
|
||||||
|
|
||||||
|
|
@ -139,9 +138,4 @@ public partial class AddGroupServerWindow
|
||||||
ViewModel.SelectedChildren = lstChild.SelectedItems.Cast<ProfileItem>().ToList();
|
ViewModel.SelectedChildren = lstChild.SelectedItems.Cast<ProfileItem>().ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MenuSelectAllChild_Click(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
lstChild.SelectAll();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue