/// <summary>
        /// Find All the duplicate Files By CheckSum
        /// </summary>
        /// <param name="files">ArrayList of Files</param>
        /// <returns>ArrayList</returns>
        public ArrayList findDuplicatesByCheckSum(ArrayList files)
        {
            var duplicateFiles = new ArrayList();
            var count = 0;
            var duplicateId = 0;
            fileStruct previous = new fileStruct { checksum = "000" };

            foreach (fileStruct file in files)
            {
                if (String.Equals(file.checksum,previous.checksum))
                {
                    if (count == 0)
                    {
                        duplicateId++;
                        previous.duplicationNumber = duplicateId;
                        duplicateFiles.Add(previous);
                    }
                    file.duplicationNumber = duplicateId;
                    duplicateFiles.Add(file);
                    count++;
                }
                else
                {
                    previous = file;
                    count = 0;
                }

            }
            return duplicateFiles;
        }
        public ArrayList findDuplicatesByFileName(ArrayList files)
        {
            var duplicateFiles = new ArrayList();
            var count = 0;
            var duplicateId = 0;
            fileStruct previous = new fileStruct { fileName = "" };

            foreach (fileStruct file in files)
            {
                if (String.Equals(file.fileName, previous.fileName))
                {
                    if (count == 0)
                    {
                        duplicateId++;
                        previous.duplicationNumber = duplicateId;
                        duplicateFiles.Add(previous);
                    }
                    file.duplicationNumber = duplicateId;
                    duplicateFiles.Add(file);
                    count++;
                }
                else
                {
                    previous = file;
                    count = 0;
                }

            }
            return duplicateFiles;
        }
        private void FindFilesClick(object sender, RoutedEventArgs e)
        {
            ClearVars();
            stopBtn.IsEnabled = true;
            clearBtn.IsEnabled = false;
            if(!Directory.Exists(searchDir.Text)){
                var msg = "Directory " + searchDir.Text + " does not exists.";
                MessageBox.Show(msg, "No Such Directory");
                return;
            }

            if(string.IsNullOrEmpty(searchPattern.Text))
                searchPattern.Text = "*";
            var di = new DirectoryInfo(searchDir.Text);
            var files = di.GetFiles(searchPattern.Text, _dirChoice);

            double value = 0;
            progressBar1.Minimum = 0;
            progressBar1.Maximum = files.Length;
            progressBar1.Value = 0;

            var updatePbDelegate = new UpdateProgressBarDelegate(progressBar1.SetValue);
            var updateCurFile = new UpdateLabelDelegate(curFileLabel.SetValue);

            foreach (var file in files)
            {
                if (_stop)
                {
                    _stop = false;
                    break;
                }
                value += 1;
                Dispatcher.Invoke(updatePbDelegate,
                    System.Windows.Threading.DispatcherPriority.Background,
                    new object[] { ProgressBar.ValueProperty, value });

                var progressMessage = "Scanning: " + file.FullName;
                Dispatcher.Invoke(updateCurFile,
                    System.Windows.Threading.DispatcherPriority.Background,
                    new object[] { TextBox.TextProperty, progressMessage });

                var md5 = "";
                if (!_nameOnly)
                {
                    var findHash = new findMD5();
                    md5 = findHash.getFilesMD5Hash(file.FullName);
                }

                var fStruct = new fileStruct{ checksum = md5, fileName = file.Name, fullPath = file.FullName, creationDate=file.CreationTime };
                _listOfFiles.Add(fStruct);
            }

            curFileLabel.Text = "";
            ArrayList duplicates = new ArrayList();

            if (_nameOnly)
            {
                _listOfFiles.Sort(_compareByFileName);
                duplicates = _duplicateFiles.findDuplicatesByFileName(_listOfFiles);
            }
            else
            {
                _listOfFiles.Sort(_compareByCheckSum);
                duplicates = _duplicateFiles.findDuplicatesByCheckSum(_listOfFiles);
            }

            foreach(fileStruct file in duplicates){
                fileStructListView.Items.Add(file);
            }
            stopBtn.IsEnabled = false;
            clearBtn.IsEnabled = true;
            selectOldestBtn.IsEnabled = true;
            selectNewestBtn.IsEnabled = true;
            progressBar1.Value = 0;
        }