mirror of
https://github.com/2dust/v2rayN.git
synced 2025-08-29 22:36:20 +00:00
Merge branch 'userpac'
# Conflicts: # v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx
This commit is contained in:
commit
162bbd9191
9 changed files with 178 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
@ -43,6 +44,12 @@ public class PacHandler
|
|||
}
|
||||
|
||||
_pacText = File.ReadAllText(path).Replace("__PROXY__", $"PROXY 127.0.0.1:{_httpPort};DIRECT;");
|
||||
|
||||
var userPac = LoadUserPac(_configPath);
|
||||
if (userPac != "")
|
||||
{
|
||||
_pacText = _pacText.Replace(" [],\n []", userPac);
|
||||
}
|
||||
}
|
||||
|
||||
private static void RunListener()
|
||||
|
@ -100,4 +107,32 @@ public class PacHandler
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string LoadUserPac(string configPath)
|
||||
{
|
||||
var userPac = "";
|
||||
var userPacPath = Path.Combine(_configPath, "pacUser.txt");
|
||||
if (File.Exists(userPacPath))
|
||||
{
|
||||
userPac = File.ReadAllText(userPacPath);
|
||||
}
|
||||
return userPac;
|
||||
}
|
||||
|
||||
public static void SaveUserPac(string directDomains, string proxyDomains, string configPath)
|
||||
{
|
||||
var directDomainsArray = directDomains.Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
var proxyDomainsArray = proxyDomains.Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
|
||||
var userPac = directDomainsArray.Aggregate("[\n", (current, directDomain) => $"{current} \"{directDomain}\",\n");
|
||||
|
||||
userPac += " ],\n [\n";
|
||||
|
||||
userPac = proxyDomainsArray.Aggregate(userPac, (current, proxyDomain) => $"{current} \"{proxyDomain}\",\n");
|
||||
|
||||
userPac += "]";
|
||||
|
||||
var path = Path.Combine(configPath, "pacUser.txt");
|
||||
File.WriteAllText(path, userPac);
|
||||
}
|
||||
}
|
27
v2rayN/v2rayN/Resx/ResUI.Designer.cs
generated
27
v2rayN/v2rayN/Resx/ResUI.Designer.cs
generated
|
@ -2887,6 +2887,33 @@ namespace v2rayN.Resx {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 User Pac settings 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string TbSettingsUserPac {
|
||||
get {
|
||||
return ResourceManager.GetString("TbSettingsUserPac", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Direct domains(One at a line): 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string TbSettingsUserPacDirectDomains {
|
||||
get {
|
||||
return ResourceManager.GetString("TbSettingsUserPacDirectDomains", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Proxy domains(One at a line): 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string TbSettingsUserPacProxyDomains {
|
||||
get {
|
||||
return ResourceManager.GetString("TbSettingsUserPacProxyDomains", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 ShortId 的本地化字符串。
|
||||
/// </summary>
|
||||
|
|
|
@ -1009,4 +1009,13 @@
|
|||
<data name="TbSettingsEnableHWA" xml:space="preserve">
|
||||
<value>فعالسازی شتابدهنده سختافزاری (نیاز به راهاندازی مجدد)</value>
|
||||
</data>
|
||||
<data name="TbSettingsUserPac" xml:space="preserve">
|
||||
<value>User Pac settings</value>
|
||||
</data>
|
||||
<data name="TbSettingsUserPacProxyDomains" xml:space="preserve">
|
||||
<value>Proxy domains(One at a line):</value>
|
||||
</data>
|
||||
<data name="TbSettingsUserPacDirectDomains" xml:space="preserve">
|
||||
<value>Direct domains(One at a line):</value>
|
||||
</data>
|
||||
</root>
|
|
@ -814,6 +814,15 @@
|
|||
<data name="TbSettingsUser" xml:space="preserve">
|
||||
<value>Auth user</value>
|
||||
</data>
|
||||
<data name="TbSettingsUserPac" xml:space="preserve">
|
||||
<value>User Pac settings</value>
|
||||
</data>
|
||||
<data name="TbSettingsUserPacDirectDomains" xml:space="preserve">
|
||||
<value>Direct domains(One at a line):</value>
|
||||
</data>
|
||||
<data name="TbSettingsUserPacProxyDomains" xml:space="preserve">
|
||||
<value>Proxy domains(One at a line):</value>
|
||||
</data>
|
||||
<data name="TbClearSystemProxy" xml:space="preserve">
|
||||
<value>Clear system proxy</value>
|
||||
</data>
|
||||
|
|
|
@ -1051,4 +1051,13 @@
|
|||
<data name="TbSettingsEnableHWA" xml:space="preserve">
|
||||
<value>Включить аппаратное ускорение (требуется перезагрузка)</value>
|
||||
</data>
|
||||
<data name="TbSettingsUserPac" xml:space="preserve">
|
||||
<value>User Pac settings</value>
|
||||
</data>
|
||||
<data name="TbSettingsUserPacProxyDomains" xml:space="preserve">
|
||||
<value>Proxy domains(One at a line):</value>
|
||||
</data>
|
||||
<data name="TbSettingsUserPacDirectDomains" xml:space="preserve">
|
||||
<value>Direct domains(One at a line):</value>
|
||||
</data>
|
||||
</root>
|
|
@ -1135,4 +1135,13 @@
|
|||
<data name="TbRoutingRuleIP" xml:space="preserve">
|
||||
<value>IP 或 IP CIDR</value>
|
||||
</data>
|
||||
<data name="TbSettingsUserPac" xml:space="preserve">
|
||||
<value>用户Pac设置</value>
|
||||
</data>
|
||||
<data name="TbSettingsUserPacDirectDomains" xml:space="preserve">
|
||||
<value>直连的域名(每行一个):</value>
|
||||
</data>
|
||||
<data name="TbSettingsUserPacProxyDomains" xml:space="preserve">
|
||||
<value>需要代理的域名(每行一个):</value>
|
||||
</data>
|
||||
</root>
|
|
@ -3,6 +3,7 @@ using ReactiveUI.Fody.Helpers;
|
|||
using Splat;
|
||||
using System.Reactive;
|
||||
using System.Windows;
|
||||
using PacLib;
|
||||
using v2rayN.Handler;
|
||||
using v2rayN.Mode;
|
||||
using v2rayN.Resx;
|
||||
|
@ -96,6 +97,13 @@ namespace v2rayN.ViewModels
|
|||
|
||||
#endregion CoreType
|
||||
|
||||
#region User Pac
|
||||
|
||||
[Reactive] public string userPacDirectDomains { get; set; }
|
||||
[Reactive] public string userPacProxyDomains { get; set; }
|
||||
|
||||
#endregion System proxy
|
||||
|
||||
public ReactiveCommand<Unit, Unit> SaveCmd { get; }
|
||||
|
||||
public OptionSettingViewModel(Window view)
|
||||
|
@ -177,6 +185,8 @@ namespace v2rayN.ViewModels
|
|||
|
||||
InitCoreType();
|
||||
|
||||
InitUserPac();
|
||||
|
||||
SaveCmd = ReactiveCommand.Create(() =>
|
||||
{
|
||||
SaveSetting();
|
||||
|
@ -333,6 +343,8 @@ namespace v2rayN.ViewModels
|
|||
{
|
||||
UI.ShowWarning(ResUI.OperationFailed);
|
||||
}
|
||||
|
||||
SaveUserPac();
|
||||
}
|
||||
|
||||
private int SaveCoreType()
|
||||
|
@ -371,5 +383,25 @@ namespace v2rayN.ViewModels
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void InitUserPac()
|
||||
{
|
||||
var userPac = PacHandler.LoadUserPac(Utils.GetConfigPath());
|
||||
if (userPac == "") return;
|
||||
|
||||
userPac = userPac.Replace(" \"", "").Replace("\",", "");
|
||||
var arr = userPac.Split(" ],\n [\n", StringSplitOptions.RemoveEmptyEntries);
|
||||
userPacDirectDomains = arr[0].Replace("[\n", "");
|
||||
userPacProxyDomains = arr[1].Replace("]", "");
|
||||
}
|
||||
|
||||
private int SaveUserPac()
|
||||
{
|
||||
var result = -1;
|
||||
|
||||
PacHandler.SaveUserPac(userPacDirectDomains, userPacProxyDomains, Utils.GetConfigPath());
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -954,6 +954,51 @@
|
|||
Style="{StaticResource DefComboBox}" />
|
||||
</Grid>
|
||||
</TabItem>
|
||||
|
||||
<TabItem Header="{x:Static resx:ResUI.TbSettingsUserPac}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="1*"></ColumnDefinition>
|
||||
<ColumnDefinition Width="1*"></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
<DockPanel Margin="{StaticResource SettingItemMargin}">
|
||||
<TextBlock
|
||||
Grid.Row="1"
|
||||
Margin="{StaticResource SettingItemMargin}"
|
||||
VerticalAlignment="Center"
|
||||
DockPanel.Dock="Top"
|
||||
Style="{StaticResource ToolbarTextBlock}"
|
||||
Text="{x:Static resx:ResUI.TbSettingsUserPacDirectDomains}" />
|
||||
<TextBox
|
||||
x:Name="txtUserPacDirectDomains"
|
||||
Margin="{StaticResource SettingItemMargin}"
|
||||
VerticalAlignment="Stretch"
|
||||
AcceptsReturn="True"
|
||||
BorderThickness="1"
|
||||
Style="{StaticResource DefTextBox}"
|
||||
TextWrapping="Wrap"
|
||||
VerticalScrollBarVisibility="Auto" />
|
||||
</DockPanel>
|
||||
<DockPanel Grid.Column="1" Margin="{StaticResource SettingItemMargin}">
|
||||
<TextBlock
|
||||
Grid.Row="1"
|
||||
Margin="{StaticResource SettingItemMargin}"
|
||||
VerticalAlignment="Center"
|
||||
DockPanel.Dock="Top"
|
||||
Style="{StaticResource ToolbarTextBlock}"
|
||||
Text="{x:Static resx:ResUI.TbSettingsUserPacProxyDomains}" />
|
||||
<TextBox
|
||||
x:Name="txtUserPacProxyDomains"
|
||||
Margin="{StaticResource SettingItemMargin}"
|
||||
VerticalAlignment="Stretch"
|
||||
AcceptsReturn="True"
|
||||
BorderThickness="1"
|
||||
Style="{StaticResource DefTextBox}"
|
||||
TextWrapping="Wrap"
|
||||
VerticalScrollBarVisibility="Auto" />
|
||||
</DockPanel>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
</DockPanel>
|
||||
</reactiveui:ReactiveWindow>
|
|
@ -181,6 +181,9 @@ namespace v2rayN.Views
|
|||
this.Bind(ViewModel, vm => vm.CoreType5, v => v.cmbCoreType5.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.CoreType6, v => v.cmbCoreType6.Text).DisposeWith(disposables);
|
||||
|
||||
this.Bind(ViewModel, vm => vm.userPacDirectDomains, v => v.txtUserPacDirectDomains.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.userPacProxyDomains, v => v.txtUserPacProxyDomains.Text).DisposeWith(disposables);
|
||||
|
||||
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue