Exemplo n.º 1
0
        // ------------------------------		functions   ----------------------------------------------------------

        public void     DoSearch(string startDir, string sFor, bool subDirs, ref int findCount)
        {
            var searchList1 = new List <string>();

            string[] validExtensions = new     [] { ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tif", ".ico", ".wmf", ".emf" };
            if (subDirs)
            {
                searchList1 = Directory.GetFiles(startDir, "*.*", SearchOption.AllDirectories)
                              .Where(file => validExtensions.Any(file.ToLower().EndsWith))
                              .ToList();
            }
            else
            {
                searchList1 = Directory.GetFiles(startDir)
                              .Where(file => validExtensions.Any(file.ToLower().EndsWith))
                              .ToList();
            }
            var fc = new FilenameComparer();

            searchList1.Sort(fc);

            string sForReg = WildcardToRegex(sFor);

            foreach (string picPath in searchList1)
            {
                string fName = Path.GetFileName(picPath);
                if (Regex.IsMatch(fName, sForReg, RegexOptions.IgnoreCase))
                {
                    //int strPos = Path.GetFileName(picPath).IndexOf(sFor);
                    //if (strPos > -1){
                    ListViewItem item = this.listSearch.Items.Add(picPath);
                    item.ImageIndex = 0;
                    _searchList2.Add(picPath);
                }
            }
            findCount = _searchList2.Count;
        }
Exemplo n.º 2
0
        // ------------------------------   BackgroundWorker  ----------------------------------------------------------

        public bool ScanImages(BackgroundWorker bw)
        // called by: BackgroundWorker1DoWork
        // shown with ExifDataShow
        {
            var  dashImgList = new List <string>();
            bool allDirs     = false;

            if (allDirs)
            {
                dashImgList = Directory.GetFiles(_imgDir, "*.*", SearchOption.AllDirectories)
                              .Where(file => _validExtensions.Any(file.ToLower().EndsWith))
                              .ToList();
            }
            else
            {
                dashImgList = Directory.GetFiles(_imgDir)
                              .Where(file => _validExtensions.Any(file.ToLower().EndsWith))
                              .ToList();
            }
            FilenameComparer fc = new FilenameComparer();

            dashImgList.Sort(fc);

            int      exType;
            string   orientation;
            string   model;
            DateTime dtOriginal;
            int      timeOfD;
            string   expotime;
            string   fnumber;
            string   fLength;
            bool     flash;
            string   exposi;
            string   lens;
            string   scene;
            bool     gps;
            bool     face;
            string   exError;
            DateTime nullDate = DateTime.MinValue;
            int      maxTicks = dashImgList.Count() / 100;

            if (maxTicks < 1)
            {
                maxTicks = 1;
            }
            bw.ReportProgress(maxTicks, T._("Start"));

            int      fCount    = 0;
            DateTime priorDate = DateTime.MaxValue;
            var      spanDict  = new Dictionary <int, int>();

            ExifRead.ResetBox();

            foreach (string picPath in dashImgList)
            {
                ExifRead.CheckExif(out exType, out orientation, out model, out dtOriginal, out timeOfD, out expotime, out fnumber, out fLength, out flash, out exposi, out lens, out scene,
                                   out gps, out face, out exError, picPath);
                DateTime dtCreation = File.GetCreationTime(picPath);
                DateTime dtChanged  = File.GetLastWriteTime(picPath);
                DateTime dtFile;
                if (dtCreation < dtChanged)
                {
                    dtFile = dtCreation;
                }
                else
                {
                    dtFile = dtChanged;
                }

                exList.Add(new Exif(exType, model, dtOriginal, timeOfD,
                                    expotime, fnumber, fLength, flash, exposi, lens, scene,
                                    gps, face, picPath, dtFile));
                if (exError != "")
                {
                    errorList.Add(exError);
                }
                fCount++;
                int mod = fCount % 100;
                if (mod == 0)
                {
                    bw.ReportProgress(-1, "");
                }

                if (dtOriginal != nullDate)
                {
                    //Debug.WriteLine("path: " + picPath + " " + dtOriginal.ToString());
                    _dateCount++;
                    if (_minDate > dtOriginal)
                    {
                        _minDate = dtOriginal;
                    }
                    if (_maxDate < dtOriginal)
                    {
                        _maxDate = dtOriginal;
                    }

                    if (_dateCount > 1)
                    {
                        TimeSpan span    = dtOriginal.Subtract(priorDate);
                        int      spanSec = Math.Abs((int)span.TotalSeconds);
                        spanDict.Add(fCount, spanSec);
                    }
                    priorDate = dtOriginal;
                }

                if (dicExift.ContainsKey(exType))
                {
                    dicExift[exType] += 1;
                }
                else
                {
                    dicExift[exType] = 1;
                }
                if (dicModel.ContainsKey(model))
                {
                    dicModel[model] += 1;
                }
                else
                {
                    dicModel[model] = 1;
                }
                if (dicToD.ContainsKey(timeOfD))
                {
                    dicToD[timeOfD] += 1;
                }
                else
                {
                    dicToD[timeOfD] = 1;
                }

                if (dicExpot.ContainsKey(expotime))
                {
                    dicExpot[expotime] += 1;
                }
                else
                {
                    dicExpot[expotime] = 1;
                }
                if (dicFNum.ContainsKey(fnumber))
                {
                    dicFNum[fnumber] += 1;
                }
                else
                {
                    dicFNum[fnumber] = 1;
                }

                if (dicFLen.ContainsKey(fLength))
                {
                    dicFLen[fLength] += 1;
                }
                else
                {
                    dicFLen[fLength] = 1;
                }
                if (flash)
                {
                    ++_flashCount;
                }
                if (dicExposi.ContainsKey(exposi))
                {
                    dicExposi[exposi] += 1;
                }
                else
                {
                    dicExposi[exposi] = 1;
                }

                if (dicLens.ContainsKey(lens))
                {
                    dicLens[lens] += 1;
                }
                else
                {
                    dicLens[lens] = 1;
                }
                if (dicScene.ContainsKey(scene))
                {
                    dicScene[scene] += 1;
                }
                else
                {
                    dicScene[scene] = 1;
                }

                if (gps)
                {
                    ++_gpsCount;
                }
                if (face)
                {
                    ++_faceCount;
                }
            }
            return(true);
        }
Exemplo n.º 3
0
        public bool DirScan(out int picCount, string picPath, bool allDirs)
        {
            bool dirChanged = true;
            // called by: PicScan - open, refesh, drop, main: formShow, recent
            string picDir = "";

            if (File.Exists(picPath))
            {
                picDir = Path.GetDirectoryName(picPath);
            }
            else if (Directory.Exists(picPath))
            {
                picDir = picPath;
            }
            else if (Directory.Exists(Path.GetDirectoryName(picPath)))
            {
                picDir = Path.GetDirectoryName(picPath);
            }
            if (_picDir != picDir)
            {
                _picDir = picDir;
                var iList = new List <string>();
                if (allDirs)
                {
                    iList = Directory.GetFiles(picDir, "*.*", SearchOption.AllDirectories)
                            .Where(file => _validExtensions.Any(file.ToLower().EndsWith))
                            .ToList();
                }
                else
                {
                    iList = Directory.GetFiles(picDir)
                            .Where(file => _validExtensions.Any(file.ToLower().EndsWith))
                            .ToList();
                }
                FilenameComparer fc = new FilenameComparer();
                iList.Sort(fc);
                _imList.Clear();

                foreach (string fName in iList)
                {
                    _imList.Add(new ImgFile(fName, DateTime.MinValue, DateTime.MinValue));
                }
            }
            else
            {
                if (_picDir == "")
                {
                    ;                // first run
                }
                else
                {
                    //	Debug.WriteLine("no dir change");
                    dirChanged = false;
                }
            }
            picCount = _imList.Count();
            if (picCount == 0)
            {
                _picDir = "";                              // fix for re-scan
            }
            return(dirChanged);
        }