// Copyright (c) Microsoft Corporation // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. #pragma once #include #include #include #include namespace PowerRenameLib { /// /// Helper class for formatting and parsing metadata values /// Provides static utility functions for converting metadata to human-readable strings /// and parsing raw metadata values /// class MetadataFormatHelper { public: // Formatting functions - Convert metadata values to display strings /// /// Format aperture value (f-number) /// /// Aperture value (e.g., 2.8) /// Formatted string (e.g., "f/2.8") static std::wstring FormatAperture(double aperture); /// /// Format shutter speed /// /// Shutter speed in seconds /// Formatted string (e.g., "1/100s" or "2.5s") static std::wstring FormatShutterSpeed(double speed); /// /// Format ISO value /// /// ISO speed value /// Formatted string (e.g., "ISO 400") static std::wstring FormatISO(int64_t iso); /// /// Format flash status /// /// Flash value from EXIF /// Formatted string (e.g., "Flash On" or "Flash Off") static std::wstring FormatFlash(int64_t flashValue); /// /// Format GPS coordinate /// /// Coordinate value in decimal degrees /// true for latitude, false for longitude /// Formatted string (e.g., "40°26.76'N") static std::wstring FormatCoordinate(double coord, bool isLatitude); /// /// Format SYSTEMTIME to string /// /// SYSTEMTIME structure /// Formatted string (e.g., "2024-03-15 14:30:45") static std::wstring FormatSystemTime(const SYSTEMTIME& st); // Parsing functions - Convert raw metadata to usable values /// /// Parse GPS rational value from PROPVARIANT /// /// PROPVARIANT containing GPS rational data /// Parsed double value static double ParseGPSRational(const PROPVARIANT& pv); /// /// Parse single rational value from byte array /// /// Byte array containing rational data /// Offset in the byte array /// Parsed double value (numerator / denominator) static double ParseSingleRational(const uint8_t* bytes, size_t offset); /// /// Parse single signed rational value from byte array /// /// Byte array containing signed rational data /// Offset in the byte array /// Parsed double value (signed numerator / signed denominator) static double ParseSingleSRational(const uint8_t* bytes, size_t offset); /// /// Parse GPS coordinates from PROPVARIANT values /// /// PROPVARIANT containing latitude /// PROPVARIANT containing longitude /// PROPVARIANT containing latitude reference (N/S) /// PROPVARIANT containing longitude reference (E/W) /// Pair of (latitude, longitude) in decimal degrees static std::pair ParseGPSCoordinates( const PROPVARIANT& latitude, const PROPVARIANT& longitude, const PROPVARIANT& latRef, const PROPVARIANT& lonRef); /// /// Sanitize a string to make it safe for use in filenames /// Replaces illegal filename characters (< > : " / \ | ? * and control chars) with underscore /// Also removes trailing dots and spaces which Windows doesn't allow at end of filename /// /// IMPORTANT: This should ONLY be called in ExtractPatterns to avoid performance waste. /// Do NOT call this function when reading raw metadata values. /// /// String to sanitize /// Sanitized string safe for use in filename static std::wstring SanitizeForFileName(const std::wstring& str); }; }