Fix broken TUN if custom geo file is selected

This commit is contained in:
runetfreedom 2024-10-15 03:08:37 +03:00
parent 24afe8bde4
commit 65f14705fe
9 changed files with 32 additions and 17 deletions

View file

@ -114,11 +114,21 @@
@"http://www.msftconnecttest.com/connecttest.txt", @"http://www.msftconnecttest.com/connecttest.txt",
}; };
public static readonly List<string> GeoSourceNames = new() {
"", //Default
"Russia",
};
public static readonly List<string> GeoFilesSources = new() { public static readonly List<string> GeoFilesSources = new() {
GeoUrl, GeoUrl,
@"https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/{0}.dat", @"https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/{0}.dat",
}; };
public static readonly List<string> SingboxRulesetSources = new() {
SingboxRulesetUrl,
@"https://raw.githubusercontent.com/runetfreedom/russia-v2ray-rules-dat/refs/heads/release/sing-box/rule-set-{0}/{1}.srs",
};
public static readonly Dictionary<string, string> UserAgentTexts = new() public static readonly Dictionary<string, string> UserAgentTexts = new()
{ {
{"chrome","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36" }, {"chrome","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36" },

View file

@ -140,7 +140,7 @@
{ {
public string defIEProxyExceptions { get; set; } public string defIEProxyExceptions { get; set; }
public string subConvertUrl { get; set; } = string.Empty; public string subConvertUrl { get; set; } = string.Empty;
public string? geoSourceUrl { get; set; } public int geoSource { get; set; } = 0;
} }
[Serializable] [Serializable]

View file

@ -1367,12 +1367,16 @@ namespace ServiceLib.Services.CoreConfig
} }
else else
{ {
var geoUrl = Global.SingboxRulesetSources.Count <= _config.constItem.geoSource
? Global.SingboxRulesetUrl
: Global.SingboxRulesetSources[_config.constItem.geoSource];
customRuleset = new() customRuleset = new()
{ {
type = "remote", type = "remote",
format = "binary", format = "binary",
tag = item, tag = item,
url = string.Format(Global.SingboxRulesetUrl, item.StartsWith(geosite) ? geosite : geoip, item), url = string.Format(geoUrl, item.StartsWith(geosite) ? geosite : geoip, item),
download_detour = Global.ProxyTag download_detour = Global.ProxyTag
}; };
} }

View file

@ -451,10 +451,11 @@ namespace ServiceLib.Services
_config = config; _config = config;
_updateFunc = updateFunc; _updateFunc = updateFunc;
var geoUrl = string.IsNullOrEmpty(config?.constItem.geoSourceUrl) var geoIndex = config?.constItem.geoSource ?? 0;
var geoUrl = Global.GeoFilesSources.Count <= geoIndex
? Global.GeoUrl ? Global.GeoUrl
: config.constItem.geoSourceUrl; : Global.GeoFilesSources[geoIndex];
var url = string.Format(Global.GeoUrl, geoName); var url = string.Format(geoUrl, geoName);
var fileName = Utils.GetTempPath(Utils.GetGuid()); var fileName = Utils.GetTempPath(Utils.GetGuid());
DownloadService downloadHandle = new(); DownloadService downloadHandle = new();

View file

@ -65,7 +65,7 @@ namespace ServiceLib.ViewModels
[Reactive] public bool EnableHWA { get; set; } [Reactive] public bool EnableHWA { get; set; }
[Reactive] public string SubConvertUrl { get; set; } [Reactive] public string SubConvertUrl { get; set; }
[Reactive] public int MainGirdOrientation { get; set; } [Reactive] public int MainGirdOrientation { get; set; }
[Reactive] public string GeoFileSourceUrl { get; set; } [Reactive] public int GeoFileSource { get; set; }
#endregion UI #endregion UI
@ -165,7 +165,7 @@ namespace ServiceLib.ViewModels
EnableHWA = _config.guiItem.enableHWA; EnableHWA = _config.guiItem.enableHWA;
SubConvertUrl = _config.constItem.subConvertUrl; SubConvertUrl = _config.constItem.subConvertUrl;
MainGirdOrientation = (int)_config.uiItem.mainGirdOrientation; MainGirdOrientation = (int)_config.uiItem.mainGirdOrientation;
GeoFileSourceUrl = _config.constItem.geoSourceUrl; GeoFileSource = _config.constItem.geoSource;
#endregion UI #endregion UI
@ -318,7 +318,7 @@ namespace ServiceLib.ViewModels
_config.guiItem.enableHWA = EnableHWA; _config.guiItem.enableHWA = EnableHWA;
_config.constItem.subConvertUrl = SubConvertUrl; _config.constItem.subConvertUrl = SubConvertUrl;
_config.uiItem.mainGirdOrientation = (EGirdOrientation)MainGirdOrientation; _config.uiItem.mainGirdOrientation = (EGirdOrientation)MainGirdOrientation;
_config.constItem.geoSourceUrl = GeoFileSourceUrl; _config.constItem.geoSource = GeoFileSource;
//systemProxy //systemProxy
_config.systemProxyItem.systemProxyExceptions = systemProxyExceptions; _config.systemProxyItem.systemProxyExceptions = systemProxyExceptions;

View file

@ -619,7 +619,7 @@
Classes="Margin8" Classes="Margin8"
Text="{x:Static resx:ResUI.TbSettingsGeoFilesSource}" /> Text="{x:Static resx:ResUI.TbSettingsGeoFilesSource}" />
<ComboBox <ComboBox
x:Name="cmbGetFilesSourceUrl" x:Name="cmbGetFilesSource"
Grid.Row="22" Grid.Row="22"
Grid.Column="1" Grid.Column="1"
Width="300" Width="300"

View file

@ -83,9 +83,9 @@ namespace v2rayN.Desktop.Views
{ {
cmbSubConvertUrl.Items.Add(it); cmbSubConvertUrl.Items.Add(it);
}); });
Global.GeoFilesSources.ForEach(it => Global.GeoSourceNames.ForEach(it =>
{ {
cmbGetFilesSourceUrl.Items.Add(it); cmbGetFilesSource.Items.Add(it);
}); });
foreach (EGirdOrientation it in Enum.GetValues(typeof(EGirdOrientation))) foreach (EGirdOrientation it in Enum.GetValues(typeof(EGirdOrientation)))
{ {
@ -136,7 +136,7 @@ namespace v2rayN.Desktop.Views
this.Bind(ViewModel, vm => vm.SpeedPingTestUrl, v => v.cmbSpeedPingTestUrl.SelectedValue).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SpeedPingTestUrl, v => v.cmbSpeedPingTestUrl.SelectedValue).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SubConvertUrl, v => v.cmbSubConvertUrl.SelectedValue).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SubConvertUrl, v => v.cmbSubConvertUrl.SelectedValue).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.MainGirdOrientation, v => v.cmbMainGirdOrientation.SelectedIndex).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.MainGirdOrientation, v => v.cmbMainGirdOrientation.SelectedIndex).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.GeoFileSourceUrl, v => v.cmbGetFilesSourceUrl.SelectedValue).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.GeoFileSource, v => v.cmbGetFilesSource.SelectedIndex).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.notProxyLocalAddress, v => v.tognotProxyLocalAddress.IsChecked).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.notProxyLocalAddress, v => v.tognotProxyLocalAddress.IsChecked).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.systemProxyAdvancedProtocol, v => v.cmbsystemProxyAdvancedProtocol.SelectedValue).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.systemProxyAdvancedProtocol, v => v.cmbsystemProxyAdvancedProtocol.SelectedValue).DisposeWith(disposables);

View file

@ -855,12 +855,12 @@
Style="{StaticResource ToolbarTextBlock}" Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbSettingsGeoFilesSource}" /> Text="{x:Static resx:ResUI.TbSettingsGeoFilesSource}" />
<ComboBox <ComboBox
x:Name="cmbGetFilesSourceUrl" x:Name="cmbGetFilesSource"
Grid.Row="22" Grid.Row="22"
Grid.Column="1" Grid.Column="1"
Width="300" Width="300"
Margin="{StaticResource Margin8}" Margin="{StaticResource Margin8}"
IsEditable="True" IsEditable="False"
Style="{StaticResource DefComboBox}" /> Style="{StaticResource DefComboBox}" />
</Grid> </Grid>
</ScrollViewer> </ScrollViewer>

View file

@ -85,9 +85,9 @@ namespace v2rayN.Views
{ {
cmbSubConvertUrl.Items.Add(it); cmbSubConvertUrl.Items.Add(it);
}); });
Global.GeoFilesSources.ForEach(it => Global.GeoSourceNames.ForEach(it =>
{ {
cmbGetFilesSourceUrl.Items.Add(it); cmbGetFilesSource.Items.Add(it);
}); });
foreach (EGirdOrientation it in Enum.GetValues(typeof(EGirdOrientation))) foreach (EGirdOrientation it in Enum.GetValues(typeof(EGirdOrientation)))
{ {
@ -149,7 +149,7 @@ namespace v2rayN.Views
this.Bind(ViewModel, vm => vm.EnableHWA, v => v.togEnableHWA.IsChecked).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.EnableHWA, v => v.togEnableHWA.IsChecked).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SubConvertUrl, v => v.cmbSubConvertUrl.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SubConvertUrl, v => v.cmbSubConvertUrl.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.MainGirdOrientation, v => v.cmbMainGirdOrientation.SelectedIndex).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.MainGirdOrientation, v => v.cmbMainGirdOrientation.SelectedIndex).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.GeoFileSourceUrl, v => v.cmbGetFilesSourceUrl.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.GeoFileSource, v => v.cmbGetFilesSource.SelectedIndex).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.notProxyLocalAddress, v => v.tognotProxyLocalAddress.IsChecked).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.notProxyLocalAddress, v => v.tognotProxyLocalAddress.IsChecked).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.systemProxyAdvancedProtocol, v => v.cmbsystemProxyAdvancedProtocol.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.systemProxyAdvancedProtocol, v => v.cmbsystemProxyAdvancedProtocol.Text).DisposeWith(disposables);