[*] Improve internal path consistency

[*] Removes some unnecessary panics
This commit is contained in:
Reece Wilson 2023-09-12 20:48:35 +01:00
parent bf03124f92
commit 6181d97c3c
6 changed files with 120 additions and 12 deletions

View File

@ -143,6 +143,12 @@ namespace Aurora::IO::FS
AUKN_SYM bool DirsInDirectory(const AuString &string, AuList<AuString> &dirs)
{
if (string.empty())
{
SysPushErrorArg("Cannot open an IO handle to the provided empty path");
return false;
}
auto itr = ReadDir(string);
if (!itr)
{
@ -174,12 +180,19 @@ namespace Aurora::IO::FS
AuMemoryViewWrite writeView;
size_t offset;
if (path.empty())
{
SysPushErrorArg("Cannot open an IO handle to the provided empty path");
return false;
}
status = false;
offset = 0;
win32Path = Locale::ConvertFromUTF8(NormalizePathRet(path));
if (win32Path.empty())
{
SysPushErrorMemory();
return false;
}
@ -238,12 +251,26 @@ namespace Aurora::IO::FS
{
try
{
DWORD dwAttrib = ::GetFileAttributesW(Locale::ConvertFromUTF8(NormalizePathRet(path)).c_str());
if (path.empty())
{
SysPushErrorArg("Cannot open an IO handle to the provided empty path");
return false;
}
auto translatedPath = Locale::ConvertFromUTF8(NormalizePathRet(path));
if (translatedPath.empty())
{
SysPushErrorMemory();
return false;
}
DWORD dwAttrib = ::GetFileAttributesW(translatedPath.c_str());
return ((dwAttrib != INVALID_FILE_ATTRIBUTES) &&
!(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
}
catch (...)
{
SysPushErrorCatch();
return false;
}
}
@ -252,12 +279,26 @@ namespace Aurora::IO::FS
{
try
{
DWORD dwAttrib = ::GetFileAttributesW(Locale::ConvertFromUTF8(NormalizePathRet(path)).c_str());
if (path.empty())
{
SysPushErrorArg("Cannot open an IO handle to the provided empty path");
return false;
}
auto translatedPath = Locale::ConvertFromUTF8(NormalizePathRet(path));
if (translatedPath.empty())
{
SysPushErrorMemory();
return false;
}
DWORD dwAttrib = ::GetFileAttributesW(translatedPath.c_str());
return ((dwAttrib != INVALID_FILE_ATTRIBUTES) &&
(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
}
catch (...)
{
SysPushErrorCatch();
return false;
}
}
@ -266,10 +307,24 @@ namespace Aurora::IO::FS
{
try
{
return CreateDirectories(NormalizePathRet(path), false);
if (path.empty())
{
SysPushErrorArg("Cannot open an IO handle to the provided empty path");
return false;
}
auto translatedPath = NormalizePathRet(path);
if (translatedPath.empty())
{
SysPushErrorMemory();
return false;
}
return CreateDirectories(translatedPath, false);
}
catch (...)
{
SysPushErrorCatch();
return false;
}
}
@ -278,7 +333,19 @@ namespace Aurora::IO::FS
{
try
{
if (path.empty())
{
SysPushErrorArg("Cannot open an IO handle to the provided empty path");
return false;
}
auto translatedPath = Locale::ConvertFromUTF8(NormalizePathRet(path));
if (translatedPath.empty())
{
SysPushErrorMemory();
return false;
}
if (::DeleteFileW(translatedPath.c_str()))
{
return true;
@ -293,6 +360,7 @@ namespace Aurora::IO::FS
}
catch (...)
{
SysPushErrorCatch();
return false;
}
}
@ -327,6 +395,7 @@ namespace Aurora::IO::FS
}
catch (...)
{
SysPushErrorCatch();
return false;
}
}

View File

@ -48,24 +48,38 @@ namespace Aurora::IO::FS
// Working directory
if (path[iOffset] == '.')
{
SysAssert(Process::GetWorkingDirectory(buffer));
buffer += kPathSplitter;
if (!Process::GetWorkingDirectory(buffer))
{
result.clear();
return;
}
}
// Binary directory
else if (path[iOffset] == '^')
{
SysAssert(Process::GetProcDirectory(buffer));
buffer += kPathSplitter;
if (!Process::GetProcDirectory(buffer))
{
result.clear();
return;
}
}
// Local Aurora profile
else if (path[iOffset] == '~')
{
SysAssert(FS::GetProfileDomain(buffer));
if (!FS::GetProfileDomain(buffer))
{
result.clear();
return;
}
}
// Global Aurora profile
else if (path[iOffset] == '!')
{
SysAssert(FS::GetSystemDomain(buffer));
if (!FS::GetSystemDomain(buffer))
{
result.clear();
return;
}
}
else if (path[iOffset] == '?')
{

View File

@ -49,7 +49,7 @@ namespace Aurora::IO::FS
}
catch (...)
{
str = {};
AuResetMember(str);
}
}

View File

@ -41,6 +41,7 @@ namespace Aurora::IO::FS
auto pathex = NormalizePathRet(path);
if (pathex.empty())
{
SysPushErrorMemory();
return false;
}

View File

@ -14,6 +14,8 @@
#define _USE_GET_CWD
#endif
#include <Source/IO/FS/FS.hpp>
namespace Aurora::Process
{
AUKN_SYM bool GetWorkingDirectory(AuString &path)
@ -36,6 +38,11 @@ namespace Aurora::Process
path = Locale::ConvertFromWChar(eh.data(), length);
if (!path.ends_with(AuFS::kPathSplitter))
{
path += AuFS::kPathSplitter;
}
return true;
#elif defined(AURORA_PLATFORM_ANDROID)
@ -52,6 +59,11 @@ namespace Aurora::Process
path.resize(strlen(path.data()));
if (!path.ends_with(AuFS::kPathSplitter))
{
path += AuFS::kPathSplitter;
}
return true;
#endif
@ -195,7 +207,13 @@ namespace Aurora::Process
cachedPartialPath = cachedFullPath.substr(0, indexA);
}
if (!cachedPartialPath.ends_with(AuFS::kPathSplitter))
{
cachedPartialPath += AuFS::kPathSplitter;
}
returnCached:
module = cachedModule;
fullPath = cachedFullPath;
partialPath = cachedPartialPath;

View File

@ -55,7 +55,7 @@ namespace Aurora::Processes
static void OpenerThread()
{
CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
(void)CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
RunTasks();
CoUninitialize();
}
@ -97,6 +97,12 @@ namespace Aurora::Processes
auto path = AuIOFS::NormalizePathRet(file);
bool bFileExists {};
if (path.empty())
{
SysPushErrorMemory();
return;
}
if (!(bFileExists = AuFS::FileExists(path)) &&
!AuFS::DirExists(path))
{