CaptureMoment 0.1.0
Free and open-source non-destructive photo editor
Loading...
Searching...
No Matches
sidecar_xmp_path_strategy.cpp
Go to the documentation of this file.
1
10#include <spdlog/spdlog.h>
11#include <filesystem>
12
14
15std::string SidecarXmpPathStrategy::getXmpPathForImage(std::string_view source_image_path) const
16{
17 if (source_image_path.empty()) {
18 spdlog::error("SidecarXmpPathStrategy::getXmpPathForImage: Source image path is empty.");
19 return {};
20 }
21
22 std::filesystem::path image_path_obj(source_image_path);
23
24 // Append ".xmp" to the existing filename in the same directory
25 std::filesystem::path xmp_path_obj = image_path_obj;
26 xmp_path_obj += ".xmp";
27
28 spdlog::debug("SidecarXmpPathStrategy::getXmpPathForImage: Mapped '{}' to XMP path: '{}'", source_image_path, xmp_path_obj.string());
29 return xmp_path_obj.string();
30}
31
32std::string SidecarXmpPathStrategy::getImagePathFromXmp(std::string_view xmp_path) const
33{
34 if (xmp_path.empty()) {
35 spdlog::error("SidecarXmpPathStrategy::getImagePathFromXmp: XMP path is empty.");
36 return {};
37 }
38
39 std::filesystem::path xmp_path_obj(xmp_path);
40 std::string xmp_ext = xmp_path_obj.extension().string();
41
42 // Check if the file ends with ".xmp"
43 if (xmp_ext.size() >= 4 && xmp_ext.substr(xmp_ext.size() - 4) == ".xmp")
44 {
45 // Remove the last 4 characters (.xmp) to reconstruct the original filename
46 std::string original_ext = xmp_ext.substr(0, xmp_ext.size() - 4);
47 std::string original_stem = xmp_path_obj.stem().string(); // Stem includes filename without extension
48 std::string reconstructed_name = original_stem + original_ext;
49
50 std::filesystem::path original_path = xmp_path_obj.parent_path() / reconstructed_name;
51 spdlog::debug("SidecarXmpPathStrategy::getImagePathFromXmp: Reconstructed image path '{}' from XMP path: '{}'", original_path.string(), xmp_path);
52 return original_path.string();
53 } else {
54 spdlog::warn("SidecarXmpPathStrategy::getImagePathFromXmp: XMP path does not end with '.xmp': '{}'", xmp_path);
55 return {};
56 }
57}
58
59} // namespace CaptureMoment::Core::Serializer
std::string getXmpPathForImage(std::string_view source_image_path) const override
Calculates the XMP file path associated with a given source image path.
std::string getImagePathFromXmp(std::string_view xmp_path) const override
Calculates the source image path associated with a given XMP file path.
Declaration of SidecarXmpPathStrategy class.
CaptureMoment — footer