diff --git a/Source/IO/FS/DirDeleter.cpp b/Source/IO/FS/DirDeleter.cpp index 4927f9f3..f47927b2 100644 --- a/Source/IO/FS/DirDeleter.cpp +++ b/Source/IO/FS/DirDeleter.cpp @@ -50,40 +50,48 @@ namespace Aurora::IO::FS virtual StatEx *Next() override { + StatEx *pNext {}; if (!this->pDir) { return {}; } - auto pNext = this->pDir->Next(); - while (!pNext) + try { - DoNext(); - - if (!this->pDir) - { - return {}; - } - pNext = this->pDir->Next(); - } - - if (curSubDir.size()) - { - pNext->fileName.insert(pNext->fileName.begin(), curSubDir.begin(), curSubDir.end()); - } - - if (pNext->bExistsDirectory) - { - nextLevel.push_back(pNext->fileName + "/"); - nextLevel2.push_back(pNext->fileName + "/"); - } - else - { - if (!AuFS::Remove(pNext->path)) + while (!pNext) { - this->failedPaths.push_back(pNext->fileName); + DoNext(); + + if (!this->pDir) + { + return {}; + } + + pNext = this->pDir->Next(); } + + if (curSubDir.size()) + { + pNext->fileName.insert(pNext->fileName.begin(), curSubDir.begin(), curSubDir.end()); + } + + if (pNext->bExistsDirectory) + { + nextLevel.push_back(pNext->fileName + "/"); + nextLevel2.push_back(pNext->fileName + "/"); + } + else + { + if (!AuFS::Remove(pNext->path)) + { + this->failedPaths.push_back(pNext->fileName); + } + } + } + catch (...) + { + SysPushErrorCatch(); } return pNext; @@ -107,19 +115,27 @@ namespace Aurora::IO::FS auto pObj = AuMakeShared(); SysCheckNotNullMemory(pObj, false); - if (!pObj->OpenDir(string)) + try { - return {}; + if (!pObj->OpenDir(string)) + { + return {}; + } + + while (pObj->Next()) + { + + } + + pObj->RemoveDirs(); + + AuFS::Remove(string); + } + catch (...) + { + SysPushErrorCatch(); } - while (pObj->Next()) - { - - } - - pObj->RemoveDirs(); - - AuFS::Remove(string); return !AuFS::DirExists(string); } @@ -128,44 +144,51 @@ namespace Aurora::IO::FS auto pObj = AuMakeShared(); SysCheckNotNullMemory(pObj, false); - if (!pObj->OpenDir(string)) + try { - return {}; - } - - while (pObj->Next()) - { - - } - - pObj->RemoveDirs(); - - AuFS::Remove(string); - - if (AuFS::DirExists(string)) - { - for (const auto &str : pObj->failedPaths) + if (!pObj->OpenDir(string)) { - auto normalizedUserDir = string + "/" ; - auto normalizedUserDir2 = normalizedUserDir + str; - - if (AuFS::FileExists(normalizedUserDir2) || - AuFS::DirExists(normalizedUserDir2)) - { - if (AuEndsWith(normalizedUserDir, "//") || - AuEndsWith(normalizedUserDir, "\\/")) - { - normalizedUserDir.pop_back(); - normalizedUserDir[normalizedUserDir.size() - 1] = '/'; - } - - normalizedUserDir += str; - - failingPaths.push_back(normalizedUserDir); - } + return {}; } - return false; + while (pObj->Next()) + { + + } + + pObj->RemoveDirs(); + + AuFS::Remove(string); + + if (AuFS::DirExists(string)) + { + for (const auto &str : pObj->failedPaths) + { + auto normalizedUserDir = string + "/"; + auto normalizedUserDir2 = normalizedUserDir + str; + + if (AuFS::FileExists(normalizedUserDir2) || + AuFS::DirExists(normalizedUserDir2)) + { + if (AuEndsWith(normalizedUserDir, "//") || + AuEndsWith(normalizedUserDir, "\\/")) + { + normalizedUserDir.pop_back(); + normalizedUserDir[normalizedUserDir.size() - 1] = '/'; + } + + normalizedUserDir += str; + + failingPaths.push_back(normalizedUserDir); + } + } + + return false; + } + } + catch (...) + { + SysPushErrorCatch(); } return true; diff --git a/Source/IO/FS/FSRecursion.cpp b/Source/IO/FS/FSRecursion.cpp index aae692b3..9a83b2a5 100644 --- a/Source/IO/FS/FSRecursion.cpp +++ b/Source/IO/FS/FSRecursion.cpp @@ -48,31 +48,39 @@ namespace Aurora::IO::FS virtual StatEx *Next() override { + StatEx *pNext {}; if (!this->pDir) { return {}; } - auto pNext = this->pDir->Next(); - while (!pNext) + try { - DoNext(); - if (!this->pDir) + pNext = this->pDir->Next(); + while (!pNext) { - return {}; + DoNext(); + if (!this->pDir) + { + return {}; + } + + pNext = this->pDir->Next(); } - pNext = this->pDir->Next(); - } + if (curSubDir.size()) + { + pNext->fileName.insert(pNext->fileName.begin(), curSubDir.begin(), curSubDir.end()); + } - if (curSubDir.size()) - { - pNext->fileName.insert(pNext->fileName.begin(), curSubDir.begin(), curSubDir.end()); + if (pNext->bExistsDirectory) + { + nextLevel.push_back(pNext->fileName + "/"); + } } - - if (pNext->bExistsDirectory) + catch (...) { - nextLevel.push_back(pNext->fileName + "/"); + SysPushErrorCatch(); } return pNext; @@ -88,9 +96,16 @@ namespace Aurora::IO::FS return {}; } - if (!pObj->OpenDir(string)) + try { - return {}; + if (!pObj->OpenDir(string)) + { + return {}; + } + } + catch (...) + { + SysPushErrorCatch(); } return pObj; diff --git a/Source/Process/AuPaths.cpp b/Source/Process/AuPaths.cpp index 4030a7f4..df6a9987 100644 --- a/Source/Process/AuPaths.cpp +++ b/Source/Process/AuPaths.cpp @@ -20,15 +20,22 @@ namespace Aurora::Process { AUKN_SYM bool GetWorkingDirectory(AuString &path) { + #if !defined(AURORA_IS_MODERNNT_DERIVED) + if (!AuTryResize(path, 0x4000)) { return false; } + #endif + #if defined(AURORA_IS_MODERNNT_DERIVED) std::wstring eh; - eh.resize(path.size()); + if (!AuTryResize(eh, 0x4000)) + { + return false; + } auto length = ::GetCurrentDirectoryW(eh.size(), eh.data()); if (length == 0) @@ -36,11 +43,19 @@ namespace Aurora::Process return false; } - path = Locale::ConvertFromWChar(eh.data(), length); + path = AuMove(Locale::ConvertFromWChar(eh.data(), length)); - if (!path.ends_with(AuFS::kPathSplitter)) + try { - path += AuFS::kPathSplitter; + if (!path.ends_with(AuFS::kPathSplitter)) + { + path += AuFS::kPathSplitter; + } + } + catch (...) + { + SysPushErrorCatch(); + return false; } return true; @@ -174,46 +189,56 @@ namespace Aurora::Process static bool GetModulePath(const AuString *&module, const AuString *&partialPath, const AuString *&fullPath) { static AuString cachedModule, cachedPartialPath, cachedFullPath; - static bool init = false; - static AuThreadPrimitives::SpinLock spinlock; - char spitter; - - AU_TRY_LOCK_GUARD_RET_DEF(spinlock); - - if (AuExchange(init, true)) + static AuInitOnce gInitOnce; + static bool bFailed {}; + + if (!AuThreading::InitOnceLocker::TryLock(&gInitOnce, true)) { - if (!cachedModule.size()) + gInitOnce.Wait(); + } + else + { + try { - return false; + char spitter; + + if (GetModulePathSlow(cachedFullPath, spitter)) + { + auto indexA = cachedFullPath.find_last_of(spitter); + if (indexA != AuString::npos) + { + cachedModule = cachedFullPath.substr(indexA + 1); + cachedPartialPath = cachedFullPath.substr(0, indexA); + } + else + { + bFailed = true; + } + + if (!cachedPartialPath.ends_with(AuFS::kPathSplitter)) + { + cachedPartialPath += AuFS::kPathSplitter; + } + } + else + { + bFailed = true; + } + } + catch (...) + { + bFailed = true; + SysPushErrorCatch(); } - goto returnCached; + AuThreading::InitOnceLocker::Finish(&gInitOnce, bFailed); } - if (!GetModulePathSlow(cachedFullPath, spitter)) + if (bFailed) { return false; } - // this scope is required for c++20, bleh - { - auto indexA = cachedFullPath.find_last_of(spitter); - if (indexA == AuString::npos) - { - return false; - } - - cachedModule = cachedFullPath.substr(indexA + 1); - cachedPartialPath = cachedFullPath.substr(0, indexA); - } - - if (!cachedPartialPath.ends_with(AuFS::kPathSplitter)) - { - cachedPartialPath += AuFS::kPathSplitter; - } - - returnCached: - module = &cachedModule; fullPath = &cachedFullPath; partialPath = &cachedPartialPath;