public static int PopulateFile(DataGridView dataGridView, FileEntryAttribute fileEntryAttribute, ShowWhatColumns showWhatColumns, Metadata metadataAutoCorrected, bool onlyRefresh) { //----------------------------------------------------------------- //Chech if need to stop if (GlobalData.IsApplicationClosing) { return(-1); } if (!DataGridViewHandler.GetIsAgregated(dataGridView)) { return(-1); //Not default columns or rows added } if (DataGridViewHandler.GetIsPopulatingFile(dataGridView)) { return(-1); //In progress doing so } //Check if file is in DataGridView if (!DataGridViewHandler.DoesColumnFilenameExist(dataGridView, fileEntryAttribute.FileFullPath)) { return(-1); } //When file found, Tell it's populating file, avoid two process updates DataGridViewHandler.SetIsPopulatingFile(dataGridView, true); //----------------------------------------------------------------- FileEntryBroker fileEntryBrokerReadVersion = fileEntryAttribute.GetFileEntryBroker(MetadataBrokerType.ExifTool); Image thumbnail = DatabaseAndCacheThumbnail.ReadThumbnailFromCacheOnly(fileEntryBrokerReadVersion); if (thumbnail == null && metadataAutoCorrected != null) { thumbnail = DatabaseAndCacheThumbnail.ReadThumbnailFromCacheOnly(metadataAutoCorrected.FileEntry); } Metadata metadataExiftool = DatabaseAndCacheMetadataExiftool.ReadMetadataFromCacheOnly(fileEntryBrokerReadVersion); if (metadataExiftool != null) { metadataExiftool = new Metadata(metadataExiftool); } if (metadataAutoCorrected != null) { metadataExiftool = metadataAutoCorrected; //If AutoCorrect is run, use AutoCorrect values. Needs to be after DataGridViewHandler.AddColumnOrUpdateNew, so orignal metadata stored will not be overwritten } ReadWriteAccess readWriteAccessColumn = (FileEntryVersionHandler.IsReadOnlyType(fileEntryAttribute.FileEntryVersion) || metadataExiftool == null) ? ReadWriteAccess.ForceCellToReadOnly : ReadWriteAccess.AllowCellReadAndWrite; int columnIndex = DataGridViewHandler.AddColumnOrUpdateNew( dataGridView, fileEntryAttribute, thumbnail, metadataExiftool, readWriteAccessColumn, showWhatColumns, DataGridViewGenericCellStatus.DefaultEmpty(), out FileEntryVersionCompare fileEntryVersionCompareReason); //Chech if populated and new refresh data if (onlyRefresh && FileEntryVersionHandler.NeedUpdate(fileEntryVersionCompareReason) && !DataGridViewHandler.IsColumnPopulated(dataGridView, columnIndex)) { fileEntryVersionCompareReason = FileEntryVersionCompare.LostNoneEqualFound_ContinueSearch; //No need to populate } //----------------------------------------------------------------- if (FileEntryVersionHandler.NeedUpdate(fileEntryVersionCompareReason)) { //Media DataGridViewHandler.AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia), false); DataGridViewHandler.AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagMediaDateTaken), TimeZoneLibrary.ToStringSortable(metadataExiftool?.MediaDateTaken), false, false); DataGridViewHandler.AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagGPSLocationDateTime), TimeZoneLibrary.ToStringW3CDTF_UTC_Convert(metadataExiftool?.LocationDateTime), false, false); //Suggestion header DataGridViewHandler.AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerSuggestion), false); //Dates and/or time in filename DataGridViewHandler.AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerDatesTimeInFilename), false); FileDateTimeReader fileDateTimeReader = new FileDateTimeReader(Properties.Settings.Default.RenameDateFormats); List <DateTime> dates = fileDateTimeReader.ListAllDateTimes(Path.GetFileNameWithoutExtension(fileEntryAttribute.FileFullPath)); for (int i = 0; i < dates.Count; i++) { DataGridViewHandler.AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerDatesTimeInFilename, tagDatesFoundInFilename + (i + 1).ToString()), TimeZoneLibrary.ToStringSortable(dates[i]), true, false); } //Metadata DataGridViewHandler.AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMetadataDates), false); DataGridViewHandler.AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMetadataDates, tagFileDate), TimeZoneLibrary.ToStringW3CDTF(metadataExiftool?.FileDate), true, false); DataGridViewHandler.AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMetadataDates, tagFileSmartDate), TimeZoneLibrary.ToStringW3CDTF(metadataExiftool?.FileSmartDate(Properties.Settings.Default.RenameDateFormats)), true, false); DataGridViewHandler.AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMetadataDates, tagFileDateCreated), TimeZoneLibrary.ToStringW3CDTF(metadataExiftool?.FileDateCreated), true, false); DataGridViewHandler.AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMetadataDates, tagFileDateModified), TimeZoneLibrary.ToStringW3CDTF(metadataExiftool?.FileDateModified), true, false); DataGridViewHandler.AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMetadataDates, tagFileLastAccessed), TimeZoneLibrary.ToStringW3CDTF(metadataExiftool?.FileDateAccessed), true, false); //BeginInvoke(new Action<DataGridView, FileEntryAttribute>(PopulateExiftoolData), dataGridView, fileEntryAttribute); //PopulateExiftoolData(dataGridView, fileEntryAttribute); PopulateTimeZone(dataGridView, columnIndex, null); DataGridViewHandler.SetColumnPopulatedFlag(dataGridView, columnIndex, true); } //----------------------------------------------------------------- DataGridViewHandler.SetIsPopulatingFile(dataGridView, false); //----------------------------------------------------------------- return(columnIndex); }
private static void PopulateKeywords(DataGridView dataGridView, Metadata metadata, int columnIndex, MetadataBrokerType metadataBrokerType, FileEntryAttribute fileEntryAttribute) { foreach (KeywordTag tag in metadata.PersonalKeywordTags) { if (tag.Confidence >= MediaAiTagConfidence) { int rowIndex = AddRowKeywords(dataGridView, columnIndex, new DataGridViewGenericRow(headerKeywords, tag.Keyword, ReadWriteAccess.ForceCellToReadOnly), tag.Keyword, new DataGridViewGenericCellStatus(MetadataBrokerType.Empty, SwitchStates.Undefine, true), true); List <KeywordTag> keywordTags = new List <KeywordTag>(); keywordTags.Add(new KeywordTag(tag.Keyword)); List <string> newKeywords = AutoKeywordHandler.NewKeywords(AutoKeywordConvertions, null, null, null, null, null, keywordTags); DataGridViewHandler.SetCellToolTipText(dataGridView, columnIndex, rowIndex, "Running AutoCorrect will add these keywords", newKeywords); //Updated default cell status with new staus DataGridViewGenericCellStatus dataGridViewGenericCellStatus = new DataGridViewGenericCellStatus(DataGridViewHandler.GetCellStatus(dataGridView, columnIndex, rowIndex)); dataGridViewGenericCellStatus.MetadataBrokerType |= metadataBrokerType; if (fileEntryAttribute.FileEntryVersion != FileEntryVersion.CompatibilityFixedAndAutoUpdated && fileEntryAttribute.FileEntryVersion != FileEntryVersion.MetadataToSave) { if (dataGridViewGenericCellStatus.SwitchState == SwitchStates.Undefine) { dataGridViewGenericCellStatus.SwitchState = (dataGridViewGenericCellStatus.MetadataBrokerType & MetadataBrokerType.ExifTool) == MetadataBrokerType.ExifTool ? SwitchStates.On : SwitchStates.Off; } } else { dataGridViewGenericCellStatus.SwitchState = (dataGridViewGenericCellStatus.MetadataBrokerType & MetadataBrokerType.ExifTool) == MetadataBrokerType.ExifTool ? SwitchStates.On : SwitchStates.Off; DataGridViewGenericRow dataGridViewGenericRow = DataGridViewHandler.GetRowDataGridViewGenericRow(dataGridView, rowIndex); if (dataGridViewGenericRow != null && dataGridViewGenericRow.ReadWriteAccess == ReadWriteAccess.AllowCellReadAndWrite) { dataGridViewGenericRow.ReadWriteAccess = ReadWriteAccess.ForceCellToReadOnly; for (int columnIndexUpdate = 0; columnIndexUpdate < DataGridViewHandler.GetColumnCount(dataGridView); columnIndexUpdate++) { DataGridViewHandler.SetCellReadOnlyDependingOfStatus(dataGridView, columnIndexUpdate, rowIndex, dataGridViewGenericCellStatus); } } } DataGridViewHandler.SetCellStatus(dataGridView, columnIndex, rowIndex, dataGridViewGenericCellStatus, false); } } //If updated, check if any keyword are removed from the list int keywordsStarts = DataGridViewHandler.GetRowHeaderItemStarts(dataGridView, headerKeywords); int keywordsEnds = DataGridViewHandler.GetRowHeaderItemsEnds(dataGridView, headerKeywords); for (int rowIndex = keywordsStarts; rowIndex <= keywordsEnds; rowIndex++) { DataGridViewGenericCellStatus dataGridViewGenericCellStatus = DataGridViewHandler.GetCellStatus(dataGridView, columnIndex, rowIndex); if ((dataGridViewGenericCellStatus.MetadataBrokerType & metadataBrokerType) == metadataBrokerType) { DataGridViewGenericRow dataGridViewGenericRow = DataGridViewHandler.GetRowDataGridViewGenericRow(dataGridView, rowIndex); if (!metadata.PersonalKeywordTags.Contains(new KeywordTag(dataGridViewGenericRow.RowName))) { if ((dataGridViewGenericCellStatus.MetadataBrokerType & metadataBrokerType) == MetadataBrokerType.ExifTool && dataGridViewGenericCellStatus.SwitchState == SwitchStates.On) { dataGridViewGenericCellStatus.SwitchState = SwitchStates.Undefine; } dataGridViewGenericCellStatus.MetadataBrokerType &= ~metadataBrokerType; //Remove flag if line deleted DataGridViewHandler.SetCellStatus(dataGridView, columnIndex, rowIndex, dataGridViewGenericCellStatus, false); } } } }
public static int PopulateFile(DataGridView dataGridView, FileEntryAttribute fileEntryAttribute, ShowWhatColumns showWhatColumns, Metadata metadataAutoCorrected, bool onlyRefresh) { //----------------------------------------------------------------- //Chech if need to stop if (GlobalData.IsApplicationClosing) { return(-1); } if (!DataGridViewHandler.GetIsAgregated(dataGridView)) { return(-1); //Not default columns or rows added } if (DataGridViewHandler.GetIsPopulatingFile(dataGridView)) { return(-1); //In progress doing so } //Check if file is in DataGridView if (!DataGridViewHandler.DoesColumnFilenameExist(dataGridView, fileEntryAttribute.FileFullPath)) { return(-1); } //When file found, Tell it's populating file, avoid two process updates DataGridViewHandler.SetIsPopulatingFile(dataGridView, true); //----------------------------------------------------------------- FileEntryBroker fileEntryBrokerReadVersion = fileEntryAttribute.GetFileEntryBroker(MetadataBrokerType.ExifTool); Image thumbnail = DatabaseAndCacheThumbnail.ReadThumbnailFromCacheOnly(fileEntryBrokerReadVersion); if (thumbnail == null && metadataAutoCorrected != null) { thumbnail = DatabaseAndCacheThumbnail.ReadThumbnailFromCacheOnly(metadataAutoCorrected.FileEntry); } Metadata metadataExiftool = DatabaseAndCacheMetadataExiftool.ReadMetadataFromCacheOnly(fileEntryBrokerReadVersion); if (metadataExiftool != null) { metadataExiftool = new Metadata(metadataExiftool); } if (metadataAutoCorrected != null) { metadataExiftool = metadataAutoCorrected; //If AutoCorrect is run, use AutoCorrect values. Needs to be after DataGridViewHandler.AddColumnOrUpdateNew, so orignal metadata stored will not be overwritten } ReadWriteAccess readWriteAccessColumn = (FileEntryVersionHandler.IsReadOnlyType(fileEntryAttribute.FileEntryVersion) || metadataExiftool == null) ? ReadWriteAccess.ForceCellToReadOnly : ReadWriteAccess.AllowCellReadAndWrite; int columnIndex = DataGridViewHandler.AddColumnOrUpdateNew( dataGridView, fileEntryAttribute, thumbnail, metadataExiftool, readWriteAccessColumn, showWhatColumns, DataGridViewGenericCellStatus.DefaultEmpty(), out FileEntryVersionCompare fileEntryVersionCompareReason); //Chech if populated and new refresh data if (onlyRefresh && FileEntryVersionHandler.NeedUpdate(fileEntryVersionCompareReason) && !DataGridViewHandler.IsColumnPopulated(dataGridView, columnIndex)) { fileEntryVersionCompareReason = FileEntryVersionCompare.LostNoneEqualFound_ContinueSearch; //No need to populate } //----------------------------------------------------------------- if (FileEntryVersionHandler.NeedUpdate(fileEntryVersionCompareReason)) { DataGridViewHandler.SetDataGridViewAllowUserToAddRows(dataGridView, true); //Media int rowIndex; AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia), false); rowIndex = AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagAlbum), metadataExiftool?.PersonalAlbum, false); List <string> newKeywords = AutoKeywordHandler.NewKeywords(AutoKeywordConvertions, null, null, metadataExiftool?.PersonalAlbum, null, null, null); DataGridViewHandler.SetCellToolTipText(dataGridView, columnIndex, rowIndex, "Running AutoCorrect will add these keywords", newKeywords); rowIndex = AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagTitle), metadataExiftool?.PersonalTitle, false); newKeywords = AutoKeywordHandler.NewKeywords(AutoKeywordConvertions, null, metadataExiftool?.PersonalTitle, null, null, null, null); DataGridViewHandler.SetCellToolTipText(dataGridView, columnIndex, rowIndex, "Running AutoCorrect will add these keywords", newKeywords); rowIndex = AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagDescription), metadataExiftool?.PersonalDescription, false); newKeywords = AutoKeywordHandler.NewKeywords(AutoKeywordConvertions, null, null, null, metadataExiftool?.PersonalDescription, null, null); DataGridViewHandler.SetCellToolTipText(dataGridView, columnIndex, rowIndex, "Running AutoCorrect will add these keywords", newKeywords); rowIndex = AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagComments), metadataExiftool?.PersonalComments, false); newKeywords = AutoKeywordHandler.NewKeywords(AutoKeywordConvertions, null, null, null, null, metadataExiftool?.PersonalComments, null); DataGridViewHandler.SetCellToolTipText(dataGridView, columnIndex, rowIndex, "Running AutoCorrect will add these keywords", newKeywords); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagRating), metadataExiftool?.PersonalRating, false); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagAuthor), metadataExiftool?.PersonalAuthor, false); // Microsoft Phontos AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMicrosoftPhotos), false); Metadata metadataMicrosoftPhotos = null; if (metadataExiftool != null) { metadataMicrosoftPhotos = DatabaseAndCacheMetadataMicrosoftPhotos.ReadMetadataFromCacheOrDatabase(new FileEntryBroker(fileEntryBrokerReadVersion, MetadataBrokerType.MicrosoftPhotos)); } AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMicrosoftPhotos, tagAlbum), metadataMicrosoftPhotos?.PersonalAlbum, true); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMicrosoftPhotos, tagTitle), metadataMicrosoftPhotos?.PersonalTitle, true); // Folder path as Album AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerFolder), false); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerFolder, tagAlbum), new DirectoryInfo(fileEntryBrokerReadVersion.Directory).Name, true); //Windows Live Photo Gallery AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerWindowsLivePhotoGallery), false); Metadata metadataWindowsLivePhotoGallery = null; if (metadataExiftool != null) { metadataWindowsLivePhotoGallery = DatabaseAndCacheMetadataWindowsLivePhotoGallery.ReadMetadataFromCacheOrDatabase(new FileEntryBroker(fileEntryBrokerReadVersion, MetadataBrokerType.WindowsLivePhotoGallery)); } AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerWindowsLivePhotoGallery, tagTitle), metadataWindowsLivePhotoGallery?.PersonalTitle, true); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerWindowsLivePhotoGallery, tagRating), metadataWindowsLivePhotoGallery?.PersonalRating, true); // WebScarping AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerWebScraping), false); Metadata metadataWebScraping = null; if (metadataExiftool != null) { metadataWebScraping = DatabaseAndCacheMetadataExiftool.ReadWebScraperMetadataFromCacheOrDatabase(new FileEntryBroker(fileEntryBrokerReadVersion, MetadataBrokerType.WebScraping)); } AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerWebScraping, tagAlbum), metadataWebScraping?.PersonalAlbum, true); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerWebScraping, tagTitle), metadataWebScraping?.PersonalTitle, true); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerKeywords), false); if (fileEntryAttribute.FileEntryVersion == FileEntryVersion.CompatibilityFixedAndAutoUpdated || fileEntryAttribute.FileEntryVersion == FileEntryVersion.MetadataToSave) { int keywordsStarts = DataGridViewHandler.GetRowHeaderItemStarts(dataGridView, headerKeywords); int keywordsEnds = DataGridViewHandler.GetRowHeaderItemsEnds(dataGridView, headerKeywords); for (int rowIndexToClean = keywordsStarts; rowIndexToClean <= keywordsEnds; rowIndexToClean++) { DataGridViewGenericCellStatus dataGridViewGenericCellStatus = new DataGridViewGenericCellStatus(MetadataBrokerType.Empty, SwitchStates.Undefine, true); DataGridViewHandler.SetCellReadOnlyDependingOfStatus(dataGridView, columnIndex, rowIndexToClean, dataGridViewGenericCellStatus); DataGridViewHandler.SetCellStatus(dataGridView, columnIndex, rowIndexToClean, dataGridViewGenericCellStatus, false); } } if (metadataExiftool != null) { PopulateKeywords(dataGridView, metadataExiftool, columnIndex, metadataExiftool.Broker, fileEntryAttribute); } if (metadataMicrosoftPhotos != null) { PopulateKeywords(dataGridView, metadataMicrosoftPhotos, columnIndex, metadataMicrosoftPhotos.Broker, fileEntryAttribute); } if (metadataWindowsLivePhotoGallery != null) { PopulateKeywords(dataGridView, metadataWindowsLivePhotoGallery, columnIndex, metadataWindowsLivePhotoGallery.Broker, fileEntryAttribute); } if (metadataWebScraping != null) { PopulateKeywords(dataGridView, metadataWebScraping, columnIndex, metadataWebScraping.Broker, fileEntryAttribute); } DataGridViewHandler.SetColumnPopulatedFlag(dataGridView, columnIndex, true); } //----------------------------------------------------------------- DataGridViewHandler.SetIsPopulatingFile(dataGridView, false); //----------------------------------------------------------------- return(columnIndex); }
private static int AddRowKeywords(DataGridView dataGridView, int columnIndex, DataGridViewGenericRow dataGridViewGenericDataRow, object value, DataGridViewGenericCellStatus dataGridViewGenericCellStatusDefaults, bool sort) { int rowIndex = DataGridViewHandler.AddRow(dataGridView, columnIndex, dataGridViewGenericDataRow, value, dataGridViewGenericCellStatusDefaults, sort); return(rowIndex); }
private static int AddRowRegion(DataGridView dataGridView, MetadataBrokerType metadataBrokerType, Metadata metadata, int columnIndex, DataGridViewGenericRow dataGridViewGenericRow, RegionStructure regionStructureToAdd, DataGridViewGenericCellStatus dataGridViewGenericCellStatusDefaults) { #region Find Row to Edit or Where to add bool rowFound = false; int lastHeaderRowFound = -1; bool rowBlankFound = false; int firstBlankFound = -1; int rowIndexRowFound = -1; int startSearchRow = 0; for (int rowIndex = startSearchRow; rowIndex < DataGridViewHandler.GetRowCountWithoutEditRow(dataGridView); rowIndex++) { DataGridViewGenericRow dataGridViewGenericRowCheck = DataGridViewHandler.GetRowDataGridViewGenericRow(dataGridView, rowIndex); if (!dataGridViewGenericRowCheck.IsHeader && !dataGridViewGenericRow.IsHeader && //Is row dataGridViewGenericRowCheck.HeaderName == dataGridViewGenericRow.HeaderName && dataGridViewGenericRowCheck.RowName == dataGridViewGenericRow.RowName) { //Check if region match RegionStructure regionStructureInCell = DataGridViewHandler.GetCellValue(dataGridView, columnIndex, rowIndex) as RegionStructure; if (regionStructureToAdd != null && regionStructureInCell != null) { if (metadata != null && metadata.MediaHeight != null && metadata.MediaWidth != null) { Size imageSize = new Size((int)metadata.MediaWidth, (int)metadata.MediaHeight); Rectangle mediaRectangleToAdd = regionStructureToAdd.GetImageRegionPixelRectangle(imageSize); Rectangle mediaRectangleCell = regionStructureInCell.GetImageRegionPixelRectangle(imageSize); if (RegionStructure.RectangleEqual(mediaRectangleToAdd, mediaRectangleCell)) { rowFound = true; rowIndexRowFound = rowIndex; break; // return rowIndex; } } } if (regionStructureInCell == null) { rowBlankFound = true; if (firstBlankFound == -1) { firstBlankFound = rowIndex; } } } #region Sorting if (dataGridViewGenericRow.IsHeader && //A normal row is add (not header) //dataGridViewGenericRowCheck.IsHeader && //If header, then check if same header name dataGridViewGenericRow.HeaderName.CompareTo(dataGridViewGenericRowCheck.HeaderName) >= 0) { lastHeaderRowFound = rowIndex; //Remember head row found } //Add sorted if (!dataGridViewGenericRow.IsHeader && //A normal row is add (not header) dataGridViewGenericRowCheck.IsHeader && //If header, then check if same header name dataGridViewGenericRowCheck.HeaderName == dataGridViewGenericRow.HeaderName) { lastHeaderRowFound = rowIndex; //Remember head row found } if (!dataGridViewGenericRow.IsHeader && //A normal row is add (not header) !dataGridViewGenericRowCheck.IsHeader && //If header, then check if same header name dataGridViewGenericRowCheck.HeaderName == dataGridViewGenericRow.HeaderName && dataGridViewGenericRow.RowName.CompareTo(dataGridViewGenericRowCheck.RowName) >= 0) { lastHeaderRowFound = rowIndex; //If lower or eaual, remeber last } #endregion } #endregion #region Update row or Add int rowIndexUsed; if (rowFound) //Found row and cell with correct region { rowIndexUsed = rowIndexRowFound; RegionStructure regionStructureInCell = DataGridViewHandler.GetCellRegionStructure(dataGridView, columnIndex, rowIndexUsed); if (regionStructureInCell == null || regionStructureInCell?.Thumbnail == null || (metadata.Broker == MetadataBrokerType.ExifTool && regionStructureToAdd.Thumbnail != null)) { DataGridViewHandler.SetCellValue(dataGridView, columnIndex, rowIndexUsed, regionStructureToAdd, false); //Prioritize ExifTool } } else if (rowBlankFound) //Found row and but no cell with correct region { rowIndexUsed = firstBlankFound; RegionStructure regionStructureInCell = DataGridViewHandler.GetCellRegionStructure(dataGridView, columnIndex, rowIndexUsed); if (regionStructureInCell == null || regionStructureInCell?.Thumbnail == null || (metadata.Broker == MetadataBrokerType.ExifTool && regionStructureToAdd.Thumbnail != null)) { DataGridViewHandler.SetCellValue(dataGridView, columnIndex, rowIndexUsed, regionStructureToAdd, false); //Prioritize ExifTool } } else //No postion found, add on sorted location { //lastHeaderRowFound rowIndexUsed = DataGridViewHandler.AddRow(dataGridView, columnIndex, dataGridViewGenericRow, DataGridViewHandler.GetFavoriteList(dataGridView), regionStructureToAdd, dataGridViewGenericCellStatusDefaults, lastHeaderRowFound, true, true, true); } #endregion SetCellDefault(dataGridView, metadataBrokerType, columnIndex, rowIndexUsed); //No DirtyFlagSet DataGridViewHandler.SetCellRowHeight(dataGridView, rowIndexUsed, DataGridViewHandler.GetCellRowHeight(dataGridView)); #region Delete from suggestion DataGridViewHandler.DeleteRow(dataGridView, headerPeopleSuggestion, regionStructureToAdd.Name); DataGridViewHandler.DeleteRow(dataGridView, headerPeopleMostUsed, regionStructureToAdd.Name); #endregion return(rowIndexUsed); }
public static int PopulateFile(DataGridView dataGridView, FileEntryAttribute fileEntryAttribute, ShowWhatColumns showWhatColumns, Metadata metadataAutoCorrected, bool onlyRefresh) { //----------------------------------------------------------------- //Chech if need to stop if (GlobalData.IsApplicationClosing) { return(-1); } if (!DataGridViewHandler.GetIsAgregated(dataGridView)) { return(-1); //Not default columns or rows added } if (DataGridViewHandler.GetIsPopulatingFile(dataGridView)) { return(-1); //In progress doing so } //Check if file is in DataGridView, and needs updated if (!DataGridViewHandler.DoesColumnFilenameExist(dataGridView, fileEntryAttribute.FileFullPath)) { return(-1); } //When file found, Tell it's populating file, avoid two process updates DataGridViewHandler.SetIsPopulatingFile(dataGridView, true); //----------------------------------------------------------------- List <string> regionNamesAddedPeople = new List <string>(); List <string> regionNamesAddedTopMost = new List <string>(); List <string> regionNamesAddedDateInterval = new List <string>(); for (int rowIndex = 0; rowIndex < DataGridViewHandler.GetRowCountWithoutEditRow(dataGridView); rowIndex++) { DataGridViewGenericRow dataGridViewGenericRow = DataGridViewHandler.GetRowDataGridViewGenericRow(dataGridView, rowIndex); if (dataGridViewGenericRow != null && !dataGridViewGenericRow.IsHeader) { if (dataGridViewGenericRow.HeaderName == headerPeople && !regionNamesAddedPeople.Contains(dataGridViewGenericRow.RowName)) { regionNamesAddedPeople.Add(dataGridViewGenericRow.RowName); } else if (dataGridViewGenericRow.HeaderName == headerPeopleSuggestion && !regionNamesAddedDateInterval.Contains(dataGridViewGenericRow.RowName)) { regionNamesAddedDateInterval.Add(dataGridViewGenericRow.RowName); } else if (dataGridViewGenericRow.HeaderName == headerPeopleMostUsed && !regionNamesAddedTopMost.Contains(dataGridViewGenericRow.RowName)) { regionNamesAddedTopMost.Add(dataGridViewGenericRow.RowName); } } } //----------------------------------------------------------------- FileEntryBroker fileEntryBrokerReadVersion = fileEntryAttribute.GetFileEntryBroker(MetadataBrokerType.ExifTool); Image thumbnail = DatabaseAndCacheThumbnail.ReadThumbnailFromCacheOnly(fileEntryBrokerReadVersion); if (thumbnail == null && metadataAutoCorrected != null) { thumbnail = DatabaseAndCacheThumbnail.ReadThumbnailFromCacheOnly(metadataAutoCorrected.FileEntry); } Metadata metadataExiftool = DatabaseAndCacheMetadataExiftool.ReadMetadataFromCacheOnly(fileEntryBrokerReadVersion); if (metadataExiftool != null) { metadataExiftool = new Metadata(metadataExiftool); } if (metadataAutoCorrected != null) { metadataExiftool = metadataAutoCorrected; //If AutoCorrect is run, use AutoCorrect values. Needs to be after DataGridViewHandler.AddColumnOrUpdateNew, so orignal metadata stored will not be overwritten } ReadWriteAccess readWriteAccessColumn = (FileEntryVersionHandler.IsReadOnlyType(fileEntryAttribute.FileEntryVersion) || metadataExiftool == null) ? ReadWriteAccess.ForceCellToReadOnly : ReadWriteAccess.AllowCellReadAndWrite; int columnIndex = DataGridViewHandler.AddColumnOrUpdateNew( dataGridView, fileEntryAttribute, thumbnail, metadataExiftool, readWriteAccessColumn, showWhatColumns, DataGridViewGenericCellStatus.DefaultEmpty(), out FileEntryVersionCompare fileEntryVersionCompareReason); //Chech if populated and new refresh data if (onlyRefresh && FileEntryVersionHandler.NeedUpdate(fileEntryVersionCompareReason) && !DataGridViewHandler.IsColumnPopulated(dataGridView, columnIndex)) { fileEntryVersionCompareReason = FileEntryVersionCompare.LostNoneEqualFound_ContinueSearch; //No need to populate } //----------------------------------------------------------------- if (FileEntryVersionHandler.NeedUpdate(fileEntryVersionCompareReason)) { DataGridViewHandler.SetDataGridViewAllowUserToAddRows(dataGridView, true); AddRowHeader(dataGridView, columnIndex, new DataGridViewGenericRow(headerPeople), false); //Remove column data, due to Populate People append data - for (int rowIndex = 0; rowIndex < DataGridViewHandler.GetRowCountWithoutEditRow(dataGridView); rowIndex++) { DataGridViewHandler.SetCellValue(dataGridView, columnIndex, rowIndex, null, false); DataGridViewGenericCellStatus dataGridViewGenericCellStatusDefault = new DataGridViewGenericCellStatus(MetadataBrokerType.Empty, SwitchStates.Disabled, true); DataGridViewHandler.SetCellDefaultAfterUpdated(dataGridView, dataGridViewGenericCellStatusDefault, columnIndex, rowIndex); } if (metadataExiftool != null) { Metadata metadataCopy = new Metadata(metadataExiftool); Metadata metadataWindowsLivePhotoGallery = DatabaseAndCacheMetadataWindowsLivePhotoGallery.ReadMetadataFromCacheOrDatabase(new FileEntryBroker(fileEntryBrokerReadVersion, MetadataBrokerType.WindowsLivePhotoGallery)); Metadata metadataWindowsLivePhotoGalleryCopy = metadataWindowsLivePhotoGallery == null ? null : new Metadata(metadataWindowsLivePhotoGallery); Metadata metadataMicrosoftPhotos = DatabaseAndCacheMetadataMicrosoftPhotos.ReadMetadataFromCacheOrDatabase(new FileEntryBroker(fileEntryBrokerReadVersion, MetadataBrokerType.MicrosoftPhotos)); Metadata metadataMicrosoftPhotosCopy = metadataMicrosoftPhotos == null ? null : new Metadata(metadataMicrosoftPhotos); Metadata metadataWebScraping = DatabaseAndCacheMetadataExiftool.ReadWebScraperMetadataFromCacheOrDatabase(new FileEntryBroker(fileEntryBrokerReadVersion, MetadataBrokerType.WebScraping)); Metadata metadataWebScrapingCopy = metadataWebScraping == null ? null : new Metadata(metadataWebScraping); //Remove doubles and add names where missing, only work with copy, don't change metadata in buffer. //Don't remove region in ExifTool metadata when found other places if (metadataWindowsLivePhotoGalleryCopy != null) { metadataCopy.PersonalRegionSetNamelessRegions(metadataWindowsLivePhotoGalleryCopy.PersonalRegionList); } if (metadataMicrosoftPhotosCopy != null) { metadataCopy.PersonalRegionSetNamelessRegions(metadataMicrosoftPhotosCopy.PersonalRegionList); } if (metadataWebScrapingCopy != null) { metadataWebScrapingCopy.MediaHeight = metadataCopy.MediaHeight; metadataWebScrapingCopy.MediaWidth = metadataCopy.MediaWidth; metadataWebScrapingCopy.MediaOrientation = metadataCopy.MediaOrientation; metadataWebScrapingCopy.MediaVideoLength = metadataCopy.MediaVideoLength; if (metadataCopy != null) { metadataCopy.PersonalRegionSetRegionlessRegions(metadataWebScrapingCopy.PersonalRegionList); } if (metadataWindowsLivePhotoGalleryCopy != null) { metadataWindowsLivePhotoGalleryCopy.PersonalRegionSetRegionlessRegions(metadataWebScrapingCopy.PersonalRegionList); } if (metadataMicrosoftPhotosCopy != null) { metadataMicrosoftPhotosCopy.PersonalRegionSetRegionlessRegions(metadataWebScrapingCopy.PersonalRegionList); } } //Populate PopulatePeople(dataGridView, metadataCopy, columnIndex, metadataCopy.Broker); if (metadataWindowsLivePhotoGalleryCopy != null) { PopulatePeople(dataGridView, metadataWindowsLivePhotoGalleryCopy, columnIndex, metadataWindowsLivePhotoGalleryCopy.Broker); } if (metadataMicrosoftPhotosCopy != null) { PopulatePeople(dataGridView, metadataMicrosoftPhotosCopy, columnIndex, metadataMicrosoftPhotosCopy.Broker); } if (metadataWebScrapingCopy != null) { PopulatePeople(dataGridView, metadataWebScrapingCopy, columnIndex, metadataWebScrapingCopy.Broker); } //Remember names added foreach (RegionStructure regionStructure in metadataExiftool.PersonalRegionList) { if (!regionNamesAddedPeople.Contains(regionStructure.Name)) { regionNamesAddedPeople.Add(regionStructure.Name); } } } DataGridViewHandler.SetColumnPopulatedFlag(dataGridView, columnIndex, true); } if (FileEntryVersionHandler.IsCurrenOrUpdatedVersion(fileEntryAttribute.FileEntryVersion) && metadataExiftool != null) { #region Suggestion of Names - Near date int columnIndexDummy = -1; List <string> regioNameSuggestions = null; DateTime? dateTimeSmartDate = metadataExiftool.FileSmartDate(RenameDateFormats); if (dateTimeSmartDate != null) { DateTime date = new DateTime(((DateTime)dateTimeSmartDate).Year, ((DateTime)dateTimeSmartDate).Month, ((DateTime)dateTimeSmartDate).Day); DateTime dateTimeFrom = date.AddDays(-SuggestRegionNameNearByDays); DateTime dateTimeTo = date.AddDays(SuggestRegionNameNearByDays); bool isHeaderPeopleSuggestionAdded = false; regioNameSuggestions = DatabaseAndCacheMetadataExiftool.ListAllRegionNamesNearByCache(MetadataBrokerType.ExifTool, (DateTime)dateTimeFrom, (DateTime)dateTimeTo, SuggestRegionNameNearByTopMostCount); if (regioNameSuggestions != null && regioNameSuggestions.Count > 0) { foreach (string regionName in regioNameSuggestions) { if (!string.IsNullOrWhiteSpace(regionName)) { if (regionNamesAddedTopMost.Contains(regionName)) { DataGridViewHandler.DeleteRow(dataGridView, headerPeopleMostUsed, regionName); regionNamesAddedTopMost.Remove(regionName); } if (!regionNamesAddedPeople.Contains(regionName)) { if (!isHeaderPeopleSuggestionAdded) { AddRowHeader(dataGridView, columnIndexDummy, new DataGridViewGenericRow(headerPeopleSuggestion), false); isHeaderPeopleSuggestionAdded = true; } AddRowHeader(dataGridView, columnIndexDummy, new DataGridViewGenericRow(headerPeopleSuggestion, regionName), true); } } } } } #endregion #region Suggestion of names - Top Most List <string> regioNamesTopMost = DatabaseAndCacheMetadataExiftool.ListAllPersonalRegionName(SuggestRegionNameNearByTopMostCount - regionNamesAddedTopMost.Count, regionNamesAddedPeople, regioNameSuggestions); if (regioNamesTopMost != null && regioNamesTopMost.Count > 0) { AddRowHeader(dataGridView, columnIndexDummy, new DataGridViewGenericRow(headerPeopleMostUsed), false); foreach (string regionName in regioNamesTopMost) { AddRowHeader(dataGridView, columnIndexDummy, new DataGridViewGenericRow(headerPeopleMostUsed, regionName), true); } } #endregion AddRowHeader(dataGridView, columnIndexDummy, new DataGridViewGenericRow(headerPeopleAdded), false); } //DataGridViewHandler.Refresh(dataGridView); //----------------------------------------------------------------- DataGridViewHandler.SetIsPopulatingFile(dataGridView, false); //----------------------------------------------------------------- return(columnIndex); }
public static void AddColumnSelectedFiles( DataGridView dataGridView, ThumbnailPosterDatabaseCache databaseAndCacheThumbnail, HashSet <FileEntry> imageListViewItems, ReadWriteAccess readWriteAccessForColumn, ShowWhatColumns showWhatColumns, DataGridViewGenericCellStatus dataGridViewGenericCellStatusDefault) { foreach (FileEntry imageListViewItem in imageListViewItems) { FileEntryAttribute fileEntryAttribute = new FileEntryAttribute(imageListViewItem.FileFullPath, imageListViewItem.LastWriteDateTime, FileEntryVersion.CurrentVersionInDatabase); Image thumbnail = null; if (databaseAndCacheThumbnail != null) { thumbnail = databaseAndCacheThumbnail.ReadThumbnailFromCacheOnly(fileEntryAttribute.FileEntry); } DataGridViewHandler.AddColumnOrUpdateNew(dataGridView, fileEntryAttribute, thumbnail, null, readWriteAccessForColumn, showWhatColumns, dataGridViewGenericCellStatusDefault, out _); } }
public static int PopulateFile(DataGridView dataGridView, DataGridView dataGridViewDate, FileEntryAttribute fileEntryAttribute, ShowWhatColumns showWhatColumns, Metadata metadataAutoCorrected, bool onlyRefresh) { //----------------------------------------------------------------- //Chech if need to stop if (GlobalData.IsApplicationClosing) { return(-1); } if (!DataGridViewHandler.GetIsAgregated(dataGridView)) { return(-1); //Not default columns or rows added } if (DataGridViewHandler.GetIsPopulatingFile(dataGridView)) { return(-1); //In progress doing so } //Check if file is in DataGridView, and needs updated if (!DataGridViewHandler.DoesColumnFilenameExist(dataGridView, fileEntryAttribute.FileFullPath)) { return(-1); } //When file found, Tell it's populating file, avoid two process updates DataGridViewHandler.SetIsPopulatingFile(dataGridView, true); //----------------------------------------------------------------- FileEntryBroker fileEntryBrokerReadVersion = fileEntryAttribute.GetFileEntryBroker(MetadataBrokerType.ExifTool); Image thumbnail = DatabaseAndCacheThumbnail.ReadThumbnailFromCacheOnly(fileEntryBrokerReadVersion); if (thumbnail == null && metadataAutoCorrected != null) { thumbnail = DatabaseAndCacheThumbnail.ReadThumbnailFromCacheOnly(metadataAutoCorrected.FileEntry); } Metadata metadataExiftool = DatabaseAndCacheMetadataExiftool.ReadMetadataFromCacheOnly(fileEntryBrokerReadVersion); if (metadataExiftool != null) { metadataExiftool = new Metadata(metadataExiftool); } if (metadataAutoCorrected != null) { metadataExiftool = metadataAutoCorrected; //If AutoCorrect is run, use AutoCorrect values. Needs to be after DataGridViewHandler.AddColumnOrUpdateNew, so orignal metadata stored will not be overwritten } ReadWriteAccess readWriteAccessColumn = (FileEntryVersionHandler.IsReadOnlyType(fileEntryAttribute.FileEntryVersion) || metadataExiftool == null) ? ReadWriteAccess.ForceCellToReadOnly : ReadWriteAccess.AllowCellReadAndWrite; int columnIndex = DataGridViewHandler.AddColumnOrUpdateNew( dataGridView, fileEntryAttribute, thumbnail, metadataExiftool, readWriteAccessColumn, showWhatColumns, DataGridViewGenericCellStatus.DefaultEmpty(), out FileEntryVersionCompare fileEntryVersionCompareReason); //Chech if populated and new refresh data if (onlyRefresh && FileEntryVersionHandler.NeedUpdate(fileEntryVersionCompareReason) && !DataGridViewHandler.IsColumnPopulated(dataGridView, columnIndex)) { fileEntryVersionCompareReason = FileEntryVersionCompare.LostNoneEqualFound_ContinueSearch; //No need to populate } //----------------------------------------------------------------- if (FileEntryVersionHandler.NeedUpdate(fileEntryVersionCompareReason)) { //Media int rowIndex; AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia)); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagMediaCoordinates), metadataExiftool?.LocationCoordinate, false); rowIndex = AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagLocationName), metadataExiftool?.LocationName, false); List <string> newKeywords = AutoKeywordHandler.NewKeywords(AutoKeywordConvertions, metadataExiftool?.LocationName, null, null, null, null, null); DataGridViewHandler.SetCellToolTipText(dataGridView, columnIndex, rowIndex, "Running AutoCorrect will add these keywords", newKeywords); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagCity), metadataExiftool?.LocationCity, false); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagProvince), metadataExiftool?.LocationState, false); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagCountry), metadataExiftool?.LocationCountry, false); //List<string> newKeywords = AutoKeywordHandler.NewKeywords(autoKeywordConvertions, metadataCopy.LocationName, metadataCopy.PersonalTitle, // metadataCopy.PersonalAlbum, metadataCopy.PersonalDescription, metadataCopy.PersonalComments, metadataCopy.PersonalKeywordTags); //Google location history AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerGoogleLocations)); if (metadataExiftool != null) { CameraOwner cameraOwnerPrint = new CameraOwner(metadataExiftool.CameraMake, metadataExiftool.CameraModel, ""); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerGoogleLocations, tagCameraMakeModel), cameraOwnerPrint, true); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerGoogleLocations, tagCameraOwner), "Owner???", false); DataGridViewGenericColumn gridViewGenericColumnCheck = DataGridViewHandler.GetColumnDataGridViewGenericColumn(dataGridView, columnIndex); PopulateCameraOwner(dataGridView, columnIndex, readWriteAccessColumn, metadataExiftool.CameraMake, metadataExiftool.CameraModel); } else { if (!DataGridViewHandler.IsColumnPopulated(dataGridView, columnIndex)) { AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagCameraMakeModel), "", false); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerGoogleLocations, tagCameraOwner), "Select Camera owner/locations", true); } } AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerGoogleLocations, tagGoogleCoordinateUTC), metadataExiftool?.LocationCoordinate, true); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerNearByLocations)); PopulateGoogleHistoryCoordinateAndNearby(dataGridView, dataGridViewDate, columnIndex, TimeZoneShift, AccepedIntervalSecound); //Nominatim.API AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerNominatim)); PopulateGrivViewMapNomnatatim(dataGridView, columnIndex, metadataExiftool?.LocationCoordinate, onlyFromCache: true, canReverseGeocoder: false, forceReloadUsingReverseGeocoder: false, createNewAccurateLocationUsingSearchLocation: false); //WebScraper //headerWebScraping = "WebScraper"; // WebScarping AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerWebScraping)); Metadata metadataWebScraping = null; if (metadataExiftool != null) { metadataWebScraping = DatabaseAndCacheMetadataExiftool.ReadWebScraperMetadataFromCacheOrDatabase(new FileEntryBroker(fileEntryBrokerReadVersion, MetadataBrokerType.WebScraping)); } AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerWebScraping, tagLocationName), metadataWebScraping?.LocationName, true); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerWebScraping, tagCountry), metadataWebScraping?.LocationCountry, true); //Microsoft Photos Locations Metadata metadataMicrosoftPhotos = null; if (metadataExiftool != null) { metadataMicrosoftPhotos = DatabaseAndCacheMetadataMicrosoftPhotos.ReadMetadataFromCacheOrDatabase( new FileEntryBroker(fileEntryBrokerReadVersion, MetadataBrokerType.MicrosoftPhotos)); } AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMicrosoftPhotos)); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMicrosoftPhotos, tagExternalCoordinates), metadataMicrosoftPhotos?.LocationCoordinate, true); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMicrosoftPhotos, tagLocationName), metadataMicrosoftPhotos?.LocationName, true); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMicrosoftPhotos, tagCity), metadataMicrosoftPhotos?.LocationCity, true); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMicrosoftPhotos, tagProvince), metadataMicrosoftPhotos?.LocationState, true); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMicrosoftPhotos, tagCountry), metadataMicrosoftPhotos?.LocationCountry, true); //Windows Live Photo Gallary Locations Metadata metadataWindowsLivePhotoGallery = null; if (metadataExiftool != null) { metadataWindowsLivePhotoGallery = DatabaseAndCacheMetadataWindowsLivePhotoGallery.ReadMetadataFromCacheOrDatabase( new FileEntryBroker(fileEntryBrokerReadVersion, MetadataBrokerType.WindowsLivePhotoGallery)); } AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerWindowsLivePhotoGallery)); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerWindowsLivePhotoGallery, tagExternalCoordinates), metadataWindowsLivePhotoGallery?.LocationCoordinate, true); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerWindowsLivePhotoGallery, tagLocationName), metadataWindowsLivePhotoGallery?.LocationName, true); //Browser AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerBrowser)); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerBrowser, tagExternalCoordinates), "", true); DataGridViewHandler.SetColumnPopulatedFlag(dataGridView, columnIndex, true); } //----------------------------------------------------------------- DataGridViewHandler.SetIsPopulatingFile(dataGridView, false); //----------------------------------------------------------------- return(columnIndex); }