Пример #1
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);
        }