mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-27 21:01:37 +00:00
Slightly refactor resolved path usage.
This commit is contained in:
parent
261907ed12
commit
cb7b8a0d2d
5 changed files with 17 additions and 24 deletions
|
|
@ -54,7 +54,7 @@ struct FindHandle : KernelObject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addDirectory(std::u8string_view((const char8_t*)FileSystem::TransformPath(path)));
|
addDirectory(FileSystem::ResolvePath(path, false));
|
||||||
|
|
||||||
iterator = searchResult.begin();
|
iterator = searchResult.begin();
|
||||||
}
|
}
|
||||||
|
|
@ -75,15 +75,6 @@ struct FindHandle : KernelObject
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::filesystem::path TransformOrRedirectPath(const char* path)
|
|
||||||
{
|
|
||||||
std::filesystem::path redirectedPath = ModLoader::RedirectPath(path);
|
|
||||||
if (redirectedPath.empty())
|
|
||||||
redirectedPath = std::u8string_view((const char8_t*)FileSystem::TransformPath(path));
|
|
||||||
|
|
||||||
return redirectedPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
SWA_API FileHandle* XCreateFileA
|
SWA_API FileHandle* XCreateFileA
|
||||||
(
|
(
|
||||||
const char* lpFileName,
|
const char* lpFileName,
|
||||||
|
|
@ -98,7 +89,7 @@ SWA_API FileHandle* XCreateFileA
|
||||||
assert(((dwShareMode & ~(FILE_SHARE_READ | FILE_SHARE_WRITE)) == 0) && "Unknown share mode bits.");
|
assert(((dwShareMode & ~(FILE_SHARE_READ | FILE_SHARE_WRITE)) == 0) && "Unknown share mode bits.");
|
||||||
assert(((dwCreationDisposition & ~(CREATE_NEW | CREATE_ALWAYS)) == 0) && "Unknown creation disposition bits.");
|
assert(((dwCreationDisposition & ~(CREATE_NEW | CREATE_ALWAYS)) == 0) && "Unknown creation disposition bits.");
|
||||||
|
|
||||||
std::filesystem::path filePath = TransformOrRedirectPath(lpFileName);
|
std::filesystem::path filePath = FileSystem::ResolvePath(lpFileName, true);
|
||||||
std::fstream fileStream;
|
std::fstream fileStream;
|
||||||
std::ios::openmode fileOpenMode = std::ios::binary;
|
std::ios::openmode fileOpenMode = std::ios::binary;
|
||||||
if (dwDesiredAccess & (GENERIC_READ | FILE_READ_DATA))
|
if (dwDesiredAccess & (GENERIC_READ | FILE_READ_DATA))
|
||||||
|
|
@ -343,7 +334,7 @@ uint32_t XReadFileEx(FileHandle* hFile, void* lpBuffer, uint32_t nNumberOfBytesT
|
||||||
|
|
||||||
uint32_t XGetFileAttributesA(const char* lpFileName)
|
uint32_t XGetFileAttributesA(const char* lpFileName)
|
||||||
{
|
{
|
||||||
std::filesystem::path filePath = TransformOrRedirectPath(lpFileName);
|
std::filesystem::path filePath = FileSystem::ResolvePath(lpFileName, true);
|
||||||
if (std::filesystem::is_directory(filePath))
|
if (std::filesystem::is_directory(filePath))
|
||||||
return FILE_ATTRIBUTE_DIRECTORY;
|
return FILE_ATTRIBUTE_DIRECTORY;
|
||||||
else if (std::filesystem::is_regular_file(filePath))
|
else if (std::filesystem::is_regular_file(filePath))
|
||||||
|
|
@ -366,8 +357,15 @@ uint32_t XWriteFile(FileHandle* hFile, const void* lpBuffer, uint32_t nNumberOfB
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* FileSystem::TransformPath(const std::string_view& path)
|
std::filesystem::path FileSystem::ResolvePath(const std::string_view& path, bool checkForMods)
|
||||||
{
|
{
|
||||||
|
if (checkForMods)
|
||||||
|
{
|
||||||
|
std::filesystem::path resolvedPath = ModLoader::ResolvePath(path);
|
||||||
|
if (!resolvedPath.empty())
|
||||||
|
return resolvedPath;
|
||||||
|
}
|
||||||
|
|
||||||
thread_local std::string builtPath;
|
thread_local std::string builtPath;
|
||||||
builtPath.clear();
|
builtPath.clear();
|
||||||
|
|
||||||
|
|
@ -393,12 +391,7 @@ const char* FileSystem::TransformPath(const std::string_view& path)
|
||||||
|
|
||||||
std::replace(builtPath.begin(), builtPath.end(), '\\', '/');
|
std::replace(builtPath.begin(), builtPath.end(), '\\', '/');
|
||||||
|
|
||||||
return builtPath.c_str();
|
return std::u8string_view((const char8_t*)builtPath.c_str());
|
||||||
}
|
|
||||||
|
|
||||||
SWA_API const char* XExpandFilePathA(const char* path)
|
|
||||||
{
|
|
||||||
return FileSystem::TransformPath(path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GUEST_FUNCTION_HOOK(sub_82BD4668, XCreateFileA);
|
GUEST_FUNCTION_HOOK(sub_82BD4668, XCreateFileA);
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,5 @@
|
||||||
|
|
||||||
struct FileSystem
|
struct FileSystem
|
||||||
{
|
{
|
||||||
static const char* TransformPath(const std::string_view& path);
|
static std::filesystem::path ResolvePath(const std::string_view& path, bool checkForMods);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -182,8 +182,8 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
KiSystemStartup();
|
KiSystemStartup();
|
||||||
|
|
||||||
const char *modulePath = FileSystem::TransformPath(GAME_XEX_PATH);
|
auto modulePath = FileSystem::ResolvePath(GAME_XEX_PATH, false);
|
||||||
uint32_t entry = LdrLoadModule(std::u8string_view((const char8_t*)(modulePath)));
|
uint32_t entry = LdrLoadModule(modulePath);
|
||||||
|
|
||||||
if (!runInstallerWizard)
|
if (!runInstallerWizard)
|
||||||
Video::CreateHostDevice(sdlVideoDriver);
|
Video::CreateHostDevice(sdlVideoDriver);
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ struct Mod
|
||||||
|
|
||||||
static std::vector<Mod> g_mods;
|
static std::vector<Mod> g_mods;
|
||||||
|
|
||||||
std::filesystem::path ModLoader::RedirectPath(std::string_view path)
|
std::filesystem::path ModLoader::ResolvePath(std::string_view path)
|
||||||
{
|
{
|
||||||
if (g_mods.empty())
|
if (g_mods.empty())
|
||||||
return {};
|
return {};
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ struct ModLoader
|
||||||
{
|
{
|
||||||
static inline std::filesystem::path s_saveFilePath;
|
static inline std::filesystem::path s_saveFilePath;
|
||||||
|
|
||||||
static std::filesystem::path RedirectPath(std::string_view path);
|
static std::filesystem::path ResolvePath(std::string_view path);
|
||||||
|
|
||||||
static std::vector<std::filesystem::path>* GetIncludeDirectories(size_t modIndex);
|
static std::vector<std::filesystem::path>* GetIncludeDirectories(size_t modIndex);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue