From fe81b51dcb38130c62d545777642d3314ac5d8e3 Mon Sep 17 00:00:00 2001
From: 2dust <31833384+2dust@users.noreply.github.com>
Date: Fri, 4 Oct 2024 15:22:32 +0800
Subject: [PATCH] Add BackupAndRestore
---
.../Views/BackupAndRestoreView.axaml | 231 ++++++++++++++++++
.../Views/BackupAndRestoreView.axaml.cs | 70 ++++++
v2rayN/v2rayN.Desktop/Views/MainWindow.axaml | 1 +
.../v2rayN.Desktop/Views/MainWindow.axaml.cs | 9 +
v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj | 3 +-
.../v2rayN/Views/BackupAndRestoreView.xaml.cs | 7 +-
6 files changed, 313 insertions(+), 8 deletions(-)
create mode 100644 v2rayN/v2rayN.Desktop/Views/BackupAndRestoreView.axaml
create mode 100644 v2rayN/v2rayN.Desktop/Views/BackupAndRestoreView.axaml.cs
diff --git a/v2rayN/v2rayN.Desktop/Views/BackupAndRestoreView.axaml b/v2rayN/v2rayN.Desktop/Views/BackupAndRestoreView.axaml
new file mode 100644
index 00000000..0aa5fda9
--- /dev/null
+++ b/v2rayN/v2rayN.Desktop/Views/BackupAndRestoreView.axaml
@@ -0,0 +1,231 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/v2rayN/v2rayN.Desktop/Views/BackupAndRestoreView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/BackupAndRestoreView.axaml.cs
new file mode 100644
index 00000000..47df76bb
--- /dev/null
+++ b/v2rayN/v2rayN.Desktop/Views/BackupAndRestoreView.axaml.cs
@@ -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
+ {
+ 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();
+ 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 UpdateViewHandler(EViewAction action, object? obj)
+ {
+ return await Task.FromResult(true);
+ }
+ }
+}
\ No newline at end of file
diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml
index 9262a677..4eb4bd2d 100644
--- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml
+++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml
@@ -78,6 +78,7 @@
+
diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs
index 81125ebe..4e9f9197 100644
--- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs
+++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs
@@ -6,6 +6,7 @@ using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.ReactiveUI;
using Avalonia.Threading;
+using DialogHostAvalonia;
using ReactiveUI;
using Splat;
using System.ComponentModel;
@@ -19,6 +20,7 @@ namespace v2rayN.Desktop.Views
{
private static Config _config;
private WindowNotificationManager? _manager;
+ private BackupAndRestoreView? _backupAndRestoreView;
public MainWindow()
{
@@ -34,6 +36,7 @@ namespace v2rayN.Desktop.Views
menuSettingsSetUWP.Click += menuSettingsSetUWP_Click;
menuPromotion.Click += menuPromotion_Click;
menuClose.Click += menuClose_Click;
+ menuBackupAndRestore.Click += MenuBackupAndRestore_Click;
var IsAdministrator = true;//WindowsUtils.IsAdministrator();
MessageBus.Current.Listen(Global.CommandSendSnackMsg).Subscribe(x => DelegateSnackMsg(x));
@@ -365,6 +368,12 @@ namespace v2rayN.Desktop.Views
//ViewModel?.ScanScreenTaskAsync(result);
}
+ private void MenuBackupAndRestore_Click(object sender, RoutedEventArgs e)
+ {
+ _backupAndRestoreView ??= new BackupAndRestoreView(this);
+ DialogHost.Show(_backupAndRestoreView);
+ }
+
#endregion Event
#region UI
diff --git a/v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj b/v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj
index 02497df6..3b5d8198 100644
--- a/v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj
+++ b/v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj
@@ -40,7 +40,6 @@
Never
-
-
+
diff --git a/v2rayN/v2rayN/Views/BackupAndRestoreView.xaml.cs b/v2rayN/v2rayN/Views/BackupAndRestoreView.xaml.cs
index 34c6dc1d..33052044 100644
--- a/v2rayN/v2rayN/Views/BackupAndRestoreView.xaml.cs
+++ b/v2rayN/v2rayN/Views/BackupAndRestoreView.xaml.cs
@@ -32,12 +32,7 @@ namespace v2rayN.Views
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)
{