|
| 1 | +using CompressedFileViewer.Settings; |
| 2 | +using System; |
| 3 | +using System.Collections.Generic; |
| 4 | +using System.Linq; |
| 5 | +using System.Text; |
| 6 | +using System.Threading.Tasks; |
| 7 | +using System.Windows; |
| 8 | +using System.Windows.Controls; |
| 9 | +using System.Windows.Data; |
| 10 | +using System.Windows.Documents; |
| 11 | +using System.Windows.Input; |
| 12 | +using System.Windows.Media; |
| 13 | +using System.Windows.Media.Imaging; |
| 14 | +using System.Windows.Shapes; |
| 15 | + |
| 16 | +namespace CompressedFileViewer.Windows; |
| 17 | +/// <summary> |
| 18 | +/// Interaktionslogik für XZSettingsDialog.xaml |
| 19 | +/// </summary> |
| 20 | +public partial class XZSettingsDialog : Window, ISettingsDialog |
| 21 | +{ |
| 22 | + static XZSettingsDialog() |
| 23 | + { |
| 24 | + SettingsDialog.RegistSettingsDialog(XZSettings.ALGORITHM_NAME, typeof(XZSettingsDialog)); |
| 25 | + } |
| 26 | + |
| 27 | + public XZSettingsDialog() |
| 28 | + { |
| 29 | + InitializeComponent(); |
| 30 | + } |
| 31 | + |
| 32 | + Settings.XZSettings? settings; |
| 33 | + |
| 34 | + public CompressionSettings? CompressionSettings |
| 35 | + { |
| 36 | + get => settings; |
| 37 | + set |
| 38 | + { |
| 39 | + settings = (Settings.XZSettings?)value; |
| 40 | + txtBufferSize.Text = settings!.BufferSize.ToString(); |
| 41 | + txtComprLevel.Text = ((int)settings.CompressionLevel).ToString(); |
| 42 | + txtThreads.Text = settings.Threads.ToString(); |
| 43 | + chkMultiThreading.IsChecked = settings.MultiThreading; |
| 44 | + lstSuffix.Items.Clear(); |
| 45 | + foreach (var suffix in settings.Extensions) |
| 46 | + _ = lstSuffix.Items.Add(suffix); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + private void AddSuffix(object sender, RoutedEventArgs e) |
| 51 | + { |
| 52 | + string suffix = txtSuffix.Text.Trim(); |
| 53 | + if (string.IsNullOrWhiteSpace(suffix)) return; |
| 54 | + if (!suffix.StartsWith('.')) |
| 55 | + suffix = '.' + suffix; |
| 56 | + foreach (string items in lstSuffix.Items) |
| 57 | + if (items.Equals(suffix, StringComparison.OrdinalIgnoreCase)) |
| 58 | + return; |
| 59 | + _ = lstSuffix.Items.Add(suffix); |
| 60 | + } |
| 61 | + |
| 62 | + private void DeleteSuffix(object sender, RoutedEventArgs e) |
| 63 | + { |
| 64 | + if(lstSuffix.SelectedIndex != -1) |
| 65 | + lstSuffix.Items.RemoveAt(lstSuffix.SelectedIndex); |
| 66 | + } |
| 67 | + |
| 68 | + private void Button_Click(object sender, RoutedEventArgs e) |
| 69 | + { |
| 70 | + int comprLevel = int.Parse(txtComprLevel.Text); |
| 71 | + int bufferSize = int.Parse(txtBufferSize.Text); |
| 72 | + int threads = int.Parse(txtThreads.Text); |
| 73 | + |
| 74 | + settings!.Extensions.Clear(); |
| 75 | + settings.Extensions.AddRange(lstSuffix.Items.Cast<string>()); |
| 76 | + settings.CompressionLevel = (Joveler.Compression.XZ.LzmaCompLevel)comprLevel; |
| 77 | + settings.BufferSize = bufferSize; |
| 78 | + settings.MultiThreading = chkMultiThreading.IsChecked == true; |
| 79 | + settings.Threads = threads; |
| 80 | + this.DialogResult = true; |
| 81 | + Close(); |
| 82 | + } |
| 83 | + |
| 84 | + private void Cancel(object sender, RoutedEventArgs e) |
| 85 | + { |
| 86 | + this.DialogResult = false; |
| 87 | + Close(); |
| 88 | + } |
| 89 | + |
| 90 | + private void Default(object sender, RoutedEventArgs e) |
| 91 | + { |
| 92 | + var settings = Preferences.Default.XZSettings; |
| 93 | + txtBufferSize.Text = settings!.BufferSize.ToString(); |
| 94 | + txtComprLevel.Text = settings.CompressionLevel.ToString(); |
| 95 | + lstSuffix.Items.Clear(); |
| 96 | + foreach (var suffix in settings.Extensions) |
| 97 | + _ = lstSuffix.Items.Add(suffix); |
| 98 | + |
| 99 | + } |
| 100 | +} |
0 commit comments