mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-04 05:51:19 +12:00
I keep messing up
This commit is contained in:
parent
3922ef5e85
commit
d5f6cd5bd6
3 changed files with 80 additions and 1 deletions
62
src/Cafe/Filesystem/FSPath.cpp
Normal file
62
src/Cafe/Filesystem/FSPath.cpp
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
#include "FSPath.h"
|
||||||
|
|
||||||
|
#ifndef BOOST_OS_UNIX
|
||||||
|
FSPath& FSPath::operator/= (const FSPath & other)
|
||||||
|
{
|
||||||
|
*this /= other;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
FSPath& FSPath::operator/= (const FSPath & other)
|
||||||
|
{
|
||||||
|
// todo: implement caching.
|
||||||
|
|
||||||
|
// explore directories recursively and find the matching cases.
|
||||||
|
fs::path relPath = other.relative_path();
|
||||||
|
fs::path correctedPath = empty() ? other.root_path() : *this;
|
||||||
|
|
||||||
|
// helper function to convert a path's alphabet characters to lowercase.
|
||||||
|
auto static lowercase_path = [](fs::path const & path)
|
||||||
|
{
|
||||||
|
std::wstring string = path.wstring();
|
||||||
|
for (auto& i : string)
|
||||||
|
{
|
||||||
|
i = std::isalpha(i) ? std::tolower(i) : i;
|
||||||
|
}
|
||||||
|
return string;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool found;
|
||||||
|
for (auto const &it : relPath)
|
||||||
|
{
|
||||||
|
found = false;
|
||||||
|
std::error_code listErr;
|
||||||
|
for (auto const& dirEntry : fs::directory_iterator{correctedPath, listErr})
|
||||||
|
{
|
||||||
|
fs::path entryName = dirEntry.path().filename();
|
||||||
|
if (lowercase_path(entryName) == lowercase_path(it))
|
||||||
|
{
|
||||||
|
correctedPath /= entryName;
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if we can't iterate directory, just copy the original case.
|
||||||
|
if(listErr)
|
||||||
|
{
|
||||||
|
correctedPath /= it;
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found)
|
||||||
|
*this = correctedPath;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
18
src/Cafe/Filesystem/FSPath.h
Normal file
18
src/Cafe/Filesystem/FSPath.h
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#pragma once
|
||||||
|
#include "Common/precompiled.h"
|
||||||
|
|
||||||
|
class FSPath : public fs::path {
|
||||||
|
public:
|
||||||
|
FSPath() = default;
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
FSPath(const T & other) : fs::path(other) {};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
static FSPath Convert(const T& input) {
|
||||||
|
FSPath p;
|
||||||
|
p /= input;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
FSPath& operator/= (const FSPath & other);
|
||||||
|
};
|
|
@ -224,7 +224,6 @@ class fscDeviceHostFSC : public fscDeviceC {
|
||||||
|
|
||||||
FSCVirtualFile* fscDeviceOpenByPathIgnoreCase(std::wstring_view pathString, FSC_ACCESS_FLAG accessFlags, sint32* fscStatus)
|
FSCVirtualFile* fscDeviceOpenByPathIgnoreCase(std::wstring_view pathString, FSC_ACCESS_FLAG accessFlags, sint32* fscStatus)
|
||||||
{
|
{
|
||||||
// todo: implement caching.
|
|
||||||
*fscStatus = FSC_STATUS_OK;
|
*fscStatus = FSC_STATUS_OK;
|
||||||
|
|
||||||
FSPath correctedPath = FSPath::Convert(pathString);
|
FSPath correctedPath = FSPath::Convert(pathString);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue