示例#1
0
        private DateTimeOffset?ProcessFile(FileInfo file, DateTimeOffset?suggestion = null)
        {
            MediaInfo info      = null;
            bool      fromCache = false;

            if (Options.CacheFileInfo)
            {
                MediaInfo cachedData;
                if (Cache.CacheLookup(file, out cachedData))
                {
                    info      = cachedData;
                    fromCache = true;
                }
            }

            if (null == info)
            {
                info = MediaInfoFactory.GetMediaInfo(file, Options.DataParser);
            }

            if (Options.CacheFileInfo && !fromCache)
            {
                Cache.Add(info);
            }

            bool moveThisFile = info.Type == MediaType.Image || info.Type == MediaType.Video;

            string action = moveThisFile ? this.Options.CopyInsteadOfMove ? "Copy" : "Move" : "Skipped";

            DateTimeOffset?dateTaken = info.Taken;

            if (!dateTaken.HasValue && info.Type == MediaType.Video && suggestion.HasValue)
            {
                if (this.Options.VerboseOutput)
                {
                    Console.WriteLine("Infering date for {0} as {1}", file.Name, suggestion);
                }
                dateTaken = suggestion;
            }

            if (moveThisFile && dateTaken.HasValue)
            {
                string        targetFullName  = dateTaken.Value.ToString(Options.DirectoryFormat);
                DirectoryInfo targetDirectory = new DirectoryInfo(Path.Combine(this.Destination.FullName, targetFullName));
                string        targetPath      = Path.Combine(targetDirectory.FullName, file.Name);

                // Write verbose output about what we're doing
                Console.WriteLine("{0}: {1}\t{2}\t{3}\t{4}\t{5}", action, file.Name, info.Type, info.Taken, info.CameraMake, info.CameraModel);

                if (this.Options.VerboseOutput)
                {
                    if (this.Options.CopyInsteadOfMove)
                    {
                        Console.WriteLine("Copying {0} to {1}", file.Name, targetPath);
                    }
                    else
                    {
                        Console.WriteLine("Moving {0} to {1}", file.Name, targetPath);
                    }
                }

                // Check to see if the destination already exists
                FileInfo destination = new FileInfo(targetPath);
                if (destination.Exists)
                {
                    FileAlreadyExists(file, targetPath);
                }
                else
                {
                    if (!Options.Simulate)
                    {
                        targetDirectory.Create();
                        DoFileAction(file, targetPath);
                    }
                }
            }
            else if (Options.VerboseOutput && moveThisFile)
            {
                Console.WriteLine("Skipping file (no date taken): " + info.Filename);
            }
            else if (Options.VerboseOutput)
            {
                Console.WriteLine("Skipping file (not included type): " + info.Filename);
            }

            return(dateTaken);
        }
示例#2
0
 public void Add(MediaInfo parsedFile)
 {
     memoryCache[ComputeSha256Hash(parsedFile.FullPath)] = parsedFile;
     HasChanged = true;
 }