ConfigEdit.cs (4915B)
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Text.RegularExpressions; 5 using System.Windows.Forms; 6 7 namespace LanTool 8 { 9 /// <summary> 10 /// Formular zur Bearbeitung aller im LanTool bekannten Einstellungen 11 /// </summary> 12 internal partial class ConfigEdit: Form 13 { 14 public List<string> excludeExtension = new List<string>(); 15 public List<string> restrictExtension = new List<string>(); 16 public List<string> myDisks = new List<string>(); 17 public List<string> otherDisks = new List<string>(); 18 public int Md5FileSize = 10000; 19 public bool AutoScanMyDisks = false; 20 public bool AutoScanOtherDisks = false; 21 public bool ShowIgnoredClones = false; 22 public bool HideExcludedFiles = false; 23 public bool HideExistingFiles = false; 24 public bool RemoveMarks = false; 25 public bool TreatEqualNames = false; 26 public bool LowerPriority = false; 27 public string HeaderExtension = String.Empty; 28 public string DefaultOfflineFile = String.Empty; 29 30 private string _basePath; 31 32 /// <summary> 33 /// Konstruktor 34 /// </summary> 35 public ConfigEdit(string basePath) 36 { 37 InitializeComponent(); 38 39 _basePath = basePath; 40 } 41 42 private void ConfigEdit_Load(object sender, EventArgs e) 43 { 44 this.txtMD5Length.Text = Md5FileSize.ToString(); 45 this.chkAutoUpdateMyDisks.Checked = AutoScanMyDisks; 46 this.chkAutoUpdateOtherDisks.Checked = AutoScanOtherDisks; 47 this.chkShowIgnoredClones.Checked = ShowIgnoredClones; 48 this.chkHideExcludedFiles.Checked = HideExcludedFiles; 49 this.chkHideExistingFiles.Checked = HideExistingFiles; 50 this.chkRemoveMarks.Checked = RemoveMarks; 51 this.chkTreatEqualNames.Checked = TreatEqualNames; 52 this.chkLowerPriority.Checked = LowerPriority; 53 this.txtDefaultOfflineFile.Text = DefaultOfflineFile; 54 this.txtHeaderExtension.Text = HeaderExtension; 55 56 foreach (string s in excludeExtension) 57 { 58 this.BlackListBox.Items.Add(s); 59 } 60 foreach (string s in restrictExtension) 61 { 62 this.WhiteListBox.Items.Add(s); 63 } 64 foreach (string s in myDisks) 65 { 66 this.MyDisksBox.Items.Add(s); 67 } 68 foreach (string s in otherDisks) 69 { 70 this.OtherDisksBox.Items.Add(s); 71 } 72 } 73 74 private void OkButton_Click(object sender, EventArgs e) 75 { 76 try 77 { 78 this.Md5FileSize = System.Int32.Parse(this.txtMD5Length.Text); 79 } 80 catch 81 { 82 // Bei Fehleingaben ignorieren 83 } 84 AutoScanMyDisks = this.chkAutoUpdateMyDisks.Checked; 85 AutoScanOtherDisks = this.chkAutoUpdateOtherDisks.Checked; 86 ShowIgnoredClones = this.chkShowIgnoredClones.Checked; 87 HideExcludedFiles = this.chkHideExcludedFiles.Checked; 88 HideExistingFiles = this.chkHideExistingFiles.Checked; 89 RemoveMarks = this.chkRemoveMarks.Checked; 90 TreatEqualNames = this.chkTreatEqualNames.Checked; 91 DefaultOfflineFile = this.txtDefaultOfflineFile.Text; 92 LowerPriority = this.chkLowerPriority.Checked; 93 HeaderExtension = this.txtHeaderExtension.Text; 94 excludeExtension.Clear(); 95 foreach (string s in this.BlackListBox.Items) 96 { 97 excludeExtension.Add(s); 98 } 99 restrictExtension.Clear(); 100 foreach (string s in this.WhiteListBox.Items) 101 { 102 restrictExtension.Add(s); 103 } 104 myDisks.Clear(); 105 foreach (string s in this.MyDisksBox.Items) 106 { 107 myDisks.Add(s); 108 } 109 otherDisks.Clear(); 110 foreach (string s in this.OtherDisksBox.Items) 111 { 112 otherDisks.Add(s); 113 } 114 this.DialogResult = DialogResult.OK; 115 this.Close(); 116 } 117 118 #region Eventhandler auf diverse Controls 119 120 private void btnRemoveDefaultOfflineFile_Click(object sender, EventArgs e) 121 { 122 txtDefaultOfflineFile.Text = String.Empty; 123 } 124 125 private void btnSelectDefaultOfflineFile_Click(object sender, EventArgs e) 126 { 127 using (OpenFileDialog fd = new OpenFileDialog()) 128 { 129 fd.Filter = "LanTool-Verzeichnis-Export (*.files)|*.files|Textdateien (*.txt)|*.txt"; 130 fd.DefaultExt = "*.files"; 131 fd.FileName = "MeinePlatten.files"; 132 fd.InitialDirectory = _basePath; 133 fd.CheckFileExists = true; 134 fd.CheckPathExists = true; 135 fd.Multiselect = false; 136 fd.AutoUpgradeEnabled = true; 137 if (fd.ShowDialog(this) == DialogResult.OK) 138 { 139 // wenn die Datei im gleichen Verzeichnis wie das LanTool liegt, 140 // dann nur den Dateinamen speichern 141 if (fd.FileName.StartsWith(_basePath)) 142 { 143 fd.FileName = fd.FileName.Remove(0, _basePath.Length); 144 } 145 txtDefaultOfflineFile.Text = fd.FileName; 146 } 147 } 148 } 149 150 private void txtHeaderExtension_Validating(object sender, CancelEventArgs e) 151 { 152 if (!Regex.IsMatch(txtHeaderExtension.Text, "^[A-Za-z0-9_#+!]*$")) 153 { 154 MessageBox.Show("Es wurden ungültige Zeichen eingegeben." + Environment.NewLine + Environment.NewLine + 155 "Erlaubte Zeichen sind:" + Environment.NewLine + "Groß- und Kleinbuchstaben A bis Z" + Environment.NewLine + 156 "Ziffern 0 bis 9" + Environment.NewLine + "Sonderzeichen _ # + !"); 157 e.Cancel = true; 158 } 159 } 160 161 #endregion 162 } 163 }