Skip to content

Commit

Permalink
Custom geo file source from settings (2dust#5829)
Browse files Browse the repository at this point in the history
Co-authored-by: 2dust <31833384+2dust@users.noreply.github.com>
  • Loading branch information
runetfreedom and 2dust authored Oct 14, 2024
1 parent 2698137 commit c6caf29
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 4 deletions.
5 changes: 5 additions & 0 deletions v2rayN/ServiceLib/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ public class Global
@"http://www.msftconnecttest.com/connecttest.txt",
};

public static readonly List<string> GeoFilesSources = new() {
GeoUrl,
@"https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/{0}.dat",
};

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" },
Expand Down
2 changes: 2 additions & 0 deletions v2rayN/ServiceLib/Models/ConfigItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public class GUIItem
public int trayMenuServersLimit { get; set; } = 20;

public bool enableHWA { get; set; } = false;

public string geoSourceUrl { get; set; }
}

[Serializable]
Expand Down
13 changes: 12 additions & 1 deletion v2rayN/ServiceLib/Resx/ResUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion v2rayN/ServiceLib/Resx/ResUI.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1322,9 +1322,12 @@
<value>Host filter</value>
</data>
<data name="TipActiveServer" xml:space="preserve">
<value>Active</value>
<value>Active</value>
</data>
<data name="menuStorageUI" xml:space="preserve">
<value>Save Interface Layout</value>
</data>
<data name="TbSettingsGeoFilesSource" xml:space="preserve">
<value>Geo files source</value>
</data>
</root>
6 changes: 4 additions & 2 deletions v2rayN/ServiceLib/Services/UpdateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ public void UpdateSubscriptionProcess(Config config, string subId, bool blProxy,

public async Task UpdateGeoFileAll(Config config, Action<bool, string> updateFunc)
{
await UpdateGeoFile("geosite", _config, updateFunc);
await UpdateGeoFile("geoip", _config, updateFunc);
await UpdateGeoFile("geosite", config, updateFunc);
await UpdateGeoFile("geoip", config, updateFunc);
_updateFunc?.Invoke(true, string.Format(ResUI.MsgDownloadGeoFileSuccessfully, "geo"));
}

Expand Down Expand Up @@ -450,6 +450,8 @@ private async Task UpdateGeoFile(string geoName, Config config, Action<bool, str
{
_config = config;
_updateFunc = updateFunc;

var geoUrl = !String.IsNullOrEmpty(config?.guiItem.geoSourceUrl) ? config.guiItem.geoSourceUrl : Global.GeoUrl;
var url = string.Format(Global.GeoUrl, geoName);
var fileName = Utils.GetTempPath(Utils.GetGuid());

Expand Down
3 changes: 3 additions & 0 deletions v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class OptionSettingViewModel : MyReactiveObject
[Reactive] public bool EnableHWA { get; set; }
[Reactive] public string SubConvertUrl { get; set; }
[Reactive] public int MainGirdOrientation { get; set; }
[Reactive] public string GeoFileSourceUrl { get; set; }

#endregion UI

Expand Down Expand Up @@ -164,6 +165,7 @@ public OptionSettingViewModel(Func<EViewAction, object?, Task<bool>>? updateView
EnableHWA = _config.guiItem.enableHWA;
SubConvertUrl = _config.constItem.subConvertUrl;
MainGirdOrientation = (int)_config.uiItem.mainGirdOrientation;
GeoFileSourceUrl = _config.guiItem.geoSourceUrl;

#endregion UI

Expand Down Expand Up @@ -316,6 +318,7 @@ private async Task SaveSettingAsync()
_config.guiItem.enableHWA = EnableHWA;
_config.constItem.subConvertUrl = SubConvertUrl;
_config.uiItem.mainGirdOrientation = (EGirdOrientation)MainGirdOrientation;
_config.guiItem.geoSourceUrl = GeoFileSourceUrl;

//systemProxy
_config.systemProxyItem.systemProxyExceptions = systemProxyExceptions;
Expand Down
14 changes: 14 additions & 0 deletions v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
Expand Down Expand Up @@ -610,6 +611,19 @@
Grid.Column="1"
Width="300"
Classes="Margin8" />

<TextBlock
Grid.Row="22"
Grid.Column="0"
VerticalAlignment="Center"
Classes="Margin8"
Text="{x:Static resx:ResUI.TbSettingsGeoFilesSource}" />
<ComboBox
x:Name="cmbGetFilesSourceUrl"
Grid.Row="22"
Grid.Column="1"
Width="300"
Classes="Margin8" />
</Grid>
</ScrollViewer>
</TabItem>
Expand Down
5 changes: 5 additions & 0 deletions v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public OptionSettingWindow()
{
cmbSubConvertUrl.Items.Add(it);
});
Global.GeoFilesSources.ForEach(it =>
{
cmbGetFilesSourceUrl.Items.Add(it);
});
foreach (EGirdOrientation it in Enum.GetValues(typeof(EGirdOrientation)))
{
cmbMainGirdOrientation.Items.Add(it.ToString());
Expand Down Expand Up @@ -132,6 +136,7 @@ public OptionSettingWindow()
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.MainGirdOrientation, v => v.cmbMainGirdOrientation.SelectedIndex).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.GeoFileSourceUrl, v => v.cmbGetFilesSourceUrl.SelectedValue).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);
Expand Down
18 changes: 18 additions & 0 deletions v2rayN/v2rayN/Views/OptionSettingWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
Expand Down Expand Up @@ -845,6 +846,23 @@
Width="300"
Margin="{StaticResource Margin8}"
Style="{StaticResource DefComboBox}" />


<TextBlock
Grid.Row="22"
Grid.Column="0"
Margin="{StaticResource SettingItemMargin}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbSettingsGeoFilesSource}" />
<ComboBox
x:Name="cmbGetFilesSourceUrl"
Grid.Row="22"
Grid.Column="1"
Width="300"
Margin="{StaticResource SettingItemMargin}"
IsEditable="True"
Style="{StaticResource DefComboBox}" />
</Grid>
</ScrollViewer>
</TabItem>
Expand Down
5 changes: 5 additions & 0 deletions v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public OptionSettingWindow()
{
cmbSubConvertUrl.Items.Add(it);
});
Global.GeoFilesSources.ForEach(it =>
{
cmbGetFilesSourceUrl.Items.Add(it);
});
foreach (EGirdOrientation it in Enum.GetValues(typeof(EGirdOrientation)))
{
cmbMainGirdOrientation.Items.Add(it.ToString());
Expand Down Expand Up @@ -145,6 +149,7 @@ public OptionSettingWindow()
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.MainGirdOrientation, v => v.cmbMainGirdOrientation.SelectedIndex).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.GeoFileSourceUrl, v => v.cmbGetFilesSourceUrl.Text).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);
Expand Down

0 comments on commit c6caf29

Please sign in to comment.