Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Make case-sensitive file systems work on filename missmatches
- Loading branch information
Showing
8 changed files
with
176 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| #include "dir_list_ci.h" | ||
|
|
||
| #include "../DirManager/dirman.h" | ||
| #include "strings.h" | ||
| #include <SDL2/SDL_stdinc.h> | ||
|
|
||
|
|
||
| DirListCI::DirListCI(const std::string &curDir) | ||
| : m_curDir(curDir) | ||
| { | ||
| rescan(); | ||
| } | ||
|
|
||
| void DirListCI::setCurDir(const std::string &path) | ||
| { | ||
| m_curDir = path; | ||
| rescan(); | ||
| } | ||
|
|
||
| static void replaceSlashes(std::string &str, const std::string &from) | ||
| { | ||
| str.clear(); | ||
| if(from.empty()) | ||
| return; | ||
|
|
||
| str.reserve(from.size()); | ||
|
|
||
| char prevC = '\0'; | ||
|
|
||
| for(char c : from) | ||
| { | ||
| if(c == '\\') | ||
| c = '/'; // Replace backslashes | ||
| if(c == '/' && prevC == '/') | ||
| continue; // skip duplicated slashes | ||
| prevC = c; | ||
| str.push_back(c); | ||
| } | ||
| } | ||
|
|
||
| std::string DirListCI::resolveFileCase(const std::string &in_name) | ||
| { | ||
| #ifdef _WIN32 | ||
| return name; // no need on Windows | ||
| #else | ||
| if(in_name.empty()) | ||
| return in_name; | ||
|
|
||
| std::string name; | ||
| replaceSlashes(name, in_name); | ||
|
|
||
| // For sub-directory path, look deeply | ||
| auto subDir = name.find('/'); | ||
| if(subDir != std::string::npos) | ||
| { | ||
| auto sdName = resolveDirCase(name.substr(0, subDir)); | ||
| DirListCI sd(m_curDir + "/" + sdName); | ||
| return sdName + "/" + sd.resolveFileCase(name.substr(subDir + 1)); | ||
| } | ||
|
|
||
| // keep MixerX path arguments untouched | ||
| auto pathArgs = name.find('|'); | ||
| if(pathArgs != std::string::npos) | ||
| { | ||
| auto n = name.substr(0, pathArgs); | ||
| for(std::string &c : m_fileList) | ||
| { | ||
| if(SDL_strcasecmp(c.c_str(), n.c_str()) == 0) | ||
| return c + name.substr(pathArgs); | ||
| } | ||
| } | ||
| else | ||
| for(std::string &c : m_fileList) | ||
| { | ||
| if(SDL_strcasecmp(c.c_str(), name.c_str()) == 0) | ||
| return c; | ||
| } | ||
|
|
||
| return name; | ||
| #endif | ||
| } | ||
|
|
||
| std::string DirListCI::resolveDirCase(const std::string &name) | ||
| { | ||
| #ifdef _WIN32 | ||
| return name; | ||
| #else | ||
| if(name.empty()) | ||
| return name; | ||
|
|
||
| for(std::string &c : m_dirList) | ||
| { | ||
| if(SDL_strcasecmp(c.c_str(), name.c_str()) == 0) | ||
| return c; | ||
| } | ||
|
|
||
| return name; | ||
| #endif | ||
| } | ||
|
|
||
| void DirListCI::rescan() | ||
| { | ||
| m_fileList.clear(); | ||
| m_dirList.clear(); | ||
| if(m_curDir.empty()) | ||
| return; | ||
|
|
||
| DirMan d(m_curDir); | ||
| d.getListOfFiles(m_fileList); | ||
| d.getListOfFolders(m_dirList); | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #ifndef DIRLISTCI_H | ||
| #define DIRLISTCI_H | ||
|
|
||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| /** | ||
| * @brief Case-Insensitive directory list | ||
| */ | ||
| class DirListCI | ||
| { | ||
| std::string m_curDir; | ||
| std::vector<std::string> m_fileList; | ||
| std::vector<std::string> m_dirList; | ||
| public: | ||
| DirListCI(const std::string &curDir = std::string()); | ||
| void setCurDir(const std::string &path); | ||
|
|
||
| std::string resolveFileCase(const std::string &name); | ||
| std::string resolveDirCase(const std::string &name); | ||
|
|
||
| void rescan(); | ||
| }; | ||
|
|
||
| #endif // DIRLISTCI_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters