Example #1
0
        private int FileIsDuplicate(FileProp fp)
        {
            //  nejake stejne dlouhe soubory ?
            int SameSizeCount = CRCList.Count(n => n.FileSize == fp.FileSize);

            if (SameSizeCount <= 0)
            {
                return(0); // zadny stejne dlouhy souboru - nemusim tedy pocitat CRC
            }
            else
            {
                // nejdriv spocitat CRC aktualniho souboru
                fp.CRC = Vt.Adler32.FileChecksum(fp.OrigFileName);

                // tak bohuzel nejake stejne velke soubory :-/ musim tedu u nich spocitat CRC :-/
                for (int i = 0; i < CRCList.Count; i++)
                {
                    if (CRCList[i].FileSize == fp.FileSize)
                    {
                        // jeste neni CRC spoctena ? - asi bych to nemusel pocitat u vsech ... ale nebudu to dale komplikovat :-)
                        if (CRCList[i].CRC <= 0)
                        {
                            CRCList[i].CRC = Vt.Adler32.FileChecksum(CRCList[i].NewFileName);
                        }
                    }
                }

                //  pres linq ;-) teda zjistim, zda tu jsou nejake stejne CRC
                return(CRCList.Count(n => n.CRC == fp.CRC));
            }
        }
Example #2
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////
        private bool ProccessFile(string SourceFileName,
                                  bool FromNarFile,
                                  string SourceRoot,
                                  string DestRoot,
                                  string Forepart,
                                  string ExifKey,
                                  string NoExifKey,
                                  string DupFolder,
                                  bool MoveMode,
                                  bool MoveDuplicate,
                                  bool CBCreateDaySubDirectoryChecked,
                                  bool IgnoreSubfolder,
                                  ArrayList PreferExifDate,
                                  ref int PicCount,
                                  ref int NoExifCount,
                                  ref ArrayList PicFileNames,
                                  ref string ErrorLog)
        {
            DateTime ExifDate    = DateTime.MinValue;
            string   NewFileName = "";

            bool ExifExist  = false;
            bool LoadResult = false; // zda se povedl nacist JPEG soubor

            // kvuli duplicitam
            FileProp fp = new FileProp(SourceFileName);

            //using(
            Jpeg VtJpeg = new Jpeg();

            {
                // zkusim nahrat jpeg soubor
                Exception LoadEx = null;
                LoadResult = VtJpeg.LoadFromFile(SourceFileName, out LoadEx);
                if (LoadResult)
                {
                    // nahrani se povedlo - jeste juknu na CRC (pres adlera)
                    //fp.CRC = Vt.Adler32.FileChecksum(SourceFileName);
                    fp.FileSize = new FileInfo(SourceFileName).Length; // az bude cas mohlo by se udelat, ze CRC se bude pocitat jen u stejne velkych souboru - tim by se to melo dost uruchlit
                    fp.DupCount = FileIsDuplicate(fp);

                    // obsahuje exif informaci o datumu
                    ExifExist = ExistAnyDateTimeExifTag(ref VtJpeg);
                    if (ExifExist)
                    {
                        ExifDate = GetPreferedDateTime(ref VtJpeg, PreferExifDate);
                        string ExifEquip = GetEquip(ref VtJpeg);
                        NewFileName = MakeExifFileName(ExifKey, Forepart, ExifDate, PicCount, NoExifCount, ExifEquip, fp.DupCount);
                    }
                    else
                    {
                        NewFileName = MakeExifFileName(NoExifKey, Forepart, ExifDate, PicCount, NoExifCount, "", fp.DupCount);
                    }
                }
                else
                {
                    NewFileName = Path.GetFileName(SourceFileName);
                    AddErrorLog(ref ErrorLog, SourceFileName, LoadEx);
                }
            }

            if (LoadResult)
            {
                VtJpeg.Dispose();
            }

            // koncovka (obsahuje i tecku !)
            string Extension = Path.GetExtension(SourceFileName);
            // stara cesta bez filename
            string OldPath = Path.GetDirectoryName(SourceFileName);
            // source root ze slashem
            string SourceRootEx = AddSlash(SourceRoot);

            // novy adresar
            // nebrat v uvahu sub adresare a fotky sypat jen do day-adresare rovnou pod root ?
            string NewPath;

            if (IgnoreSubfolder)
            {
                NewPath = AddSlash(DestRoot);
            }
            else
            {
                // relativni kus cety
                string RelativePath = OldPath.Remove(0, SourceRootEx.Length - 1);
                NewPath = AddSlash(AddSlash(DestRoot) + KillFirstSlash(RelativePath));
            }

            // tvorit sub-adresare dle jednotlivych dni ??
            if (CBCreateDaySubDirectoryChecked)
            {
                string DaySubDir = MakeDaySubDirName(ExifDate, LoadResult, DupFolder, fp.DupCount);
                NewPath = AddSlash(NewPath + DaySubDir);
            }

            // cele finalni nove filename i s cestou
            string NewFileNameNoExt = AddSlash(NewPath) + NewFileName + (FromNarFile ? ".NAR" : string.Empty);

            NewFileName = AddSlash(NewPath) + NewFileName + (FromNarFile ? ".NAR" : string.Empty) + Extension;

            if (File.Exists(NewFileName))
            {
                NewFileName = GenerateExtendedFileName(NewFileNameNoExt, Extension);
            }

            // Text = NewFileName; => ve vlaknu nejde (neplatna operace mezi procesy)
            if (MoveDuplicate || (fp.DupCount <= 0)) // kopirovat i duplikovane soubory ??
            {
                CopyFile(SourceFileName, NewFileName, NewPath, MoveMode);
            }
            PicCount++;
            if (!ExifExist)
            {
                NoExifCount++;
            }
            PicFileNames.Add(NewFileName);

            // pridam so seznamu CRC - kvuli duplicitnim souboru
            fp.NewFileName = NewFileName;
            CRCList.Add(fp);

            // posilam zpet vysledek nacteni souboru
            return(LoadResult);
        }