/// <summary> /// Move sidecar files when those exist /// </summary> /// <param name="inputFileSubPath">from path</param> /// <param name="toFileSubPath">to path</param> private void MoveSidecarFile(string inputFileSubPath, string toFileSubPath) { // json sidecar move var jsonInputFileSubPathSidecarFile = JsonSidecarLocation .JsonLocation(inputFileSubPath); var jsonSidecarFile = JsonSidecarLocation.JsonLocation(toFileSubPath); if (_iStorage.ExistFile(jsonInputFileSubPathSidecarFile)) { _iStorage.FileMove(jsonInputFileSubPathSidecarFile, jsonSidecarFile); } // xmp sidecar file move if (!ExtensionRolesHelper.IsExtensionForceXmp(inputFileSubPath)) { return; } var xmpInputFileSubPathSidecarFile = ExtensionRolesHelper .ReplaceExtensionWithXmp(inputFileSubPath); var xmpSidecarFile = ExtensionRolesHelper .ReplaceExtensionWithXmp(toFileSubPath); if (_iStorage.ExistFile(xmpInputFileSubPathSidecarFile)) { _iStorage.FileMove(xmpInputFileSubPathSidecarFile, xmpSidecarFile); } }
public FileIndexItem XmpGetSidecarFile(FileIndexItem databaseItem) { if (databaseItem == null) { databaseItem = new FileIndexItem(); } // Parse an xmp file for this location var xmpSubPath = ExtensionRolesHelper.ReplaceExtensionWithXmp(databaseItem.FilePath); // also add when the file is a jpeg, we are not writing to it then if (_iStorage.ExistFile(xmpSubPath)) { databaseItem.AddSidecarExtension("xmp"); } // Read content from sidecar xmp file if (!ExtensionRolesHelper.IsExtensionForceXmp(databaseItem.FilePath) || !_iStorage.ExistFile(xmpSubPath)) { return(databaseItem); } // Read the text-content of the xmp file. var xmp = new PlainTextFileHelper().StreamToString(_iStorage.ReadStream(xmpSubPath)); // Get the data from the xmp databaseItem = GetDataFromString(xmp, databaseItem); return(databaseItem); }
/// <summary> /// Create a XMP file when it not exist /// </summary> /// <param name="updateModel">model</param> /// <param name="inputSubPaths">list of paths</param> /// <returns>void</returns> internal async Task CreateXmpFileIsNotExist(FileIndexItem updateModel, List <string> inputSubPaths) { foreach (var subPath in inputSubPaths) { // only for raw files if (!ExtensionRolesHelper.IsExtensionForceXmp(subPath)) { return; } var withXmp = ExtensionRolesHelper.ReplaceExtensionWithXmp(subPath); if (_iStorage.IsFolderOrFile(withXmp) != FolderOrFileModel.FolderOrFileTypeList.Deleted) { continue; } new ExifCopy(_iStorage, _thumbnailStorage, _exifTool, _readMeta).XmpCreate(withXmp); var comparedNames = FileIndexCompareHelper.Compare(new FileIndexItem(), updateModel); var command = ExifToolCommandLineArgs(updateModel, comparedNames, true); await _exifTool.WriteTagsAsync(withXmp, command); } }
private void RemoveXmpSideCarFile(DetailView detailViewItem) { // remove the sidecar file (if exist) if (ExtensionRolesHelper.IsExtensionForceXmp(detailViewItem.FileIndexItem .FileName)) { _iStorage.FileDelete( ExtensionRolesHelper.ReplaceExtensionWithXmp(detailViewItem .FileIndexItem.FilePath)); } }
/// <summary> /// This list will be included in the zip /// </summary> /// <param name="fileIndexResultsList">the items</param> /// <param name="thumbnail">add the thumbnail or the source image</param> /// <returns>list of file paths</returns> public async Task <List <string> > CreateListToExport(List <FileIndexItem> fileIndexResultsList, bool thumbnail) { var filePaths = new List <string>(); foreach (var item in fileIndexResultsList.Where(p => p.Status == FileIndexItem.ExifStatus.Ok).ToList()) { if (thumbnail) { var sourceThumb = Path.Combine(_appSettings.ThumbnailTempFolder, ThumbnailNameHelper.Combine(item.FileHash, ThumbnailSize.Large, true)); await new Thumbnail(_iStorage, _thumbnailStorage, _logger) .CreateThumb(item.FilePath, item.FileHash, true); filePaths.Add(sourceThumb); continue; } var sourceFile = _appSettings.DatabasePathToFilePath(item.FilePath, false); if (!_hostFileSystemStorage.ExistFile(sourceFile)) { continue; } // the jpeg file for example filePaths.Add(sourceFile); // when there is .xmp sidecar file (but only when file is a RAW file, ignored when for example jpeg) if (!ExtensionRolesHelper.IsExtensionForceXmp(item.FilePath) || !_iStorage.ExistFile( ExtensionRolesHelper.ReplaceExtensionWithXmp( item.FilePath))) { continue; } var xmpFileFullPath = _appSettings.DatabasePathToFilePath( ExtensionRolesHelper.ReplaceExtensionWithXmp( item.FilePath), false); if (!_hostFileSystemStorage.ExistFile(xmpFileFullPath)) { continue; } filePaths.Add(xmpFileFullPath); } return(filePaths); }
internal bool ExistXmpSidecarForThisFileType(ImportIndexItem importIndexItem) { if (string.IsNullOrEmpty(importIndexItem.SourceFullFilePath)) { return(false); } // Support for include sidecar files var xmpSourceFullFilePath = ExtensionRolesHelper.ReplaceExtensionWithXmp(importIndexItem .SourceFullFilePath); return(ExtensionRolesHelper.IsExtensionForceXmp(importIndexItem .SourceFullFilePath) && _filesystemStorage.ExistFile(xmpSourceFullFilePath)); }
/// <summary> /// For Raw files us an external .xmp sidecar file, and add this to the PathsList /// </summary> /// <param name="inputSubPaths">list of files to update</param> /// <returns>list of files, where needed for raw-files there are .xmp used</returns> private List <string> PathsListTagsFromFile(List <string> inputSubPaths) { var pathsList = new List <string>(); foreach (var subPath in inputSubPaths) { if (ExtensionRolesHelper.IsExtensionForceXmp(subPath)) { var xmpPath = ExtensionRolesHelper.ReplaceExtensionWithXmp(subPath); pathsList.Add(xmpPath); continue; } pathsList.Add(subPath); } return(pathsList); }
/// <summary> /// Add a .xmp sidecar file /// </summary> /// <param name="subPath"></param> /// <returns></returns> public async Task <string> XmpSync(string subPath) { // only for raw files if (!ExtensionRolesHelper.IsExtensionForceXmp(subPath)) { return(subPath); } var withXmp = ExtensionRolesHelper.ReplaceExtensionWithXmp(subPath); // only for files that not exist yet if (_iStorage.IsFolderOrFile(withXmp) != FolderOrFileModel.FolderOrFileTypeList.Deleted) { return(withXmp); } XmpCreate(withXmp); // Now copy content using exifTool await CopyExifPublish(subPath, withXmp); return(withXmp); }
internal async Task <ImportIndexItem> Importer(ImportIndexItem importIndexItem, ImportSettingsModel importSettings) { if (importIndexItem.Status != ImportStatus.Ok) { return(importIndexItem); } // True when exist and file type is raw var xmpExistForThisFileType = ExistXmpSidecarForThisFileType(importIndexItem); if (xmpExistForThisFileType || (_appSettings.ExifToolImportXmpCreate && ExtensionRolesHelper.IsExtensionForceXmp(importIndexItem.FilePath))) { // When a xmp file already exist (only for raws) // AND when this created afterwards with the ExifToolImportXmpCreate setting (only for raws) importIndexItem.FileIndexItem.AddSidecarExtension("xmp"); } // Add item to database await AddToQueryAndImportDatabaseAsync(importIndexItem, importSettings); // Copy if (_appSettings.IsVerbose()) { _logger.LogInformation("[Import] Next Action = Copy" + $" {importIndexItem.SourceFullFilePath} {importIndexItem.FilePath}"); } using (var sourceStream = _filesystemStorage.ReadStream(importIndexItem.SourceFullFilePath)) await _subPathStorage.WriteStreamAsync(sourceStream, importIndexItem.FilePath); // Copy the sidecar file if (xmpExistForThisFileType) { var xmpSourceFullFilePath = ExtensionRolesHelper.ReplaceExtensionWithXmp(importIndexItem.SourceFullFilePath); var destinationXmpFullPath = ExtensionRolesHelper.ReplaceExtensionWithXmp(importIndexItem.FilePath); _filesystemStorage.FileCopy(xmpSourceFullFilePath, destinationXmpFullPath); } await CreateSideCarFile(importIndexItem, xmpExistForThisFileType); // Run Exiftool to Update for example colorClass UpdateImportTransformations.QueryUpdateDelegate?updateItemAsync = null; if (importSettings.IndexMode) { updateItemAsync = new QueryFactory( new SetupDatabaseTypes(_appSettings), _query, _memoryCache, _appSettings, _logger).Query() !.UpdateItemAsync; } importIndexItem.FileIndexItem = await _updateImportTransformations.UpdateTransformations(updateItemAsync, importIndexItem.FileIndexItem, importSettings.ColorClass, importIndexItem.DateTimeFromFileName, importSettings.IndexMode); DeleteFileAfter(importSettings, importIndexItem); if (_appSettings.IsVerbose()) { _console.Write("+"); } return(importIndexItem); }
public void ExtensionRolesHelperTest_IsExtensionForceXmp_Negative() { var result = ExtensionRolesHelper.IsExtensionForceXmp("/test.jpg"); Assert.AreEqual(false, result); }
public void ExtensionRolesHelperTest_IsExtensionForceXmp_Positive() { var result = ExtensionRolesHelper.IsExtensionForceXmp("/test.arw"); Assert.AreEqual(true, result); }