From d03a86292e45cc456e8801464880a54076988624 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Fri, 6 Sep 2024 15:51:06 +0800 Subject: [PATCH] Add SaveFileDialog --- v2rayN/v2rayN/Common/UI.cs | 20 ++++++++++++++++++++ v2rayN/v2rayN/Views/ProfilesView.xaml.cs | 10 ++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/v2rayN/v2rayN/Common/UI.cs b/v2rayN/v2rayN/Common/UI.cs index b89cdf79f5..29caed2246 100644 --- a/v2rayN/v2rayN/Common/UI.cs +++ b/v2rayN/v2rayN/Common/UI.cs @@ -35,5 +35,25 @@ public static MessageBoxResult ShowYesNo(string msg) return true; } + + public static bool? SaveFileDialog(out string fileName, string filter) + { + fileName = string.Empty; + + SaveFileDialog fileDialog = new() + { + Filter = filter, + FilterIndex = 2, + RestoreDirectory = true + }; + if (fileDialog.ShowDialog() != true) + { + return false; + } + + fileName = fileDialog.FileName; + + return true; + } } } \ No newline at end of file diff --git a/v2rayN/v2rayN/Views/ProfilesView.xaml.cs b/v2rayN/v2rayN/Views/ProfilesView.xaml.cs index bffda55d17..b6d0ee76d2 100644 --- a/v2rayN/v2rayN/Views/ProfilesView.xaml.cs +++ b/v2rayN/v2rayN/Views/ProfilesView.xaml.cs @@ -129,17 +129,11 @@ private async Task UpdateViewHandler(EViewAction action, object? obj) case EViewAction.SaveFileDialog: if (obj is null) return false; - SaveFileDialog fileDialog = new() - { - Filter = "Config|*.json", - FilterIndex = 2, - RestoreDirectory = true - }; - if (fileDialog.ShowDialog() != true) + if (UI.SaveFileDialog(out string fileName, "Config|*.json") != true) { return false; } - ViewModel?.Export2ClientConfigResult(fileDialog.FileName, (ProfileItem)obj); + ViewModel?.Export2ClientConfigResult(fileName, (ProfileItem)obj); break; case EViewAction.AddServerWindow: