예제 #1
0
        private void openTitleDateButton_Click(object sender, EventArgs e)
        {
            clickedHardCodedDate = false;
            var form = new TitleDateForm();

            form.OnSave += res => imageNameConfig = res;
            form.Show(this);
        }
예제 #2
0
        public void FixDates(List <string> files, List <DateType> datesToChange, ImageNameConfig imageNameConfig = null, DateTime?hardCodedDate = null)
        {
            Console.Clear();
            //Zowel datum van file als name getten
            //Naar priority date kijken voor welke ge moet pakken (de oudste)
            //datesToChange alteren
            for (int k = 0; k < files.Count; k++)
            {
                string   file     = files[k];
                DateTime now      = DateTime.Now;
                DateTime nameDate = now;
                try
                {
                    //Get date from name
                    if (imageNameConfig != null)
                    {
                        string[] formats = imageNameConfig.DateFormats.ToArray();
                        for (int i = 0; i < imageNameConfig.Scenarios.Count; i++)
                        {
                            string fileName = Path.GetFileNameWithoutExtension(file);

                            Scenario scenario = imageNameConfig.Scenarios[i];
                            if (scenario.Conditions.Any(x => x.Compile()(fileName)))
                            {
                                for (int j = 0; j < scenario.Actions.Count; j++)
                                {
                                    Action action = scenario.Actions[j];
                                    fileName = Regex.Replace(
                                        fileName,
                                        Regex.Escape(action.OldValue),
                                        action.NewValue.Replace("$", "$$"),
                                        RegexOptions.IgnoreCase
                                        );
                                }
                            }

                            DateTime temp;
                            bool     titleSuccess = DateTime.TryParseExact(fileName, formats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out temp);
                            if (titleSuccess)
                            {
                                nameDate = temp;
                                break;
                            }
                        }
                    }

                    //Get date from file
                    DateTime takenDate        = now;
                    DateTime createdDate      = now;
                    DateTime modifiedDate     = now;
                    DateTime mediaCreatedDate = now;

                    modifiedDate = File.GetLastWriteTime(file);
                    createdDate  = File.GetCreationTime(file);

                    try
                    {
                        var directories     = ImageMetadataReader.ReadMetadata(file);
                        var subIfdDirectory = directories.OfType <ExifSubIfdDirectory>().FirstOrDefault();
                        if (subIfdDirectory != null)
                        {
                            takenDate = subIfdDirectory.GetDateTime(ExifDirectoryBase.TagDateTimeOriginal);
                        }
                    }
                    catch (Exception e)
                    {
                    }

                    DateTime earliest = new List <DateTime> {
                        nameDate, createdDate, takenDate, modifiedDate
                    }.Min();
                    if (hardCodedDate != null)
                    {
                        earliest = hardCodedDate ?? earliest;
                    }

                    if (earliest.Ticks == now.Ticks)
                    {
                        Console.WriteLine($"{k}: {File.GetLastWriteTime(file)} -> BAD \t\t\t\t: {Path.GetFileName(file)}");
                        continue;
                    }
                    Console.WriteLine($"{k}: {File.GetLastWriteTime(file)} -> {earliest}: \t\t{Path.GetFileName(file)}");
                    File.SetLastWriteTime(file, earliest);
                    File.SetCreationTime(file, earliest);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"{k}: {File.GetLastWriteTime(file)} -> ERROR: \t\t{Path.GetFileName(file)}");
                }
            }
        }
예제 #3
0
 public TitleDateForm()
 {
     InitializeComponent(); imageNameConfig = new ImageNameConfig();
 }