private PropertiesChangeResult UpdateImageAttributes(bool needToSetDateTaken, bool needToSetTitle)
        {
            DateTime valueForDateTaken = DateTime.MinValue;

            if (needToSetDateTaken)
            {
                valueForDateTaken = GetValueForDateTaken();
            }

            string valueForTitle = null;

            if (needToSetTitle)
            {
                valueForTitle = GetValueForTitle();
            }

            if (string.IsNullOrEmpty(valueForTitle) && valueForDateTaken == DateTime.MinValue)
            {
                string expectedToChangeValue = string.Concat(needToSetDateTaken ? "date taken " : null, needToSetTitle ? "title" : null);
                s_logger.Debug($"not changing {m_imageFileName} because didn't find meaningful values (expected to change {expectedToChangeValue})");
                return(PropertiesChangeResult.NoNeed);
            }

            var  runExifTool = new RunExifTool(m_imageFileName, m_simulationMode);
            bool operationResult;

            if (!string.IsNullOrEmpty(valueForTitle) && valueForDateTaken != DateTime.MinValue)
            {
                operationResult = runExifTool.SetDateAndTitle(valueForTitle, valueForDateTaken);
            }
            else if (valueForDateTaken == DateTime.MinValue)
            {
                operationResult = runExifTool.SetTitle(valueForTitle);
            }
            else
            {
                operationResult = runExifTool.SetDateTaken(valueForDateTaken);
            }

            return(operationResult ? PropertiesChangeResult.Success : PropertiesChangeResult.Failure);
        }
예제 #2
0
        private Dictionary <string, string> LoadImageProperties()
        {
            LoadFileProperties();
            AddFileSystemProperties();
            var    runExifTool     = new RunExifTool(m_imageFileName, m_simulationMode);
            string imageProperties = runExifTool.GetImageProperties();

            if (!string.IsNullOrEmpty(imageProperties))
            {
                m_propsSeparated = imageProperties.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

                FillExifProperty(ImagePropertyIds.Title);
                FillExifProperty(ImagePropertyIds.ExifToolTitle);
                FillExifProperty(ImagePropertyIds.ExifToolSubject);
                FillExifProperty(ImagePropertyIds.ExifDateTaken);
            }
            else
            {
                s_logger.Debug($"didn't get image properties through Exif for {m_imageFileName}");
            }

            return(m_imageProperties);
        }
        private bool ChangeImageTitle(string valueForTitle)
        {
            var runExifTool = new RunExifTool(m_imageFileName, m_simulationMode);

            return(runExifTool.SetTitle(valueForTitle));
        }