mirror of
https://github.com/cemu-project/Cemu.git
synced 2026-07-10 01:24:41 -06:00
Simplify code a lot
This commit is contained in:
parent
9002a7c914
commit
97b5622705
@ -1,31 +1,19 @@
|
||||
#include "Common/unix/FileStream_unix.h"
|
||||
|
||||
std::optional<fs::path> findPathCI(const fs::path& path)
|
||||
fs::path findPathCI(const fs::path& path)
|
||||
{
|
||||
if (fs::exists(path)) return path;
|
||||
if (!path.has_parent_path()) return {};
|
||||
auto parentPath = path.parent_path();
|
||||
std::string fName = path.filename().string();
|
||||
|
||||
fs::path fName = path.filename();
|
||||
fs::path parentPath = path.parent_path();
|
||||
if (!fs::exists(parentPath))
|
||||
{
|
||||
auto tempParentPath = findPathCI(parentPath);
|
||||
if (tempParentPath.has_value())
|
||||
parentPath = std::move(tempParentPath.value());
|
||||
else
|
||||
return {};
|
||||
if (fs::exists(parentPath / fName))
|
||||
return parentPath / fName;
|
||||
}
|
||||
return findPathCI(findPathCI(parentPath) / fName);
|
||||
|
||||
std::error_code listErr;
|
||||
for (auto&& dirEntry: fs::directory_iterator(parentPath, listErr))
|
||||
{
|
||||
std::string dirFName = dirEntry.path().filename().string();
|
||||
if (boost::iequals(dirFName, fName))
|
||||
{
|
||||
for (auto&& dirEntry : fs::directory_iterator(parentPath, listErr))
|
||||
if (boost::iequals(dirEntry.path().filename().string(), fName.string()))
|
||||
return dirEntry;
|
||||
}
|
||||
}
|
||||
|
||||
return parentPath / fName;
|
||||
}
|
||||
|
||||
@ -42,7 +30,7 @@ FileStream* FileStream::openFile(const wchar_t* path, bool allowWrite)
|
||||
FileStream* FileStream::openFile2(const fs::path& path, bool allowWrite)
|
||||
{
|
||||
//return openFile(path.generic_wstring().c_str(), allowWrite);
|
||||
FileStream* fs = new FileStream(findPathCI(path).value_or(path), true, allowWrite);
|
||||
FileStream* fs = new FileStream(findPathCI(path), true, allowWrite);
|
||||
if (fs->m_isValid)
|
||||
return fs;
|
||||
delete fs;
|
||||
@ -61,7 +49,7 @@ FileStream* FileStream::createFile(std::string_view path)
|
||||
|
||||
FileStream* FileStream::createFile2(const fs::path& path)
|
||||
{
|
||||
FileStream* fs = new FileStream(findPathCI(path).value_or(path), false, false);
|
||||
FileStream* fs = new FileStream(findPathCI(path), false, false);
|
||||
if (fs->m_isValid)
|
||||
return fs;
|
||||
delete fs;
|
||||
@ -219,12 +207,12 @@ FileStream::FileStream(const fs::path& path, bool isOpen, bool isWriteable)
|
||||
{
|
||||
if (isOpen)
|
||||
{
|
||||
m_fileStream.open(findPathCI(path).value_or(path), isWriteable ? (std::ios_base::in | std::ios_base::out | std::ios_base::binary) : (std::ios_base::in | std::ios_base::binary));
|
||||
m_fileStream.open(findPathCI(path), isWriteable ? (std::ios_base::in | std::ios_base::out | std::ios_base::binary) : (std::ios_base::in | std::ios_base::binary));
|
||||
m_isValid = m_fileStream.is_open();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_fileStream.open(findPathCI(path).value_or(path), std::ios_base::in | std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);
|
||||
m_fileStream.open(findPathCI(path), std::ios_base::in | std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);
|
||||
m_isValid = m_fileStream.is_open();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user