Skip to content

Commit

Permalink
Add BackupAndRestore
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Oct 4, 2024
1 parent 90ba804 commit fe81b51
Show file tree
Hide file tree
Showing 6 changed files with 313 additions and 8 deletions.
231 changes: 231 additions & 0 deletions v2rayN/v2rayN.Desktop/Views/BackupAndRestoreView.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
<UserControl
x:Class="v2rayN.Desktop.Views.BackupAndRestoreView"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:resx="clr-namespace:ServiceLib.Resx;assembly=ServiceLib"
xmlns:vms="clr-namespace:ServiceLib.ViewModels;assembly=ServiceLib"
d:DesignHeight="450"
d:DesignWidth="800"
x:DataType="vms:BackupAndRestoreViewModel"
mc:Ignorable="d">

<DockPanel Margin="16">
<DockPanel Classes="Margin8" DockPanel.Dock="Bottom">
<TextBlock
Name="txtMsg"
HorizontalAlignment="Left"
Classes="Margin8" />
</DockPanel>

<StackPanel>
<Border
Margin="0"
VerticalAlignment="Center"
Theme="{StaticResource CardBorder}">

<Grid Classes="Margin8">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300" />
<ColumnDefinition Width="200" />
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0"
Grid.Column="0"
Classes="Margin8"
Text="{x:Static resx:ResUI.menuLocalBackupAndRestore}" />

<TextBlock
Grid.Row="1"
Grid.Column="0"
VerticalAlignment="Center"
Classes="Margin8"
Text="{x:Static resx:ResUI.menuLocalBackup}" />
<Button
Name="menuLocalBackup"
Grid.Row="1"
Grid.Column="1"
VerticalAlignment="Center"
Classes="Margin8"
Content="{x:Static resx:ResUI.menuLocalBackup}" />

<Separator Grid.Row="2" Grid.ColumnSpan="2" />

<TextBlock
Grid.Row="3"
Grid.Column="0"
VerticalAlignment="Center"
Classes="Margin8"
Text="{x:Static resx:ResUI.menuLocalRestore}" />
<Button
Name="menuLocalRestore"
Grid.Row="3"
Grid.Column="1"
VerticalAlignment="Center"
Classes="Margin8"
Content="{x:Static resx:ResUI.menuLocalRestore}" />
</Grid>
</Border>
<Border
Margin="0"
VerticalAlignment="Center"
Theme="{StaticResource CardBorder}">
<Grid Classes="Margin8">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300" />
<ColumnDefinition Width="200" />
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal">
<TextBlock
Grid.Row="0"
Grid.Column="0"
Classes="Margin8"
Text="{x:Static resx:ResUI.menuRemoteBackupAndRestore}" />

<Button
Width="30"
Height="30"
Margin="10,0"
Theme="{DynamicResource BorderlessButton}">
<Button.Content>
<PathIcon
Width="20"
Height="20"
Data="M511.9,276.3c43.8,0 79.2,-35.5 79.2,-79.2 0,-43.8 -35.5,-79.2 -79.2,-79.2 -43.8,0 -79.2,35.5 -79.2,79.2 0,43.8 35.5,79.2 79.2,79.2zM511.9,434.8c-43.8,0 -79.2,35.5 -79.2,79.2 0,43.8 35.5,79.2 79.2,79.2 43.8,0 79.2,-35.5 79.2,-79.2 0,-43.8 -35.5,-79.2 -79.2,-79.2zM511.9,751.8c-43.8,0 -79.2,35.4 -79.2,79.2 0,43.8 35.5,79.2 79.2,79.2 43.8,0 79.2,-35.5 79.2,-79.2 0,-43.8 -35.5,-79.2 -79.2,-79.2z"
Foreground="{DynamicResource ButtonDefaultTertiaryForeground}" />
</Button.Content>
<Button.Flyout>
<Flyout>
<StackPanel>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="300" />
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0"
Grid.Column="0"
VerticalAlignment="Center"
Classes="Margin8"
Text="{x:Static resx:ResUI.LvWebDavUrl}" />

<TextBox
x:Name="txtWebDavUrl"
Grid.Row="0"
Grid.Column="1"
VerticalAlignment="Center"
Classes="Margin8"
TextWrapping="Wrap" />

<TextBlock
Grid.Row="1"
Grid.Column="0"
VerticalAlignment="Center"
Classes="Margin8"
Text="{x:Static resx:ResUI.LvWebDavUserName}" />

<TextBox
x:Name="txtWebDavUserName"
Grid.Row="1"
Grid.Column="1"
VerticalAlignment="Center"
Classes="Margin8" />

<TextBlock
Grid.Row="2"
Grid.Column="0"
VerticalAlignment="Center"
Classes="Margin8"
Text="{x:Static resx:ResUI.LvWebDavPassword}" />

<TextBox
x:Name="txtWebDavPassword"
Grid.Row="2"
Grid.Column="1"
VerticalAlignment="Center"
Classes="Margin8" />

<TextBlock
Grid.Row="3"
Grid.Column="0"
VerticalAlignment="Center"
Classes="Margin8"
Text="{x:Static resx:ResUI.LvWebDavDirName}" />

<TextBox
x:Name="txtWebDavDirName"
Grid.Row="3"
Grid.Column="1"
VerticalAlignment="Center"
Classes="Margin8" />

<Button
x:Name="menuWebDavCheck"
Grid.Row="4"
Grid.Column="1"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Classes="Margin8"
Content="{x:Static resx:ResUI.LvWebDavCheck}" />
</Grid>
</StackPanel>
</Flyout>
</Button.Flyout>
</Button>

</StackPanel>

<TextBlock
Grid.Row="1"
Grid.Column="0"
VerticalAlignment="Center"
Classes="Margin8"
Text="{x:Static resx:ResUI.menuRemoteBackup}" />
<Button
Name="menuRemoteBackup"
Grid.Row="1"
Grid.Column="1"
VerticalAlignment="Center"
Classes="Margin8"
Content="{x:Static resx:ResUI.menuRemoteBackup}" />

<Separator Grid.Row="2" Grid.ColumnSpan="3" />
<TextBlock
Grid.Row="3"
Grid.Column="0"
VerticalAlignment="Center"
Classes="Margin8"
Text="{x:Static resx:ResUI.menuRemoteRestore}" />
<Button
Name="menuRemoteRestore"
Grid.Row="3"
Grid.Column="1"
VerticalAlignment="Center"
Classes="Margin8"
Content="{x:Static resx:ResUI.menuRemoteRestore}" />
</Grid>
</Border>
</StackPanel>
</DockPanel>
</UserControl>
70 changes: 70 additions & 0 deletions v2rayN/v2rayN.Desktop/Views/BackupAndRestoreView.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.ReactiveUI;
using ReactiveUI;
using Splat;
using System.Reactive.Disposables;
using v2rayN.Desktop.Common;

namespace v2rayN.Desktop.Views
{
public partial class BackupAndRestoreView : ReactiveUserControl<BackupAndRestoreViewModel>
{
private NoticeHandler? _noticeHandler;
private Window _window;

public BackupAndRestoreView(Window window)
{
_window = window;

InitializeComponent();
menuLocalBackup.Click += MenuLocalBackup_Click;
menuLocalRestore.Click += MenuLocalRestore_Click;

ViewModel = new BackupAndRestoreViewModel(UpdateViewHandler);

_noticeHandler = Locator.Current.GetService<NoticeHandler>();
this.WhenActivated(disposables =>
{
this.Bind(ViewModel, vm => vm.OperationMsg, v => v.txtMsg.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.url, v => v.txtWebDavUrl.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.userName, v => v.txtWebDavUserName.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.password, v => v.txtWebDavPassword.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.dirName, v => v.txtWebDavDirName.Text).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.WebDavCheckCmd, v => v.menuWebDavCheck).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.RemoteBackupCmd, v => v.menuRemoteBackup).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.RemoteRestoreCmd, v => v.menuRemoteRestore).DisposeWith(disposables);
});
}

private async void MenuLocalBackup_Click(object? sender, RoutedEventArgs e)
{
var fileName = await UI.SaveFileDialog(_window, "Zip|*.zip");
if (fileName.IsNullOrEmpty())
{
return;
}

ViewModel?.LocalBackup(fileName);
}

private async void MenuLocalRestore_Click(object? sender, RoutedEventArgs e)
{
var fileName = await UI.OpenFileDialog(_window, null);
if (fileName.IsNullOrEmpty())
{
return;
}

ViewModel?.LocalRestore(fileName);
}

private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
{
return await Task.FromResult(true);
}
}
}
1 change: 1 addition & 0 deletions v2rayN/v2rayN.Desktop/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<MenuItem x:Name="menuSettingsSetUWP" Header="{x:Static resx:ResUI.TbSettingsSetUWP}" />
<MenuItem x:Name="menuClearServerStatistics" Header="{x:Static resx:ResUI.menuClearServerStatistics}" />
<Separator />
<MenuItem x:Name="menuBackupAndRestore" Header="{x:Static resx:ResUI.menuBackupAndRestore}" />
<MenuItem x:Name="menuOpenTheFileLocation" Header="{x:Static resx:ResUI.menuOpenTheFileLocation}" />
</MenuItem>

Expand Down
9 changes: 9 additions & 0 deletions v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Avalonia.Interactivity;
using Avalonia.ReactiveUI;
using Avalonia.Threading;
using DialogHostAvalonia;
using ReactiveUI;
using Splat;
using System.ComponentModel;
Expand All @@ -19,6 +20,7 @@ public partial class MainWindow : ReactiveWindow<MainWindowViewModel>
{
private static Config _config;
private WindowNotificationManager? _manager;
private BackupAndRestoreView? _backupAndRestoreView;

public MainWindow()
{
Expand All @@ -34,6 +36,7 @@ public MainWindow()
menuSettingsSetUWP.Click += menuSettingsSetUWP_Click;
menuPromotion.Click += menuPromotion_Click;
menuClose.Click += menuClose_Click;
menuBackupAndRestore.Click += MenuBackupAndRestore_Click;

var IsAdministrator = true;//WindowsUtils.IsAdministrator();
MessageBus.Current.Listen<string>(Global.CommandSendSnackMsg).Subscribe(x => DelegateSnackMsg(x));
Expand Down Expand Up @@ -365,6 +368,12 @@ public async Task ScanScreenTaskAsync()
//ViewModel?.ScanScreenTaskAsync(result);
}

private void MenuBackupAndRestore_Click(object sender, RoutedEventArgs e)
{
_backupAndRestoreView ??= new BackupAndRestoreView(this);
DialogHost.Show(_backupAndRestoreView);
}

#endregion Event

#region UI
Expand Down
3 changes: 1 addition & 2 deletions v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
<EmbeddedResource Include="v2rayN.ico">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>

</ItemGroup>

</Project>
7 changes: 1 addition & 6 deletions v2rayN/v2rayN/Views/BackupAndRestoreView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,7 @@ public BackupAndRestoreView()
this.BindCommand(ViewModel, vm => vm.RemoteBackupCmd, v => v.menuRemoteBackup).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.RemoteRestoreCmd, v => v.menuRemoteRestore).DisposeWith(disposables);
});
}

private void MenuRemoteRestore_Click(object sender, RoutedEventArgs e)
{
throw new NotImplementedException();
}
}

private void MenuLocalBackup_Click(object sender, RoutedEventArgs e)
{
Expand Down

0 comments on commit fe81b51

Please sign in to comment.