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: