From 302be665e2bdd6fb00628ad6310b161dcf8c834d Mon Sep 17 00:00:00 2001
From: Syping <schiedelrafael@keppe.org>
Date: Mon, 27 Mar 2023 17:49:35 +0200
Subject: [PATCH] RagePhoto: use C++17 u8path when available

---
 src/RagePhoto.cpp | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/RagePhoto.cpp b/src/RagePhoto.cpp
index f2dbaa6..f596b85 100644
--- a/src/RagePhoto.cpp
+++ b/src/RagePhoto.cpp
@@ -27,6 +27,10 @@
 #include <iostream>
 #include <iterator>
 
+#if (RAGEPHOTO_CXX_STD >= 17) && (__cplusplus >= 201703L)
+#include <filesystem>
+#endif
+
 #ifdef RAGEPHOTO_BENCHMARK
 #include <chrono>
 #endif
@@ -587,7 +591,11 @@ bool RagePhoto::load(const std::string &data)
 
 bool RagePhoto::loadFile(const std::string &filename)
 {
+#if (RAGEPHOTO_CXX_STD >= 17) && (__cplusplus >= 201703L)
+    std::ifstream ifs(std::filesystem::u8path(filename), std::ios::in | std::ios::binary);
+#else
     std::ifstream ifs(filename, std::ios::in | std::ios::binary);
+#endif
     if (ifs.is_open()) {
         std::string sdata(std::istreambuf_iterator<char>{ifs}, {});
         ifs.close();
@@ -955,7 +963,11 @@ bool RagePhoto::saveFile(const std::string &filename, uint32_t photoFormat)
     bool ok;
     const std::string &sdata = save(photoFormat, &ok);
     if (ok) {
+#if (RAGEPHOTO_CXX_STD >= 17) && (__cplusplus >= 201703L)
+        std::ofstream ofs(std::filesystem::u8path(filename), std::ios::out | std::ios::binary | std::ios::trunc);
+#else
         std::ofstream ofs(filename, std::ios::out | std::ios::binary | std::ios::trunc);
+#endif
         if (!ofs.is_open()) {
             m_data->error = Error::Uninitialised; // 0
             return false;