Rayburn Davis
2014-09-15 fb4519e5c864e7c153b6bafcf79275ed36a9bda3
commit | author | age
344044 1 ´╗┐using System;
RD 2 using System.Collections;
3 using System.Collections.Generic;
4 using System.ComponentModel;
5 using System.Data;
6 using System.Drawing;
7 //using System.Linq;
8 using System.Text;
9 using System.Windows.Forms;
10 using System.Runtime.InteropServices;
11 using System.Threading;
12 using System.IO;
13 using System.Diagnostics;
14 using Microsoft.Win32;
15 using System.Net;
16 using System.Text.RegularExpressions;
17 using System.Security.Cryptography;
18 using System.Xml;
19 using System.Resources;
20 using System.Reflection;
21 using System.Globalization;
22 using System.Net.Sockets;
fb4519 23 using DupliDelete.Duplicate_Search_Engine;
344044 24
RD 25 //using System.Design;
26
27
28 namespace DupliDelete
29 {
30     public partial class Form1 : Form
31     {
32         public bool filelist_mode = false;
33         public bool in_search = false; // true if a search phrase is entered
34         RunUndoScript ruds1;
35         bool search_thread_running = false;
36         public string version_string;// = GetVersionString();
37         Thread search_thread;
38
39         DuplicateListView.DrawIndex BackwardIndex, ForwardIndex;
40
41         private string GetVersionString()
42         {
43             return this.Text.Substring(this.Text.LastIndexOf(' ') + 1);
44         }
45
46         public string ReturnVersion()
47         {
48             return GetVersionString();
49         }
50
51         public ArrayList listview_items = new ArrayList(1);
52
53         [DllImport("Kernel32.dll", CharSet = CharSet.Unicode)]
54         static extern bool CreateHardLink(string lpFileName, string lpExistingFileName, IntPtr lpSecurityAttributes);
55
56         [DllImport("Kernel32.dll", CharSet = CharSet.Unicode, SetLastError=true)]
57         static extern bool CreateSymbolicLink(string lpFileName, string lpExistingFileName, Int32 dwFlags);
58
59         [DllImport("User32.dll", CharSet = CharSet.Unicode)]
60         static extern int SendMessage(IntPtr hwnd, int Msg, IntPtr wParam, IntPtr lParam);
61
62         [DllImport("User32.dll", CharSet = CharSet.Unicode)]
63         static extern int SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter, int X, int Y, int cx, int cy, uint flags);
64
65         [DllImport("User32.dll", CharSet = CharSet.Unicode)]
66         static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
67
68         [DllImport("shlwapi.dll", SetLastError = true)]
69         static extern int PathRelativePathTo(StringBuilder pszPath, string pszFrom, int dwAttrFrom, string pszTo, int dwAttrTo);
70
71         public Form1()
72         {
73             InitializeComponent();
74         }
75
76         private void toolStripButton1_Click(object sender, EventArgs e)
77         {
78             if (GlobalBuffers.working)
79                 return;
80             if (GlobalBuffers.Duplicates == null || GlobalBuffers.Duplicates.Count == 0)
81                 return;
82
83             //if (listView1.CheckedIndices.Count == 0)
84             //return;
85
86             string search_mode;
87             search_mode = GlobalBuffers.SettingsManager.FindSettingStringSingle("search_mode");
88
89             if (search_mode == "cbad" && filelist_mode == false)
90             {
91                 MessageBox.Show("Since Duplicate Commander is currently set to find files based on actual data, this command is not available.", "Duplicate Commander", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
92                 return;
93             }
94
95             ThreadStart ts = new ThreadStart(CompareGroup);
96             Thread t = new Thread(ts);
97
98             checking_window = new Checking();
99             checking_window.Text = "Comparing groups...";
100             checking_window.statusText.Text = "Please wait...";
101             checking_window.staticText = false;
102
103             long_process_listener = new LongProcessListener(checking_window, this);
104
105             t.Start();
106         }
107
108         public void CompareGroup()
109         {
110             double prg = (double)100 / GlobalBuffers.Duplicates.Count;
111             double prg2 = (double)0.0;
112             int i, j, k;
113             ObjectInfo file;
114             ErrorClass errors = new ErrorClass(this, "The following files could not be compared.");
115             DuplicateFinder.ChecksumReadStatus checksum_status;
116             ObjectInfoCollection file_collection = new ObjectInfoCollection();
117             int same_count = 0;
118             int sum = -1;
119
120             for (i = 0; i < GlobalBuffers.Duplicates.Count; i++)
121             {
122                 if (GlobalBuffers.Duplicates[i].GetGroupCheckState() != 2)
123                 {
124                     if (checking_window.cancel_clicked == true)
125                     {
126                         long_process_listener.Complete = true;
127                         return;
128                     }
129
130                     for (j = 0; j < GlobalBuffers.Duplicates[i].Count; j++)
131                     {
132                         if (checking_window.cancel_clicked == true)
133                         {
134                             long_process_listener.Complete = true;
135                             return;
136                         }
137
138                         checking_window.progressText = "Comparing file " + (j + 1) + " of group " + (i + 1);
139
140                         file = new ObjectInfo(GlobalBuffers.Duplicates[i][j].Filename, GlobalBuffers.Duplicates[i][j].Size, ObjectInfo.FileType.File);
141
142                         checksum_status = ReadFileChecksum(file, 100);
143
144                         if (checksum_status != DuplicateFinder.ChecksumReadStatus.Success)
145                         {
146                             if (checksum_status == DuplicateFinder.ChecksumReadStatus.AccessDenied)
147                                 errors.AddError(GlobalBuffers.Duplicates[i][j].Filename, "Access was denied.");
148                             if (checksum_status == DuplicateFinder.ChecksumReadStatus.FileNotFound)
149                                 errors.AddError(GlobalBuffers.Duplicates[i][j].Filename, "The file was not found.");
150                             if (checksum_status == DuplicateFinder.ChecksumReadStatus.UnknownError)
151                                 errors.AddError(GlobalBuffers.Duplicates[i][j].Filename, "The error is unknown.");
152                         }
153                         else
154                             file_collection.Add(file);
155                     }
156
157                     if (file_collection.Count == GlobalBuffers.Duplicates[i].Count)
158                     {
159                         for (k = 0; k < file_collection.Count; k++)
160                         {
161                             if (sum != -1 && sum != file_collection[k].ChecksumSum.Sum)
162                                 break;
163                             else
164                                 same_count++;
165
166                             sum = file_collection[k].ChecksumSum.Sum;
167                         }
168
169                         if (same_count == GlobalBuffers.Duplicates[i].Count)
170                         {
171                             GlobalBuffers.Duplicates[i].State = DuplicateGroup.GroupState.TrueDuplicate;
172                         }
173                         else
174                             GlobalBuffers.Duplicates[i].State = DuplicateGroup.GroupState.FalseDuplicate;
175                     }
176                     else
177                         GlobalBuffers.Duplicates[i].State = DuplicateGroup.GroupState.FalseDuplicate;
178
179                     file_collection.Clear();
180                     same_count = 0;
181                     sum = -1;
182                 }
183
184                 prg2 = (double)prg * i;
185
186                 checking_window.progress = (double)prg2;
187
188             }
189
190
191
192             long_process_listener.Complete = true;
193
194             GlobalBuffers.mainList.Invalidate();
195
196             errors.ShowErrorWindow();
197
198         }
199
200         private DuplicateFinder.ChecksumReadStatus ReadFileChecksum(ObjectInfo fileInfo, int percent)
201         {
202             if (fileInfo.Checksum == null)
203             {
204                 byte[] temp;
205                 int j;
206                 double percent_size = (double)0.0;
207                 SHA1 sha_handle;
208                 byte[] checksum_data = new byte[2097152];
209
210                 FileChecksum checksum1 = new FileChecksum();
211
212                 double progress;
213
214                 sha_handle = SHA1.Create();
215
216                 if (DirectoryEnumerator.Exists(fileInfo.Name))
217                 {
218                     FileStream fs1;
219                     try
220                     {
221                         fs1 = new FileStream(fileInfo.Name, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
222                     }
223                     catch (UnauthorizedAccessException)
224                     {
225                         return DuplicateFinder.ChecksumReadStatus.AccessDenied;
226                     }
227                     catch (FileNotFoundException)
228                     {
229                         return DuplicateFinder.ChecksumReadStatus.FileNotFound;
230                     }
231                     catch (IOException)
232                     {
233                         return DuplicateFinder.ChecksumReadStatus.UnknownError;
234                     }
235
236                     // FileChecksumScanInProgress = true;
237                     // FileChecksumObject = fileInfo;
238
239                     // GetFileInformationByHandle(fs1.SafeFileHandle.DangerousGetHandle(), out fileInfo.FileInfo);
240
241                     percent_size = (double)percent / 100 * fs1.Length;
242                     percent_size = RoundSize(percent_size);
243
244                     double loop_count = (double)percent_size / 2097152;
245
246                     // FileChecksumProgress = (double)0;
247                     progress = (double)100 / loop_count;
248
249                     int i;
250                     double remainder;
251
252                     for (i = 0; i < (int)loop_count; i++)
253                     {
254                         if (checking_window.cancel_clicked == true)
255                             break;
256
257                         /*  if (cancel_clicked == true)
258                           {
259                               fs1.Close();
260                               return -1;
261                           } */
262                         fs1.Read(checksum_data, 0, 2097152);
263
264                         temp = sha_handle.ComputeHash(checksum_data, 0, 2097152);
265
266                         for (j = 0; j < 16; j++)
267                             checksum1.checksum[j] += temp[j];
268
269
270
271                         //  FileChecksumProgress += (double)progress;
272                     }
273                     if ((double)loop_count > (int)loop_count)
274                     {
275                         /* if (cancel_clicked == true)
276                          {
277                              fs1.Close();
278                              return -1;
279                          }*/
280                         remainder = loop_count - (int)loop_count;
281                         remainder = (double)remainder * 2097152;
282
283                         fs1.Read(checksum_data, 0, (int)remainder);
284
285                         temp = sha_handle.ComputeHash(checksum_data, 0, (int)remainder);
286
287                         for (j = 0; j < 16; j++)
288                             checksum1.checksum[j] += temp[j];
289
290                         //compare_prg2 += (double)compare_prg;
291                     }
292
293                     fs1.Close();
294
295                     fileInfo.Checksum = checksum1.checksum;
296                     fileInfo.ChecksumSum = new ChecksumSum(ChecksumSum.returnSum(checksum1.checksum));
297
298                 }
299                 else
300                 {
301                     // FileChecksumScanInProgress = false;
302                     return DuplicateFinder.ChecksumReadStatus.FileNotFound;
303                 }
304
305             }
306             else
307             {
308                 // FileChecksumScanInProgress = false;
309                 return DuplicateFinder.ChecksumReadStatus.UnknownError;
310             }
311
312             //FileChecksumScanInProgress = false;
313
314             return DuplicateFinder.ChecksumReadStatus.Success;
315         }
316
317         private double RoundSize(double percent_size)
318         {
319             return ((double)percent_size > (int)percent_size ? (double)percent_size + 1 : (double)percent_size);
320         }
321
322         private void Form1_Load(object sender, EventArgs e)
323         {
324
325             //    Duplicate_Commander.RSTreeView.RSTreeNode tn = new Duplicate_Commander.RSTreeView.RSTreeNode();
326
327             //    tn.Text = "Test";
328             //  rsTreeView1.Nodes.Add(tn);
329
330             /*     IndeterminableTreeNode item = new IndeterminableTreeNode();
331                  item.Text = "Test!";
332                  item.Checked = 0;
333
334                  IndeterminableTreeNode item2 = new IndeterminableTreeNode();
335                  item2.Text = "Test2";
336                  item2.Checked = 0;
337                  item.Nodes.Add(item2);
338
339                  item.Expand();
340                  fileSystemTreeview.Nodes.Add(item); */
341
342             if (!File.Exists(GlobalBuffers.OptionsPath))
343             {
344                 MessageBox.Show("The options.ini file does not exist at \"" + Application.StartupPath + "\". Please reinstall or redownload Duplicate Commander.", "Duplicate Commander", MessageBoxButtons.OK, MessageBoxIcon.Error);
345                 this.Dispose(true);
346                 Application.Exit();
347             }
348             else
349             {
350                 GlobalBuffers.SettingsManager = SettingsManager.Load(GlobalBuffers.OptionsPath);
351
352                 GlobalBuffers.main_form = this;
353
354                // int t = 0;
355                 //int z = 1 / t;
356
357                 GlobalBuffers.mainList = mainList;
358
359                 OperatingSystem OSVer = System.Environment.OSVersion;
360
361                 if (OSVer.Version.Major >= 5)
362                 {
363                     menuStrip.BackgroundImage = global::DupliDelete.Properties.Resources.toolbar;
364                     commandStrip.BackgroundImage = global::DupliDelete.Properties.Resources.toolbarbg;
365                     commandStrip.BackgroundImageLayout = ImageLayout.Stretch;
366
367                     searchStrip.BackgroundImage = global::DupliDelete.Properties.Resources.toolbarbg;
368                     searchStrip.BackgroundImageLayout = ImageLayout.Stretch;
369
370                 }
371
372                 // get this version; it's stored in the title of the window
373                 version_string = GetVersionString();
fb4519 374                 Text = "Duplicate Commander 3.2.41117"; //+ Assembly.GetExecutingAssembly().GetName().Version.Major + "." + Assembly.GetExecutingAssembly().GetName().Version.Minor + "." + Assembly.GetExecutingAssembly().GetName().Version.Revision;
344044 375
RD 376                 // check for updates
377                 ThreadStart ts1 = new ThreadStart(CheckForUpdates);
378                 Thread update_checker_thread = new Thread(ts1);
379                 if (GlobalBuffers.SettingsManager.FindSettingStringSingle( "update_check") == "0")
380                     update_checker_thread.Start();
381
382                 // hide the listview until it's time to scan
383                 // mainList.Visible = false;
384
385                 // if the user's manual doesn't exist, this is the portable version; hide the User's Manual menu entry
386                 if (!File.Exists(Application.StartupPath + "\\" + "dcum.chm"))
387                 {
388                     usersManualToolStripMenuItem.Visible = false;
389                     toolStripSeparator2.Visible = false;
390                 }
391
392                 if (GlobalBuffers.SettingsManager.FindSettingStringSingle( "portable") == "1")
393                     GlobalBuffers.Portable = true;
394                 else
395                     GlobalBuffers.Portable = false;
396
397                 // check if this is the user's first time running DC
398                 CheckIfFirstTime();
399
400                 // check for drives that do not support hard links
401                 CheckFilesystems();
402
403
404                 LoadSettings(); // load listview and other settings into memory that we need now
405
406                 timer1.Start();
407
408                 GlobalBuffers.MainFormLoaded = true;
409
410                 GlobalBuffers.mainList.Columns[0].Width = Width - 470;
411
412             }
413         }
414
415         protected override void OnLoad(EventArgs e)
416         {
417             base.OnLoad(e);
418         }
419
420
421
422         protected override void OnPaintBackground(PaintEventArgs e)
423         {
424             base.OnPaintBackground(e);
425         }
426
427         // the delete button was clicked in the listview (?)
428         void Delete_ButtonClicked(EventArgs e)
429         {
430             DeleteSelectedItem();
431         }
432
433         // The Search button on the toolbar was clicked
434         /*void Search_ButtonClicked(EventArgs e)
435         {
436             if (GlobalBuffers.working)
437                 return;
438             ScanCriteria sc1 = new ScanCriteria();
439
440             sc1.Owner = this;
441             sc1.ShowDialog();
442             sc1.Tag = null;
443         }*/
444
445         /// <summary>
446         /// Checks to see if there are any drives that do not support hard links
447         /// </summary>
448         private void CheckFilesystems()
449         {
450             int i, fat32_count = 0;
451             DriveInfo[] drives = DriveInfo.GetDrives();
452
453             for (i = 0; i < drives.Length; i++)
454             {
455                 if (drives[i].DriveType == DriveType.Fixed && drives[i].IsReady == true && drives[i].DriveFormat != "NTFS")
456                     fat32_count++;
457             }
458
459             if (fat32_count > 0 && GlobalBuffers.SettingsManager.FindSettingStringSingle( "dont_warn_ntfs") == "0")
460                 MessageBox.Show("One or more fixed drives on your system is not formatted with the NTFS filesystem. You will not be able to create hard links on these drives.", "Duplicate Commander", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
461         }
462
463         private void viewToolStripMenuItem_Click(object sender, EventArgs e)
464         {
465
466         }
467
468         private void toolStripTextBox1_Click(object sender, EventArgs e)
469         {
470         }
471
472         private void toolStripTextBox1_KeyPress(object sender, KeyPressEventArgs e)
473         {
474         }
475
476         // the user typed something into the search box
477         private void toolStripTextBox1_TextChanged(object sender, EventArgs e)
478         {
479             if (DontUpdateSearchQuery == false)
480             {
481                 ThreadStart ts1 = new ThreadStart(ProcessSearchBoxThread);
482                 search_thread = new Thread(ts1);
483
484                 search_thread.Start();
485             }
486         }
487
488         public void ProcessSearchBoxThread()
489         {
490             if (search_thread_running == false)
491             {
492                 ProcessSearchBox();
493             }
494         }
495
496         public void ProcessSearchBox()
497         {
498             if (mainList.Visible != true)
499                 return;
500
501             search_thread_running = true;
502             int i, j;
503             int item_count = 0;
504             bool ensure_visible = true;
505             string search_text = "", old_search_text = "";
506             double prg;
507
508             this.Invoke((MethodInvoker)delegate
509             {
510                 search_text = searchListTextbox.Text;
511             });
512
513             if (search_text != "")
514             {
515                 while (search_text != old_search_text && search_text != "")
516                 {
517                     old_search_text = search_text;
518                     Thread.Sleep(200);
519                     this.Invoke((MethodInvoker)delegate
520                     {
521                         search_text = searchListTextbox.Text;
522                     });
523                 }
524
525                 if (search_text == "")
526                 {
527                     goto no_text;
528                 }
529
530
531                 in_search = true;
532
533                 GlobalBuffers.mainList.HighLightedIndexes.Clear();
534
535                 prg = (double)100 / GlobalBuffers.Duplicates.Count;
536
537                 for (i = 0; i < GlobalBuffers.Duplicates.Count; i++)
538                 {
539                     for (j = 0; j < GlobalBuffers.Duplicates[i].Count; j++)
540                     {
541                         if ((GlobalBuffers.Duplicates[i][j].Filename.ToLower().IndexOf(search_text.ToLower())) != -1)
542                         {
543                             if (ensure_visible == true)
544                             {
545                                 GlobalBuffers.mainList.EnsureVisible(new DuplicateListView.DrawIndex(i, -1, null));
546                                 ensure_visible = false;
547                             }
548
549                             GlobalBuffers.Duplicates[i][j].Highlighted = true;
550                             GlobalBuffers.mainList.HighLightedIndexes.Add(GlobalBuffers.Duplicates[i].RollingTotal + j);
551
552                             item_count++;
553                         }
554                         else
555                             GlobalBuffers.Duplicates[i][j].Highlighted = false;
556
557                     }
558
559                 }
560
561                 
562
563                 this.Invoke((MethodInvoker)delegate
564                 {
565                     jumpUpButton.ToolTipText = "Jump to previous page of search matches";
566                     jumpDownButton.ToolTipText = "Jump to next page of search matches";
567
568                     statusBarPanel5.Text = (item_count != 1 ? item_count + " items " : "1 item ") + "found";
569
570                     EnableArrows(false);
571                 });
572                 search_thread_running = false;
573             }
574         no_text:
575             if (search_text == "")
576             {
577
578                 this.Invoke((MethodInvoker)delegate
579                 {
580                    // GlobalBuffers.mainList.verticalScrollbar.Value = 0;
581                    // GlobalBuffers.mainList.DrawStartIndex.Group = 0;
582                    // GlobalBuffers.mainList.DrawStartIndex.Duplicate = -1;
583                     GlobalBuffers.mainList.HighLightedIndexes.Clear();
584
585                     for (i = 0; i < GlobalBuffers.Duplicates.Count; i++)
586                     {
587                         for (j = 0; j < GlobalBuffers.Duplicates[i].Count; j++)
588                         {
589                             GlobalBuffers.Duplicates[i][j].Highlighted = false;
590                         }
591                     }
592
593                     jumpUpButton.ToolTipText = "Jump to previous checked item";
594                     jumpDownButton.ToolTipText = "Jump to next of checked item";
595
596                     SetStatusBarData(true);
597                 });
598
599                 in_search = false;
600             }
601             search_thread_running = false;
602
603             mainList.Invalidate();
604         }
605
606         private void ParseExtensions(string in_exp, ArrayList extensions)
607         {
608             int ext_start = in_exp.ToLower().IndexOf("ext(");
609             if (ext_start == -1)
610                 return;
611             int ext_end = in_exp.ToLower().IndexOf(")", ext_start);
612             int comma_index = ext_start + 4;
613             int i;
614             int count = 0;
615             string out_ext;
616
617             for (i = ext_start + 4; i <= ext_end; i++)
618             {
619                 if (in_exp[i] == ',' || i == ext_end)
620                 {
621                     out_ext = in_exp.Substring(comma_index, count);
622                     extensions.Add((string)out_ext);
623
624                     comma_index = i + 1;
625                     count = -1;
626                 }
627                 count++;
628             }
629         }
630
631         private void listView1_Click(object sender, EventArgs e)
632         {
633             //EnableArrows(false);
634         }
635
636         private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
637         {
638             DuplicateObject selected_item = GlobalBuffers.mainList.GetItem(GlobalBuffers.mainList.SelectedItem.Group, GlobalBuffers.mainList.SelectedItem.Duplicate);
639             DuplicateObject selected_item_group = GlobalBuffers.mainList.GetItem(GlobalBuffers.mainList.SelectedItem.Group, -1);
640
641
642             if (selected_item == null || selected_item_group == null)
643             {
644                 e.Cancel = true;
645                 return;
646             }
647
648             //  if (GlobalBuffers.mainList.GetItem(GlobalBuffers.mainList.SelectedItem.Group, GlobalBuffers.mainList.SelectedItem.Data))
649             //      e.Cancel = true;
650
651
652             if (selected_item.ObjectType == DuplicateObject.Type.Group)
653             {
654                 if (selected_item_group.DuplicateGroup.ContainsLink == true)
655                 {
656                     checkAllFiles.Visible = false;
657                     checkAllFilesInThisGroupExcept.Visible = false;
658                     unCheckAllFilesInThisGroupExcept.Visible = false;
659                     openContainingFolder.Visible = false;
660                     deleteThisFile.Visible = false;
661                     openThisFile.Visible = false;
662                     deleteThisFolder.Visible = false;
663                     itemRightClickSeperator.Visible = false;
664                     disconnectFileFromHardLinkGroup.Visible = false;
665                     excludeContainingOrParentFolder.Visible = false;
666                     excludeThisFilesExtensionToolStripMenuItem.Visible = false;
667                     disconnectAllFilesFromHardLinkGroupToolStrip.Visible = true;
668                 }
669                 else
670                 {
671                     e.Cancel = true;
672                 }
673             }
674             else
675             {
676                 checkAllFiles.Visible = true;
677                 openContainingFolder.Visible = true;
678                 deleteThisFile.Visible = true;
679                 openThisFile.Visible = true;
680                 deleteThisFolder.Visible = true;
681                 itemRightClickSeperator.Visible = true;
682                 disconnectFileFromHardLinkGroup.Visible = true;
683                 excludeContainingOrParentFolder.Visible = true;
684                 disconnectAllFilesFromHardLinkGroupToolStrip.Visible = false;
685
686
687                 if (selected_item_group.DuplicateGroup.ContainsLink == true)
688                     disconnectFileFromHardLinkGroup.Visible = true;
689                 else
690                     disconnectFileFromHardLinkGroup.Visible = false;
691             }
692         }
693
694         public void LoadSettings()
695         {
696             ExtendedDebugData.AddEntry(1, "Loading settings");
697
698
699
700             if (GlobalBuffers.SettingsManager.FindSettingStringSingle( "show_delete") == "1")
701                 mainList.DeleteButton = true;
702             else
703                 mainList.DeleteButton = false;
704
705             if (GlobalBuffers.SettingsManager.FindSettingStringSingle( "show_link") == "1")
706                 mainList.LinkButton = true;
707             else
708                 mainList.LinkButton = false;
709
710             if (GlobalBuffers.SettingsManager.FindSettingStringSingle( "highlight_items") == "1")
711                 mainList.HighlightMouseOverItems = true;
712             else
713                 mainList.HighlightMouseOverItems = false;
714
715             if (GlobalBuffers.SettingsManager.FindSettingStringSingle( "auto_remove_1") == "1")
716                 GlobalBuffers.DeleteOneFileGroups = true;
717             else
718                 GlobalBuffers.DeleteOneFileGroups = false;
719
720             if (GlobalBuffers.SettingsManager.FindSettingStringSingle( "display_style") == "1")
721                 GlobalBuffers.DisplayStyle = GlobalBuffers.FileNameDisplayStyle.FullPath;
722             else
723                 GlobalBuffers.DisplayStyle = GlobalBuffers.FileNameDisplayStyle.FilenameThenPath;
724
725             GlobalBuffers.MinimumFileSize = Convert.ToInt64(GlobalBuffers.SettingsManager.FindSettingStringSingle( "minimum_size"));
726             GlobalBuffers.MinimumFileSizeMetric = Convert.ToInt32(GlobalBuffers.SettingsManager.FindSettingStringSingle( "minimum_size_metric"));
727
728             GlobalBuffers.MaximumFileSize = Convert.ToInt64(GlobalBuffers.SettingsManager.FindSettingStringSingle( "maximum_size"));
729             GlobalBuffers.MaximumFileSizeMetric = Convert.ToInt32(GlobalBuffers.SettingsManager.FindSettingStringSingle( "maximum_size_metric"));
730
731             if (GlobalBuffers.SettingsManager.FindSettingStringSingle( "search_mode") == "cbf")
732             {
733                 GlobalBuffers.CompareByActualData = false;
734                 GlobalBuffers.CompareByFilename = true;
735             }
736             else
737             {
738                 GlobalBuffers.CompareByFilename = false;
739                 GlobalBuffers.CompareByActualData = true;
740             }
741
742             if (GlobalBuffers.SettingsManager.FindSettingStringSingle( "check_extension") == "1")
743                 GlobalBuffers.CompareByExtension = true;
744             else
745                 GlobalBuffers.CompareByExtension = false;
746             if (GlobalBuffers.SettingsManager.FindSettingStringSingle( "check_file_size") == "1")
747                 GlobalBuffers.CompareBySize = true;
748             else
749                 GlobalBuffers.CompareBySize = false;
750             if (GlobalBuffers.SettingsManager.FindSettingStringSingle( "check_date_time") == "1")
751                 GlobalBuffers.CompareByTimestamp = true;
752             else
753                 GlobalBuffers.CompareByTimestamp = false;
754
755             string[] folders, inclusions;
756             folders = GlobalBuffers.SettingsManager.FindSettingStringMultiple( "folders");
757             inclusions = GlobalBuffers.SettingsManager.FindSettingStringMultiple( "inclusions");
758
759             GlobalBuffers.scan_folders = folders;
760
761             if (inclusions != null && inclusions.Length != 0)
762                 GlobalBuffers.FileTypeInclusions = inclusions;
763             else
764                 GlobalBuffers.FileTypeInclusions = null;
765
766             if (GlobalBuffers.MainFormLoaded == false)
767             {
768                 if (GlobalBuffers.SettingsManager.FindSettingStringSingle( "maximized") == "yes")
769                     this.WindowState = FormWindowState.Maximized;
770                 else
771                 {
772
773                     int pos_x = Convert.ToInt32(GlobalBuffers.SettingsManager.FindSettingStringSingle( "pos_x"));
774                     int pos_y = Convert.ToInt32(GlobalBuffers.SettingsManager.FindSettingStringSingle( "pos_y"));
775
776                     int width = Convert.ToInt32(GlobalBuffers.SettingsManager.FindSettingStringSingle( "size_width"));
777                     int height = Convert.ToInt32(GlobalBuffers.SettingsManager.FindSettingStringSingle( "size_height"));
778
779                     if (width == 0 || height == 0)
780                     {
781                         width = 700;
782                         height = 500;
783                     }
784
785                     this.Size = new System.Drawing.Size(width, height);
786
787                     this.Location = new Point(pos_x, pos_y);
788
789                 }
790             }
791
792             int scroll_step = GlobalBuffers.SettingsManager.FindSettingStringSingleInt("scroll_step");
793             GlobalBuffers.WheelSkip = scroll_step;
794
795             LoadRecentFileList();
796
797             if (GlobalBuffers.SettingsManager.FindSettingStringSingle( "large_icons") == "0")
798                 LoadSmallToolbar();
799             
800           //  LoadPinnedList();
801         }
802
803         public void LoadSmallToolbar()
804         {
805             int i;
806
807             //commandStrip.ImageList = null;
808             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(global::DupliDelete.Properties.Resources));
809
810             for (i = 0; i < commandStrip.Items.Count; i++)
811             {
812                 if (!(commandStrip.Items[i] is ToolStripSeparator))
813                 {
814
815                     if ((string)commandStrip.Items[i].Tag != null)
816                     {
817                         commandStrip.Items[i].Size = new System.Drawing.Size(16, 16);
818                         commandStrip.Items[i].Image = ((System.Drawing.Image)(resources.GetObject(commandStrip.Items[i].Tag + "_classic")));
819                     }
820                 }
821             }
822
823
824             for (i = 0; i < searchStrip.Items.Count; i++)
825             {
826                 if (!(searchStrip.Items[i] is ToolStripSeparator || searchStrip.Items[i] is ToolStripTextBox))
827                 {
828                     //commandStrip.Items[i].Image = ((System.Drawing.Image)(resources.GetObject(commandStrip.Items[i].Tag + "_smaller")));
829
830                     if ((string)searchStrip.Items[i].Tag != null)
831                     {
832                         searchStrip.Items[i].Size = new System.Drawing.Size(16, 16);
833                         searchStrip.Items[i].Image = ((System.Drawing.Image)(resources.GetObject(searchStrip.Items[i].Tag + "_classic")));
834                     }
835                 }
836             }
837         }
838
839         private void optionsToolStripMenuItem_Click(object sender, EventArgs e)
840         {
841             Options opt_wnd1 = new Options();
842
843             opt_wnd1.Owner = this;
844             opt_wnd1.ShowDialog();
845
846             LoadSettings();
847             GlobalBuffers.mainList.Invalidate();
848         }
849
850         private void toolStripButton3_Click(object sender, EventArgs e)
851         {
852             if (GlobalBuffers.working)
853                 return;
854             if (GlobalBuffers.Duplicates == null || GlobalBuffers.Duplicates.Count == 0)
855                 return;
856             if (GlobalBuffers.Duplicates.TotalCheckedItems == 0)
857             {
858                 MessageBox.Show("Please check an item first.", "Duplicate Commander", MessageBoxButtons.OK, MessageBoxIcon.Error);
859                 return;
860             }
861             int i, j;
862             int checked_group_count = 0;
863             //HardLinkWindow hlw1 = new HardLinkWindow();
864
865             GlobalBuffers.CreateHardLinkData = new CreateHardLinkData();
866
867             //int no_confirm = GlobalBuffers.SettingsManager.FindSettingStringSingleInt( "no_confirm");
868
869             //if (no_confirm == 0 && (DialogResult)MessageBox.Show("This command will create hard links from the checked file in every group. This means that every file in a group that is not checked will be deleted and replaced with a hard link that points to the checked file in the group. Please be sure of what you're doing before you proceed.\n\nAre you sure?", "Duplicate Commander", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No)
870                // return;
871
872             for (i = 0; i < GlobalBuffers.Duplicates.Count; i++)
873             {
874                 for (j = 0; j < GlobalBuffers.Duplicates[i].Count; j++)
875                 {
876                     if (GlobalBuffers.Duplicates[i][j].Checked == true)
877                     {
878                         checked_group_count++;
879                         if (checked_group_count > 1)
880                         {
881                             MessageBox.Show("More than 1 file out of one or more groups are checked. In order to create hard links, only 1 file must be checked from each group because that is the file that all other files in the group will point to.", "Duplicate Commander", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
882                             //duplicateList.EnsureVisible(i);
883                             return;
884                         }
885                     }
886                 }
887
888                 checked_group_count = 0;
889             }
890
891             Forms.CreateHardLinksWindow chl = new Forms.CreateHardLinksWindow();
892             chl.Owner = this;
893             chl.ShowDialog();
894
895            /* DialogResult r = MessageBox.Show("Would you like to create an undo script? If you think you may need to undo this operation in the future, it is highly recommended.", "Duplicate Commander", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);
896             if (r == System.Windows.Forms.DialogResult.Yes)
897             {
898                 SaveFileDialog sfd1 = new SaveFileDialog();
899                 sfd1.Title = "Please specify the place to save the undo script...";
900                 sfd1.Filter = "Duplicate Commander Undo Script (*.dds)|*.dds||";
901                 sfd1.ShowDialog();
902
903                 if (sfd1.FileName == "")
904                 {
905                     if ((DialogResult)MessageBox.Show("You did not specify a place to save an undo script. To continue without saving one, click OK.", "Duplicate Commander", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.Cancel)
906                         return;
907                     GlobalBuffers.CreateHardLinkData.CreateUndoScript = false;
908                 }
909                 else
910                 {
911                     GlobalBuffers.CreateHardLinkData.CreateUndoScript = true;
912                     GlobalBuffers.CreateHardLinkData.UndoScriptPath = sfd1.FileName;
913                 }
914             }
915             else if (r == System.Windows.Forms.DialogResult.No)
916             {
917                 GlobalBuffers.CreateHardLinkData.CreateUndoScript = false;
918
919                 //EnableArrows(false);
920             }
921
922             */
923
924             if (GlobalBuffers.CreateHardLinkData.Canceled == false)
925             {
926                 checking_window = new Checking();
927                 checking_window.Text = "Creating hard links";
928                 checking_window.Owner = this;
929
930                 long_process_listener = new LongProcessListener(checking_window, this);
931
932                 ThreadStart ts = new ThreadStart(CreateHardLinks);
933                 Thread t = new Thread(ts);
934
935                 t.Start();
936             }
937         }
938
939         private void toolStripButton4_Click(object sender, EventArgs e)
940         {
941             if (GlobalBuffers.working)
942                 return;
943             if (GlobalBuffers.Duplicates == null || GlobalBuffers.Duplicates.Count == 0)
944                 return;
945             if (GlobalBuffers.Duplicates.TotalCheckedItems == 0)
946             {
947                 MessageBox.Show("Please check an item first.", "Duplicate Commander", MessageBoxButtons.OK, MessageBoxIcon.Error);
948                 return;
949             }
950             ThreadStart ts1;
951             Thread t;
952
953             int no_confirm = GlobalBuffers.SettingsManager.FindSettingStringSingleInt( "no_confirm");
954
955             if (no_confirm == 0 && (DialogResult)MessageBox.Show("You are about to delete all checked files to the Recycle Bin. Are you sure?", "Duplicate Commander", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No)
956                 return;
957             else
958             {
959
960                 checking_window = new Checking();
961                 checking_window.Text = "Deleting items...";
962                 checking_window.statusText.Text = "Please wait...";
963                 long_process_listener = new LongProcessListener(checking_window, this);
964
965                 ts1 = new ThreadStart(DeleteChecked);
966                 t = new Thread(ts1);
967                 t.Start();
968
969                 EnableArrows(false);
970             }
971         }
972
973         private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
974         {
975             About ab1 = new About();
976
977             ab1.Owner = this;
978             ab1.ShowDialog();
979         }
980
981         private void toolStripButton6_Click(object sender, EventArgs e)
982         {
983             if (GlobalBuffers.working)
984                 return;
985             if (GlobalBuffers.Duplicates == null || GlobalBuffers.Duplicates.Count == 0)
986                 return;
987
988             ThreadStart ts = new ThreadStart(CheckAllButFirst);
989             Thread t = new Thread(ts);
990
991             checking_window = new Checking();
992             long_process_listener = new LongProcessListener(checking_window, this);
993
994             t.Start();
995         }
996
997         private void CheckAllButFirst()
998         {
999             int i = 0, j = 0;
1000             double prg = (double)100 / GlobalBuffers.Duplicates.Count, prg2 = (double)0.0;
1001             int group_count = 0, duplicate_count = 0;
1002
1003
1004             for (i = 0; i < GlobalBuffers.Duplicates.Count; i++)
1005             {
1006                 duplicate_count = 0;
1007
1008                 if (checking_window.cancel_clicked == true)
1009                     break;
1010
1011                 GlobalBuffers.Duplicates[i][0].Checked = false;
1012
1013                 for (j = 1; j < GlobalBuffers.Duplicates[i].Count; j++)
1014                 {
1015                     checking_window.progressText = "Processing duplicate " + (duplicate_count + 1).ToString() + " of group " + (group_count + 1).ToString();
1016
1017                     GlobalBuffers.Duplicates[i][j].Checked = true;
1018                     duplicate_count++;
1019                 }
1020
1021                 prg2 += (double)prg;
1022                 group_count++;
1023             }
1024
1025             mainList.Invalidate();
1026
1027             this.Invoke((MethodInvoker)delegate
1028             {
1029                 SetStatusBarData(false);
1030
1031                 EnableArrows(false);
1032             });
1033
1034             long_process_listener.Complete = true;
1035         }
1036
1037         private void toolStripButton7_Click(object sender, EventArgs e)
1038         {
1039             if (GlobalBuffers.working)
1040                 return;
1041             if (GlobalBuffers.Duplicates == null || GlobalBuffers.Duplicates.Count == 0)
1042                 return;
1043             if (GlobalBuffers.Duplicates.TotalCheckedItems == 0)
1044             {
1045                 MessageBox.Show("Please check an item first.", "Duplicate Commander", MessageBoxButtons.OK, MessageBoxIcon.Error);
1046                 return;
1047             }
1048
1049             MoveCheckedWindow mcw1 = new MoveCheckedWindow();
1050
1051             mcw1.Owner = this;
1052             mcw1.ShowDialog();
1053             if (GlobalBuffers.folders_ok_clicked == true)
1054             {
1055                 ThreadStart ts = new ThreadStart(MoveCheckedItemsToFolder);
1056                 Thread t = new Thread(ts);
1057
1058                 checking_window = new Checking();
1059                 checking_window.Text = "Moving files...";
1060                 checking_window.statusText.Text = "Please wait...";
1061
1062                 long_process_listener = new LongProcessListener(checking_window, this);
1063
1064                 t.Start();
1065             }
1066         }
1067
1068         private void MoveCheckedItemsToFolder()
1069         {
1070             int i, j;
1071             string folder = GlobalBuffers.MoveFilesData.Folder;
1072             double prg = (double)100 / GlobalBuffers.Duplicates.Count;
1073             double prg2 = (double)0.0;
1074             TextFileStream tfs1 = null;
1075             if (GlobalBuffers.MoveFilesData.UndoListPath != "" && GlobalBuffers.MoveFilesData.CreateUndoList == true)
1076                 tfs1 = new TextFileStream(GlobalBuffers.MoveFilesData.UndoListPath, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
1077             string moved_filename;
1078             int copy_filename_loop = 1;
1079             int group_count = 0, duplicate_count = 0;
1080             ErrorClass errors = new ErrorClass(this, "The following files could not be moved.");
1081
1082             GlobalBuffers.working = true;
1083
1084             for (i = 0; i < GlobalBuffers.Duplicates.Count; i++)
1085             {
1086                 duplicate_count = 0;
1087                 if (checking_window.cancel_clicked == true)
1088                 {
1089                     break;
1090                 }
1091
1092                 for (j = 0; j < GlobalBuffers.Duplicates[i].Count; j++)
1093                 {
1094                     if (checking_window.cancel_clicked == true)
1095                     {
1096                         break;
1097                     }
1098
1099                     if (GlobalBuffers.Duplicates[i][j].Checked == true)
1100                     {
1101                         moved_filename = folder + "\\" + System.IO.Path.GetFileName(GlobalBuffers.Duplicates[i][j].Filename);
1102
1103                         copy_filename_loop = 1;
1104
1105                         while (System.IO.File.Exists(moved_filename) == true)
1106                         {
1107                             moved_filename = folder + "\\" + System.IO.Path.GetFileNameWithoutExtension(GlobalBuffers.Duplicates[i][j].Filename) + "(" + copy_filename_loop + ")" + System.IO.Path.GetExtension(System.IO.Path.GetFileNameWithoutExtension(GlobalBuffers.Duplicates[i][j].Filename)) + System.IO.Path.GetExtension(GlobalBuffers.Duplicates[i][j].Filename);
1108                             copy_filename_loop++;
1109                         }
1110
1111                         try
1112                         {
1113                             if (File.Exists(GlobalBuffers.Duplicates[i][j].Filename))
1114                                 File.Move(GlobalBuffers.Duplicates[i][j].Filename, moved_filename);
1115                             else
1116                             {
1117                                 errors.AddError(GlobalBuffers.Duplicates[i][j].Filename, "The source file does not exist.");
1118                                 continue;
1119                             }
1120
1121                         }
1122                         catch
1123                         {
1124
1125                         }
1126                         if (GlobalBuffers.MoveFilesData.CreateUndoList == true)
1127                             tfs1.WriteLine(tfs1, "<move>" + "\"" + moved_filename + "\"" + ",?," + "\"" + GlobalBuffers.Duplicates[i][j].Filename + "\"");
1128
1129                     }
1130                     checking_window.progressText = "Processing duplicate " + (duplicate_count + 1).ToString() + " of group " + (group_count + 1).ToString();
1131                     duplicate_count++;
1132
1133                 }
1134
1135                 group_count++;
1136                 prg2 += (double)prg;
1137                 checking_window.progress = (int)prg2;
1138
1139             }
1140
1141             if (GlobalBuffers.MoveFilesData.UndoListPath != "" && GlobalBuffers.MoveFilesData.CreateUndoList == true)
1142                 tfs1.Close();
1143
1144             this.Invoke((MethodInvoker)delegate
1145             {
1146                 SetStatusBarData(false);
1147             });
1148
1149             GlobalBuffers.working = false;
1150
1151             long_process_listener.Complete = true;
1152             errors.ShowErrorWindow();
1153         }
1154
1155         public static void WriteUndoScript(TextFileStream tfs1, int operation, string file_to_process, string destination_path)
1156         {
1157             tfs1.WriteLine(tfs1, (operation == 1 ? "<copy>" : "<move>") + "\"" + file_to_process + "\"" + ",?," + "\"" + destination_path + "\"");
1158         }
1159
1160         private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
1161         {
1162             if (GlobalBuffers.working)
1163                 return;
1164             if (GlobalBuffers.Duplicates == null || GlobalBuffers.Duplicates.Count == 0)
1165                 return;
1166
1167             ThreadStart ts = new ThreadStart(CheckAll);
1168             checking_window = new Checking();
1169             long_process_listener = new LongProcessListener(checking_window, this);
1170
1171             Thread t = new Thread(ts);
1172             t.Start();
1173
1174         }
1175
1176         private void CheckAll()
1177         {
1178             int i, j;
1179             double progress_step = (double)100 / GlobalBuffers.Duplicates.Count;
1180             int group_count = 0, duplicate_count = 0;
1181
1182
1183             for (i = 0; i < GlobalBuffers.Duplicates.Count; i++)
1184             {
1185                 if (checking_window.cancel_clicked == true)
1186                     break;
1187
1188                 duplicate_count = 0;
1189
1190                 for (j = 0; j < GlobalBuffers.Duplicates[i].Count; j++)
1191                 {
1192                     if (checking_window.cancel_clicked == true)
1193                         break;
1194                     GlobalBuffers.Duplicates[i][j].Checked = true;
1195
1196                     checking_window.progressText = "Processing duplicate " + (duplicate_count + 1).ToString() + " of group " + (group_count + 1).ToString();
1197                     duplicate_count++;
1198
1199                 }
1200
1201                 group_count++;
1202             }
1203
1204             mainList.Invalidate();
1205
1206             this.Invoke((MethodInvoker)delegate
1207             {
1208                 SetStatusBarData(false);
1209
1210                 EnableArrows(false);
1211             });
1212
1213             long_process_listener.Complete = true;
1214         }
1215
1216         public void uncheckAllItemsToolStripMenuItem_Click(object sender, EventArgs e)
1217         {
1218             if (GlobalBuffers.working)
1219                 return;
1220             if (GlobalBuffers.Duplicates == null || GlobalBuffers.Duplicates.Count == 0)
1221                 return;
1222
1223             ThreadStart ts = new ThreadStart(UncheckAll);
1224             checking_window = new Checking();
1225             long_process_listener = new LongProcessListener(checking_window, this);
1226
1227             Thread t = new Thread(ts);
1228             t.Start();
1229
1230         }
1231
1232         public void UncheckAll()
1233         {
1234             int i, j;
1235             double progress_step = (double)100 / GlobalBuffers.Duplicates.Count;
1236             int group_count = 0, duplicate_count = 0;
1237
1238             for (i = 0; i < GlobalBuffers.Duplicates.Count; i++)
1239             {
1240                 duplicate_count = 0;
1241                 if (checking_window.cancel_clicked == true)
1242                     break;
1243
1244                 for (j = 0; j < GlobalBuffers.Duplicates[i].Count; j++)
1245                 {
1246                     if (checking_window.cancel_clicked == true)
1247                         break;
1248                     GlobalBuffers.Duplicates[i][j].Checked = false;
1249
1250                     checking_window.progressText = "Processing duplicate " + (duplicate_count + 1).ToString() + " of group " + (group_count + 1).ToString();
1251                     duplicate_count++;
1252                 }
1253                 group_count++;
1254             }
1255
1256             mainList.Invalidate();
1257
1258             this.Invoke((MethodInvoker)delegate
1259             {
1260                 SetStatusBarData(false);
1261
1262                 EnableArrows(false);
1263             });
1264
1265             long_process_listener.Complete = true;
1266         }
1267
1268         public void DeleteChecked()
1269         {
1270             GlobalBuffers.working = true;
1271             int i, j;
1272             ErrorClass errors = new ErrorClass(GlobalBuffers.main_form, "The following files could not be deleted.");
1273             double prg, prg2 = (double)0.0;
1274             GlobalBuffers.working = true;
1275             int group_count = 0, duplicate_count = 0;
1276
1277             prg = (double)100 / GlobalBuffers.Duplicates.Count;
1278
1279             for (i = 0; i < GlobalBuffers.Duplicates.Count; i++)
1280             {
1281                 duplicate_count = 0;
1282
1283                 if (checking_window.cancel_clicked == true)
1284                     break;
1285
1286                 for (j = 0; j < GlobalBuffers.Duplicates[i].Count; j++)
1287                 {
1288                     if (checking_window.cancel_clicked == true)
1289                         break;
1290
1291                     if (GlobalBuffers.Duplicates[i][j].Checked == true)
1292                     {
1293                         if (File.Exists(GlobalBuffers.Duplicates[i][j].Filename) == false)
1294                             errors.AddError(GlobalBuffers.Duplicates[i][j].Filename, "The file does not exist.");
1295
1296                         try
1297                         {
1298                             FileOperationAPIWrapper.MoveToRecycleBin(GlobalBuffers.Duplicates[i][j].Filename);
1299                         }
1300                         catch (Exception)
1301                         {
1302                             errors.AddError(GlobalBuffers.Duplicates[i][j].Filename, "The file may be read-only or in use by another process.");
1303                             checking_window.cancel_clicked = true;
1304                             break;
1305                         }
1306
1307                         if (GlobalBuffers.Duplicates[i].RemoveAt(j, true) == DuplicateGroup.RemoveStatus.RemovedFile)
1308                             j--;
1309                         else
1310                         {
1311                             i--;
1312                             break;
1313                         }
1314                     }
1315
1316                     checking_window.progressText = "Processing duplicate " + (duplicate_count + 1).ToString() + " of group " + (group_count + 1).ToString();
1317                     duplicate_count++;
1318
1319                 }
1320
1321                 prg2 += (double)prg;
1322                 checking_window.progress = (int)prg2;
1323                 group_count++;
1324             }
1325
1326             GlobalBuffers.working = false;
1327             long_process_listener.Complete = true;
1328
1329             SetStatusBarData(false);
1330
1331             mainList.Invalidate();
1332
1333             long_process_listener.Complete = true;
1334
1335             errors.ShowErrorWindow();
1336         }
1337
1338
1339         private void toolStripMenuItem3_Click(object sender, EventArgs e)
1340         {
1341             try
1342             {
1343                 DuplicateObject selected = GlobalBuffers.mainList.GetItem(GlobalBuffers.mainList.SelectedItem.Group, GlobalBuffers.mainList.SelectedItem.Duplicate);
1344                 string folder = Path.GetDirectoryName(selected.DuplicateFile.Filename);
1345
1346                 if (selected.ObjectType == DuplicateObject.Type.File)
1347                 {
1348                     if (!Directory.Exists(folder))
1349                         MessageBox.Show("The selected file's containing folder does not exist.", "Duplicate Commander", MessageBoxButtons.OK, MessageBoxIcon.Information);
1350
1351                     System.Diagnostics.Process.Start(folder);
1352                 }
1353             }
1354             catch (Win32Exception)
1355             {
1356                 MessageBox.Show("Could not open the selected file's containing folder.", "Duplicate Commander", MessageBoxButtons.OK, MessageBoxIcon.Information);
1357             }
1358         }
1359
1360         private void toolStripMenuItem5_Click(object sender, EventArgs e)
1361         {
1362             try
1363             {
1364                 DuplicateObject selected = GlobalBuffers.mainList.GetItem(GlobalBuffers.mainList.SelectedItem.Group, GlobalBuffers.mainList.SelectedItem.Duplicate);
1365
1366                 if (selected.ObjectType == DuplicateObject.Type.File)
1367                 {
1368                     if (!File.Exists(selected.DuplicateFile.Filename))
1369                     {
1370                         MessageBox.Show(this, "The selected file does not exist.", "Duplicate Commander", MessageBoxButtons.OK, MessageBoxIcon.Error);
1371                         return;
1372                     }
1373
1374                     System.Diagnostics.Process.Start(selected.DuplicateFile.Filename);
1375                 }
1376             }
1377             catch (Win32Exception)
1378             {
1379                 MessageBox.Show(this, "Could not open the selected file.", "Duplicate Commander", MessageBoxButtons.OK, MessageBoxIcon.Error);
1380             }
1381         }
1382
1383         private void toolStripMenuItem4_Click(object sender, EventArgs e)
1384         {
1385             DeleteSelectedItem();
1386         }
1387
1388
1389
1390         public void DeleteSelectedItem()
1391         {
1392             if (GlobalBuffers.mainList.SelectedItem.Group == -1 || GlobalBuffers.mainList.SelectedItem.Group >= GlobalBuffers.mainList.SelectedItem.Data.Count)
1393                 return;
1394             if (GlobalBuffers.Duplicates == null || GlobalBuffers.Duplicates.Count == 0)
1395                 return;
1396
1397             int i;
1398             DialogResult dr = DialogResult.No;
1399             int no_confirm = GlobalBuffers.SettingsManager.FindSettingStringSingleInt( "no_confirm");
1400             ErrorClass errors = new ErrorClass(this, "The following files could not be deleted.");
1401             DuplicateListView.DrawIndex selected_item = new DuplicateListView.DrawIndex(GlobalBuffers.mainList.SelectedItem.Group, GlobalBuffers.mainList.SelectedItem.Duplicate, GlobalBuffers.mainList.DrawStartIndex.Data);
1402             DuplicateObject selected_object = GlobalBuffers.mainList.GetItem(GlobalBuffers.mainList.SelectedItem.Group, GlobalBuffers.mainList.SelectedItem.Duplicate);
1403
1404             if (selected_object.ObjectType == DuplicateObject.Type.File)
1405             {
1406                 if (no_confirm == 0)
1407                     dr = MessageBox.Show("Are you sure you want to delete the selected file?", "Duplicate Commander", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
1408                 if (no_confirm == 1 || dr == DialogResult.Yes)
1409                 {
1410                     if (!File.Exists(selected_object.DuplicateFile.Filename))
1411                     {
1412                         MessageBox.Show("The selected file does not exist. It may have already been deleted.", "Duplicate Commander", MessageBoxButtons.OK, MessageBoxIcon.Error);
1413                         return;
1414                     }
1415
1416                     try
1417                     {
1418                         FileOperationAPIWrapper.MoveToRecycleBin(selected_object.DuplicateFile.Filename);
1419                     }
1420                     catch (Exception)
1421                     {
1422                         errors.AddError(selected_object.DuplicateFile.Filename, "The file may be read-only or in use by another process.");
1423                         errors.ShowErrorWindow();
1424                         return;
1425                     }
1426                 }
1427                 else
1428                     return;
1429
1430
1431
1432                 GlobalBuffers.Duplicates[selected_item.Group].RemoveAt(selected_item.Duplicate, true);
1433
1434             }
1435             else
1436             {
1437                 if (no_confirm == 0)
1438                     dr = MessageBox.Show("Are you sure you want to delete the selected group?", "Duplicate Commander", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
1439                 if (no_confirm == 1 || dr == DialogResult.Yes)
1440                 {
1441                     DuplicateObject group = GlobalBuffers.mainList.GetItem(GlobalBuffers.mainList.SelectedItem.Group, -1);
1442
1443                     for (i = 0; i < group.DuplicateGroup.Count; i++)
1444                     {
1445                         try
1446                         {
1447                             FileOperationAPIWrapper.MoveToRecycleBin(GlobalBuffers.Duplicates[GlobalBuffers.mainList.SelectedItem.Group][i].Filename);
1448                         }
1449                         catch (Exception)
1450                         {
1451                             errors.AddError(GlobalBuffers.Duplicates[GlobalBuffers.mainList.SelectedItem.Group][i].Filename, "The file may be read-only or in use by another process.");
1452                             errors.ShowErrorWindow();
1453                             return;
1454                         }
1455
1456                         if (GlobalBuffers.Duplicates[GlobalBuffers.mainList.SelectedItem.Group].RemoveAt(i, true) == DuplicateGroup.RemoveStatus.RemovedFile)
1457                             i--;
1458                         else
1459                             break;
1460                     }
1461                 }
1462                 else
1463                     return;
1464
1465
1466             }
1467
1468             SetStatusBarData(false);
1469             mainList.Invalidate();
1470         }
1471
1472         private void listView1_KeyDown(object sender, KeyEventArgs e)
1473         {
1474             if (e.KeyData == Keys.Delete)
1475             {
1476                 DeleteSelectedItem();
1477             }
1478         }
1479
1480         private void toolStripButton1_Click_1(object sender, EventArgs e)
1481         {
1482
1483         }
1484
1485
1486
1487         private void toolStripButton12_Click(object sender, EventArgs e)
1488         {
1489             if (GlobalBuffers.working)
1490                 return;
1491             if (mainList.Visible == false)
1492                 return;
1493             if (GlobalBuffers.Duplicates == null || GlobalBuffers.Duplicates.Count == 0)
1494                 return;
1495             ThreadStart ts = new ThreadStart(CheckFirst);
1496             Thread t = new Thread(ts);
1497             checking_window = new Checking();
1498             long_process_listener = new LongProcessListener(checking_window, this);
1499
1500             t.Start();
1501         }
1502
1503         private void CheckFirst()
1504         {
1505             int i, j;
1506             double prg = (double)100 / GlobalBuffers.Duplicates.Count, prg2 = (double)0.0;
1507             int group_count = 0, duplicate_count = 0;
1508
1509             for (i = 0; i < GlobalBuffers.Duplicates.Count; i++)
1510             {
1511                 duplicate_count = 0;
1512                 if (checking_window.cancel_clicked == true)
1513                     break;
1514
1515                 if (GlobalBuffers.Duplicates[i].Count >= 1)
1516                 {
1517                     for (j = 0; j < GlobalBuffers.Duplicates[i].Count; j++)
1518                     {
1519                         GlobalBuffers.Duplicates[i][j].Checked = j == 0 ? true : false;
1520
1521                         checking_window.progressText = "Processing duplicate " + (duplicate_count + 1).ToString() + " of group " + (group_count + 1).ToString();
1522
1523                         duplicate_count++;
1524                     }
1525                 }
1526
1527                 group_count++;
1528                 prg2 += (double)prg;
1529                 checking_window.progress = prg2;
1530             }
1531
1532             mainList.Invalidate();
1533
1534             this.Invoke((MethodInvoker)delegate
1535             {
1536                 SetStatusBarData(false);
1537
1538                 EnableArrows(false);
1539             });
1540
1541             long_process_listener.Complete = true;
1542         }
1543
1544         private void runUndoScriptToolStripMenuItem_Click(object sender, EventArgs e)
1545         {
1546             if (GlobalBuffers.working)
1547                 return;
1548             OpenFileDialog ofd1 = new OpenFileDialog();
1549             ruds1 = new RunUndoScript();
1550
1551             ofd1.Title = "Specify the undo script...";
1552             ofd1.Filter = "Duplicate Commander Undo Script (*.dds)|*.dds||";
1553
1554             ofd1.InitialDirectory = "C:\\";
1555
1556             ofd1.ShowDialog();
1557
1558             if (ofd1.FileName != "")
1559             {
1560                 ParseUndoScript(ofd1.FileName);
1561
1562                 ruds1.Tag = (string)ofd1.FileName;
1563                 ruds1.Owner = this;
1564                 ruds1.ShowDialog();
1565             }
1566             //ExecuteUndoScript(ofd1.FileName);
1567         }
1568
1569         private void ParseUndoScript(string in_file)
1570         {
1571             string[] contents = File.ReadAllLines(in_file);
1572             string file1, file2;
1573             ListViewItem lvi1;
1574             int i = 0;
1575             int operation;
1576
1577             for (i = 0; i < contents.Length; i++)
1578             {
1579                 if (contents[i].Substring(0, 6) == "<copy>")
1580                     operation = 1;
1581                 else
1582                     operation = 2;
1583                 file1 = contents[i].Substring(7, contents[i].IndexOf(",?,") - 8);
1584                 file2 = contents[i].Substring(contents[i].LastIndexOf(",?,") + 4, contents[i].Length - (contents[i].LastIndexOf(",?,") + 4) - 1);
1585
1586                 lvi1 = new ListViewItem();
1587                 if (operation == 1)
1588                     lvi1.Text = "Copy";
1589                 else
1590                     lvi1.Text = "Move";
1591                 lvi1.SubItems.Add(file1);
1592                 lvi1.SubItems.Add(file2);
1593                 lvi1.SubItems.Add("");
1594                 lvi1.Tag = (int)operation;
1595
1596                 ruds1.listView1.Items.Add(lvi1);
1597             }
1598         }
1599
1600         private void ExecuteUndoScript(string in_file)
1601         {
1602             TextFileStream tfs1 = new TextFileStream(in_file, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Read);
1603             string buffer, file1, file2;
1604             StringByte sb1 = new StringByte();
1605             int operation;
1606
1607             while (tfs1.Position < tfs1.Length)
1608             {
1609                 sb1 = tfs1.ReadLine();
1610
1611                 buffer = sb1.out_string;
1612                 if (buffer.Substring(0, 5) == "<copy>")
1613                     operation = 1;
1614                 else
1615                     operation = 2;
1616                 file1 = buffer.Substring(5, buffer.LastIndexOf(",?,"));
1617                 file2 = buffer.Substring(5, buffer.LastIndexOf(",?,") + 3);
1618
1619                 if ((File.Exists(file1)))
1620                 {
1621                     if (operation == 1)
1622                         System.IO.File.Copy(file1, file2);
1623                     else
1624                         System.IO.File.Move(file1, file2);
1625                 }
1626             }
1627
1628             tfs1.Close();
1629         }
1630
1631         private void toolStripButton5_Click(object sender, EventArgs e)
1632         {
1633             if (GlobalBuffers.working)
1634                 return;
1635             if (GlobalBuffers.Duplicates == null || GlobalBuffers.Duplicates.Count == 0)
1636                 return;
1637
1638             ThreadStart ts = new ThreadStart(CheckSmallest);
1639             checking_window = new Checking();
1640             long_process_listener = new LongProcessListener(checking_window, this);
1641
1642             Thread t = new Thread(ts);
1643             t.Start();
1644         }
1645
1646         private void CheckSmallest()
1647         {
1648             int i, j, index = -1;
1649             long smallest = -1;
1650             double prg_step = (double)100 / GlobalBuffers.Duplicates.Count;
1651             double prg = 0;
1652             int group_count = 0, duplicate_count = 0;
1653
1654             //   checking_window = new Checking();
1655
1656             //   long_process_listener = new LongProcessListener(checking_window, this);
1657
1658             for (i = 0; i < GlobalBuffers.Duplicates.Count; i++)
1659             {
1660                 duplicate_count = 0;
1661                 if (checking_window.cancel_clicked == true)
1662                     break;
1663
1664                 for (j = 0; j < GlobalBuffers.Duplicates[i].Count; j++)
1665                 {
1666                     if (GlobalBuffers.Duplicates[i][j].Size < smallest || smallest == -1)
1667                     {
1668                         smallest = GlobalBuffers.Duplicates[i][j].Size;
1669                         index = j;
1670                     }
1671
1672                     GlobalBuffers.Duplicates[i][j].Checked = false;
1673
1674                     checking_window.progressText = "Processing duplicate " + (duplicate_count + 1).ToString() + " of group " + (group_count + 1).ToString();
1675                     duplicate_count++;
1676                 }
1677
1678                 GlobalBuffers.Duplicates[i][index].Checked = true;
1679
1680                 smallest = -1;
1681
1682                 prg += (double)prg_step;
1683                 group_count++;
1684                 checking_window.progress = prg;
1685
1686             }
1687             mainList.Invalidate();
1688
1689             this.Invoke((MethodInvoker)delegate
1690             {
1691                 SetStatusBarData(false);
1692                 EnableArrows(false);
1693             });
1694
1695             long_process_listener.Complete = true;
1696
1697         }
1698
1699         private void toolStripButton13_Click(object sender, EventArgs e)
1700         {
1701             if (GlobalBuffers.working)
1702                 return;
1703             if (GlobalBuffers.Duplicates == null || GlobalBuffers.Duplicates.Count == 0)
1704                 return;
1705
1706             ThreadStart ts = new ThreadStart(CheckLargest);
1707             checking_window = new Checking();
1708             long_process_listener = new LongProcessListener(checking_window, this);
1709
1710             Thread t = new Thread(ts);
1711             t.Start();
1712         }
1713
1714         private void CheckLargest()
1715         {
1716             int i, j, index = -1;
1717             long largest = -1;
1718             double prg_step = (double)100 / GlobalBuffers.Duplicates.Count;
1719             double prg = 0;
1720             int group_count = 0, duplicate_count = 0;
1721
1722             for (i = 0; i < GlobalBuffers.Duplicates.Count; i++)
1723             {
1724                 duplicate_count = 0;
1725                 if (checking_window.cancel_clicked == true)
1726                     break;
1727
1728                 for (j = 0; j < GlobalBuffers.Duplicates[i].Count; j++)
1729                 {
1730                     if (GlobalBuffers.Duplicates[i][j].Size > largest || largest == -1)
1731                     {
1732                         largest = GlobalBuffers.Duplicates[i][j].Size;
1733                         index = j;
1734                     }
1735
1736                     GlobalBuffers.Duplicates[i][j].Checked = false;
1737
1738                     checking_window.progressText = "Processing duplicate " + (duplicate_count + 1).ToString() + " of group " + (group_count + 1).ToString();
1739                     duplicate_count++;
1740                 }
1741
1742                 GlobalBuffers.Duplicates[i][index].Checked = true;
1743
1744                 largest = -1;
1745
1746                 prg += (double)prg_step;
1747
1748                 checking_window.progress = prg;
1749                 group_count++;
1750             }
1751             mainList.Invalidate();
1752
1753             this.Invoke((MethodInvoker)delegate
1754             {
1755                 SetStatusBarData(false);
1756                 EnableArrows(false);
1757             });
1758
1759             long_process_listener.Complete = true;
1760         }
1761
1762         private void toolStripButton14_Click(object sender, EventArgs e)
1763         {
1764             if (GlobalBuffers.working)
1765                 return;
1766             if (GlobalBuffers.Duplicates == null || GlobalBuffers.Duplicates.Count == 0)
1767                 return;
1768
1769             checking_window = new Checking();
1770             long_process_listener = new LongProcessListener(checking_window, this);
1771
1772             ThreadStart ts = new ThreadStart(CheckOldest);
1773             Thread t = new Thread(ts);
1774
1775             t.Start();
1776         }
1777
1778         private void CheckOldest()
1779         {
1780             double oldest = (double)-1;
1781             int i, j, index = -1;
1782             double prg_step = 100 / GlobalBuffers.Duplicates.Count;
1783             int group_count = 0, duplicate_count = 0;
1784
1785             for (i = 0; i < GlobalBuffers.Duplicates.Count; i++)
1786             {
1787                 duplicate_count = 0;
1788                 if (checking_window.cancel_clicked == true)
1789                     break;
1790
1791                 for (j = 0; j < GlobalBuffers.Duplicates[i].Count; j++)
1792                 {
1793                     double quantity = (double)quantizeTime(GlobalBuffers.Duplicates[i][j].DateModified);
1794
1795                     if (quantity < oldest || oldest == -1)
1796                     {
1797                         oldest = (double)quantity;
1798                         index = j;
1799                     }
1800
1801                     GlobalBuffers.Duplicates[i][j].Checked = false;
1802
1803                     checking_window.progressText = "Processing duplicate " + (duplicate_count + 1).ToString() + " of group " + (group_count + 1).ToString();
1804                     duplicate_count++;
1805                 }
1806
1807                 GlobalBuffers.Duplicates[i][index].Checked = true;
1808                 oldest = -1;
1809
1810                 group_count++;
1811                 checking_window.progress += (double)prg_step;
1812             }
1813             mainList.Invalidate();
1814
1815             SetStatusBarData(false);
1816
1817             EnableArrows(false);
1818
1819             long_process_listener.Complete = true;
1820         }
1821
1822         private void toolStripButton15_Click(object sender, EventArgs e)
1823         {
1824             if (GlobalBuffers.working)
1825                 return;
1826             if (GlobalBuffers.Duplicates == null || GlobalBuffers.Duplicates.Count == 0)
1827                 return;
1828
1829             checking_window = new Checking();
1830             long_process_listener = new LongProcessListener(checking_window, this);
1831
1832             ThreadStart ts = new ThreadStart(CheckNewest);
1833             Thread t = new Thread(ts);
1834
1835             t.Start();
1836
1837         }
1838
1839         private void CheckNewest()
1840         {
1841             double newest = (double)-1;
1842             int i, j, index = -1;
1843             double prg_step = 100 / GlobalBuffers.Duplicates.Count;
1844             int group_count = 0, duplicate_count = 0;
1845
1846             for (i = 0; i < GlobalBuffers.Duplicates.Count; i++)
1847             {
1848                 duplicate_count = 0;
1849                 if (checking_window.cancel_clicked == true)
1850                     break;
1851
1852                 for (j = 0; j < GlobalBuffers.Duplicates[i].Count; j++)
1853                 {
1854                     double quantity = (double)quantizeTime(GlobalBuffers.Duplicates[i][j].DateModified);
1855
1856                     if (quantity > newest || newest == -1)
1857                     {
1858                         newest = (double)quantity;
1859                         index = j;
1860                     }
1861
1862                     GlobalBuffers.Duplicates[i][j].Checked = false;
1863
1864                     checking_window.progressText = "Processing duplicate " + (duplicate_count + 1).ToString() + " of group " + (group_count + 1).ToString();
1865                     duplicate_count++;
1866                 }
1867
1868                 GlobalBuffers.Duplicates[i][index].Checked = true;
1869                 newest = -1;
1870
1871                 checking_window.progress += (double)prg_step;
1872                 group_count++;
1873             }
1874             mainList.Invalidate();
1875
1876             SetStatusBarData(false);
1877
1878             EnableArrows(false);
1879
1880             long_process_listener.Complete = true;
1881         }
1882
1883         string copy_selected_path;
1884
1885         private void toolStripButton16_Click(object sender, EventArgs e)
1886         {
1887             if (GlobalBuffers.working)
1888                 return;
1889             if (GlobalBuffers.Duplicates == null || GlobalBuffers.Duplicates.Count == 0)
1890                 return;
1891             if (GlobalBuffers.Duplicates.TotalCheckedItems == 0)
1892             {
1893                 MessageBox.Show("Please check an item first.", "Duplicate Commander", MessageBoxButtons.OK, MessageBoxIcon.Error);
1894                 return;
1895             }
1896
1897             FolderBrowserDialog fbd1 = new FolderBrowserDialog();
1898
1899             fbd1.Description = "Specify the folder where you want the checked duplicates copied to.";
1900             fbd1.ShowNewFolderButton = true;
1901
1902             fbd1.ShowDialog();
1903
1904             if (fbd1.SelectedPath != "")
1905             {
1906                 copy_selected_path = fbd1.SelectedPath;
1907
1908                 checking_window = new Checking();
1909                 checking_window.Text = "Copying files...";
1910                 checking_window.statusText.Text = "Please wait...";
1911
1912                 long_process_listener = new LongProcessListener(checking_window, this);
1913
1914                 ThreadStart ts = new ThreadStart(CopyChecked);
1915                 Thread t = new Thread(ts);
1916                 t.Start();
1917             }
1918         }
1919
1920         public void CopyChecked()
1921         {
1922             int i, j;
1923             double prg = (double)100 / GlobalBuffers.Duplicates.Count;
1924             double prg2 = (double)0.0;
1925             string copy_filename = "";
1926             int group_count = 0, duplicate_count = 0;
1927             int copy_filename_loop = 1;
1928             ErrorClass errors = new ErrorClass(this, "The following files could not be copied.");
1929
1930
1931             for (i = 0; i < GlobalBuffers.Duplicates.Count; i++)
1932             {
1933                 duplicate_count = 0;
1934
1935                 for (j = 0; j < GlobalBuffers.Duplicates[i].Count; j++)
1936                 {
1937                     if (GlobalBuffers.Duplicates[i][j].Checked == true)
1938                     {
1939                         copy_filename_loop = 1;
1940                         copy_filename = copy_selected_path + "\\" + Path.GetFileName(GlobalBuffers.Duplicates[i][j].Filename);
1941
1942                         while (System.IO.File.Exists(copy_filename) == true)
1943                         {
1944                             copy_filename = copy_selected_path + "\\" + System.IO.Path.GetFileNameWithoutExtension(GlobalBuffers.Duplicates[i][j].Filename) + "(" + copy_filename_loop + ")" + System.IO.Path.GetExtension(System.IO.Path.GetFileNameWithoutExtension(GlobalBuffers.Duplicates[i][j].Filename)) + System.IO.Path.GetExtension(GlobalBuffers.Duplicates[i][j].Filename);
1945                             copy_filename_loop++;
1946                         }
1947
1948                         if (File.Exists(GlobalBuffers.Duplicates[i][j].Filename))
1949                             File.Copy(GlobalBuffers.Duplicates[i][j].Filename, copy_filename, true);
1950                         else
1951                             errors.AddError(GlobalBuffers.Duplicates[i][j].Filename, "The source file does not exist.");
1952                     }
1953
1954
1955                     checking_window.progressText = "Processing duplicate " + (duplicate_count + 1).ToString() + " of group " + (group_count + 1).ToString();
1956                     duplicate_count++;
1957
1958                 }
1959
1960                 group_count++;
1961                 prg2 += (double)prg;
1962                 checking_window.progress = (double)prg2;
1963             }
1964
1965             long_process_listener.Complete = true;
1966             errors.ShowErrorWindow();
1967         }
1968
1969
1970         CheckAllInFolder check_all_dialog;
1971
1972         private void toolStripButton17_Click(object sender, EventArgs e)
1973         {
1974             if (GlobalBuffers.working)
1975                 return;
1976             if (GlobalBuffers.Duplicates == null || GlobalBuffers.Duplicates.Count == 0)
1977                 return;
1978
1979             check_all_dialog = new CheckAllInFolder();
1980
1981             check_all_dialog.Owner = this;
1982             check_all_dialog.ShowDialog();
1983
1984             checking_window = new Checking();
1985             long_process_listener = new LongProcessListener(checking_window, this);
1986
1987             ThreadStart ts = new ThreadStart(CheckAllInFolder);
1988             Thread t = new Thread(ts);
1989
1990             t.Start();
1991
1992         }
1993
1994         private void CheckAllInFolder()
1995         {
1996             string folder;
1997             int i, j, k;
1998             bool already_checked_first = false;
1999             string old_status_text = statusBarPanel1.Text;
2000             double prg = (double)100 / GlobalBuffers.Duplicates.Count, prg2 = 0;
2001             int group_count = 0, duplicate_count = 0;
2002
2003             if (GlobalBuffers.folders_ok_clicked == true)
2004             {
2005                 if (GlobalBuffers.CheckAllInFolderData.FoldersToCheck.Count > 0)
2006                 {
2007                     if (GlobalBuffers.CheckAllInFolderData.PersistentCheck == false)
2008                     {
2009                         for (i = 0; i < GlobalBuffers.Duplicates.Count; i++)
2010                         {
2011                             if (checking_window.cancel_clicked == true)
2012                                 break;
2013
2014                             for (j = 0; j < GlobalBuffers.Duplicates[i].Count; j++)
2015                             {
2016                                 GlobalBuffers.Duplicates[i][j].Checked = false;
2017                             }
2018                         }
2019                     }
2020
2021                     for (i = 0; i < GlobalBuffers.Duplicates.Count; i++)
2022                     {
2023                         duplicate_count = 0;
2024                         if (checking_window.cancel_clicked == true)
2025                             break;
2026
2027                         for (j = 0; j < GlobalBuffers.Duplicates[i].Count; j++)
2028                         {
2029                             folder = Path.GetDirectoryName(GlobalBuffers.Duplicates[i][j].Filename);
2030
2031                             for (k = 0; k < GlobalBuffers.CheckAllInFolderData.FoldersToCheck.Count; k++)
2032                             {
2033                                 if (GlobalBuffers.CheckAllInFolderData.CheckOnlyOne == true
2034                                         && already_checked_first == true)
2035                                     break;
2036
2037                                 if (folder == (string)GlobalBuffers.CheckAllInFolderData.FoldersToCheck[k])
2038                                 {
2039                                     if (GlobalBuffers.CheckAllInFolderData.CheckOnlyOne == true && already_checked_first == false || GlobalBuffers.CheckAllInFolderData.CheckOnlyOne == false)
2040                                     {
2041                                        // GlobalBuffers.Duplicates[i][j].Checked = true;
2042                                         GlobalBuffers.Duplicates[i][j].Checked = GlobalBuffers.CheckAllInFolderData.CheckType == CheckJobDialogData.CheckTypes.Check ? true : false;
2043                                         already_checked_first = true;
2044                                     }
2045                                     if (GlobalBuffers.CheckAllInFolderData.CheckOnlyOne == true
2046                                         && already_checked_first == true)
2047                                         break;
2048                                 }
2049                             }
2050
2051                             checking_window.progressText = "Processing duplicate " + (duplicate_count + 1).ToString() + " of group " + (group_count + 1).ToString();
2052                             duplicate_count++;
2053
2054                         }
2055                         already_checked_first = false;
2056
2057                         prg2 += (double)prg;
2058
2059                         checking_window.progress = prg2;
2060                         group_count++;
2061                     }
2062
2063                     statusBarPanel1.Text = old_status_text;
2064                     mainList.Invalidate();
2065
2066                     SetStatusBarData(false);
2067
2068                     EnableArrows(false);
2069                 }
2070
2071             }
2072             long_process_listener.Complete = true;
2073         }
2074
2075         CheckAllByExtension check_by_extension;
2076
2077         private void toolStripButton18_Click(object sender, EventArgs e)
2078         {
2079             if (GlobalBuffers.working)
2080                 return;
2081             if (GlobalBuffers.Duplicates == null || GlobalBuffers.Duplicates.Count == 0)
2082                 return;
2083
2084             check_by_extension = new CheckAllByExtension();
2085             check_by_extension.Owner = this;
2086             check_by_extension.ShowDialog();
2087
2088             ThreadStart ts = new ThreadStart(CheckByExtension);
2089             Thread t = new Thread(ts);
2090
2091             checking_window = new Checking();
2092             long_process_listener = new LongProcessListener(checking_window, this);
2093
2094             t.Start();
2095         }
2096
2097         private void CheckByExtension()
2098         {
2099             int i, j, k, l;
2100             bool check_item = false;
2101             string extension;
2102             ArrayList check_folders = new ArrayList();
2103             double prg = (double)100 / GlobalBuffers.Duplicates.Count, prg2 = 0;
2104             string old_status_text = statusBarPanel1.Text;
2105             bool already_checked_first = false;
2106             int group_count = 0, duplicate_count = 0;
2107
2108             if (GlobalBuffers.folders_ok_clicked == true) // if the user clicked some extensions
2109             {                                                 // to check,
2110
2111                 // loop through all files in the file list
2112                 for (i = 0; i < GlobalBuffers.Duplicates.Count; i++)
2113                 {
2114                     duplicate_count = 0;
2115                     if (checking_window.cancel_clicked == true)
2116                         break;
2117                     // Has to be a file and not a group descriptor
2118                     for (j = 0; j < GlobalBuffers.Duplicates[i].Count; j++)
2119                     {
2120                         // get the extension of the current item
2121                         extension = Path.GetExtension(GlobalBuffers.Duplicates[i][j].Filename);
2122
2123                         // loop through the extensions that the user wanted to check
2124                         for (k = 0; k < GlobalBuffers.CheckByExtensionData.ExtensionsToCheck.Count; k++)
2125                         {
2126                             if (checking_window.cancel_clicked == true)
2127                                 break;
2128
2129                             // loop through any folders the user limited the file check by
2130                             for (l = 0; l < GlobalBuffers.CheckByExtensionData.FolderExclusions.Count; l++)
2131                             {
2132                                 if (checking_window.cancel_clicked == true)
2133                                     break;
2134
2135                                 // if the current item equals one of the checked folders to limit to,
2136                                 if (Path.GetDirectoryName(GlobalBuffers.Duplicates[i][j].Filename) == (string)GlobalBuffers.CheckByExtensionData.FolderExclusions[l])
2137                                 {
2138                                     check_item = true; // set the check item flag
2139                                     break;
2140                                 }
2141                             }
2142
2143                             // if we have an item to check, and the user limited the file check to specific folders,
2144                             // and the extension of the current item equals the current checked extension
2145                             // OR
2146                             // the user didn't limit the check by specfic folders and the extension of the current file
2147                             // matches the current checked extension
2148                             if (check_item == true && GlobalBuffers.CheckByExtensionData.ExcludeToCertainFolders == true && extension == (string)GlobalBuffers.CheckByExtensionData.ExtensionsToCheck[k] || GlobalBuffers.CheckByExtensionData.ExcludeToCertainFolders == false && extension.ToLower() == ((string)GlobalBuffers.CheckByExtensionData.ExtensionsToCheck[k]).ToLower())
2149                             {
2150                                 if (GlobalBuffers.CheckByExtensionData.CheckOnlyOne == true && already_checked_first == false || GlobalBuffers.CheckByExtensionData.CheckOnlyOne == false)
2151                                 {
2152                                     if(GlobalBuffers.CheckByExtensionData.CheckType == CheckJobDialogData.CheckTypes.Check)
2153                                         GlobalBuffers.Duplicates[i][j].Checked = true;
2154                                     else
2155                                         GlobalBuffers.Duplicates[i][j].Checked = false;
2156
2157                                     already_checked_first = true;
2158
2159                                     check_item = false;
2160
2161                                     continue;
2162                                 }
2163                             }
2164                             else
2165                             {
2166                                 if (GlobalBuffers.CheckByExtensionData.PersistentCheck != true)
2167                                     GlobalBuffers.Duplicates[i][j].Checked = false;
2168
2169                                 check_item = false;
2170
2171                                 continue;
2172                             }
2173
2174                             check_item = false;
2175
2176                         }
2177
2178                         checking_window.progressText = "Processing duplicate " + (duplicate_count + 1).ToString() + " of group " + (group_count + 1).ToString();
2179                         duplicate_count++;
2180
2181                     }
2182
2183                     already_checked_first = false;
2184
2185                     prg2 += (double)prg;
2186
2187                     checking_window.progress = prg2;
2188                     group_count++;
2189                 }
2190
2191                 statusBarPanel1.Text = old_status_text;
2192
2193                 mainList.Invalidate();
2194
2195                 SetStatusBarData(false);
2196
2197                 EnableArrows(false);
2198
2199             }
2200
2201             long_process_listener.Complete = true;
2202
2203         }
2204
2205         private void toolStripButton19_Click(object sender, EventArgs e)
2206         {
2207             if (GlobalBuffers.working)
2208                 return;
2209             if (GlobalBuffers.Duplicates == null || GlobalBuffers.Duplicates.Count == 0)
2210                 return;
2211
2212             CheckByFileSize cs1 = new CheckByFileSize();
2213
2214             cs1.Owner = this;
2215             cs1.ShowDialog();
2216
2217             ThreadStart ts = new ThreadStart(CheckByFileSize);
2218             Thread t = new Thread(ts);
2219
2220             checking_window = new Checking();
2221             long_process_listener = new LongProcessListener(checking_window, this);
2222
2223             t.Start();
2224         }
2225
2226         private void toolStripButton20_Click(object sender, EventArgs e)
2227         {
2228             if (GlobalBuffers.working)
2229                 return;
2230
2231             if (GlobalBuffers.Duplicates == null || GlobalBuffers.Duplicates.Count == 0)
2232                 return;
2233
2234             if (GlobalBuffers.mainList.SelectedItem.Group == -1 && GlobalBuffers.mainList.SelectedItem.Duplicate == -1)
2235                 return;
2236
2237             ThreadStart ts = new ThreadStart(CheckAllOfSelectedGroup);
2238             Thread t = new Thread(ts);
2239
2240             checking_window = new Checking();
2241             long_process_listener = new LongProcessListener(checking_window, this);
2242
2243             t.Start();
2244         }
2245
2246         private void CheckAllOfSelectedGroup()
2247         {
2248             int i, old_selected;
2249             double prg, prg2 = (double)0.0;
2250
2251             old_selected = GlobalBuffers.mainList.SelectedItem.Duplicate;
2252
2253             GlobalBuffers.mainList.SelectedItem.Duplicate = -1;
2254             DuplicateObject selected_group = GlobalBuffers.mainList.GetItem(GlobalBuffers.mainList.SelectedItem.Group, GlobalBuffers.mainList.SelectedItem.Duplicate);
2255
2256             prg = (double)100 / selected_group.DuplicateGroup.Count;
2257
2258             for (i = 0; i < selected_group.DuplicateGroup.Count; i++)
2259             {
2260                 if (checking_window.cancel_clicked == true)
2261                     break;
2262
2263                 selected_group.DuplicateGroup[i].Checked = true;
2264
2265                 prg2 += (double)prg;
2266                 checking_window.progress = prg2;
2267             }
2268
2269             GlobalBuffers.mainList.SelectedItem.Duplicate = old_selected;
2270
2271             mainList.Invalidate();
2272
2273             this.Invoke((MethodInvoker)delegate
2274             {
2275                 SetStatusBarData(false);
2276
2277                 EnableArrows(false);
2278             });
2279
2280             long_process_listener.Complete = true;
2281         }
2282
2283         private void usersManualToolStripMenuItem_Click(object sender, EventArgs e)
2284         {
2285             Process p1 = new Process();
2286
2287             p1.StartInfo = new ProcessStartInfo { FileName = "dcum.chm", UseShellExecute = true };
2288             p1.Start();
2289         }
2290
2291         private void toolStripButton10_Click_2(object sender, EventArgs e)
2292         {
2293             if (GlobalBuffers.working)
2294                 return;
2295             if (GlobalBuffers.Duplicates == null || GlobalBuffers.Duplicates.Count == 0)
2296                 return;
2297
2298             ThreadStart ts = new ThreadStart(InvertChecked);
2299             Thread t = new Thread(ts);
2300             checking_window = new Checking();
2301             long_process_listener = new LongProcessListener(checking_window, this);
2302
2303             t.Start();
2304         }
2305
2306         private void InvertChecked()
2307         {
2308             int i, j;
2309             double prg = (double)100 / GlobalBuffers.Duplicates.Count;
2310             double prg2 = (double)0.0;
2311
2312             for (i = 0; i < GlobalBuffers.Duplicates.Count; i++)
2313             {
2314                 if (checking_window.cancel_clicked == true)
2315                     break;
2316
2317                 for (j = 0; j < GlobalBuffers.Duplicates[i].Count; j++)
2318                 {
2319                     if (checking_window.cancel_clicked == true)
2320                         break;
2321
2322                     if (GlobalBuffers.Duplicates[i][j].Checked == true)
2323                         GlobalBuffers.Duplicates[i][j].Checked = false;
2324                     else
2325                         GlobalBuffers.Duplicates[i][j].Checked = true;
2326                 }
2327
2328                 prg2 += (double)prg;
2329                 checking_window.progress = prg2;
2330             }
2331
2332             GlobalBuffers.mainList.Invalidate();
2333
2334             if (filelist_mode == false)
2335             {
2336                 this.Invoke((MethodInvoker)delegate
2337                 {
2338                     statusBarPanel1.Text = GlobalBuffers.DuplicateCountStatusText;
2339                     statusBarPanel2.Text = GlobalBuffers.SetCountStatusText;
2340                     statusBarPanel3.Text = GlobalBuffers.WastedSpaceStatusText;
2341                     statusBarPanel4.Text = GlobalBuffers.duration;
2342                 });
2343             }
2344             else
2345             {
2346                 SetStatusBarData(false);
2347             }
2348
2349             EnableArrows(false);
2350
2351             long_process_listener.Complete = true;
2352         }
2353
2354         private void toolStripMenuItem6_Click_1(object sender, EventArgs e)
2355         {
2356             DeleteFolder df1 = new DeleteFolder();
2357             DialogResult dr = DialogResult.No;
2358             int no_confirm = GlobalBuffers.SettingsManager.FindSettingStringSingleInt( "no_confirm");
2359
2360
2361             DuplicateObject selected = GlobalBuffers.mainList.GetItem(GlobalBuffers.mainList.SelectedItem.Group, GlobalBuffers.mainList.SelectedItem.Duplicate);
2362
2363             df1.Owner = this;
2364             df1.Tag = (string)selected.DuplicateFile.Filename;
2365             df1.ShowDialog();
2366
2367             if ((string)df1.Tag != "")
2368             {
2369                 //if (no_confirm == 0)
2370                 dr = MessageBox.Show("CAUTION! You are about to delete " + "\"" + (string)df1.Tag + "\", as well as all of its files and subfolders to the Recycle Bin. Know what you're doing before you proceed.\n\nAre you sure?", "Duplicate Commander", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
2371                 if (dr == DialogResult.Yes)
2372                 {
2373                     checking_window = new Checking();
2374                     checking_window.Text = "Deleting folder and subfolders";
2375                     checking_window.staticText = false;
2376                     checking_window.statusText.Text = "Please wait...";
2377                     long_process_listener = new LongProcessListener(checking_window, this);
2378
2379                     folder_to_delete = (string)df1.Tag;
2380
2381                     ThreadStart ts = new ThreadStart(DeleteFolderThread);
2382                     Thread t = new Thread(ts);
2383
2384                     t.Start();
2385
2386                 }
2387             }
2388         }
2389
2390         string folder_to_delete;
2391
2392         private void DeleteFolderThread()
2393         {
2394             int i, j;
2395             string folder;
2396
2397             DeleteFolder(folder_to_delete);
2398
2399             for (i = 0; i < GlobalBuffers.Duplicates.Count; i++)
2400             {
2401                 for (j = 0; j < GlobalBuffers.Duplicates[i].Count; j++)
2402                 {
2403                     folder = Path.GetDirectoryName(GlobalBuffers.Duplicates[i][j].Filename);
2404
2405                     if (folder.Contains(folder_to_delete))
2406                     {
2407                         if (GlobalBuffers.Duplicates[i].RemoveAt(j, false) == DuplicateGroup.RemoveStatus.RemovedFile)
2408                         {
2409                             j--;
2410                         }
2411                         else
2412                         {
2413                             i--;
2414                             break;
2415                         }
2416                     }
2417                 }
2418             }
2419
2420
2421             GlobalBuffers.mainList.Invalidate();
2422
2423             this.Invoke((MethodInvoker)delegate
2424             {
2425                 SetStatusBarData(false);
2426
2427                 EnableArrows(false);
2428             });
2429
2430             long_process_listener.Complete = true;
2431
2432         }
2433
2434         public void DeleteFolder(string folder)
2435         {
2436             int i = 0, j = 0;
2437             string[] found_folders;
2438             string[] found_files;
2439             List<string> folders = new List<string>();
2440             List<string> files = new List<string>();
2441             ErrorClass errors = new ErrorClass(checking_window, "The files below could not be deleted.");
2442             double prg = (double)0.0;
2443             double prg2 = (double)0.0;
2444             bool return_bool = false;
2445
2446             if (Directory.Exists(folder))
2447             {
2448                 folders.Clear();
2449                 files.Clear();
2450                 folders.Add(folder);
2451
2452                 for (i = 0; i < folders.Count; i++)
2453                 {
2454                     found_folders = Directory.GetDirectories(folders[(int)i]);
2455                     found_files = Directory.GetFiles(folders[i]);
2456
2457                     for (j = 0; j < found_folders.Length; j++)
2458                     {
2459                         folders.Add(found_folders[j]);
2460                     }
2461
2462                     for (j = 0; j < found_files.Length; j++)
2463                     {
2464                         files.Add(found_files[j]);
2465                     }
2466                 }
2467
2468                 prg = (double)100 / files.Count;
2469
2470                 for (i = 0; i < files.Count; i++)
2471                 {
2472                     try
2473                     {
2474                         FileOperationAPIWrapper.MoveToRecycleBin(files[i]);
2475                     }
2476                     catch
2477                     {
2478                         errors.AddError(files[i], "The file may be read-only or in use by another process.");
2479                     }
2480                     prg2 += (double)prg;
2481                     checking_window.progress = (int)prg2;
2482                 }
2483                 if (return_bool == false)
2484                 {
2485                     if (errors.GetErrorCount() == 0)
2486                     {
2487                         for (i = folders.Count - 1; i > -1; i--)
2488                         {
2489                             try
2490                             {
2491                                 Directory.Delete(folders[i], true);
2492                             }
2493                             catch (Exception e)
2494                             {
2495                                 errors.AddError(folders[i], e.Message);
2496                             }
2497                         }
2498                     }
2499                 }
2500                 errors.ShowErrorWindow();
2501             }
2502             else
2503                 MessageBox.Show("The selected folder does not exist. It may have already been deleted.", "Duplicate Commander", MessageBoxButtons.OK, MessageBoxIcon.Error);
2504
2505         }
2506
2507         public void CheckForUpdates()
2508         {
2509
2510             Process p1 = new Process();
2511             string update_string, alphabeta, alphabetaverstring;
2512             string temp = Path.GetTempFileName();
2513
2514             try
2515             {
2516                 WebClient wc1 = new WebClient();
2517                 wc1.DownloadFile("http://www.rayburnsoft.net/updates/DC/updateinfo.txt", temp);
2518             }
2519             catch
2520             {
2521                 return;
2522             }
2523
2524             if (File.Exists(temp))
2525             {
2526                 try
2527                 {
2528                     SettingsManager tempManager = SettingsManager.Load(temp);
2529
2530                     update_string = tempManager.FindSettingStringSingle("latest");
2531                     alphabeta = tempManager.FindSettingStringSingle("alphabeta");
2532                     alphabetaverstring = tempManager.FindSettingStringSingle("alphabetaverstring");
2533
2534
2535                     if (alphabeta == "yes" && GlobalBuffers.SettingsManager.FindSettingStringSingle( "notify_alphabeta") == "1" || alphabeta == "no")
2536                     {
2537                         if (Convert.ToDouble(update_string) > Convert.ToDouble(version_string))
2538                         {
2539                             this.Invoke((MethodInvoker)delegate
2540                             {
2541                                 if (GlobalBuffers.SettingsManager.FindSettingStringSingle( "dont_notify") != update_string)
2542                                 {
2543                                     GlobalBuffers.NewVersionString = update_string + (alphabeta == "yes" ? " " + alphabetaverstring : "");
2544                                     updateButton.Visible = true;
2545                                     updateButton.ToolTipText = "New version available!";
2546                                     updateFlasher.Start();
2547                                 }
2548                             });
2549                         }
2550                     }
2551
2552                 }
2553                 catch (Exception e)
2554                 {
2555                     System.Diagnostics.EventLog.WriteEntry("Duplicate Commander", "An error occurred while checking for updates, the error returned was:\r\t" + e.Message, EventLogEntryType.FailureAudit);
2556                 }
2557             }
2558
2559         }
2560
2561         private void saveFileListToolStripMenuItem_Click(object sender, EventArgs e)
2562         {
2563             if (GlobalBuffers.working)
2564                 return;
2565             if (mainList.Visible == false || GlobalBuffers.Duplicates.Count == 0)
2566             {
2567                 MessageBox.Show("There's nothing to save!", "Duplicate Commander", MessageBoxButtons.OK, MessageBoxIcon.Error);
2568                 return;
2569             }
2570             SaveFileDialog sfd1 = new SaveFileDialog();
2571
2572             sfd1.Title = "Specify where to save the file list...";
2573             sfd1.Filter = "Duplicate Commander list file|*.dcl";
2574
2575             sfd1.ShowDialog();
2576
2577             if (sfd1.FileName != "")
2578             {
2579                 if (Path.GetExtension(sfd1.FileName).ToLower() == ".dcl")
2580                     ExportListDCL(sfd1.FileName);
2581                 // else if (Path.GetExtension(sfd1.FileName).ToLower() == ".xml")
2582                 //     ExportListXML(sfd1.FileName);
2583             }
2584         }
2585
2586         /*private void ExportListXML(string filename)
2587         {
2588             XMLEntity list = new XMLEntity();
2589             XMLNode files = new XMLNode(XMLNode.NodeType.START_TAG, "files", "");
2590             int i, j;
2591             XMLNode group = null;
2592             XMLNode duplicate = null;
2593
2594             for (i = 0; i < GlobalBuffers.Duplicates.Count; i++)
2595             {
2596                 group = new XMLNode(XMLNode.NodeType.MARKUP, "g", "");
2597                 group.Attributes.Add(new XMLAttribute("name", GlobalBuffers.Duplicates[i].GroupName));
2598
2599                 if (GlobalBuffers.Duplicates[i].State == DuplicateGroup.GroupState.TrueDuplicate)
2600                     group.Attributes.Add(new XMLAttribute("type", "true"));
2601                 else if (GlobalBuffers.Duplicates[i].State == DuplicateGroup.GroupState.FalseDuplicate)
2602                     group.Attributes.Add(new XMLAttribute("type", "false"));
2603                 else if (GlobalBuffers.Duplicates[i].State == DuplicateGroup.GroupState.Undeterminable)
2604                     group.Attributes.Add(new XMLAttribute("type", "unknown"));
2605
2606                 for (j = 0; j < GlobalBuffers.Duplicates[i].Count; j++)
2607                 {
2608                     duplicate = new XMLNode(XMLNode.NodeType.MARKUP, "d", "");
2609
2610                     duplicate.Attributes.Add(new XMLAttribute("path", GlobalBuffers.Duplicates[i][j].Filename.Replace("\"", "?")));
2611                     duplicate.Attributes.Add(new XMLAttribute("size", GlobalBuffers.Duplicates[i][j].Size.ToString()));
2612                     duplicate.Attributes.Add(new XMLAttribute("date_modified", GlobalBuffers.Duplicates[i][j].DateModified.ToString()));
2613                     duplicate.Attributes.Add(new XMLAttribute("link", GlobalBuffers.Duplicates[i][j].Link == true ? "true" : "false"));
2614
2615                     group.Children.Add(duplicate);
2616                 }
2617
2618                 files.Children.Add(group);
2619             }
2620
2621             files.Children.Add(new XMLNode(XMLNode.NodeType.END_TAG, "files", ""));
2622             list.Collection.Add(files);
2623
2624             group = new XMLNode(XMLNode.NodeType.START_TAG, "folders", "");
2625
2626             for (i = 0; i < GlobalBuffers.folders.Count; i++)
2627             {
2628                 group.Children.Add(new XMLNode(XMLNode.NodeType.ELEMENT, "folder", GlobalBuffers.folders[i]));
2629             }
2630
2631             group.Children.Add(new XMLNode(XMLNode.NodeType.END_TAG, "folders", ""));
2632
2633             list.addToCollection(group);
2634
2635             list.dumpToDisk(filename);
2636         }*/
2637
2638         private void ExportListDCL(string filename)
2639         {
2640             int i, j;
2641             string line;
2642             TextWriter output = new StreamWriter(filename);
2643
2644             for (i = 0; i < GlobalBuffers.Duplicates.Count; i++)
2645             {
2646                 line = GlobalBuffers.Duplicates[i].GroupName + ".?..?..?.";
2647
2648                 if (GlobalBuffers.Duplicates[i].State == DuplicateGroup.GroupState.TrueDuplicate)
2649                     line += "Yes";
2650                 else if (GlobalBuffers.Duplicates[i].State == DuplicateGroup.GroupState.FalseDuplicate)
2651                     line += "No";
2652                 else
2653                     line += "Unknown";
2654
2655                 output.WriteLine(line);
2656
2657                 for (j = 0; j < GlobalBuffers.Duplicates[i].Count; j++)
2658                 {
2659                     line = GlobalBuffers.Duplicates[i][j].Filename + ".?." + DuplicateListView.DuplicateListView.FormatSizeString(GlobalBuffers.Duplicates[i][j].Size) + ".?." + GlobalBuffers.Duplicates[i][j].DateModified.ToShortDateString() + "   " + GlobalBuffers.Duplicates[i][j].DateModified.ToShortTimeString() + ".?.";
2660
2661                     output.WriteLine(line);
2662                 }
2663             }
2664
2665             for (i = 0; i < GlobalBuffers.folders.Count; i++)
2666             {
2667                 output.WriteLine("??.Folder?," + GlobalBuffers.folders[i]);
2668             }
2669
2670             output.Close();
2671         }
2672
2673         public void LoadPinnedList()
2674         {
2675             int i;
2676
2677             fileSystemTreeview.Nodes[fileSystemTreeview.Nodes.Count - 1].Nodes.Clear();
2678
2679             PinnedListCollection collection = PinnedListReaderWriter.ReadAll();
2680
2681             for (i = 0; i < collection.Count; i++)
2682             {
2683                 fileSystemTreeview.Nodes[fileSystemTreeview.Nodes.Count - 1].Nodes.Add(collection[i].Name, collection[i].Name, 3, 3);
fb4519 2684             }
RD 2685         }
2686
2687         public void LoadNetworkComputers()
2688         {
2689             int i;
2690
2691             fileSystemTreeview.Nodes.Add("Network PCs", "Network PCs", 4,4);
2692
2693             fileSystemTreeview.Nodes[fileSystemTreeview.Nodes.Count - 1].Nodes.Clear();
2694
2695             string[] clients = GlobalBuffers.SettingsManager.GetMultiple("network_clients");
2696
2697             for (i = 0; i < clients.Length; i++)
2698             {
2699                 fileSystemTreeview.Nodes[fileSystemTreeview.Nodes.Count - 1].Nodes.Add(clients[i], clients[i], 4, 4);
344044 2700             }
RD 2701         }
2702
2703         private void loadFileListToolStripMenuItem_Click(object sender, EventArgs e)
2704         {
2705             if (GlobalBuffers.working)
2706                 return;
2707             OpenFileDialog ofd1 = new OpenFileDialog();
2708
2709             ofd1.Title = "Specify the location of the file list...";
2710             ofd1.Filter = "Duplicate Commander List File (*.dcl)|*.dcl";
2711
2712             ofd1.ShowDialog();
2713
2714             if (ofd1.FileName != "")
2715             {
2716                 filelist_path = ofd1.FileName;
2717
2718                 GlobalBuffers.Duplicates = new DuplicateGroupCollection();
2719
2720                 ThreadStart ts = new ThreadStart(OpenFileList);
2721                 Thread t = new Thread(ts);
2722
2723                 checking_window = new Checking();
2724                 checking_window.Text = "Loading file list";
2725                 checking_window.staticText = true;
2726                 checking_window.progressText = "Please wait...";
2727
2728                 long_process_listener = new LongProcessListener(checking_window, this);
2729
2730                 t.Start();
2731
2732
2733             }
2734         }
2735
2736         string filelist_path;
2737         private void OpenFileList()
2738         {
2739             int i, rv;
2740             GlobalBuffers.folders.Clear();
2741             GlobalBuffers.extensions.Clear();
2742
2743             //if (Path.GetExtension(filelist_path) == ".xml")
2744             //   ImportListXML(filelist_path);
2745             if (Path.GetExtension(filelist_path) == ".dcl")
2746             {
2747                 rv = ImportListDCL(filelist_path);
2748
2749                 if (rv == -1)
2750                 {
2751                     long_process_listener.Complete = true;
2752                     return;
2753                 }
2754             }
2755
2756             filelist_mode = true;
2757
2758             GlobalBuffers.duration = "";
2759
2760
2761             this.Invoke((MethodInvoker)delegate
2762             {
2763                 mainList.AssociateWithDataProvider(GlobalBuffers.Duplicates);
2764                 mainList.Visible = true;
2765
2766                 mainList.Invalidate();
2767
2768                 SetStatusBarData(false);
2769
2770                 if (recentFileList.Items.Count == 1 && recentFileList.Items[0].Enabled == false)
2771                     recentFileList.Items.RemoveAt(0);
2772
2773                 if (recentFileList.Items.Count < 5)
2774                 {
2775                     bool found = false;
2776
2777                     for (i = 0; i < recentFileList.Items.Count; i++)
2778                     {
2779                         if (recentFileList.Items[i].Text == filelist_path)
2780                         {
2781                             found = true;
2782                             break;
2783                         }
2784                     }
2785
2786                     if (found == false)
2787                     {
2788                         recentFileList.Items.RemoveAt(0);
2789
2790                         ToolStripMenuItem new_item = new ToolStripMenuItem(filelist_path);
2791                         new_item.Click += new EventHandler(RecentClick);
2792
2793                         recentFileList.Items.Insert(0, new_item);
2794                     }
2795                     else
2796                     {
2797                         ToolStripMenuItem new_item = new ToolStripMenuItem(filelist_path);
2798                         new_item.Click += new EventHandler(RecentClick);
2799
2800                         this.Invoke((MethodInvoker)delegate
2801                         {
2802                             recentFileList.Items.RemoveAt(i);
2803                             recentFileList.Items.Insert(0, new_item);
2804                         });
2805                     }
2806                 }
2807                 else
2808                 {
2809
2810                 }
2811
2812                 ExportRecentFileList();
2813                 //LoadRecentFileList();
2814
2815             });
2816
2817         }
2818
2819
2820         private void ExportRecentFileList()
2821         {
2822             int i;
2823
2824             for (i = 0; i < 5; i++)
2825             {
2826                 if (i < recentFileList.Items.Count)
2827                 {
2828                     if (recentFileList.Items[i].Text.Contains("\\"))
2829                         GlobalBuffers.SettingsManager.Add("recent" + i.ToString(), recentFileList.Items[i].Text);
2830                 }
2831                 else
2832                 {
2833                     GlobalBuffers.SettingsManager.Add("recent" + i.ToString(), "");
2834                 }
2835             }
2836
2837             GlobalBuffers.SettingsManager.Dump(GlobalBuffers.OptionsPath);
2838         }
2839
2840         private void LoadRecentFileList()
2841         {
2842             int i;
2843
2844             recentFileList.Items.Clear();
2845
2846             for (i = 0; i < 5; i++)
2847             {
2848                 string path = GlobalBuffers.SettingsManager.FindSettingStringSingle( "recent" + i.ToString());
2849
2850                 if (path != "" && path != "-1")
2851                     recentFileList.Items.Add(path).Click += new EventHandler(RecentClick);
2852             }
2853             if (recentFileList.Items.Count == 0)
2854                 recentFileList.Items.Add("No recently opened lists").Enabled = false;
2855
2856             recentFileList.Items.Add(new ToolStripSeparator());
2857             recentFileList.Items.Add("Clear list").Click += new EventHandler(clearList_Click);
2858         }
2859
2860         void RecentClick(object sender, EventArgs e)
2861         {
2862             ToolStripDropDownItem clicked_item = (ToolStripDropDownItem)sender;
2863
2864             filelist_path = clicked_item.Text;
2865
2866             if (!File.Exists(filelist_path))
2867             {
2868                 MessageBox.Show("The selected file list doesn't exist.", "Duplicate Commander", MessageBoxButtons.OK, MessageBoxIcon.Error);
2869
2870                 return;
2871             }
2872
2873             GlobalBuffers.Duplicates = new DuplicateGroupCollection();
2874
2875             ThreadStart ts = new ThreadStart(OpenFileList);
2876             Thread t = new Thread(ts);
2877
2878             checking_window = new Checking();
2879             checking_window.Text = "Loading file list";
2880             checking_window.staticText = true;
2881             checking_window.progressText = "Please wait...";
2882
2883             long_process_listener = new LongProcessListener(checking_window, this);
2884
2885             t.Start();
2886         }
2887
2888         void PinnedClick(object sender, EventArgs e)
2889         {
2890             /*ToolStripDropDownItem clicked_item = (ToolStripDropDownItem)sender;
2891
2892             filelist_path = clicked_item.Text;
2893
2894             ThreadStart ts = new ThreadStart(OpenFileList);
2895             Thread t = new Thread(ts);
2896             t.Start();*/
2897         }
2898
2899         /* private int ImportListXML(string filename)
2900          {
2901              if (!File.Exists(filename))
2902                  return -1;
2903              int i, j;
2904              XMLEntity xml = XMLEntity.loadFromFile(filename);
2905              XMLNode group;
2906              DuplicateGroup new_group;
2907              DuplicateFile new_file;
2908              string group_type;
2909
2910              GlobalBuffers.ListMode = true;
2911
2912              XMLNode files = xml.findByName("files");
2913
2914              double prg = (double)100 / files.Children.Count;
2915
2916              for (i = 0; i < files.Children.Count; i++)
2917              {
2918                  if (files.Children[i].Type == XMLNode.NodeType.MARKUP)
2919                  {
2920                      group = files.Children[i];
2921
2922                      new_group = new DuplicateGroup();
2923                      new_group.GroupName = group.findAttribute("name");
2924
2925                      group_type = group.findAttribute("type");
2926
2927                      if (group_type == "true")
2928                          new_group.State = DuplicateGroup.GroupState.TrueDuplicate;
2929                      else if (group_type == "false")
2930                          new_group.State = DuplicateGroup.GroupState.FalseDuplicate;
2931                      else
2932                          new_group.State = DuplicateGroup.GroupState.Undeterminable;
2933
2934                      for (j = 0; j < group.Children.Count; j++)
2935                      {
2936                          new_file = new DuplicateFile(group.Children[j].findAttribute("path").Replace("?", "\""), Convert.ToInt64(group.Children[j].findAttribute("size")), DateTime.Parse(group.Children[j].findAttribute("date_modified")));
2937
2938                          if (group.Children[j].findAttribute("link") == "true")
2939                              new_file.Link = true;
2940                          else
2941                              new_file.Link = false;
2942
2943                          new_group.Add(new_file);
2944                      }
2945
2946                      GlobalBuffers.Duplicates.Add(new_group);
2947                  }
2948
2949                  checking_window.progress = (double)i * prg;
2950              }
2951
2952              XMLNode folders = xml.findByName("folders");
2953
2954              for (i = 0; i < folders.Children.Count; i++)
2955              {
2956                  if (folders.Children[i].Type == XMLNode.NodeType.ELEMENT)
2957                      GlobalBuffers.folders.Add(folders.Children[i].Value);
2958              }
2959
2960              GlobalBuffers.mainList.Invalidate();
2961
2962              long_process_listener.Complete = true;
2963
2964              return 0;
2965          }*/
2966
2967         private int ImportListDCL(string filename)
2968         {
2969             //  try
2970             // {
2971             DuplicateGroup new_group = null;
2972             DuplicateFile new_file = null;
2973             string[] list;
2974             int i, j;
2975             double prg;
2976             int delimiter_index = 0, delimiter_count = 0, old_delimiter_index = 0;
2977             bool list_mode = false;
2978
2979
2980
2981             list = File.ReadAllLines(filename);
2982
2983             prg = (double)100 / (list.Length - 1);
2984
2985             for (i = 0; i < list.Length; i++)
2986             {
2987                 if (i == 1140)
2988                 {
2989                     int zx = 0;
2990                     zx = 122;
2991                 }
2992                 if (list[i].Contains(".?..?..?."))
2993                 {
2994                     if (new_group != null)
2995                         GlobalBuffers.Duplicates.Add(new_group);
2996
2997                     new_group = new DuplicateGroup();
2998
2999                     new_group.GroupName = list[i].Substring(0, list[i].IndexOf(".?."));
3000                 }
3001                 else if (list[i].Contains("??.Folder?,"))
3002                 {
3003                     list_mode = true;
3004
3005                     GlobalBuffers.folders.Add(list[i].Substring(11));
3006                 }
3007                 else
3008                 {
3009                     for (j = 0; j < 3; j++)
3010                     {
3011                         old_delimiter_index = delimiter_index;
3012
3013                         if (delimiter_count == 0)
3014                             delimiter_index = list[i].IndexOf(".?.");
3015                         else
3016                         {
3017                             delimiter_index = list[i].IndexOf(".?.", delimiter_index + 2);
3018                         }
3019
3020                         if (delimiter_count == 0)
3021                         {
3022                             new_file = new DuplicateFile(list[i].Substring(0, delimiter_index), 0, DateTime.Now);
3023                         }
3024                         else if (delimiter_count == 1)
3025                         {
3026                             new_file.Size = (long)DuplicateFinder.formatSizeString(list[i].Substring(old_delimiter_index + 3, delimiter_index - old_delimiter_index - 3));
3027                         }
3028                         else if (delimiter_count == 2)
3029                         {
3030                             int date_time_len = list[i].Length - 3 - (old_delimiter_index + 3);
3031                             new_file.DateModified = DateTime.Parse(list[i].Substring(old_delimiter_index + 3, date_time_len));
3032                         }
3033
3034                         delimiter_count++;
3035
3036                         if (delimiter_count == 3)
3037                         {
3038                             delimiter_count = 0;
3039                             delimiter_index = 0;
3040
3041                             new_group.Add(new_file);
3042                         }
3043                     }
3044
3045                     // if (i < list.Length - 1)
3046                     //     i++;
3047                     //  else
3048                     //     break;
3049                 }
3050
3051
3052                 // if (i < list.Length - 1)
3053                 //    i--;
3054
3055                 checking_window.progress = (double)i * prg;
3056
3057                 // checking_window.progress = prg2;
3058             }
3059
3060             GlobalBuffers.ListMode = true;
3061
3062             if (list_mode == false) // we haven't found the folders section so we probably are in a legacy list
3063             {
3064                 CacheFoldersLegacy();
3065             }
3066
3067             long_process_listener.Complete = true;
3068
3069             this.Invoke((MethodInvoker)delegate
3070             {
3071                 BackColor = Color.FromKnownColor(KnownColor.Control);
3072                 mainList.AssociateWithDataProvider(GlobalBuffers.Duplicates);
3073                 mainList.Visible = true;
3074                 mainList.Invalidate();
3075             });
3076             // }
3077             // catch
3078             // {
3079             //     MessageBox.Show(this, "The specified file is invalid.", "Duplicate Commander", MessageBoxButtons.OK, MessageBoxIcon.Error);
3080             long_process_listener.Complete = true;
3081             //     return -1;
3082             // }
3083
3084             return 0;
3085         }
3086
3087         private void CacheFoldersLegacy()
3088         {
3089             this.Invoke((MethodInvoker)delegate
3090             {
3091                 statusBarPanel1.Text = "Caching folders...";
3092             });
3093
3094             string folder;
3095             bool dont_add = false;
3096             int i, j, k;
3097             FileInfo finfo1;
3098             double div = 0;
3099             double prg, prg2 = (double)0.0;
3100
3101             prg = (double)100 / GlobalBuffers.Duplicates.Count;
3102
3103             for (i = 0; i < GlobalBuffers.Duplicates.Count; i++)
3104             {
3105                 for (j = 0; j < GlobalBuffers.Duplicates[i].Count; j++)
3106                 {
3107                     finfo1 = new System.IO.FileInfo(GlobalBuffers.Duplicates[i][j].Filename);
3108                     folder = finfo1.DirectoryName;
3109
3110                     for (k = 0; k < GlobalBuffers.folders.Count; k++)
3111                     {
3112                         if (GlobalBuffers.folders[k] == folder)
3113                         {
3114                             dont_add = true;
3115                             continue;
3116                         }
3117                     }
3118                     if (dont_add == true)
3119                         dont_add = false;
3120                     else
3121                     {
3122                         GlobalBuffers.folders.Add(folder);
3123                     }
3124                 }
3125
3126                 prg2 += (double)prg;
3127                 div = (double)prg2 / 5;
3128
3129                 this.Invoke((MethodInvoker)delegate
3130                 {
3131                     statusBarPanel1.Text = "Caching folders (may take a minute)...(" + ((int)prg2).ToString() + "%)";
3132                 });
3133
3134             }
3135         }
3136
3137         private void checkbyString_Click(object sender, EventArgs e)
3138         {
3139             if (GlobalBuffers.working)
3140                 return;
3141             if (GlobalBuffers.Duplicates == null || GlobalBuffers.Duplicates.Count == 0)
3142                 return;
3143
3144             CheckByString cbs1 = new CheckByString();
3145
3146             cbs1.Owner = this;
3147             cbs1.ShowDialog();
3148
3149             ThreadStart ts = new ThreadStart(CheckByString);
3150             Thread t = new Thread(ts);
3151
3152             checking_window = new Checking();
3153             long_process_listener = new LongProcessListener(checking_window, this);
3154
3155             t.Start();
3156         }
3157
3158         private void CheckByString()
3159         {
3160             int i, j, k;
3161             bool check_item = false;
3162             double prg = (double)100 / GlobalBuffers.Duplicates.Count, prg2 = 0;
3163             bool already_checked_first = false;
3164             int group_count = 0, duplicate_count = 0;
3165
3166             if (GlobalBuffers.CheckByStringData.String == "")
3167                 return;
3168
3169             if (GlobalBuffers.folders_ok_clicked == true)
3170             {
3171                 for (i = 0; i < GlobalBuffers.Duplicates.Count; i++)
3172                 {
3173                     duplicate_count = 0;
3174                     if (checking_window.cancel_clicked == true)
3175                         break;
3176
3177                     for (j = 0; j < GlobalBuffers.Duplicates[i].Count; j++)
3178                     {
3179                         for (k = 0; k < GlobalBuffers.CheckByStringData.FolderExclusions.Count; k++)
3180                         {
3181                             if (checking_window.cancel_clicked == true)
3182                                 break;
3183
3184                             // see if the item matches one of the included folders we're to limit
3185                             // the check to, and if it is, break the loop and handle it
3186                             //if ((duplicateList.Items[i]).Text.Substring(0, (duplicateList.Items[i]).Text.LastIndexOf("\\") + (CountOccurrencesInString((duplicateList.Items[i]).Text, "\\") == 1 ? 1 : 0)) == (string)GlobalBuffers.CheckByStringData.FolderExclusions[k])
3187                             if (Path.GetDirectoryName(GlobalBuffers.Duplicates[i][j].Filename) == GlobalBuffers.CheckByStringData.FolderExclusions[k])
3188                             {
3189                                 check_item = true;
3190                                 break;
3191                             }
3192                         }
3193
3194                         // if the user did select to limit to specific folders, and this is one of the folders,
3195                         // see if it contains the inserted string and if it does, check the ite,
3196                         if (check_item == true && GlobalBuffers.CheckByStringData.ExcludeToCertainFolders == true || GlobalBuffers.CheckByStringData.ExcludeToCertainFolders == false)
3197                         {
3198                             // this complicated line simply checks if match case is enabled or not, along with the string check
3199                             // the only difference between the true and false portions is the presence of ToLower
3200
3201                             if (!GlobalBuffers.CheckByStringData.RegularExpression)
3202                             {
3203                                 if ((GlobalBuffers.CheckByStringData.MatchCase == true ? GlobalBuffers.Duplicates[i][j].Filename.Contains(GlobalBuffers.CheckByStringData.String) : GlobalBuffers.Duplicates[i][j].Filename.ToLower().Contains(GlobalBuffers.CheckByStringData.String.ToLower())))
3204                                 {
3205                                     if (GlobalBuffers.CheckByStringData.CheckOnlyOne == true && already_checked_first == false || GlobalBuffers.CheckByStringData.CheckOnlyOne == false)
3206                                     {
3207                                         GlobalBuffers.Duplicates[i][j].Checked = true;
3208                                         already_checked_first = true; // check one item
3209                                     }
3210                                 }
3211                                 else
3212                                 {
3213                                     // persistent check equals false
3214                                     if (GlobalBuffers.CheckByStringData.PersistentCheck == false)
3215                                         GlobalBuffers.Duplicates[i][j].Checked = false;
3216                                 }
3217                             }
3218                             else
3219                             {
3220                                 // exp_match = new Regex(GlobalBuffers.CheckByStringData.String, RegexOptions.IgnoreCase | RegexOptions.Singleline);
3221                                 //  if(exp_match.IsMatch(GlobalBuffers.CheckByStringData.String( 
3222                             }
3223                         }
3224                         else if (check_item == false && GlobalBuffers.CheckByStringData.ExcludeToCertainFolders == false)
3225                         {
3226                             if (GlobalBuffers.CheckByStringData.PersistentCheck == false)
3227                                 GlobalBuffers.Duplicates[i][j].Checked = false;
3228                         }
3229                         check_item = false;
3230                     }
3231
3232                     already_checked_first = false;
3233
3234                     prg2 += (double)prg;
3235
3236                     checking_window.progress = prg2;
3237
3238                     checking_window.progressText = "Processing duplicate " + (duplicate_count + 1).ToString() + " of group " + (group_count + 1).ToString();
3239                     duplicate_count++;
3240                 }
3241
3242                 group_count++;
3243             }
3244
3245             GlobalBuffers.mainList.Invalidate();
3246
3247             this.Invoke((MethodInvoker)delegate
3248             {
3249                 SetStatusBarData(false);
3250
3251                 EnableArrows(false);
3252             });
3253
3254             long_process_listener.Complete = true;
3255         }
3256
3257         private int CountOccurrencesInString(string in_string, string what)
3258         {
3259             int index = -2, count = 0;
3260             bool first_time = true;
3261
3262             while (index != -1)
3263             {
3264                 if (first_time == true)
3265                 {
3266                     index = -1;
3267                     first_time = false;
3268                 }
3269                 index = in_string.IndexOf(what, index + 1);
3270
3271                 if (index != -1)
3272                     count++;
3273             }
3274
3275             return count;
3276         }
3277
3278         private void timer1_Tick(object sender, EventArgs e)
3279         {
3280             EnableArrows(true);
3281         }
3282
3283
3284         public void EnableArrows(bool timer)
3285         {/*
3286             if (GlobalBuffers.mainList.Visible == false || GlobalBuffers.working == true)
3287                 return;
3288
3289             if (!in_search)
3290             {
3291                 DuplicateListView.DrawIndex currentIndex = new DuplicateListView.DrawIndex(mainList.DrawStartIndex.Group, mainList.DrawStartIndex.Duplicate, mainList.DrawStartIndex.Data);
3292                 DuplicateListView.DrawIndex.IndexReturnStatus currentIndexExistence = DuplicateListView.DrawIndex.IndexReturnStatus.Exists;
3293
3294                 while (currentIndexExistence == DuplicateListView.DrawIndex.IndexReturnStatus.Exists)
3295                 {
3296                     currentIndexExistence = currentIndex.Decrement();
3297
3298                     if (currentIndexExistence == DuplicateListView.DrawIndex.IndexReturnStatus.Exists && currentIndex.ReturnItem().Checked == true)
3299                     {
3300                         this.Invoke((MethodInvoker)delegate
3301                         {
3302                             jumpUpButton.Enabled = true;
3303                         });
3304                         break;
3305                     }
3306                     else
3307                         this.Invoke((MethodInvoker)delegate
3308                         {
3309                             jumpUpButton.Enabled = false;
3310                         });
3311                 }
3312
3313                 currentIndex = mainList.DrawStartIndex.IncrementReturn(mainList.MaximumVisibleItems());
3314
3315                 if (currentIndex != null)
3316                 {
3317                     currentIndexExistence = DuplicateListView.DrawIndex.IndexReturnStatus.Exists;
3318
3319                     while (currentIndexExistence == DuplicateListView.DrawIndex.IndexReturnStatus.Exists)
3320                     {
3321                         currentIndexExistence = currentIndex.Increment();
3322
3323                         if (currentIndexExistence == DuplicateListView.DrawIndex.IndexReturnStatus.Exists && currentIndex.ReturnItem().Checked == true)
3324                         {
3325                             this.Invoke((MethodInvoker)delegate
3326                             {
3327                                 jumpDownButton.Enabled = true;
3328                             });
3329                             break;
3330                         }
3331                         else
3332                         {
3333                             this.Invoke((MethodInvoker)delegate
3334                             {
3335                                 jumpDownButton.Enabled = false;
3336                             });
3337                         }
3338                     }
3339                 }
3340                 else
3341                 {
3342                     this.Invoke((MethodInvoker)delegate
3343                     {
3344                         jumpDownButton.Enabled = false;
3345                     });
3346                 }
3347
3348             }
3349             else
3350             {
3351                /* for (int i = 0; i < mainList.HighLightedIndexes.Count; i++)
3352                 {
3353                     if (mainList.HighLightedIndexes[i] < mainList.DrawStartIndex.ReturnItem().RollingTotal)
3354                     {
3355                         this.Invoke((MethodInvoker)delegate
3356                         {
3357                             jumpUpButton.Enabled = true;
3358                         });
3359
3360                         break;
3361                     }
3362
3363                     
3364
3365                 }
3366
3367                 for (int i = 0; i < mainList.HighLightedIndexes.Count; i++)
3368                 {
3369
3370                     if (mainList.HighLightedIndexes[i] + mainList.MaximumVisibleItems() > mainList.DrawStartIndex.IncrementReturn(mainList.MaximumVisibleItems()).ReturnItem().RollingTotal)
3371                     {
3372                         this.Invoke((MethodInvoker)delegate
3373                         {
3374                             jumpDownButton.Enabled = true;
3375                         });
3376
3377                         break;
3378                     }
3379                 }00
3380             }*/
3381         }
3382
3383         /*
3384         public void EnableArrows(bool timer)
3385         {
3386             if (GlobalBuffers.mainList.Visible == false || GlobalBuffers.working == true)
3387                 return;
3388
3389             if (!in_search)
3390             {
3391                 if (GlobalBuffers.Duplicates.CheckedItems.Count == 0)
3392                 {
3393                     jumpUpButton.Enabled = false;
3394                     jumpDownButton.Enabled = false;
3395                     return;
3396                 }
3397
3398                 if (GlobalBuffers.Duplicates.CheckedItems[0].Group < mainList.DrawStartIndex.Group && GlobalBuffers.Duplicates.CheckedItems[0].Duplicate < mainList.DrawStartIndex.Duplicate)
3399                     jumpUpButton.Enabled = true;
3400                 else
3401                     jumpUpButton.Enabled = false;
3402
3403                 if (GlobalBuffers.Duplicates.CheckedItems[GlobalBuffers.Duplicates.CheckedItems.Count - 1].Group >= mainList.DrawStartIndex.IncrementReturn(mainList.MaximumVisibleItems()).Group && GlobalBuffers.Duplicates.CheckedItems[GlobalBuffers.Duplicates.CheckedItems.Count - 1].Group >= mainList.DrawStartIndex.IncrementReturn(mainList.MaximumVisibleItems()).Duplicate)
3404                     jumpDownButton.Enabled = true;
3405                 else
3406                     jumpDownButton.Enabled = false;
3407             }
3408             else
3409             {
3410                 if (GlobalBuffers.mainList.HighLightedIndexes.Count > 0 && GlobalBuffers.mainList.HighLightedIndexes[0] < GlobalBuffers.mainList.verticalScrollbar.Value + GlobalBuffers.mainList.MaximumVisibleItems())
3411                 {
3412                     jumpUpButton.Enabled = false;
3413                     jumpDownButton.Enabled = false;
3414                     return;
3415                 }
3416
3417                 if (GlobalBuffers.mainList.HighLightedIndexes.Count > 0 && GlobalBuffers.mainList.HighLightedIndexes[0] < GlobalBuffers.mainList.verticalScrollbar.Value)
3418                     jumpUpButton.Enabled = true;
3419                 else
3420                     jumpUpButton.Enabled = false;
3421
3422                 if (GlobalBuffers.mainList.HighLightedIndexes.Count > 0 && GlobalBuffers.mainList.HighLightedIndexes[GlobalBuffers.mainList.HighLightedIndexes.Count - 1] > GlobalBuffers.mainList.verticalScrollbar.Value + GlobalBuffers.mainList.MaximumVisibleItems())
3423                     jumpDownButton.Enabled = true;
3424                 else
3425                     jumpDownButton.Enabled = false;
3426             }
3427         }*/
3428
3429
3430         /*
3431         public void EnableArrows(bool timer)
3432         {
3433             if (GlobalBuffers.mainList.Visible == false || GlobalBuffers.working == true)
3434                 return;
3435
3436             int count_per_page = GlobalBuffers.mainList.MaximumVisibleItems();
3437             DuplicateObject top_object;
3438             DuplicateListView.DrawIndex backward_index = new DuplicateListView.DrawIndex(GlobalBuffers.mainList.DrawStartIndex.Group, GlobalBuffers.mainList.DrawStartIndex.Duplicate, GlobalBuffers.mainList.DrawStartIndex.Data);
3439             DuplicateListView.DrawIndex forward_index = new DuplicateListView.DrawIndex(GlobalBuffers.mainList.DrawStartIndex.Group, GlobalBuffers.mainList.DrawStartIndex.Duplicate, GlobalBuffers.mainList.DrawStartIndex.Data);
3440             DuplicateListView.DrawIndex.IndexReturnStatus in_bounds = DuplicateListView.DrawIndex.IndexReturnStatus.Exists;
3441
3442             if (in_search == false)
3443             {
3444                 if (mainList.Visible == true)
3445                 {
3446                     in_bounds = forward_index.Increment(GlobalBuffers.mainList.MaximumVisibleItems() - 1);
3447
3448                     while (in_bounds == DuplicateListView.DrawIndex.IndexReturnStatus.Exists)
3449                     {
3450                         in_bounds = forward_index.Increment();
3451
3452
3453                         if (in_bounds == DuplicateListView.DrawIndex.IndexReturnStatus.Exists)
3454                         {
3455                             top_object = mainList.GetItem(forward_index.Group, forward_index.Duplicate);
3456
3457                             if (top_object == null)
3458                                 return;
3459
3460                             if (top_object.ObjectType == DuplicateObject.Type.File)
3461                             {
3462                                 if (top_object.DuplicateFile.Checked == true)
3463                                 {
3464                                     jumpDownButton.Enabled = true;
3465                                     ForwardIndex = forward_index;
3466                                     break;
3467                                 }
3468                                 else
3469                                 {
3470                                     jumpDownButton.Enabled = false;
3471                                 }
3472                             }
3473                             if (top_object.ObjectType == DuplicateObject.Type.Group)
3474                             {
3475                                 if (top_object.DuplicateGroup.Checked == true)
3476                                 {
3477                                     jumpDownButton.Enabled = true;
3478                                     ForwardIndex = forward_index;
3479                                     break;
3480                                 }
3481                                 else
3482                                 {