mirror of
https://github.com/2dust/v2rayN.git
synced 2025-09-01 15:56:19 +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 shortId { 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>
|
||||
/// 查找类似 Confirm 的本地化字符串。
|
||||
/// </summary>
|
||||
|
|
|
@ -1069,4 +1069,7 @@
|
|||
<data name="TbSettingsEnableHWA" xml:space="preserve">
|
||||
<value>فعالسازی شتابدهنده سختافزاری (نیاز به راهاندازی مجدد)</value>
|
||||
</data>
|
||||
<data name="TbConfigContent" xml:space="preserve">
|
||||
<value>تكوين المحتوى</value>
|
||||
</data>
|
||||
</root>
|
|
@ -1147,4 +1147,7 @@
|
|||
<data name="SpeedtestingWait" xml:space="preserve">
|
||||
<value>Waiting for testing</value>
|
||||
</data>
|
||||
<data name="TbConfigContent" xml:space="preserve">
|
||||
<value>Configuration Content</value>
|
||||
</data>
|
||||
</root>
|
|
@ -1111,4 +1111,7 @@
|
|||
<data name="TbSettingsEnableHWA" xml:space="preserve">
|
||||
<value>Включить аппаратное ускорение (требуется перезагрузка)</value>
|
||||
</data>
|
||||
<data name="TbConfigContent" xml:space="preserve">
|
||||
<value>Настроить содержимое</value>
|
||||
</data>
|
||||
</root>
|
|
@ -1147,4 +1147,7 @@
|
|||
<data name="SpeedtestingWait" xml:space="preserve">
|
||||
<value>等待测试中...</value>
|
||||
</data>
|
||||
<data name="TbConfigContent" xml:space="preserve">
|
||||
<value>配置内容</value>
|
||||
</data>
|
||||
</root>
|
|
@ -40,6 +40,7 @@ namespace v2rayN.ViewModels
|
|||
else
|
||||
{
|
||||
SelectedSource = Utils.DeepCopy(profileItem);
|
||||
SelectedSource.configContent = GetContent(SelectedSource.address);
|
||||
}
|
||||
|
||||
_view = view;
|
||||
|
@ -86,12 +87,13 @@ namespace v2rayN.ViewModels
|
|||
{
|
||||
item.remarks = SelectedSource.remarks;
|
||||
item.address = SelectedSource.address;
|
||||
item.configContent = SelectedSource.configContent;
|
||||
item.coreType = SelectedSource.coreType;
|
||||
item.displayLog = SelectedSource.displayLog;
|
||||
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);
|
||||
_view.DialogResult = true;
|
||||
|
@ -129,6 +131,7 @@ namespace v2rayN.ViewModels
|
|||
if (!Utils.IsNullOrEmpty(item.indexId))
|
||||
{
|
||||
SelectedSource = Utils.DeepCopy(item);
|
||||
SelectedSource.configContent = GetContent(item.address);
|
||||
}
|
||||
IsModified = true;
|
||||
}
|
||||
|
@ -157,5 +160,35 @@ namespace v2rayN.ViewModels
|
|||
_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"
|
||||
Title="v2rayN"
|
||||
Width="700"
|
||||
Height="500"
|
||||
Height="600"
|
||||
x:TypeArguments="vms:AddServer2ViewModel"
|
||||
Background="{DynamicResource MaterialDesignPaper}"
|
||||
FontFamily="{x:Static conv:MaterialDesignFonts.MyFont}"
|
||||
|
@ -44,6 +44,7 @@
|
|||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
|
@ -104,12 +105,12 @@
|
|||
Margin="2,0,8,0"
|
||||
Content="{x:Static resx:ResUI.TbBrowse}"
|
||||
Style="{StaticResource DefButton}" />
|
||||
<Button
|
||||
<!--<Button
|
||||
x:Name="btnEdit"
|
||||
Width="100"
|
||||
Margin="2,2,8,0"
|
||||
Content="{x:Static resx:ResUI.TbEdit}"
|
||||
Style="{StaticResource DefButton}" />
|
||||
Style="{StaticResource DefButton}" />-->
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock
|
||||
|
@ -118,10 +119,29 @@
|
|||
Margin="4"
|
||||
VerticalAlignment="Center"
|
||||
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}" />
|
||||
<ComboBox
|
||||
x:Name="cmbCoreType"
|
||||
Grid.Row="3"
|
||||
Grid.Row="4"
|
||||
Grid.Column="1"
|
||||
Width="200"
|
||||
Margin="4"
|
||||
|
@ -131,7 +151,7 @@
|
|||
Style="{StaticResource MaterialDesignOutlinedComboBox}" />
|
||||
|
||||
<TextBlock
|
||||
Grid.Row="4"
|
||||
Grid.Row="5"
|
||||
Grid.Column="0"
|
||||
Margin="4"
|
||||
VerticalAlignment="Center"
|
||||
|
@ -139,13 +159,13 @@
|
|||
Text="{x:Static resx:ResUI.TbDisplayLog}" />
|
||||
<ToggleButton
|
||||
x:Name="togDisplayLog"
|
||||
Grid.Row="4"
|
||||
Grid.Row="5"
|
||||
Grid.Column="1"
|
||||
Margin="4"
|
||||
HorizontalAlignment="Left" />
|
||||
|
||||
<TextBlock
|
||||
Grid.Row="5"
|
||||
Grid.Row="6"
|
||||
Grid.Column="0"
|
||||
Margin="4"
|
||||
VerticalAlignment="Center"
|
||||
|
@ -153,7 +173,7 @@
|
|||
Text="{x:Static resx:ResUI.TbPreSocksPort}" />
|
||||
<TextBox
|
||||
x:Name="txtPreSocksPort"
|
||||
Grid.Row="5"
|
||||
Grid.Row="6"
|
||||
Grid.Column="1"
|
||||
Width="200"
|
||||
Margin="4"
|
||||
|
@ -161,7 +181,7 @@
|
|||
AcceptsReturn="True"
|
||||
Style="{StaticResource MyOutlinedTextBox}" />
|
||||
<StackPanel
|
||||
Grid.Row="6"
|
||||
Grid.Row="7"
|
||||
Grid.Column="1"
|
||||
Grid.ColumnSpan="2">
|
||||
<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.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.displayLog, v => v.togDisplayLog.IsChecked).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.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);
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue