Skip to content

Commit

Permalink
- initialize PhysFSStream to nullptr
Browse files Browse the repository at this point in the history
- make file.exists use lowercase fallback
  • Loading branch information
dgengin committed Nov 12, 2019
1 parent 22ce98a commit 302717c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/FileUtils.cpp
Expand Up @@ -8,6 +8,12 @@

namespace FileUtils
{
#ifdef FALLBACK_TO_LOWERCASE_FILENAME
static constexpr bool FALLBACK_TO_LOWERCASE = true;
#else
static constexpr bool FALLBACK_TO_LOWERCASE = false;
#endif

void initPhysFS(const char* argv0)
{
static const char* mainArgv0 = argv0;
Expand Down Expand Up @@ -272,7 +278,16 @@ namespace FileUtils

bool exists(const char* filePath) noexcept
{
return PHYSFS_exists(filePath) != 0;
auto fileExists = PHYSFS_exists(filePath) != 0;
if constexpr (FALLBACK_TO_LOWERCASE == true)
{
if (fileExists == false)
{
auto lowerCasefilePath = Utils::toLower(filePath);
fileExists = PHYSFS_exists(lowerCasefilePath.c_str()) != 0;
}
}
return fileExists;
}

std::vector<std::string> getFileList(const std::string_view filePath,
Expand Down
2 changes: 1 addition & 1 deletion src/PhysFSStream.h
Expand Up @@ -30,7 +30,7 @@ namespace sf
class PhysFSStream : public sf::InputStream, public sf::NonCopyable
{
private:
PHYSFS_File* file;
PHYSFS_File* file{ nullptr };

public:
PhysFSStream(const std::string& fileName);
Expand Down

0 comments on commit 302717c

Please sign in to comment.