Rayburn Davis
2014-10-26 ae714216bd838702edd5430a9ea1071da6482904
commit | author | age
344044 1 ´╗┐using System;
RD 2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6
7 using System.Text;
8 using System.Windows.Forms;
9
10 namespace DupliDelete
11 {
12     public partial class Options : Form
13     {
14         public Options()
15         {
16             InitializeComponent();
17         }
18
19         private void button2_Click(object sender, EventArgs e)
20         {
21             bool restart = false;
22
23             if (GlobalBuffers.SettingsManager.FindSettingStringSingleInt("large_icons") == toolbarSizeCombo.SelectedIndex && toolbarSizeCombo.SelectedIndex == 0)
24             {
25                 if (MessageBox.Show("Duplicate Commander must restart before the new toolbar icon size will take effect. Make sure you have saved any searches or file lists that you may have. Restart now?", "Duplicate Commander", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == System.Windows.Forms.DialogResult.Yes)
26                 {
27                     restart = true;
28                 }
29             }
30
31             if (checkBox13.Checked)
32                 GlobalBuffers.SettingsManager.Add(new Setting("multicore", "1"));
33             else
34                 GlobalBuffers.SettingsManager.Add(new Setting("multicore", "0"));
35
36             string[] folder_exclusions = new string[listBox1.Items.Count];
37             string[] filetype_exclusions = new string[listBox2.Items.Count];
38             string[] network_clients = new string[networkClientList.Items.Count];
39
40             if (checkBox1.Checked == true)
41                 GlobalBuffers.SettingsManager.Add("dont_warn_ntfs", "1");
42             else
43                 GlobalBuffers.SettingsManager.Add("dont_warn_ntfs", "0");
44
45             if (checkBox2.Checked == true)
46                 GlobalBuffers.SettingsManager.Add( "auto_remove_1", "1");
47             else
48                 GlobalBuffers.SettingsManager.Add( "auto_remove_1", "0");
49
50             if (checkBox3.Checked == true)
51                 GlobalBuffers.SettingsManager.Add( "show_delete", "1");
52             else
53                 GlobalBuffers.SettingsManager.Add( "show_delete", "0");
54
55             if (checkBox11.Checked == true)
56                 GlobalBuffers.SettingsManager.Add( "show_link", "1");
57             else
58                 GlobalBuffers.SettingsManager.Add( "show_link", "0");
59
60             if (checkBox6.Checked == true)
61                 GlobalBuffers.SettingsManager.Add( "no_confirm", "1");
62             else
63                 GlobalBuffers.SettingsManager.Add( "no_confirm", "0");
64
65             if (checkBox7.Checked == true)
66                 GlobalBuffers.SettingsManager.Add( "ignore_links", "1");
67             else
68                 GlobalBuffers.SettingsManager.Add( "ignore_links", "0");
69
70             if (checkBox8.Checked == true)
71                 GlobalBuffers.SettingsManager.Add( "update_check", "0");
72             else
73                 GlobalBuffers.SettingsManager.Add( "update_check", "1");
74
75             if (checkBox12.Checked == true)
76                 GlobalBuffers.SettingsManager.Add( "notify_alphabeta", "1");
77             else
78                 GlobalBuffers.SettingsManager.Add( "notify_alphabeta", "0");
79
80             
81             if (toolbarSizeCombo.SelectedIndex == 1)
82             {
83                 GlobalBuffers.SettingsManager.Add( "large_icons", "0");
84             }
85             else
86             {
87                 GlobalBuffers.SettingsManager.Add( "large_icons", "1");
88             }
89
90             if (fileDisplayCombobox.SelectedIndex == 0)
91             {
92                 GlobalBuffers.SettingsManager.Add( "display_style", "0");
93             }
94             else
95             {
96                 GlobalBuffers.SettingsManager.Add( "display_style", "1");
97
98             }
99
100             GlobalBuffers.SettingsManager.Add( "scroll_step", scrollStepUpDown.Value.ToString());
101             //INIWriter.WriteSettings(Application.StartupPath + "\\" + "options.ini", "scroll_step", scrollStepUpDown.Value.ToString());
102
103             if (checkBox9.Checked == true)
104             {
105                 try
106                 {
107                     if (Convert.ToInt32(textBox2.Text) > 100 || Convert.ToInt32(textBox2.Text) < 1)
108                     {
109                         MessageBox.Show("Please enter a file scan percentage between 1 and 100%.", "Duplicate Commander", MessageBoxButtons.OK, MessageBoxIcon.Error);
110                         tabControl1.SelectedIndex = 0;
111                         textBox2.Focus();
112                         textBox2.SelectAll();
113                         return;
114                     }
115                 }
116                 catch(Exception)
117                 {
118                     MessageBox.Show("Please check what is entered in the file scan percetage box.", "Duplicate Commander", MessageBoxButtons.OK, MessageBoxIcon.Error);
119                     tabControl1.SelectedIndex = 0;
120                     textBox2.Focus();
121                     textBox2.SelectAll();
122                     return;
123                 }
124                 GlobalBuffers.SettingsManager.Add( "file_scan_part", textBox2.Text);
125             }
126             else
127                 GlobalBuffers.SettingsManager.Add( "file_scan_part", "-1");
128
129             if (checkBox10.Checked == true)
130                 GlobalBuffers.SettingsManager.Add( "highlight_items", "1");
131             else
132                 GlobalBuffers.SettingsManager.Add( "highlight_items", "0");
133
ae7142 134             if (checkBox13.Checked == true)
RD 135                 GlobalBuffers.SettingsManager.Add("senddump", "1");
136             else
137                 GlobalBuffers.SettingsManager.Add("senddump", "0");
138
344044 139             GlobalBuffers.SettingsManager.Add( "persist_check", Convert.ToInt32(checkBox4.Checked).ToString());
RD 140             GlobalBuffers.SettingsManager.Add( "del_untrue", Convert.ToInt32(checkBox5.Checked).ToString());
141
142             //tfs1.Close();
143
144             listBox1.Items.CopyTo(folder_exclusions, 0);
145             listBox2.Items.CopyTo(filetype_exclusions, 0);
146             networkClientList.Items.CopyTo(network_clients, 0);
147
148             GlobalBuffers.SettingsManager.Add("folder_exclusions", folder_exclusions);
149             GlobalBuffers.SettingsManager.Add("filetype_exclusions", filetype_exclusions);
150             GlobalBuffers.SettingsManager.Add("network_clients", network_clients);
151
152             GlobalBuffers.SettingsManager.Dump(GlobalBuffers.OptionsPath);
153
154             if(restart == true)
155                 Application.Restart();
156
157
158             this.Close();
159         }
160
161         private void Options_Load(object sender, EventArgs e)
162         {
163             string[] folder_exclusions,filetype_exclusions, servers;
164             int tmp;
165
166             if (GlobalBuffers.SettingsManager.FindSettingStringSingle("dont_warn_ntfs") == "1")
167                 checkBox1.Checked = true;
168
169             if (GlobalBuffers.SettingsManager.FindSettingStringSingle("auto_remove_1") == "1")
170                 checkBox2.Checked = true;
171
172             if (GlobalBuffers.SettingsManager.FindSettingStringSingle("show_delete") == "1")
173                 checkBox3.Checked = true;
174
175             if (GlobalBuffers.SettingsManager.FindSettingStringSingle("show_link") == "1")
176                 checkBox11.Checked = true;
177
178             if (GlobalBuffers.SettingsManager.FindSettingStringSingle("no_confirm") == "1")
179                 checkBox6.Checked = true;
180
181             if (GlobalBuffers.SettingsManager.FindSettingStringSingle("ignore_links") == "1")
182                 checkBox7.Checked = true;
183
184             if (GlobalBuffers.SettingsManager.FindSettingStringSingle("update_check") == "0")
185                 checkBox8.Checked = true;
186
187             if (GlobalBuffers.SettingsManager.FindSettingStringSingle("highlight_items") == "1")
188                 checkBox10.Checked = true;
189
190             if (GlobalBuffers.SettingsManager.FindSettingStringSingle("notify_alphabeta") == "1")
191                 checkBox12.Checked = true;
192
ae7142 193             if (GlobalBuffers.SettingsManager.FindSettingStringSingle("senddump") == "1")
344044 194                 checkBox13.Checked = true;
RD 195
196             if (GlobalBuffers.SettingsManager.FindSettingStringSingle("large_icons") == "0")
197                 toolbarSizeCombo.SelectedIndex= 1;
198             else
199                 toolbarSizeCombo.SelectedIndex = 0;
200
201             if (GlobalBuffers.SettingsManager.FindSettingStringSingle("display_style") == "0")
202                 fileDisplayCombobox.SelectedIndex = 0;
203             else
204                 fileDisplayCombobox.SelectedIndex = 1;
205
206            int scroll_step = GlobalBuffers.SettingsManager.FindSettingStringSingleInt("scroll_step");
207             
208
209             if (scroll_step < 1)
210                 scroll_step = 1;
211             if (scroll_step > 30)
212                 scroll_step = 30;
213
214             scrollStepUpDown.Value = scroll_step;
215
216             tmp = GlobalBuffers.SettingsManager.FindSettingStringSingleInt("file_scan_part");
217             if (tmp != -1)
218             {
219                 checkBox9.Checked = true;
220                 textBox2.Enabled = true;
221                 textBox2.Text = tmp.ToString();
222             }
223
224             if (GlobalBuffers.SettingsManager.FindSettingStringSingle("persist_check") == "1")
225                 checkBox4.Checked = true;
226
227             if (GlobalBuffers.SettingsManager.FindSettingStringSingle("del_untrue") == "1")
228                 checkBox5.Checked = true;
229
230             folder_exclusions = GlobalBuffers.SettingsManager.FindSettingStringMultiple("folder_exclusions");
231             filetype_exclusions = GlobalBuffers.SettingsManager.FindSettingStringMultiple("filetype_exclusions");
232             servers = GlobalBuffers.SettingsManager.FindSettingStringMultiple("network_clients");
233
234             if (folder_exclusions != null && filetype_exclusions != null)
235             {
236                 listBox1.Items.AddRange((string[])folder_exclusions);
237                 listBox2.Items.AddRange((string[])filetype_exclusions);
238             }
239
240             if (servers != null)
241                 networkClientList.Items.AddRange(servers);
242         }
243
244         private void button1_Click(object sender, EventArgs e)
245         {
246             if (textBox1.Text != "")
247             {
248                 if (textBox1.Text[0] == '*')
249                 {
250                     textBox1.Text = textBox1.Text.Substring(1);
251                 }
252                 if (textBox1.Text[0] != '.')
253                 {
254                     MessageBox.Show("The extension was incorrectly entered. The extension always begins with a period (e.g. .txt).", "Duplicate Commander", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
255                     return;
256                 }
257                 if (!listBox2.Items.Contains((string)textBox1.Text))
258                 {
259                     listBox2.Items.Add((string)textBox1.Text.ToLower());
260                     textBox1.Text = "";
261                     textBox1.Focus();
262                 }
263             }
264         }
265
266         private void button3_Click(object sender, EventArgs e)
267         {
268             int selected_index = listBox2.SelectedIndex;
269
270             if (listBox2.SelectedItems.Count > 0)
271             {
272                 listBox2.Items.RemoveAt(selected_index);
273                 if (listBox2.Items.Count > 0 && selected_index != listBox2.Items.Count)
274                     listBox2.SelectedIndex = selected_index;//listBox2.Items.Count - 1;
275                 else
276                     listBox2.SelectedIndex = listBox2.Items.Count - 1;
277             }
278         }
279
280         private void button4_Click(object sender, EventArgs e)
281         {
282             FolderBrowserDialog fbd1 = new FolderBrowserDialog();
283
284             fbd1.ShowNewFolderButton = false;
285             fbd1.Description = "Please specify the folder that you want to exclude from checking for duplicates.";
286
287             fbd1.ShowDialog();
288
289             if (!listBox1.Items.Contains((string)fbd1.SelectedPath))
290                 listBox1.Items.Add((string)fbd1.SelectedPath);
291         }
292
293         private void button5_Click(object sender, EventArgs e)
294         {
295             int selected_index = listBox1.SelectedIndex;
296
297             if (listBox1.SelectedItems.Count > 0)
298             {
299                 listBox1.Items.RemoveAt(selected_index);
300                 if (listBox1.Items.Count > 0 && selected_index != listBox1.Items.Count)
301                     listBox1.SelectedIndex = selected_index;//listBox1.Items.Count - 1;
302                 else
303                     listBox1.SelectedIndex = listBox1.Items.Count - 1;
304             }
305         }
306
307         private void checkBox9_CheckedChanged(object sender, EventArgs e)
308         {
309             if (checkBox9.Checked == true)
310             {
311                 textBox2.Enabled = true;
312                 textBox2.Focus();
313             }
314             else
315                 textBox2.Enabled = false;
316         }
317
318         private void tabPage3_Click(object sender, EventArgs e)
319         {
320
321         }
322
323         private void checkBox9_CheckedChanged_1(object sender, EventArgs e)
324         {
325             if (checkBox9.Checked == true)
326             {
327                 textBox2.Enabled = true;
328                 textBox2.Focus();
329             }
330             else
331                 textBox2.Enabled = false;
332         }
333
334         private void addClientButton_Click(object sender, EventArgs e)
335         {
336             if (newClientTextbox.Text != "")
337             {
338                 // TODO Check IP address here
339                 if (!networkClientList.Items.Contains((string)newClientTextbox.Text))
340                 {
341                     networkClientList.Items.Add((string)newClientTextbox.Text.ToLower());
342                     newClientTextbox.Text = "";
343                     newClientTextbox.Focus();
344                 }
345             }
346         }
347
348         private void removeClientButton_Click(object sender, EventArgs e)
349         {
350             int selected_index = networkClientList.SelectedIndex;
351
352             if (networkClientList.SelectedItems.Count > 0)
353             {
354                 networkClientList.Items.RemoveAt(selected_index);
355                 if (networkClientList.Items.Count > 0 && selected_index != networkClientList.Items.Count)
356                     networkClientList.SelectedIndex = selected_index;//listBox2.Items.Count - 1;
357                 else
358                     networkClientList.SelectedIndex = networkClientList.Items.Count - 1;
359             }
360         }
361
362         
363
364         
365     }
366 }