Ejemplo n.º 1
0
        public void restore(long idx, string fname)
        {
            Duplicated di = (entries_.ContainsKey(idx)) ? entries_[idx] : null;

            if (di == null)
            {
                return;
            }
            di.restore(fname);
        }
Ejemplo n.º 2
0
        public void showDuplicate(long idx, ref PictureBox[] pics)
        {
            if (idx < 1)
            {
                idx = 1;
            }
            if (idx >= entries_.Count)
            {
                idx = entries_.Count;
            }

            Duplicated di = (entries_.ContainsKey(idx)) ? entries_[idx] : null;

            if (di == null)
            {
                return;
            }

            int           i      = 0;
            List <string> fnames = new List <string>();

            di.getFilenames(ref fnames);

            foreach (string f in fnames)
            {
                try
                {
                    pics[i]               = new PictureBox();
                    pics[i].Top           = 3;
                    pics[i].Left          = 3;
                    pics[i].Name          = "_" + idx;
                    pics[i].Width         = 380;
                    pics[i].Height        = 240;
                    pics[i].ImageLocation = f;
                    pics[i].SizeMode      = PictureBoxSizeMode.StretchImage;
                    pics[i].MouseMove    += pic_MouseMove;
                    pics[i].Paint        += pics_paintEvent;
                    pics[i].Tag           = di.isRemovable(f);
                    i++;
                }
                catch (ArgumentException e)
                {
                    MessageBox.Show(e.Message + f);
                    return;
                }
            }
        }
Ejemplo n.º 3
0
        // reads in the file which contains the MD5 hash values along with the image file names
        private void loadIn()
        {
            if (MD5file_ == "")
            {
                return;
            }

            var    reader     = new StreamReader(File.OpenRead(MD5file_), Encoding.Unicode, true);
            bool   commaFound = false;
            string hash       = "";
            string p          = "";
            Dictionary <string, string> tmp = new Dictionary <string, string>();
            int count = 0, i;

            // calculate the number of lines within the file by counting the \r\n characters
            string all = reader.ReadToEnd();

            for (i = 0; i < all.Length; i++)
            {
                if ((i + 1) == all.Length)
                {
                    break;
                }
                if ((all[i] == 0x0d) && (all[i + 1] == 0x0a))
                {
                    count++;
                }
            }
            statuslabel_.Text = "Processing file " + this.MD5file_;
            Application.DoEvents();
            progressbar_.Maximum = count;
            progressbar_.Value   = 0;

            // let's go... read in the has values <KEY> and the image file names <VALUE> char by char
            // a little bit old C style but works and executes fast
            for (i = 0; i < all.Length; i++)
            {
                if ((i + 1) == all.Length)
                {
                    break;
                }
                if ((all[i] == 0x00) || ((all[i] == 0x0d) && (all[i + 1] == 0x0a)))
                {
                    if (tmp.ContainsKey(hash))
                    {
                        // do not overwrite the value of an existing key instead add the file name
                        // to the end of teh value separated a semicolon
                        tmp[hash] += ";" + p;
                    }
                    else
                    {
                        tmp.Add(hash, p);
                    }

                    commaFound = false;
                    hash       = p = "";
                    if ((all[i] == 0x0d) && (all[i + 1] == 0x0a))
                    {
                        progressbar_.Value++;
                    }
                    i++;
                    continue;
                }
                if (all[i] == ',')
                {
                    commaFound = true;
                    i++;
                }
                if (commaFound)
                {
                    p += all[i];
                }
                else
                {
                    hash += all[i];
                }
            }
            progressbar_.Value = 0;
            statuslabel_.Text  = "Collecting duplications...";
            Application.DoEvents();
            // fill up the entries_ Dictionary map with the items containing duplicates
            // the process looks for a semicolon within the <VALUE> and if it has one
            // it will be added to the map
            // the entries_ dictionary has <ID> => <DuplicatedImage> pairs
            long id = 1;

            foreach (KeyValuePair <string, string> kvp in tmp)
            {
                if (kvp.Value.IndexOf(';') > -1)
                {
                    Duplicated di = new Duplicated();
                    di.setIndex(id);
                    di.setHash(kvp.Key);
                    di.addFilenames(kvp.Value);
                    entries_[id] = di;
                    id++;
                }
            }
            Application.DoEvents();
            statuslabel_.Text = "Ready.";

            reader.Close();
            reader.Dispose();
            reader = null;
        }