diff --git a/v2rayN/v2rayN/Common/UI.cs b/v2rayN/v2rayN/Common/UI.cs index b89cdf79..29caed22 100644 --- a/v2rayN/v2rayN/Common/UI.cs +++ b/v2rayN/v2rayN/Common/UI.cs @@ -35,5 +35,25 @@ namespace v2rayN 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 bffda55d..b6d0ee76 100644 --- a/v2rayN/v2rayN/Views/ProfilesView.xaml.cs +++ b/v2rayN/v2rayN/Views/ProfilesView.xaml.cs @@ -129,17 +129,11 @@ namespace v2rayN.Views 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: