コード例 #1
0
        /// <summary>
        /// Copies media files with new names and dates.
        /// </summary>
        static public void SaveFiles(string directory, List <Camera> cameras, ProgressBox progressBox)
        {
            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }
            var fileCount = cameras.Sum(item => item.Files.Count);

            if (progressBox != null)
            {
                progressBox.Init("Copying " + fileCount + " files.", fileCount);
            }
            foreach (var camera in cameras)
            {
                foreach (var file in camera.Files)
                {
                    Debug.Assert(File.Exists(file.FilePath));
                    SaveFile(file, GetTargetPath(directory, file));
                    if (progressBox != null)
                    {
                        progressBox.Tick();
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Analyzes media files and returns them inside their cameras.
        /// </summary>
        static public List <Camera> GetCamerasWithMediaFiles(string path, ProgressBox progressBox)
        {
            var cameras = new List <Camera>();

            Debug.Assert(Directory.Exists(path));
            var filePaths = Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories);

            if (progressBox != null)
            {
                progressBox.Init("Analyzing " + filePaths.Count() + " files.", filePaths.Count());
            }
            foreach (var filePath in filePaths)
            {
                Debug.Assert(File.Exists(filePath));
                var file   = new MediaFile(filePath);
                var camera = Analyze(file);
                Debug.Assert(cameras != null);
                if (!cameras.Contains(camera))
                {
                    cameras.Add(camera);
                }
                cameras.Find(x => x.Equals(camera)).Files.Add(file);
                if (progressBox != null)
                {
                    progressBox.Tick();
                }
            }
            return(cameras);
        }
コード例 #3
0
ファイル: Renamer.cs プロジェクト: JereKuusela/PhotoRenamer
        /// <summary>
        /// Renames media files (inside cameras) based on their date.
        /// Without date, "NULL" is added to find those files easily.
        /// </summary>
        static public void RenameFiles(List <Camera> cameras, ProgressBox progressBox, string defaultBame)
        {
            var fileCount = cameras.Sum(item => item.Files.Count);

            if (progressBox != null)
            {
                progressBox.Init("Renaming " + fileCount + " files.", fileCount);
            }
            foreach (var camera in cameras)
            {
                foreach (var mediaFile in camera.Files)
                {
                    Debug.Assert(File.Exists(mediaFile.FilePath));
                    if ((mediaFile.IsDateReal || defaultBame.Length == 0) && mediaFile.NewDate.Ticks > 0)
                    {
                        mediaFile.NewName = mediaFile.NewDate.ToString(MediaFile.STRING_FORMAT);
                    }
                    else if (defaultBame.Length > 0)
                    {
                        mediaFile.NewName = defaultBame;
                    }
                    else
                    {
                        mediaFile.NewName = "NULL_" + Path.GetFileNameWithoutExtension(mediaFile.FilePath);
                    }
                    if (camera.Tag.Length > 0)
                    {
                        mediaFile.NewName += "_" + camera.Tag;
                    }
                    mediaFile.NewName += Path.GetExtension(mediaFile.FilePath);
                    if (progressBox != null)
                    {
                        progressBox.Tick();
                    }
                }
            }
        }