Skip to content

Commit

Permalink
Fixed more case-insensitive filename issues.
Browse files Browse the repository at this point in the history
Arrows.cif and Crystal3.inf will now be loaded properly on Unix-based
systems.
  • Loading branch information
afritz1 committed Apr 29, 2018
1 parent f62cbb4 commit 9d2007a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
5 changes: 4 additions & 1 deletion OpenTESArena/src/Assets/CIFFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ namespace

CIFFile::CIFFile(const std::string &filename)
{
VFS::IStreamPtr stream = VFS::Manager::get().open(filename);
// Some filenames (i.e., Arrows.cif) have different casing between the floppy version and
// CD version, so this needs to use the case-insensitive open() method for correct behavior
// on Unix-based systems.
VFS::IStreamPtr stream = VFS::Manager::get().openCaseInsensitive(filename);
DebugAssert(stream != nullptr, "Could not open \"" + filename + "\".");

stream->seekg(0, std::ios::end);
Expand Down
5 changes: 4 additions & 1 deletion OpenTESArena/src/Assets/INFFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ const int INFFile::NO_INDEX = -1;

INFFile::INFFile(const std::string &filename)
{
VFS::IStreamPtr stream = VFS::Manager::get().open(filename);
// Some filenames (i.e., Crystal3.inf) have different casing between the floppy version and
// CD version, so this needs to use the case-insensitive open() method for correct behavior
// on Unix-based systems.
VFS::IStreamPtr stream = VFS::Manager::get().openCaseInsensitive(filename);
DebugAssert(stream != nullptr, "Could not open \"" + filename + "\".");

stream->seekg(0, std::ios::end);
Expand Down
14 changes: 7 additions & 7 deletions components/vfs/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ IStreamPtr Manager::openCaseInsensitive(const std::string &name)
// worry about filenames just like it but with different casing.
std::string newName = name;

// Case 1: All uppercase.
for (char &c : newName)
// Case 1: upper first character, lower rest.
newName.front() = std::toupper(newName.front());
for (auto iter = newName.begin() + 1; iter != newName.end(); ++iter)
{
c = std::toupper(c);
*iter = std::tolower(*iter);
}

IStreamPtr stream = this->open(newName);
Expand All @@ -93,11 +94,10 @@ IStreamPtr Manager::openCaseInsensitive(const std::string &name)
}
else
{
// Case 2: Normal case (upper first character, lower rest).
newName.front() = std::toupper(newName.front());
for (auto iter = newName.begin() + 1; iter != newName.end(); ++iter)
// Case 2: all uppercase.
for (char &c : newName)
{
*iter = std::tolower(*iter);
c = std::toupper(c);
}

stream = this->open(newName);
Expand Down

0 comments on commit 9d2007a

Please sign in to comment.