|
6 | 6 | using System.Collections.ObjectModel; |
7 | 7 | using System.ComponentModel.Composition; |
8 | 8 | using System.IO; |
| 9 | +using System.Linq; |
9 | 10 | using System.Threading; |
10 | 11 | using System.Threading.Tasks; |
| 12 | +using System.Windows; |
| 13 | +using DnsCrypt.Blacklist; |
| 14 | +using MahApps.Metro.Controls; |
| 15 | +using MahApps.Metro.Controls.Dialogs; |
11 | 16 |
|
12 | 17 | namespace SimpleDnsCrypt.ViewModels |
13 | 18 | { |
@@ -89,6 +94,39 @@ public bool IsDomainBlockLogLogging |
89 | 94 | } |
90 | 95 | } |
91 | 96 |
|
| 97 | + public async void UnblockBlockLogEntry() |
| 98 | + { |
| 99 | + try |
| 100 | + { |
| 101 | + if (_selectedDomainBlockLogLine == null) return; |
| 102 | + if (MainViewModel.Instance.DomainBlacklistViewModel == null) return; |
| 103 | + var dialogSettings = new MetroDialogSettings |
| 104 | + { |
| 105 | + DefaultText = _selectedDomainBlockLogLine.Message.ToLower(), |
| 106 | + AffirmativeButtonText = LocalizationEx.GetUiString("add", Thread.CurrentThread.CurrentCulture), |
| 107 | + NegativeButtonText = LocalizationEx.GetUiString("cancel", Thread.CurrentThread.CurrentCulture), |
| 108 | + ColorScheme = MetroDialogColorScheme.Theme |
| 109 | + }; |
| 110 | + |
| 111 | + var metroWindow = Application.Current.Windows.OfType<MetroWindow>().FirstOrDefault(); |
| 112 | + //TODO: translate |
| 113 | + var dialogResult = await metroWindow.ShowInputAsync(LocalizationEx.GetUiString("message_title_new_whitelist_rule", Thread.CurrentThread.CurrentCulture), |
| 114 | + "Rule:", dialogSettings); |
| 115 | + |
| 116 | + if (string.IsNullOrEmpty(dialogResult)) return; |
| 117 | + var newCustomRule = dialogResult.ToLower().Trim(); |
| 118 | + var parsed = DomainBlacklist.ParseBlacklist(newCustomRule, true); |
| 119 | + var enumerable = parsed as string[] ?? parsed.ToArray(); |
| 120 | + if (enumerable.Length != 1) return; |
| 121 | + MainViewModel.Instance.DomainBlacklistViewModel.DomainWhitelistRules.Add(enumerable[0]); |
| 122 | + MainViewModel.Instance.DomainBlacklistViewModel.SaveWhitelistRulesToFile(); |
| 123 | + } |
| 124 | + catch (Exception exception) |
| 125 | + { |
| 126 | + Log.Error(exception); |
| 127 | + } |
| 128 | + } |
| 129 | + |
92 | 130 | private async void DomainBlockLog(DnscryptProxyConfiguration dnscryptProxyConfiguration) |
93 | 131 | { |
94 | 132 | const string defaultLogFormat = "ltsv"; |
|
0 commit comments