mirror of
https://github.com/2dust/v2rayN.git
synced 2025-10-26 18:24:43 +00:00
feat: view and edit config content in AddServer2Window
This commit is contained in:
parent
4f120e8eb4
commit
d6d364906f
9 changed files with 91 additions and 11 deletions
|
|
@ -180,5 +180,10 @@ namespace v2rayN.Mode
|
||||||
public string publicKey { get; set; }
|
public string publicKey { get; set; }
|
||||||
public string shortId { get; set; }
|
public string shortId { get; set; }
|
||||||
public string spiderX { get; set; }
|
public string spiderX { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 自定义配置的配置文件内容
|
||||||
|
/// </summary>
|
||||||
|
public string configContent { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
9
v2rayN/v2rayN/Resx/ResUI.Designer.cs
generated
9
v2rayN/v2rayN/Resx/ResUI.Designer.cs
generated
|
|
@ -1951,6 +1951,15 @@ namespace v2rayN.Resx {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找类似 Configuration Content 的本地化字符串。
|
||||||
|
/// </summary>
|
||||||
|
public static string TbConfigContent {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("TbConfigContent", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 Confirm 的本地化字符串。
|
/// 查找类似 Confirm 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -1069,4 +1069,7 @@
|
||||||
<data name="TbSettingsEnableHWA" xml:space="preserve">
|
<data name="TbSettingsEnableHWA" xml:space="preserve">
|
||||||
<value>فعالسازی شتابدهنده سختافزاری (نیاز به راهاندازی مجدد)</value>
|
<value>فعالسازی شتابدهنده سختافزاری (نیاز به راهاندازی مجدد)</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TbConfigContent" xml:space="preserve">
|
||||||
|
<value>تكوين المحتوى</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|
@ -1147,4 +1147,7 @@
|
||||||
<data name="SpeedtestingWait" xml:space="preserve">
|
<data name="SpeedtestingWait" xml:space="preserve">
|
||||||
<value>Waiting for testing</value>
|
<value>Waiting for testing</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TbConfigContent" xml:space="preserve">
|
||||||
|
<value>Configuration Content</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|
@ -1111,4 +1111,7 @@
|
||||||
<data name="TbSettingsEnableHWA" xml:space="preserve">
|
<data name="TbSettingsEnableHWA" xml:space="preserve">
|
||||||
<value>Включить аппаратное ускорение (требуется перезагрузка)</value>
|
<value>Включить аппаратное ускорение (требуется перезагрузка)</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TbConfigContent" xml:space="preserve">
|
||||||
|
<value>Настроить содержимое</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|
@ -1147,4 +1147,7 @@
|
||||||
<data name="SpeedtestingWait" xml:space="preserve">
|
<data name="SpeedtestingWait" xml:space="preserve">
|
||||||
<value>等待测试中...</value>
|
<value>等待测试中...</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TbConfigContent" xml:space="preserve">
|
||||||
|
<value>配置内容</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|
@ -40,6 +40,7 @@ namespace v2rayN.ViewModels
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SelectedSource = Utils.DeepCopy(profileItem);
|
SelectedSource = Utils.DeepCopy(profileItem);
|
||||||
|
SelectedSource.configContent = GetContent(SelectedSource.address);
|
||||||
}
|
}
|
||||||
|
|
||||||
_view = view;
|
_view = view;
|
||||||
|
|
@ -86,12 +87,13 @@ namespace v2rayN.ViewModels
|
||||||
{
|
{
|
||||||
item.remarks = SelectedSource.remarks;
|
item.remarks = SelectedSource.remarks;
|
||||||
item.address = SelectedSource.address;
|
item.address = SelectedSource.address;
|
||||||
|
item.configContent = SelectedSource.configContent;
|
||||||
item.coreType = SelectedSource.coreType;
|
item.coreType = SelectedSource.coreType;
|
||||||
item.displayLog = SelectedSource.displayLog;
|
item.displayLog = SelectedSource.displayLog;
|
||||||
item.preSocksPort = SelectedSource.preSocksPort;
|
item.preSocksPort = SelectedSource.preSocksPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ConfigHandler.EditCustomServer(ref _config, item) == 0)
|
if (ConfigHandler.EditCustomServer(ref _config, item) == 0 && SaveContent(item) == 0)
|
||||||
{
|
{
|
||||||
_noticeHandler?.Enqueue(ResUI.OperationSuccess);
|
_noticeHandler?.Enqueue(ResUI.OperationSuccess);
|
||||||
_view.DialogResult = true;
|
_view.DialogResult = true;
|
||||||
|
|
@ -129,6 +131,7 @@ namespace v2rayN.ViewModels
|
||||||
if (!Utils.IsNullOrEmpty(item.indexId))
|
if (!Utils.IsNullOrEmpty(item.indexId))
|
||||||
{
|
{
|
||||||
SelectedSource = Utils.DeepCopy(item);
|
SelectedSource = Utils.DeepCopy(item);
|
||||||
|
SelectedSource.configContent = GetContent(item.address);
|
||||||
}
|
}
|
||||||
IsModified = true;
|
IsModified = true;
|
||||||
}
|
}
|
||||||
|
|
@ -157,5 +160,35 @@ namespace v2rayN.ViewModels
|
||||||
_noticeHandler?.Enqueue(ResUI.FailedReadConfiguration);
|
_noticeHandler?.Enqueue(ResUI.FailedReadConfiguration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string GetContent(string configFileName)
|
||||||
|
{
|
||||||
|
var content = "";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var configPath = Utils.GetConfigPath(configFileName);
|
||||||
|
content = File.ReadAllText(configPath);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Utils.SaveLog("GetContent", ex);
|
||||||
|
}
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int SaveContent(ProfileItem profileItem)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var configPath = Utils.GetConfigPath(profileItem.address);
|
||||||
|
File.WriteAllText(configPath, profileItem.configContent);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Utils.SaveLog("SaveContent", ex);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
xmlns:vms="clr-namespace:v2rayN.ViewModels"
|
xmlns:vms="clr-namespace:v2rayN.ViewModels"
|
||||||
Title="v2rayN"
|
Title="v2rayN"
|
||||||
Width="700"
|
Width="700"
|
||||||
Height="500"
|
Height="600"
|
||||||
x:TypeArguments="vms:AddServer2ViewModel"
|
x:TypeArguments="vms:AddServer2ViewModel"
|
||||||
Background="{DynamicResource MaterialDesignPaper}"
|
Background="{DynamicResource MaterialDesignPaper}"
|
||||||
FontFamily="{x:Static conv:MaterialDesignFonts.MyFont}"
|
FontFamily="{x:Static conv:MaterialDesignFonts.MyFont}"
|
||||||
|
|
@ -44,6 +44,7 @@
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="Auto" />
|
<ColumnDefinition Width="Auto" />
|
||||||
|
|
@ -104,12 +105,12 @@
|
||||||
Margin="2,0,8,0"
|
Margin="2,0,8,0"
|
||||||
Content="{x:Static resx:ResUI.TbBrowse}"
|
Content="{x:Static resx:ResUI.TbBrowse}"
|
||||||
Style="{StaticResource DefButton}" />
|
Style="{StaticResource DefButton}" />
|
||||||
<Button
|
<!--<Button
|
||||||
x:Name="btnEdit"
|
x:Name="btnEdit"
|
||||||
Width="100"
|
Width="100"
|
||||||
Margin="2,2,8,0"
|
Margin="2,2,8,0"
|
||||||
Content="{x:Static resx:ResUI.TbEdit}"
|
Content="{x:Static resx:ResUI.TbEdit}"
|
||||||
Style="{StaticResource DefButton}" />
|
Style="{StaticResource DefButton}" />-->
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<TextBlock
|
<TextBlock
|
||||||
|
|
@ -118,10 +119,29 @@
|
||||||
Margin="4"
|
Margin="4"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Style="{StaticResource ToolbarTextBlock}"
|
Style="{StaticResource ToolbarTextBlock}"
|
||||||
|
Text="{x:Static resx:ResUI.TbConfigContent}" />
|
||||||
|
<TextBox
|
||||||
|
x:Name="txtContent"
|
||||||
|
Grid.Row="3"
|
||||||
|
Grid.Column="1"
|
||||||
|
Width="400"
|
||||||
|
MaxHeight="200"
|
||||||
|
Margin="4"
|
||||||
|
VerticalAlignment="Top"
|
||||||
|
AcceptsReturn="True"
|
||||||
|
VerticalScrollBarVisibility="Auto"
|
||||||
|
Style="{StaticResource MyOutlinedTextBox}" />
|
||||||
|
|
||||||
|
<TextBlock
|
||||||
|
Grid.Row="4"
|
||||||
|
Grid.Column="0"
|
||||||
|
Margin="4"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Style="{StaticResource ToolbarTextBlock}"
|
||||||
Text="{x:Static resx:ResUI.TbCoreType}" />
|
Text="{x:Static resx:ResUI.TbCoreType}" />
|
||||||
<ComboBox
|
<ComboBox
|
||||||
x:Name="cmbCoreType"
|
x:Name="cmbCoreType"
|
||||||
Grid.Row="3"
|
Grid.Row="4"
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
Width="200"
|
Width="200"
|
||||||
Margin="4"
|
Margin="4"
|
||||||
|
|
@ -131,7 +151,7 @@
|
||||||
Style="{StaticResource MaterialDesignOutlinedComboBox}" />
|
Style="{StaticResource MaterialDesignOutlinedComboBox}" />
|
||||||
|
|
||||||
<TextBlock
|
<TextBlock
|
||||||
Grid.Row="4"
|
Grid.Row="5"
|
||||||
Grid.Column="0"
|
Grid.Column="0"
|
||||||
Margin="4"
|
Margin="4"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
|
|
@ -139,13 +159,13 @@
|
||||||
Text="{x:Static resx:ResUI.TbDisplayLog}" />
|
Text="{x:Static resx:ResUI.TbDisplayLog}" />
|
||||||
<ToggleButton
|
<ToggleButton
|
||||||
x:Name="togDisplayLog"
|
x:Name="togDisplayLog"
|
||||||
Grid.Row="4"
|
Grid.Row="5"
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
Margin="4"
|
Margin="4"
|
||||||
HorizontalAlignment="Left" />
|
HorizontalAlignment="Left" />
|
||||||
|
|
||||||
<TextBlock
|
<TextBlock
|
||||||
Grid.Row="5"
|
Grid.Row="6"
|
||||||
Grid.Column="0"
|
Grid.Column="0"
|
||||||
Margin="4"
|
Margin="4"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
|
|
@ -153,7 +173,7 @@
|
||||||
Text="{x:Static resx:ResUI.TbPreSocksPort}" />
|
Text="{x:Static resx:ResUI.TbPreSocksPort}" />
|
||||||
<TextBox
|
<TextBox
|
||||||
x:Name="txtPreSocksPort"
|
x:Name="txtPreSocksPort"
|
||||||
Grid.Row="5"
|
Grid.Row="6"
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
Width="200"
|
Width="200"
|
||||||
Margin="4"
|
Margin="4"
|
||||||
|
|
@ -161,7 +181,7 @@
|
||||||
AcceptsReturn="True"
|
AcceptsReturn="True"
|
||||||
Style="{StaticResource MyOutlinedTextBox}" />
|
Style="{StaticResource MyOutlinedTextBox}" />
|
||||||
<StackPanel
|
<StackPanel
|
||||||
Grid.Row="6"
|
Grid.Row="7"
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
Grid.ColumnSpan="2">
|
Grid.ColumnSpan="2">
|
||||||
<TextBlock
|
<TextBlock
|
||||||
|
|
|
||||||
|
|
@ -27,12 +27,13 @@ namespace v2rayN.Views
|
||||||
{
|
{
|
||||||
this.Bind(ViewModel, vm => vm.SelectedSource.remarks, v => v.txtRemarks.Text).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.SelectedSource.remarks, v => v.txtRemarks.Text).DisposeWith(disposables);
|
||||||
this.Bind(ViewModel, vm => vm.SelectedSource.address, v => v.txtAddress.Text).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.SelectedSource.address, v => v.txtAddress.Text).DisposeWith(disposables);
|
||||||
|
this.Bind(ViewModel, vm => vm.SelectedSource.configContent, v => v.txtContent.Text).DisposeWith(disposables);
|
||||||
this.Bind(ViewModel, vm => vm.SelectedSource.coreType, v => v.cmbCoreType.Text).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.SelectedSource.coreType, v => v.cmbCoreType.Text).DisposeWith(disposables);
|
||||||
this.Bind(ViewModel, vm => vm.SelectedSource.displayLog, v => v.togDisplayLog.IsChecked).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.SelectedSource.displayLog, v => v.togDisplayLog.IsChecked).DisposeWith(disposables);
|
||||||
this.Bind(ViewModel, vm => vm.SelectedSource.preSocksPort, v => v.txtPreSocksPort.Text).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.SelectedSource.preSocksPort, v => v.txtPreSocksPort.Text).DisposeWith(disposables);
|
||||||
|
|
||||||
this.BindCommand(ViewModel, vm => vm.BrowseServerCmd, v => v.btnBrowse).DisposeWith(disposables);
|
this.BindCommand(ViewModel, vm => vm.BrowseServerCmd, v => v.btnBrowse).DisposeWith(disposables);
|
||||||
this.BindCommand(ViewModel, vm => vm.EditServerCmd, v => v.btnEdit).DisposeWith(disposables);
|
//this.BindCommand(ViewModel, vm => vm.EditServerCmd, v => v.btnEdit).DisposeWith(disposables);
|
||||||
this.BindCommand(ViewModel, vm => vm.SaveServerCmd, v => v.btnSave).DisposeWith(disposables);
|
this.BindCommand(ViewModel, vm => vm.SaveServerCmd, v => v.btnSave).DisposeWith(disposables);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue