From 5f2c7bb898440c04d8341dd09e7827d1701670cd Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Sun, 9 Jan 2022 15:47:04 -0700 Subject: [PATCH] Use std::filesystem::path --- examples/opengl/OpenGL.cpp | 10 +++--- examples/tennis/Tennis.cpp | 8 ++--- include/SFML/Audio/InputSoundFile.hpp | 3 +- include/SFML/Audio/Music.hpp | 3 +- include/SFML/Audio/OutputSoundFile.hpp | 3 +- include/SFML/Audio/SoundBuffer.hpp | 5 +-- include/SFML/Audio/SoundFileFactory.hpp | 7 ++-- include/SFML/Audio/SoundFileWriter.hpp | 7 ++-- include/SFML/Graphics/Font.hpp | 2 +- include/SFML/Graphics/Image.hpp | 5 +-- include/SFML/Graphics/Shader.hpp | 7 ++-- include/SFML/Graphics/Texture.hpp | 3 +- include/SFML/Network/Ftp.hpp | 11 ++++--- include/SFML/System/FileInputStream.hpp | 3 +- include/SFML/System/InputStream.hpp | 2 +- src/SFML/Audio/ALCheck.cpp | 5 ++- src/SFML/Audio/ALCheck.hpp | 3 +- src/SFML/Audio/AudioDevice.cpp | 8 ++--- src/SFML/Audio/AudioDevice.hpp | 4 +-- src/SFML/Audio/InputSoundFile.cpp | 2 +- src/SFML/Audio/Music.cpp | 2 +- src/SFML/Audio/OutputSoundFile.cpp | 2 +- src/SFML/Audio/SoundBuffer.cpp | 4 +-- src/SFML/Audio/SoundFileFactory.cpp | 4 +-- src/SFML/Audio/SoundFileWriterFlac.cpp | 10 +++--- src/SFML/Audio/SoundFileWriterFlac.hpp | 5 +-- src/SFML/Audio/SoundFileWriterOgg.cpp | 8 ++--- src/SFML/Audio/SoundFileWriterOgg.hpp | 5 +-- src/SFML/Audio/SoundFileWriterWav.cpp | 8 ++--- src/SFML/Audio/SoundFileWriterWav.hpp | 4 +-- src/SFML/Graphics/Font.cpp | 4 +-- src/SFML/Graphics/GLCheck.cpp | 5 ++- src/SFML/Graphics/GLCheck.hpp | 3 +- src/SFML/Graphics/Image.cpp | 4 +-- src/SFML/Graphics/ImageLoader.cpp | 26 +++++++-------- src/SFML/Graphics/ImageLoader.hpp | 5 +-- src/SFML/Graphics/Shader.cpp | 14 ++++---- src/SFML/Graphics/Texture.cpp | 2 +- src/SFML/Network/Ftp.cpp | 32 +++++++------------ src/SFML/System/Android/ResourceStream.cpp | 2 +- src/SFML/System/Android/ResourceStream.hpp | 3 +- src/SFML/System/FileInputStream.cpp | 6 +++- src/SFML/Window/EGLCheck.cpp | 5 ++- src/SFML/Window/EGLCheck.hpp | 3 +- src/SFML/Window/Unix/WindowImplX11.cpp | 5 +-- .../SFML/SFML App.xctemplate/ResourcePath.hpp | 4 +-- .../SFML/SFML App.xctemplate/ResourcePath.mm | 5 +-- 47 files changed, 143 insertions(+), 138 deletions(-) diff --git a/examples/opengl/OpenGL.cpp b/examples/opengl/OpenGL.cpp index 21bba5bd1..a53570c23 100644 --- a/examples/opengl/OpenGL.cpp +++ b/examples/opengl/OpenGL.cpp @@ -17,7 +17,7 @@ #define GL_SRGB8_ALPHA8 0x8C43 #endif -std::string resourcesDir() +std::filesystem::path resourcesDir() { #ifdef SFML_SYSTEM_IOS return ""; @@ -51,13 +51,13 @@ int main() // Create a sprite for the background sf::Texture backgroundTexture; backgroundTexture.setSrgb(sRgb); - if (!backgroundTexture.loadFromFile(resourcesDir() + "background.jpg")) + if (!backgroundTexture.loadFromFile(resourcesDir() / "background.jpg")) return EXIT_FAILURE; sf::Sprite background(backgroundTexture); // Create some text to draw on top of our OpenGL object sf::Font font; - if (!font.loadFromFile(resourcesDir() + "tuffy.ttf")) + if (!font.loadFromFile(resourcesDir() / "tuffy.ttf")) return EXIT_FAILURE; sf::Text text("SFML / OpenGL demo", font); @@ -72,7 +72,7 @@ int main() // Load a texture to apply to our 3D cube sf::Texture texture; - if (!texture.loadFromFile(resourcesDir() + "logo.png")) + if (!texture.loadFromFile(resourcesDir() / "logo.png")) return EXIT_FAILURE; // Attempt to generate a mipmap for our cube texture @@ -220,7 +220,7 @@ int main() if (mipmapEnabled) { // We simply reload the texture to disable mipmapping - if (!texture.loadFromFile(resourcesDir() + "logo.png")) + if (!texture.loadFromFile(resourcesDir() / "logo.png")) return EXIT_FAILURE; mipmapEnabled = false; diff --git a/examples/tennis/Tennis.cpp b/examples/tennis/Tennis.cpp index d1b1e951c..1906ce2e7 100644 --- a/examples/tennis/Tennis.cpp +++ b/examples/tennis/Tennis.cpp @@ -12,7 +12,7 @@ #include #endif -std::string resourcesDir() +std::filesystem::path resourcesDir() { #ifdef SFML_SYSTEM_IOS return ""; @@ -44,13 +44,13 @@ int main() // Load the sounds used in the game sf::SoundBuffer ballSoundBuffer; - if (!ballSoundBuffer.loadFromFile(resourcesDir() + "ball.wav")) + if (!ballSoundBuffer.loadFromFile(resourcesDir() / "ball.wav")) return EXIT_FAILURE; sf::Sound ballSound(ballSoundBuffer); // Create the SFML logo texture: sf::Texture sfmlLogoTexture; - if(!sfmlLogoTexture.loadFromFile(resourcesDir() + "sfml_logo.png")) + if(!sfmlLogoTexture.loadFromFile(resourcesDir() / "sfml_logo.png")) return EXIT_FAILURE; sf::Sprite sfmlLogo; sfmlLogo.setTexture(sfmlLogoTexture); @@ -82,7 +82,7 @@ int main() // Load the text font sf::Font font; - if (!font.loadFromFile(resourcesDir() + "tuffy.ttf")) + if (!font.loadFromFile(resourcesDir() / "tuffy.ttf")) return EXIT_FAILURE; // Initialize the pause message diff --git a/include/SFML/Audio/InputSoundFile.hpp b/include/SFML/Audio/InputSoundFile.hpp index cbc92caa1..15ab376d9 100644 --- a/include/SFML/Audio/InputSoundFile.hpp +++ b/include/SFML/Audio/InputSoundFile.hpp @@ -29,6 +29,7 @@ // Headers //////////////////////////////////////////////////////////// #include +#include #include #include #include @@ -88,7 +89,7 @@ public: /// \return True if the file was successfully opened /// //////////////////////////////////////////////////////////// - [[nodiscard]] bool openFromFile(const std::string& filename); + [[nodiscard]] bool openFromFile(const std::filesystem::path& filename); //////////////////////////////////////////////////////////// /// \brief Open a sound file in memory for reading diff --git a/include/SFML/Audio/Music.hpp b/include/SFML/Audio/Music.hpp index 68af80c8f..d154601b0 100644 --- a/include/SFML/Audio/Music.hpp +++ b/include/SFML/Audio/Music.hpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -116,7 +117,7 @@ public: /// \see openFromMemory, openFromStream /// //////////////////////////////////////////////////////////// - [[nodiscard]] bool openFromFile(const std::string& filename); + [[nodiscard]] bool openFromFile(const std::filesystem::path& filename); //////////////////////////////////////////////////////////// /// \brief Open a music from an audio file in memory diff --git a/include/SFML/Audio/OutputSoundFile.hpp b/include/SFML/Audio/OutputSoundFile.hpp index a3104d9ea..c750d6352 100644 --- a/include/SFML/Audio/OutputSoundFile.hpp +++ b/include/SFML/Audio/OutputSoundFile.hpp @@ -29,6 +29,7 @@ // Headers //////////////////////////////////////////////////////////// #include +#include #include #include @@ -83,7 +84,7 @@ public: /// \return True if the file was successfully opened /// //////////////////////////////////////////////////////////// - [[nodiscard]] bool openFromFile(const std::string& filename, unsigned int sampleRate, unsigned int channelCount); + [[nodiscard]] bool openFromFile(const std::filesystem::path& filename, unsigned int sampleRate, unsigned int channelCount); //////////////////////////////////////////////////////////// /// \brief Write audio samples to the file diff --git a/include/SFML/Audio/SoundBuffer.hpp b/include/SFML/Audio/SoundBuffer.hpp index d79ae8322..69c94323f 100644 --- a/include/SFML/Audio/SoundBuffer.hpp +++ b/include/SFML/Audio/SoundBuffer.hpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -83,7 +84,7 @@ public: /// \see loadFromMemory, loadFromStream, loadFromSamples, saveToFile /// //////////////////////////////////////////////////////////// - [[nodiscard]] bool loadFromFile(const std::string& filename); + [[nodiscard]] bool loadFromFile(const std::filesystem::path& filename); //////////////////////////////////////////////////////////// /// \brief Load the sound buffer from a file in memory @@ -147,7 +148,7 @@ public: /// \see loadFromFile, loadFromMemory, loadFromSamples /// //////////////////////////////////////////////////////////// - [[nodiscard]] bool saveToFile(const std::string& filename) const; + [[nodiscard]] bool saveToFile(const std::filesystem::path& filename) const; //////////////////////////////////////////////////////////// /// \brief Get the array of audio samples stored in the buffer diff --git a/include/SFML/Audio/SoundFileFactory.hpp b/include/SFML/Audio/SoundFileFactory.hpp index d12e15828..5008bef9b 100644 --- a/include/SFML/Audio/SoundFileFactory.hpp +++ b/include/SFML/Audio/SoundFileFactory.hpp @@ -29,6 +29,7 @@ // Headers //////////////////////////////////////////////////////////// #include +#include #include #include #include @@ -94,7 +95,7 @@ public: /// \see createReaderFromMemory, createReaderFromStream /// //////////////////////////////////////////////////////////// - static std::unique_ptr createReaderFromFilename(const std::string& filename); + static std::unique_ptr createReaderFromFilename(const std::filesystem::path& filename); //////////////////////////////////////////////////////////// /// \brief Instantiate the right codec for the given file in memory @@ -129,7 +130,7 @@ public: /// \return A new sound file writer that can write given file, or null if no writer can handle it /// //////////////////////////////////////////////////////////// - static std::unique_ptr createWriterFromFilename(const std::string& filename); + static std::unique_ptr createWriterFromFilename(const std::filesystem::path& filename); private: @@ -145,7 +146,7 @@ private: struct WriterFactory { - bool (*check)(const std::string&); + bool (*check)(const std::filesystem::path&); std::unique_ptr (*create)(); }; using WriterFactoryArray = std::vector; diff --git a/include/SFML/Audio/SoundFileWriter.hpp b/include/SFML/Audio/SoundFileWriter.hpp index f2d72f7e1..3afeed65a 100644 --- a/include/SFML/Audio/SoundFileWriter.hpp +++ b/include/SFML/Audio/SoundFileWriter.hpp @@ -29,6 +29,7 @@ // Headers //////////////////////////////////////////////////////////// #include +#include #include @@ -58,7 +59,7 @@ public: /// \return True if the file was successfully opened /// //////////////////////////////////////////////////////////// - [[nodiscard]] virtual bool open(const std::string& filename, unsigned int sampleRate, unsigned int channelCount) = 0; + [[nodiscard]] virtual bool open(const std::filesystem::path& filename, unsigned int sampleRate, unsigned int channelCount) = 0; //////////////////////////////////////////////////////////// /// \brief Write audio samples to the open file @@ -97,13 +98,13 @@ public: /// { /// public: /// -/// [[nodiscard]] static bool check(const std::string& filename) +/// [[nodiscard]] static bool check(const std::filesystem::path& filename) /// { /// // typically, check the extension /// // return true if the writer can handle the format /// } /// -/// [[nodiscard]] bool open(const std::string& filename, unsigned int sampleRate, unsigned int channelCount) override +/// [[nodiscard]] bool open(const std::filesystem::path& filename, unsigned int sampleRate, unsigned int channelCount) override /// { /// // open the file 'filename' for writing, /// // write the given sample rate and channel count to the file header diff --git a/include/SFML/Graphics/Font.hpp b/include/SFML/Graphics/Font.hpp index 42ae89167..f0cd18e16 100644 --- a/include/SFML/Graphics/Font.hpp +++ b/include/SFML/Graphics/Font.hpp @@ -124,7 +124,7 @@ public: /// \see loadFromMemory, loadFromStream /// //////////////////////////////////////////////////////////// - [[nodiscard]] bool loadFromFile(const std::string& filename); + [[nodiscard]] bool loadFromFile(const std::filesystem::path& filename); //////////////////////////////////////////////////////////// /// \brief Load the font from a file in memory diff --git a/include/SFML/Graphics/Image.hpp b/include/SFML/Graphics/Image.hpp index f3cac62b0..d58989135 100644 --- a/include/SFML/Graphics/Image.hpp +++ b/include/SFML/Graphics/Image.hpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -125,7 +126,7 @@ public: /// \see loadFromMemory, loadFromStream, saveToFile /// //////////////////////////////////////////////////////////// - [[nodiscard]] bool loadFromFile(const std::string& filename); + [[nodiscard]] bool loadFromFile(const std::filesystem::path& filename); //////////////////////////////////////////////////////////// /// \brief Load the image from a file in memory @@ -177,7 +178,7 @@ public: /// \see create, loadFromFile, loadFromMemory /// //////////////////////////////////////////////////////////// - [[nodiscard]] bool saveToFile(const std::string& filename) const; + [[nodiscard]] bool saveToFile(const std::filesystem::path& filename) const; //////////////////////////////////////////////////////////// /// \brief Save the image to a buffer in memory diff --git a/include/SFML/Graphics/Shader.hpp b/include/SFML/Graphics/Shader.hpp index b1754f5fc..ac71301f9 100644 --- a/include/SFML/Graphics/Shader.hpp +++ b/include/SFML/Graphics/Shader.hpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -127,7 +128,7 @@ public: /// \see loadFromMemory, loadFromStream /// //////////////////////////////////////////////////////////// - [[nodiscard]] bool loadFromFile(const std::string& filename, Type type); + [[nodiscard]] bool loadFromFile(const std::filesystem::path& filename, Type type); //////////////////////////////////////////////////////////// /// \brief Load both the vertex and fragment shaders from files @@ -148,7 +149,7 @@ public: /// \see loadFromMemory, loadFromStream /// //////////////////////////////////////////////////////////// - [[nodiscard]] bool loadFromFile(const std::string& vertexShaderFilename, const std::string& fragmentShaderFilename); + [[nodiscard]] bool loadFromFile(const std::filesystem::path& vertexShaderFilename, const std::filesystem::path& fragmentShaderFilename); //////////////////////////////////////////////////////////// /// \brief Load the vertex, geometry and fragment shaders from files @@ -170,7 +171,7 @@ public: /// \see loadFromMemory, loadFromStream /// //////////////////////////////////////////////////////////// - [[nodiscard]] bool loadFromFile(const std::string& vertexShaderFilename, const std::string& geometryShaderFilename, const std::string& fragmentShaderFilename); + [[nodiscard]] bool loadFromFile(const std::filesystem::path& vertexShaderFilename, const std::filesystem::path& geometryShaderFilename, const std::filesystem::path& fragmentShaderFilename); //////////////////////////////////////////////////////////// /// \brief Load the vertex, geometry or fragment shader from a source code in memory diff --git a/include/SFML/Graphics/Texture.hpp b/include/SFML/Graphics/Texture.hpp index a33b03d08..ef50660b6 100644 --- a/include/SFML/Graphics/Texture.hpp +++ b/include/SFML/Graphics/Texture.hpp @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -127,7 +128,7 @@ public: /// \see loadFromMemory, loadFromStream, loadFromImage /// //////////////////////////////////////////////////////////// - [[nodiscard]] bool loadFromFile(const std::string& filename, const IntRect& area = IntRect()); + [[nodiscard]] bool loadFromFile(const std::filesystem::path& filename, const IntRect& area = IntRect()); //////////////////////////////////////////////////////////// /// \brief Load the texture from a file in memory diff --git a/include/SFML/Network/Ftp.hpp b/include/SFML/Network/Ftp.hpp index 2ae1aa8e0..0c8a0b08e 100644 --- a/include/SFML/Network/Ftp.hpp +++ b/include/SFML/Network/Ftp.hpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -202,14 +203,14 @@ public: /// \return Directory name /// //////////////////////////////////////////////////////////// - const std::string& getDirectory() const; + const std::filesystem::path& getDirectory() const; private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - std::string m_directory; //!< Directory extracted from the response message + std::filesystem::path m_directory; //!< Directory extracted from the response message }; @@ -442,7 +443,7 @@ public: /// \see deleteFile /// //////////////////////////////////////////////////////////// - [[nodiscard]] Response renameFile(const std::string& file, const std::string& newName); + [[nodiscard]] Response renameFile(const std::filesystem::path& file, const std::filesystem::path& newName); //////////////////////////////////////////////////////////// /// \brief Remove an existing file @@ -459,7 +460,7 @@ public: /// \see renameFile /// //////////////////////////////////////////////////////////// - [[nodiscard]] Response deleteFile(const std::string& name); + [[nodiscard]] Response deleteFile(const std::filesystem::path& name); //////////////////////////////////////////////////////////// /// \brief Download a file from the server @@ -481,7 +482,7 @@ public: /// \see upload /// //////////////////////////////////////////////////////////// - [[nodiscard]] Response download(const std::string& remoteFile, const std::string& localPath, TransferMode mode = Binary); + [[nodiscard]] Response download(const std::filesystem::path& remoteFile, const std::filesystem::path& localPath, TransferMode mode = Binary); //////////////////////////////////////////////////////////// /// \brief Upload a file to the server diff --git a/include/SFML/System/FileInputStream.hpp b/include/SFML/System/FileInputStream.hpp index 7670ccf8d..9fe74543c 100644 --- a/include/SFML/System/FileInputStream.hpp +++ b/include/SFML/System/FileInputStream.hpp @@ -34,6 +34,7 @@ #include #include #include +#include #ifdef SFML_SYSTEM_ANDROID namespace sf::priv @@ -96,7 +97,7 @@ public: /// \return True on success, false on error /// //////////////////////////////////////////////////////////// - [[nodiscard]] bool open(const std::string& filename); + [[nodiscard]] bool open(const std::filesystem::path& filename); //////////////////////////////////////////////////////////// /// \brief Read data from the stream diff --git a/include/SFML/System/InputStream.hpp b/include/SFML/System/InputStream.hpp index 475e098f4..cd1691706 100644 --- a/include/SFML/System/InputStream.hpp +++ b/include/SFML/System/InputStream.hpp @@ -119,7 +119,7 @@ public: /// /// ZipStream(const std::string& archive); /// -/// [[nodiscard]] bool open(const std::string& filename); +/// [[nodiscard]] bool open(const std::filesystem::path& filename); /// /// [[nodiscard]] Int64 read(void* data, Int64 size); /// diff --git a/src/SFML/Audio/ALCheck.cpp b/src/SFML/Audio/ALCheck.cpp index 2f1bc6afa..1cd12ff54 100644 --- a/src/SFML/Audio/ALCheck.cpp +++ b/src/SFML/Audio/ALCheck.cpp @@ -43,14 +43,13 @@ namespace sf namespace priv { //////////////////////////////////////////////////////////// -void alCheckError(const char* file, unsigned int line, const char* expression) +void alCheckError(const std::filesystem::path& file, unsigned int line, const char* expression) { // Get the last error ALenum errorCode = alGetError(); if (errorCode != AL_NO_ERROR) { - std::string fileString = file; std::string error = "Unknown error"; std::string description = "No description"; @@ -95,7 +94,7 @@ void alCheckError(const char* file, unsigned int line, const char* expression) // Log the error err() << "An internal OpenAL call failed in " - << fileString.substr(fileString.find_last_of("\\/") + 1) << "(" << line << ")." + << file.filename() << "(" << line << ")." << "\nExpression:\n " << expression << "\nError description:\n " << error << "\n " << description << '\n' << std::endl; diff --git a/src/SFML/Audio/ALCheck.hpp b/src/SFML/Audio/ALCheck.hpp index 599afdd0f..f5a99ad1c 100644 --- a/src/SFML/Audio/ALCheck.hpp +++ b/src/SFML/Audio/ALCheck.hpp @@ -29,6 +29,7 @@ // Headers //////////////////////////////////////////////////////////// #include +#include #if defined(__APPLE__) #if defined(__clang__) @@ -72,7 +73,7 @@ namespace priv /// \param expression The evaluated expression as a string /// //////////////////////////////////////////////////////////// -void alCheckError(const char* file, unsigned int line, const char* expression); +void alCheckError(const std::filesystem::path& file, unsigned int line, const char* expression); } // namespace priv diff --git a/src/SFML/Audio/AudioDevice.cpp b/src/SFML/Audio/AudioDevice.cpp index feaf677ee..317887a50 100644 --- a/src/SFML/Audio/AudioDevice.cpp +++ b/src/SFML/Audio/AudioDevice.cpp @@ -109,7 +109,7 @@ AudioDevice::~AudioDevice() //////////////////////////////////////////////////////////// -bool AudioDevice::isExtensionSupported(const std::string& extension) +bool AudioDevice::isExtensionSupported(const std::filesystem::path& extension) { // Create a temporary audio device in case none exists yet. // This device will not be used in this function and merely @@ -119,10 +119,10 @@ bool AudioDevice::isExtensionSupported(const std::string& extension) if (!audioDevice) device.emplace(); - if ((extension.length() > 2) && (extension.substr(0, 3) == "ALC")) - return alcIsExtensionPresent(audioDevice, extension.c_str()) != AL_FALSE; + if ((extension.string().length() > 2) && (extension.string().substr(0, 3) == "ALC")) + return alcIsExtensionPresent(audioDevice, extension.string().c_str()) != AL_FALSE; else - return alIsExtensionPresent(extension.c_str()) != AL_FALSE; + return alIsExtensionPresent(extension.string().c_str()) != AL_FALSE; } diff --git a/src/SFML/Audio/AudioDevice.hpp b/src/SFML/Audio/AudioDevice.hpp index 4ae9db2eb..817e868b2 100644 --- a/src/SFML/Audio/AudioDevice.hpp +++ b/src/SFML/Audio/AudioDevice.hpp @@ -29,7 +29,7 @@ // Headers //////////////////////////////////////////////////////////// #include -#include +#include namespace sf @@ -70,7 +70,7 @@ public: /// \return True if the extension is supported, false if not /// //////////////////////////////////////////////////////////// - static bool isExtensionSupported(const std::string& extension); + static bool isExtensionSupported(const std::filesystem::path& extension); //////////////////////////////////////////////////////////// /// \brief Get the OpenAL format that matches the given number of channels diff --git a/src/SFML/Audio/InputSoundFile.cpp b/src/SFML/Audio/InputSoundFile.cpp index 62ee3ceec..3cb5a19b0 100644 --- a/src/SFML/Audio/InputSoundFile.cpp +++ b/src/SFML/Audio/InputSoundFile.cpp @@ -84,7 +84,7 @@ InputSoundFile::~InputSoundFile() //////////////////////////////////////////////////////////// -bool InputSoundFile::openFromFile(const std::string& filename) +bool InputSoundFile::openFromFile(const std::filesystem::path& filename) { // If the file is already open, first close it close(); diff --git a/src/SFML/Audio/Music.cpp b/src/SFML/Audio/Music.cpp index 24bf95021..9570556c5 100644 --- a/src/SFML/Audio/Music.cpp +++ b/src/SFML/Audio/Music.cpp @@ -62,7 +62,7 @@ Music::~Music() //////////////////////////////////////////////////////////// -bool Music::openFromFile(const std::string& filename) +bool Music::openFromFile(const std::filesystem::path& filename) { // First stop the music if it was already running stop(); diff --git a/src/SFML/Audio/OutputSoundFile.cpp b/src/SFML/Audio/OutputSoundFile.cpp index edccc511e..67248a49e 100644 --- a/src/SFML/Audio/OutputSoundFile.cpp +++ b/src/SFML/Audio/OutputSoundFile.cpp @@ -48,7 +48,7 @@ OutputSoundFile::~OutputSoundFile() //////////////////////////////////////////////////////////// -bool OutputSoundFile::openFromFile(const std::string& filename, unsigned int sampleRate, unsigned int channelCount) +bool OutputSoundFile::openFromFile(const std::filesystem::path& filename, unsigned int sampleRate, unsigned int channelCount) { // If the file is already open, first close it close(); diff --git a/src/SFML/Audio/SoundBuffer.cpp b/src/SFML/Audio/SoundBuffer.cpp index 4a3d8b64c..63e5028a0 100644 --- a/src/SFML/Audio/SoundBuffer.cpp +++ b/src/SFML/Audio/SoundBuffer.cpp @@ -92,7 +92,7 @@ SoundBuffer::~SoundBuffer() //////////////////////////////////////////////////////////// -bool SoundBuffer::loadFromFile(const std::string& filename) +bool SoundBuffer::loadFromFile(const std::filesystem::path& filename) { InputSoundFile file; if (file.openFromFile(filename)) @@ -151,7 +151,7 @@ bool SoundBuffer::loadFromSamples(const Int16* samples, Uint64 sampleCount, unsi //////////////////////////////////////////////////////////// -bool SoundBuffer::saveToFile(const std::string& filename) const +bool SoundBuffer::saveToFile(const std::filesystem::path& filename) const { // Create the sound file in write mode OutputSoundFile file; diff --git a/src/SFML/Audio/SoundFileFactory.cpp b/src/SFML/Audio/SoundFileFactory.cpp index 9ea5d784c..5abc0bdaa 100644 --- a/src/SFML/Audio/SoundFileFactory.cpp +++ b/src/SFML/Audio/SoundFileFactory.cpp @@ -66,7 +66,7 @@ SoundFileFactory::WriterFactoryArray SoundFileFactory::s_writers; //////////////////////////////////////////////////////////// -std::unique_ptr SoundFileFactory::createReaderFromFilename(const std::string& filename) +std::unique_ptr SoundFileFactory::createReaderFromFilename(const std::filesystem::path& filename) { // Register the built-in readers/writers on first call ensureDefaultReadersWritersRegistered(); @@ -152,7 +152,7 @@ std::unique_ptr SoundFileFactory::createReaderFromStream(InputS //////////////////////////////////////////////////////////// -std::unique_ptr SoundFileFactory::createWriterFromFilename(const std::string& filename) +std::unique_ptr SoundFileFactory::createWriterFromFilename(const std::filesystem::path& filename) { // Register the built-in readers/writers on first call ensureDefaultReadersWritersRegistered(); diff --git a/src/SFML/Audio/SoundFileWriterFlac.cpp b/src/SFML/Audio/SoundFileWriterFlac.cpp index 789a2b90c..aaf422975 100644 --- a/src/SFML/Audio/SoundFileWriterFlac.cpp +++ b/src/SFML/Audio/SoundFileWriterFlac.cpp @@ -39,11 +39,9 @@ namespace sf namespace priv { //////////////////////////////////////////////////////////// -bool SoundFileWriterFlac::check(const std::string& filename) +bool SoundFileWriterFlac::check(const std::filesystem::path& filename) { - const std::string extension = toLower(filename.substr(filename.find_last_of('.') + 1)); - - return extension == "flac"; + return toLower(filename.extension().string()) == ".flac"; } @@ -64,7 +62,7 @@ SoundFileWriterFlac::~SoundFileWriterFlac() //////////////////////////////////////////////////////////// -bool SoundFileWriterFlac::open(const std::string& filename, unsigned int sampleRate, unsigned int channelCount) +bool SoundFileWriterFlac::open(const std::filesystem::path& filename, unsigned int sampleRate, unsigned int channelCount) { // Create the encoder m_encoder = FLAC__stream_encoder_new(); @@ -80,7 +78,7 @@ bool SoundFileWriterFlac::open(const std::string& filename, unsigned int sampleR FLAC__stream_encoder_set_sample_rate(m_encoder, sampleRate); // Initialize the output stream - if (FLAC__stream_encoder_init_file(m_encoder, filename.c_str(), nullptr, nullptr) != FLAC__STREAM_ENCODER_INIT_STATUS_OK) + if (FLAC__stream_encoder_init_file(m_encoder, filename.string().c_str(), nullptr, nullptr) != FLAC__STREAM_ENCODER_INIT_STATUS_OK) { err() << "Failed to write flac file \"" << filename << "\" (failed to open the file)" << std::endl; close(); diff --git a/src/SFML/Audio/SoundFileWriterFlac.hpp b/src/SFML/Audio/SoundFileWriterFlac.hpp index 76cead032..34d611efb 100644 --- a/src/SFML/Audio/SoundFileWriterFlac.hpp +++ b/src/SFML/Audio/SoundFileWriterFlac.hpp @@ -30,6 +30,7 @@ //////////////////////////////////////////////////////////// #include #include +#include #include @@ -53,7 +54,7 @@ public: /// \return True if the file can be written by this writer /// //////////////////////////////////////////////////////////// - [[nodiscard]] static bool check(const std::string& filename); + [[nodiscard]] static bool check(const std::filesystem::path& filename); public: @@ -79,7 +80,7 @@ public: /// \return True if the file was successfully opened /// //////////////////////////////////////////////////////////// - [[nodiscard]] bool open(const std::string& filename, unsigned int sampleRate, unsigned int channelCount) override; + [[nodiscard]] bool open(const std::filesystem::path& filename, unsigned int sampleRate, unsigned int channelCount) override; //////////////////////////////////////////////////////////// /// \brief Write audio samples to the open file diff --git a/src/SFML/Audio/SoundFileWriterOgg.cpp b/src/SFML/Audio/SoundFileWriterOgg.cpp index dd16ae0f0..915599d69 100644 --- a/src/SFML/Audio/SoundFileWriterOgg.cpp +++ b/src/SFML/Audio/SoundFileWriterOgg.cpp @@ -40,11 +40,9 @@ namespace sf namespace priv { //////////////////////////////////////////////////////////// -bool SoundFileWriterOgg::check(const std::string& filename) +bool SoundFileWriterOgg::check(const std::filesystem::path& filename) { - const std::string extension = toLower(filename.substr(filename.find_last_of('.') + 1)); - - return extension == "ogg"; + return toLower(filename.extension().string()) == ".ogg"; } @@ -67,7 +65,7 @@ SoundFileWriterOgg::~SoundFileWriterOgg() //////////////////////////////////////////////////////////// -bool SoundFileWriterOgg::open(const std::string& filename, unsigned int sampleRate, unsigned int channelCount) +bool SoundFileWriterOgg::open(const std::filesystem::path& filename, unsigned int sampleRate, unsigned int channelCount) { // Save the channel count m_channelCount = channelCount; diff --git a/src/SFML/Audio/SoundFileWriterOgg.hpp b/src/SFML/Audio/SoundFileWriterOgg.hpp index 46f2e40ab..b5600f2b1 100644 --- a/src/SFML/Audio/SoundFileWriterOgg.hpp +++ b/src/SFML/Audio/SoundFileWriterOgg.hpp @@ -30,6 +30,7 @@ //////////////////////////////////////////////////////////// #include #include +#include #include @@ -53,7 +54,7 @@ public: /// \return True if the file can be written by this writer /// //////////////////////////////////////////////////////////// - [[nodiscard]] static bool check(const std::string& filename); + [[nodiscard]] static bool check(const std::filesystem::path& filename); public: @@ -79,7 +80,7 @@ public: /// \return True if the file was successfully opened /// //////////////////////////////////////////////////////////// - [[nodiscard]] bool open(const std::string& filename, unsigned int sampleRate, unsigned int channelCount) override; + [[nodiscard]] bool open(const std::filesystem::path& filename, unsigned int sampleRate, unsigned int channelCount) override; //////////////////////////////////////////////////////////// /// \brief Write audio samples to the open file diff --git a/src/SFML/Audio/SoundFileWriterWav.cpp b/src/SFML/Audio/SoundFileWriterWav.cpp index cb4a855cb..eebf55798 100644 --- a/src/SFML/Audio/SoundFileWriterWav.cpp +++ b/src/SFML/Audio/SoundFileWriterWav.cpp @@ -75,11 +75,9 @@ namespace sf namespace priv { //////////////////////////////////////////////////////////// -bool SoundFileWriterWav::check(const std::string& filename) +bool SoundFileWriterWav::check(const std::filesystem::path& filename) { - const std::string extension = toLower(filename.substr(filename.find_last_of('.') + 1)); - - return extension == "wav"; + return toLower(filename.extension().string()) == ".wav"; } @@ -98,7 +96,7 @@ SoundFileWriterWav::~SoundFileWriterWav() //////////////////////////////////////////////////////////// -bool SoundFileWriterWav::open(const std::string& filename, unsigned int sampleRate, unsigned int channelCount) +bool SoundFileWriterWav::open(const std::filesystem::path& filename, unsigned int sampleRate, unsigned int channelCount) { // Open the file m_file.open(filename.c_str(), std::ios::binary); diff --git a/src/SFML/Audio/SoundFileWriterWav.hpp b/src/SFML/Audio/SoundFileWriterWav.hpp index 4e8cb84f9..0607e47d5 100644 --- a/src/SFML/Audio/SoundFileWriterWav.hpp +++ b/src/SFML/Audio/SoundFileWriterWav.hpp @@ -53,7 +53,7 @@ public: /// \return True if the file can be written by this writer /// //////////////////////////////////////////////////////////// - [[nodiscard]] static bool check(const std::string& filename); + [[nodiscard]] static bool check(const std::filesystem::path& filename); public: @@ -79,7 +79,7 @@ public: /// \return True if the file was successfully opened /// //////////////////////////////////////////////////////////// - [[nodiscard]] bool open(const std::string& filename, unsigned int sampleRate, unsigned int channelCount) override; + [[nodiscard]] bool open(const std::filesystem::path& filename, unsigned int sampleRate, unsigned int channelCount) override; //////////////////////////////////////////////////////////// /// \brief Write audio samples to the open file diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index a99605801..186ea3efc 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -144,7 +144,7 @@ Font& Font::operator=(Font&&) noexcept = default; //////////////////////////////////////////////////////////// -bool Font::loadFromFile(const std::string& filename) +bool Font::loadFromFile(const std::filesystem::path& filename) { #ifndef SFML_SYSTEM_ANDROID @@ -166,7 +166,7 @@ bool Font::loadFromFile(const std::string& filename) // Load the new font face from the specified file FT_Face face; - if (FT_New_Face(library, filename.c_str(), 0, &face) != 0) + if (FT_New_Face(library, filename.string().c_str(), 0, &face) != 0) { err() << "Failed to load font \"" << filename << "\" (failed to create the font face)" << std::endl; return false; diff --git a/src/SFML/Graphics/GLCheck.cpp b/src/SFML/Graphics/GLCheck.cpp index ddab040dc..8e670a5ef 100644 --- a/src/SFML/Graphics/GLCheck.cpp +++ b/src/SFML/Graphics/GLCheck.cpp @@ -36,14 +36,13 @@ namespace sf namespace priv { //////////////////////////////////////////////////////////// -void glCheckError(const char* file, unsigned int line, const char* expression) +void glCheckError(const std::filesystem::path& file, unsigned int line, const char* expression) { // Get the last error GLenum errorCode = glGetError(); if (errorCode != GL_NO_ERROR) { - std::string fileString = file; std::string error = "Unknown error"; std::string description = "No description"; @@ -102,7 +101,7 @@ void glCheckError(const char* file, unsigned int line, const char* expression) // Log the error err() << "An internal OpenGL call failed in " - << fileString.substr(fileString.find_last_of("\\/") + 1) << "(" << line << ")." + << file.filename() << "(" << line << ")." << "\nExpression:\n " << expression << "\nError description:\n " << error << "\n " << description << '\n' << std::endl; diff --git a/src/SFML/Graphics/GLCheck.hpp b/src/SFML/Graphics/GLCheck.hpp index 52f510678..accbc8cf5 100644 --- a/src/SFML/Graphics/GLCheck.hpp +++ b/src/SFML/Graphics/GLCheck.hpp @@ -30,6 +30,7 @@ //////////////////////////////////////////////////////////// #include #include +#include namespace sf @@ -60,7 +61,7 @@ namespace priv /// \param expression The evaluated expression as a string /// //////////////////////////////////////////////////////////// -void glCheckError(const char* file, unsigned int line, const char* expression); +void glCheckError(const std::filesystem::path& file, unsigned int line, const char* expression); } // namespace priv diff --git a/src/SFML/Graphics/Image.cpp b/src/SFML/Graphics/Image.cpp index a5fe06f5a..010023c5f 100644 --- a/src/SFML/Graphics/Image.cpp +++ b/src/SFML/Graphics/Image.cpp @@ -135,7 +135,7 @@ void Image::create(unsigned int width, unsigned int height, const Uint8* pixels) //////////////////////////////////////////////////////////// -bool Image::loadFromFile(const std::string& filename) +bool Image::loadFromFile(const std::filesystem::path& filename) { #ifndef SFML_SYSTEM_ANDROID @@ -165,7 +165,7 @@ bool Image::loadFromStream(InputStream& stream) //////////////////////////////////////////////////////////// -bool Image::saveToFile(const std::string& filename) const +bool Image::saveToFile(const std::filesystem::path& filename) const { return priv::ImageLoader::getInstance().saveImageToFile(filename, m_pixels, m_size); } diff --git a/src/SFML/Graphics/ImageLoader.cpp b/src/SFML/Graphics/ImageLoader.cpp index cf4c2d101..8f875e4c6 100644 --- a/src/SFML/Graphics/ImageLoader.cpp +++ b/src/SFML/Graphics/ImageLoader.cpp @@ -33,6 +33,7 @@ #include #define STB_IMAGE_WRITE_IMPLEMENTATION #include +#include #include #include @@ -96,7 +97,7 @@ ImageLoader::~ImageLoader() //////////////////////////////////////////////////////////// -bool ImageLoader::loadImageFromFile(const std::string& filename, std::vector& pixels, Vector2u& size) +bool ImageLoader::loadImageFromFile(const std::filesystem::path& filename, std::vector& pixels, Vector2u& size) { // Clear the array (just in case) pixels.clear(); @@ -105,7 +106,7 @@ bool ImageLoader::loadImageFromFile(const std::string& filename, std::vector& p //////////////////////////////////////////////////////////// -bool ImageLoader::saveImageToFile(const std::string& filename, const std::vector& pixels, const Vector2u& size) +bool ImageLoader::saveImageToFile(const std::filesystem::path& filename, const std::vector& pixels, const Vector2u& size) { // Make sure the image is not empty if (!pixels.empty() && (size.x > 0) && (size.y > 0)) @@ -247,32 +248,31 @@ bool ImageLoader::saveImageToFile(const std::string& filename, const std::vector // Deduce the image type from its extension // Extract the extension - const std::size_t dot = filename.find_last_of('.'); - const std::string extension = dot != std::string::npos ? toLower(filename.substr(dot + 1)) : ""; + const std::filesystem::path extension = filename.extension(); const Vector2i convertedSize = Vector2i(size); - if (extension == "bmp") + if (extension == ".bmp") { // BMP format - if (stbi_write_bmp(filename.c_str(), convertedSize.x, convertedSize.y, 4, pixels.data())) + if (stbi_write_bmp(filename.string().c_str(), convertedSize.x, convertedSize.y, 4, pixels.data())) return true; } - else if (extension == "tga") + else if (extension == ".tga") { // TGA format - if (stbi_write_tga(filename.c_str(), convertedSize.x, convertedSize.y, 4, pixels.data())) + if (stbi_write_tga(filename.string().c_str(), convertedSize.x, convertedSize.y, 4, pixels.data())) return true; } - else if (extension == "png") + else if (extension == ".png") { // PNG format - if (stbi_write_png(filename.c_str(), convertedSize.x, convertedSize.y, 4, pixels.data(), 0)) + if (stbi_write_png(filename.string().c_str(), convertedSize.x, convertedSize.y, 4, pixels.data(), 0)) return true; } - else if (extension == "jpg" || extension == "jpeg") + else if (extension == ".jpg" || extension == ".jpeg") { // JPG format - if (stbi_write_jpg(filename.c_str(), convertedSize.x, convertedSize.y, 4, pixels.data(), 90)) + if (stbi_write_jpg(filename.string().c_str(), convertedSize.x, convertedSize.y, 4, pixels.data(), 90)) return true; } } diff --git a/src/SFML/Graphics/ImageLoader.hpp b/src/SFML/Graphics/ImageLoader.hpp index 9608313b0..2d66d821a 100644 --- a/src/SFML/Graphics/ImageLoader.hpp +++ b/src/SFML/Graphics/ImageLoader.hpp @@ -30,6 +30,7 @@ //////////////////////////////////////////////////////////// #include #include +#include #include #include @@ -66,7 +67,7 @@ public: /// \return True if loading was successful /// //////////////////////////////////////////////////////////// - bool loadImageFromFile(const std::string& filename, std::vector& pixels, Vector2u& size); + bool loadImageFromFile(const std::filesystem::path& filename, std::vector& pixels, Vector2u& size); //////////////////////////////////////////////////////////// /// \brief Load an image from a file in memory @@ -103,7 +104,7 @@ public: /// \return True if saving was successful /// //////////////////////////////////////////////////////////// - bool saveImageToFile(const std::string& filename, const std::vector& pixels, const Vector2u& size); + bool saveImageToFile(const std::filesystem::path& filename, const std::vector& pixels, const Vector2u& size); //////////////////////////////////////////////////////////// /// \brief Save an array of pixels as an encoded image buffer diff --git a/src/SFML/Graphics/Shader.cpp b/src/SFML/Graphics/Shader.cpp index 793f36b2a..acea39ec8 100644 --- a/src/SFML/Graphics/Shader.cpp +++ b/src/SFML/Graphics/Shader.cpp @@ -74,7 +74,7 @@ namespace } // Read the contents of a file into an array of char - bool getFileContents(const std::string& filename, std::vector& buffer) + bool getFileContents(const std::filesystem::path& filename, std::vector& buffer) { std::ifstream file(filename.c_str(), std::ios_base::binary); if (file) @@ -253,7 +253,7 @@ Shader::~Shader() //////////////////////////////////////////////////////////// -bool Shader::loadFromFile(const std::string& filename, Type type) +bool Shader::loadFromFile(const std::filesystem::path& filename, Type type) { // Read the file std::vector shader; @@ -274,7 +274,7 @@ bool Shader::loadFromFile(const std::string& filename, Type type) //////////////////////////////////////////////////////////// -bool Shader::loadFromFile(const std::string& vertexShaderFilename, const std::string& fragmentShaderFilename) +bool Shader::loadFromFile(const std::filesystem::path& vertexShaderFilename, const std::filesystem::path& fragmentShaderFilename) { // Read the vertex shader file std::vector vertexShader; @@ -298,7 +298,7 @@ bool Shader::loadFromFile(const std::string& vertexShaderFilename, const std::st //////////////////////////////////////////////////////////// -bool Shader::loadFromFile(const std::string& vertexShaderFilename, const std::string& geometryShaderFilename, const std::string& fragmentShaderFilename) +bool Shader::loadFromFile(const std::filesystem::path& vertexShaderFilename, const std::filesystem::path& geometryShaderFilename, const std::filesystem::path& fragmentShaderFilename) { // Read the vertex shader file std::vector vertexShader; @@ -977,21 +977,21 @@ Shader::~Shader() //////////////////////////////////////////////////////////// -bool Shader::loadFromFile(const std::string& /* filename */, Type /* type */) +bool Shader::loadFromFile(const std::filesystem::path& /* filename */, Type /* type */) { return false; } //////////////////////////////////////////////////////////// -bool Shader::loadFromFile(const std::string& /* vertexShaderFilename */, const std::string& /* fragmentShaderFilename */) +bool Shader::loadFromFile(const std::filesystem::path& /* vertexShaderFilename */, const std::filesystem::path& /* fragmentShaderFilename */) { return false; } //////////////////////////////////////////////////////////// -bool Shader::loadFromFile(const std::string& /* vertexShaderFilename */, const std::string& /* geometryShaderFilename */, const std::string& /* fragmentShaderFilename */) +bool Shader::loadFromFile(const std::filesystem::path& /* vertexShaderFilename */, const std::filesystem::path& /* geometryShaderFilename */, const std::filesystem::path& /* fragmentShaderFilename */) { return false; } diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index 856ceb029..7b65cc37e 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -220,7 +220,7 @@ bool Texture::create(unsigned int width, unsigned int height) //////////////////////////////////////////////////////////// -bool Texture::loadFromFile(const std::string& filename, const IntRect& area) +bool Texture::loadFromFile(const std::filesystem::path& filename, const IntRect& area) { Image image; return image.loadFromFile(filename) && loadFromImage(image, area); diff --git a/src/SFML/Network/Ftp.cpp b/src/SFML/Network/Ftp.cpp index 9b2aa689a..b51da526f 100644 --- a/src/SFML/Network/Ftp.cpp +++ b/src/SFML/Network/Ftp.cpp @@ -123,7 +123,7 @@ Ftp::Response(response) //////////////////////////////////////////////////////////// -const std::string& Ftp::DirectoryResponse::getDirectory() const +const std::filesystem::path& Ftp::DirectoryResponse::getDirectory() const { return m_directory; } @@ -270,25 +270,25 @@ Ftp::Response Ftp::deleteDirectory(const std::string& name) //////////////////////////////////////////////////////////// -Ftp::Response Ftp::renameFile(const std::string& file, const std::string& newName) +Ftp::Response Ftp::renameFile(const std::filesystem::path& file, const std::filesystem::path& newName) { - Response response = sendCommand("RNFR", file); + Response response = sendCommand("RNFR", file.string()); if (response.isOk()) - response = sendCommand("RNTO", newName); + response = sendCommand("RNTO", newName.string()); return response; } //////////////////////////////////////////////////////////// -Ftp::Response Ftp::deleteFile(const std::string& name) +Ftp::Response Ftp::deleteFile(const std::filesystem::path& name) { - return sendCommand("DELE", name); + return sendCommand("DELE", name.string()); } //////////////////////////////////////////////////////////// -Ftp::Response Ftp::download(const std::string& remoteFile, const std::string& localPath, TransferMode mode) +Ftp::Response Ftp::download(const std::filesystem::path& remoteFile, const std::filesystem::path& localPath, TransferMode mode) { // Open a data channel using the given transfer mode DataChannel data(*this); @@ -296,22 +296,12 @@ Ftp::Response Ftp::download(const std::string& remoteFile, const std::string& lo if (response.isOk()) { // Tell the server to start the transfer - response = sendCommand("RETR", remoteFile); + response = sendCommand("RETR", remoteFile.string()); if (response.isOk()) { - // Extract the filename from the file path - std::string filename = remoteFile; - std::string::size_type pos = filename.find_last_of("/\\"); - if (pos != std::string::npos) - filename = filename.substr(pos + 1); - - // Make sure the destination path ends with a slash - std::string path = localPath; - if (!path.empty() && (path[path.size() - 1] != '\\') && (path[path.size() - 1] != '/')) - path += "/"; - // Create the file and truncate it if necessary - std::ofstream file((path + filename).c_str(), std::ios_base::binary | std::ios_base::trunc); + const std::filesystem::path filepath = localPath / remoteFile.filename(); + std::ofstream file(filepath, std::ios_base::binary | std::ios_base::trunc); if (!file) return Response(Response::InvalidFile); @@ -326,7 +316,7 @@ Ftp::Response Ftp::download(const std::string& remoteFile, const std::string& lo // If the download was unsuccessful, delete the partial file if (!response.isOk()) - std::remove((path + filename).c_str()); + std::remove(filepath.string().c_str()); } } diff --git a/src/SFML/System/Android/ResourceStream.cpp b/src/SFML/System/Android/ResourceStream.cpp index 6851e227d..1317a96f0 100644 --- a/src/SFML/System/Android/ResourceStream.cpp +++ b/src/SFML/System/Android/ResourceStream.cpp @@ -37,7 +37,7 @@ namespace priv { //////////////////////////////////////////////////////////// -ResourceStream::ResourceStream(const std::string& filename) : +ResourceStream::ResourceStream(const std::filesystem::path& filename) : m_file (nullptr) { ActivityStates& states = getActivity(); diff --git a/src/SFML/System/Android/ResourceStream.hpp b/src/SFML/System/Android/ResourceStream.hpp index 6b922087d..fbdb81448 100644 --- a/src/SFML/System/Android/ResourceStream.hpp +++ b/src/SFML/System/Android/ResourceStream.hpp @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -52,7 +53,7 @@ public: /// \param filename Filename of the asset /// //////////////////////////////////////////////////////////// - ResourceStream(const std::string& filename); + ResourceStream(const std::filesystem::path& filename); //////////////////////////////////////////////////////////// /// \brief Destructor diff --git a/src/SFML/System/FileInputStream.cpp b/src/SFML/System/FileInputStream.cpp index 8363ecb69..9f108219f 100644 --- a/src/SFML/System/FileInputStream.cpp +++ b/src/SFML/System/FileInputStream.cpp @@ -60,13 +60,17 @@ FileInputStream& FileInputStream::operator=(FileInputStream&&) = default; //////////////////////////////////////////////////////////// -bool FileInputStream::open(const std::string& filename) +bool FileInputStream::open(const std::filesystem::path& filename) { #ifdef SFML_SYSTEM_ANDROID m_file = std::make_unique(filename); return m_file->tell() != -1; +#else +#ifdef SFML_SYSTEM_WINDOWS + m_file.reset(_wfopen(filename.c_str(), L"rb")); #else m_file.reset(std::fopen(filename.c_str(), "rb")); +#endif return m_file != nullptr; #endif } diff --git a/src/SFML/Window/EGLCheck.cpp b/src/SFML/Window/EGLCheck.cpp index 22b20974d..b7324789e 100644 --- a/src/SFML/Window/EGLCheck.cpp +++ b/src/SFML/Window/EGLCheck.cpp @@ -38,7 +38,7 @@ namespace sf namespace priv { //////////////////////////////////////////////////////////// -void eglCheckError(const char* file, unsigned int line, const char* expression) +void eglCheckError(const std::filesystem::path& file, unsigned int line, const char* expression) { // Obtain information about the success or failure of the most recent EGL // function called in the current thread @@ -46,7 +46,6 @@ void eglCheckError(const char* file, unsigned int line, const char* expression) if (errorCode != EGL_SUCCESS) { - std::string fileString(file); std::string error = "unknown error"; std::string description = "no description"; @@ -154,7 +153,7 @@ void eglCheckError(const char* file, unsigned int line, const char* expression) // Log the error err() << "An internal EGL call failed in " - << fileString.substr(fileString.find_last_of("\\/") + 1) << " (" << line << ") : " + << file.filename() << " (" << line << ") : " << "\nExpression:\n " << expression << "\nError description:\n " << error << "\n " << description << '\n' << std::endl; diff --git a/src/SFML/Window/EGLCheck.hpp b/src/SFML/Window/EGLCheck.hpp index 367d3b70a..771e69b7d 100644 --- a/src/SFML/Window/EGLCheck.hpp +++ b/src/SFML/Window/EGLCheck.hpp @@ -29,6 +29,7 @@ // Headers //////////////////////////////////////////////////////////// #include +#include namespace sf @@ -59,7 +60,7 @@ namespace priv /// \param expression The evaluated expression as a string /// //////////////////////////////////////////////////////////// -void eglCheckError(const char* file, unsigned int line, const char* expression); +void eglCheckError(const std::filesystem::path& file, unsigned int line, const char* expression); } // namespace priv } // namespace sf diff --git a/src/SFML/Window/Unix/WindowImplX11.cpp b/src/SFML/Window/Unix/WindowImplX11.cpp index b6414e862..2c87a8926 100644 --- a/src/SFML/Window/Unix/WindowImplX11.cpp +++ b/src/SFML/Window/Unix/WindowImplX11.cpp @@ -55,6 +55,7 @@ #include #include #include +#include #ifdef SFML_OPENGL_ES #include @@ -113,7 +114,7 @@ namespace } // Find the name of the current executable - std::string findExecutableName() + std::filesystem::path findExecutableName() { // We use /proc/self/cmdline to get the command line // the user used to invoke this instance of the application @@ -737,7 +738,7 @@ m_lastInputTime (0) // The instance name should be something unique to this invocation // of the application but is rarely if ever used these days. // For simplicity, we retrieve it via the base executable name. - std::string executableName = findExecutableName(); + std::string executableName = findExecutableName().string(); std::vector windowInstance(executableName.size() + 1, 0); std::copy(executableName.begin(), executableName.end(), windowInstance.begin()); hint->res_name = windowInstance.data(); diff --git a/tools/xcode/templates/SFML/SFML App.xctemplate/ResourcePath.hpp b/tools/xcode/templates/SFML/SFML App.xctemplate/ResourcePath.hpp index c18b066c5..d748ed71a 100644 --- a/tools/xcode/templates/SFML/SFML App.xctemplate/ResourcePath.hpp +++ b/tools/xcode/templates/SFML/SFML App.xctemplate/ResourcePath.hpp @@ -29,7 +29,7 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// -#include +#include //////////////////////////////////////////////////////////// /// \brief Return the path to the resource folder. @@ -38,6 +38,6 @@ /// with the main bundle or an empty string is there is no bundle. /// //////////////////////////////////////////////////////////// -std::string resourcePath(void); +std::filesystem::path resourcePath(void); #endif diff --git a/tools/xcode/templates/SFML/SFML App.xctemplate/ResourcePath.mm b/tools/xcode/templates/SFML/SFML App.xctemplate/ResourcePath.mm index feb87bad4..c877eac0a 100644 --- a/tools/xcode/templates/SFML/SFML App.xctemplate/ResourcePath.mm +++ b/tools/xcode/templates/SFML/SFML App.xctemplate/ResourcePath.mm @@ -28,13 +28,14 @@ //////////////////////////////////////////////////////////// #include "ResourcePath.hpp" #import +#include //////////////////////////////////////////////////////////// -std::string resourcePath(void) +std::filesystem::path resourcePath(void) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - std::string rpath; + std::filesystem::path rpath; NSBundle* bundle = [NSBundle mainBundle]; if (bundle == nil) {