Exemplo n.º 1
0
        private void bwSortImageFolder_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (fmProgress.cancel)
            {
                Console.WriteLine("Done");
                if (fmProgress != null)
                {
                    fmProgress.Hide();
                    fmProgress = null;
                }
            }
            else
            {
                string newpath = "";
                string newpath2 = "";
                int lastvalue = -1;
                List<long> lastsize = new List<long>();
                if (files.Count > 1)
                {
                    var sortedfiles = (from entry in files orderby entry.Value ascending select entry);
                    newpath = fileNameCreator.createDirctory(bwFold + "\\VisualDups");
                    newpath2 = fileNameCreator.createDirctory(bwFold + "\\Duplicates");
                    if (newpath != null)
                    {
                        foreach (KeyValuePair<string, int> file in sortedfiles)
                        {
                            if (File.Exists(file.Key)) // Duplicate file name check. This is a basic 1 to 1 file check
                            {
                                if ((file.Value == lastvalue) && lastsize.Contains(imageMatcher.CalcSize(file.Key)))
                                {
                                    string path = Path.GetFileName(file.Key);
                                    path = file.Value + "_" + path;
                                    try
                                    {
                                        System.IO.File.Move(file.Key, newpath2 + "\\" + path);
                                    }
                                    catch (IOException) { }
                                }
                                else
                                {
                                    if (lastvalue == file.Value)
                                    {
                                        lastsize.Add(imageMatcher.CalcSize(file.Key));
                                    }
                                    else
                                    {
                                        lastsize.Clear();
                                        lastsize.Add(imageMatcher.CalcSize(file.Key));
                                        lastvalue = file.Value;
                                    }
                                    string path = Path.GetFileName(file.Key);
                                    path = file.Value + "_" + path;
                                    try
                                    {
                                        System.IO.File.Move(file.Key, newpath + "\\" + path);
                                    }
                                    catch (IOException) { }
                                }
                            }
                            else
                            {
                                Console.WriteLine("File already moved");
                            }
                        }
                    }
                }
                if (newpath != "")
                {

                    string[] tem = new string[64];
                    tem[0] = newpath;
                    tem[dupFold] = newpath2;
                    workingFolders = tem;
                    fileNameCreator.duplicateFolder = workingFolders[dupFold];
                    sourceCount = 1;
                    DisableButtons(false);
                    finalFold();

                }
                Console.WriteLine("Done");
                if (fmProgress != null)
                {
                    fmProgress.Hide();
                    fmProgress = null;
                }
            }
        }
Exemplo n.º 2
0
 private void sortFolderToolStripMenuItem_Click(object sender, EventArgs e)
 {
     MessageBox.Show("WARNING!: This operation will reset all current work" + Environment.NewLine + "---"+  Environment.NewLine + "This might take a VERY long time if a lot of images are similar" +  Environment.NewLine +
         "time taken can be exponental in worst case! test on subsets first");
     if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
     {
         if (Checkfolder(workingFolders, folderBrowserDialog1.SelectedPath) == false)
         {
             MessageBox.Show("Folders is already in use. Please pick different folder");
         }
         else
         {
             bwFold = folderBrowserDialog1.SelectedPath;
             files = new Dictionary<string, int>();
             fmProgress = new ProcceingDialog2();
             bwSortImageFolder.RunWorkerAsync();
            // bwSortImageFolder.
             fmProgress.ShowDialog( this );
             fmProgress = null;
         }
     }
 }