diff --git a/Source/IO/FS/FS.NT.cpp b/Source/IO/FS/FS.NT.cpp index 07d1d0d9..343551ac 100644 --- a/Source/IO/FS/FS.NT.cpp +++ b/Source/IO/FS/FS.NT.cpp @@ -143,6 +143,12 @@ namespace Aurora::IO::FS AUKN_SYM bool DirsInDirectory(const AuString &string, AuList &dirs) { + if (string.empty()) + { + SysPushErrorArg("Cannot open an IO handle to the provided empty path"); + return false; + } + auto itr = ReadDir(string); if (!itr) { @@ -173,13 +179,20 @@ namespace Aurora::IO::FS bool status; 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; } } diff --git a/Source/IO/FS/FS.cpp b/Source/IO/FS/FS.cpp index e1a8d57d..f8630427 100644 --- a/Source/IO/FS/FS.cpp +++ b/Source/IO/FS/FS.cpp @@ -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] == '?') { diff --git a/Source/IO/FS/FS.hpp b/Source/IO/FS/FS.hpp index 4c3583e5..714fc832 100644 --- a/Source/IO/FS/FS.hpp +++ b/Source/IO/FS/FS.hpp @@ -49,7 +49,7 @@ namespace Aurora::IO::FS } catch (...) { - str = {}; + AuResetMember(str); } } diff --git a/Source/IO/FS/FSTimes.NT.cpp b/Source/IO/FS/FSTimes.NT.cpp index 5b4c91bf..a8520ff2 100644 --- a/Source/IO/FS/FSTimes.NT.cpp +++ b/Source/IO/FS/FSTimes.NT.cpp @@ -41,6 +41,7 @@ namespace Aurora::IO::FS auto pathex = NormalizePathRet(path); if (pathex.empty()) { + SysPushErrorMemory(); return false; } diff --git a/Source/Process/AuPaths.cpp b/Source/Process/AuPaths.cpp index 756d126c..299414f1 100644 --- a/Source/Process/AuPaths.cpp +++ b/Source/Process/AuPaths.cpp @@ -14,6 +14,8 @@ #define _USE_GET_CWD #endif +#include + 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; diff --git a/Source/Processes/AuOpen.Win32.cpp b/Source/Processes/AuOpen.Win32.cpp index a761295f..6320eb67 100644 --- a/Source/Processes/AuOpen.Win32.cpp +++ b/Source/Processes/AuOpen.Win32.cpp @@ -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)) {