File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616/CMakeCache.txt
1717/CMakeFiles
1818/cmake_install.cmake
19+ /d2char
20+ /d2data
21+ /d2music
22+ /d2sfx
23+ /d2speech
24+ /d2video
1925/Debug
2026/Debug Clang
2127/Debug Code Analysis
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules")
1515
1616option (DGENGINE_MOVIE_SUPPORT "Enable Movie support" TRUE )
1717option (DGENGINE_DIABLO_FORMAT_SUPPORT "Enable Diablo 1-2 file format support" TRUE )
18+ option (DGENGINE_FALLBACK_TO_LOWERCASE_FILENAME "Enable falling back to all lowercase names if file is not found" TRUE )
1819
1920if (DGENGINE_MOVIE_SUPPORT)
2021 find_package (FFmpeg COMPONENTS avcodec avformat avutil swscale )
@@ -422,6 +423,10 @@ else()
422423 add_definitions (-DNO_DIABLO_FORMAT_SUPPORT )
423424endif ()
424425
426+ if (DGENGINE_FALLBACK_TO_LOWERCASE_FILENAME)
427+ add_definitions (-DFALLBACK_TO_LOWERCASE_FILENAME )
428+ endif ()
429+
425430add_executable (${PROJECT_NAME } ${SOURCE_FILES} )
426431
427432target_link_libraries (${PROJECT_NAME } stdc++fs )
Original file line number Diff line number Diff line change 2020// distribution.
2121
2222#include " PhysFSStream.h"
23+ #include " Utils/Utils.h"
24+
25+ #ifdef FALLBACK_TO_LOWERCASE_FILENAME
26+ static constexpr bool FALLBACK_TO_LOWERCASE = false ;
27+ #else
28+ static constexpr bool FALLBACK_TO_LOWERCASE = true ;
29+ #endif
30+
31+ sf::PhysFSStream::PhysFSStream (const std::string& fileName)
32+ {
33+ load (fileName);
34+ }
2335
2436sf::PhysFSStream::PhysFSStream (const char * fileName)
2537{
26- file = PHYSFS_openRead (fileName);
38+ load (fileName);
2739}
2840
2941sf::PhysFSStream::~PhysFSStream ()
@@ -34,12 +46,37 @@ sf::PhysFSStream::~PhysFSStream()
3446 }
3547}
3648
49+ bool sf::PhysFSStream::load (const std::string& fileName)
50+ {
51+ if (file == nullptr )
52+ {
53+ file = PHYSFS_openRead (fileName.c_str ());
54+ }
55+ if constexpr (FALLBACK_TO_LOWERCASE == true )
56+ {
57+ if (file == nullptr )
58+ {
59+ auto lowerCaseFileName = Utils::toLower (fileName);
60+ file = PHYSFS_openRead (lowerCaseFileName.c_str ());
61+ }
62+ }
63+ return (file != nullptr );
64+ }
65+
3766bool sf::PhysFSStream::load (const char * fileName)
3867{
3968 if (file == nullptr )
4069 {
4170 file = PHYSFS_openRead (fileName);
4271 }
72+ if constexpr (FALLBACK_TO_LOWERCASE == true )
73+ {
74+ if (file == nullptr )
75+ {
76+ auto lowerCaseFileName = Utils::toLower (fileName);
77+ file = PHYSFS_openRead (lowerCaseFileName.c_str ());
78+ }
79+ }
4380 return (file != nullptr );
4481}
4582
Original file line number Diff line number Diff line change @@ -33,11 +33,11 @@ namespace sf
3333 PHYSFS_File* file;
3434
3535 public:
36- PhysFSStream (const std::string& fileName) : PhysFSStream(fileName.c_str()) {}
36+ PhysFSStream (const std::string& fileName);
3737 PhysFSStream (const char * fileName);
3838 ~PhysFSStream () override ;
3939
40- bool load (const std::string& fileName) { return load (fileName. c_str ()); }
40+ bool load (const std::string& fileName);
4141 bool load (const char * fileName);
4242
4343 sf::Int64 read (void * data, sf::Int64 size) noexcept override ;
You can’t perform that action at this time.
0 commit comments