Skip to content

Commit 7ace712

Browse files
committed
fs separator handling (windows)
1 parent 3f6ef2c commit 7ace712

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

Assets/Assets.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ ptr<File> LoadMap(const std::string& filename)
7272
ptr<File> LoadSFX(const std::string& filename)
7373
{
7474
static const char* const extensions[] = {"wav", NULL};
75+
76+
int i = filename.find('\\');
77+
int j = filename.find('/');
78+
79+
// Check if the path already contains a path. If so we should not use the pre defined base path
80+
if (i >= 0 || j >= 0)
81+
{
82+
return LoadFile(filename, extensions);
83+
}
84+
7585
return LoadFile(BASE_PATH_SFX + filename, extensions);
7686
}
7787

Assets/FileIndex.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,22 @@ static ptr<File> LoadVirtualFile(const std::string& filename_)
5757
return NULL;
5858
}
5959

60+
static inline void ReplaceAll2(std::string& str, const std::string& from, const std::string& to)
61+
{
62+
size_t start_pos = 0;
63+
while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
64+
str.replace(start_pos, from.length(), to);
65+
start_pos += to.length(); // Handles case where 'to' is a substring of 'from'
66+
}
67+
}
68+
6069
ptr<File> LoadFile(string filename, const char* const * Extensions)
6170
{
6271
// Strip the extension of the filename
6372
string ext;
73+
74+
ReplaceAll2(filename, "/", "\\");
75+
6476
string::size_type sep = filename.find_last_of("\\/");
6577
string::size_type dot = filename.find_last_of(".");
6678
if (dot != string::npos && dot > sep) {

0 commit comments

Comments
 (0)