4 using namespace CYB::Platform::Win32;
5 using namespace CYB::API::String;
8 if (ADirectory != SystemPath::EXECUTABLE_IMAGE
9 && ADirectory != SystemPath::EXECUTABLE
10 && ADirectory != SystemPath::RESOURCE
11 && ADirectory != SystemPath::TEMPORARY
12 && ADirectory != SystemPath::USER
13 && ADirectory != SystemPath::WORKING)
15 auto& MM(
Core().FModuleManager);
17 case SystemPath::EXECUTABLE_IMAGE:
18 case SystemPath::EXECUTABLE: {
19 auto Module(MM.Call<Modules::Kernel32::GetModuleHandleW>(
nullptr));
20 if (Module !=
nullptr) {
21 wchar_t Buffer[MAX_PATH];
22 if (MM.Call<Modules::Kernel32::GetModuleFileNameW>(Module, Buffer, DWORD(MAX_PATH)) != 0)
23 if (ADirectory == SystemPath::EXECUTABLE) {
24 if (MM.Call<Modules::ShellAPI::PathRemoveFileSpecW>(Buffer) != 0)
32 case SystemPath::RESOURCE:
33 return GetResourceDirectory();
34 case SystemPath::TEMPORARY: {
37 wchar_t Buffer[MAX_PATH];
38 if (MM.Call<Modules::Kernel32::GetTempPathW>(Win32::DWORD(MAX_PATH), Buffer) == 0)
46 CreateDirectory(Result);
52 if(ThrowCode == Exception::SystemData::STREAM_NOT_WRITABLE)
59 case SystemPath::WORKING:
61 wchar_t Buffer[MAX_PATH];
62 if (MM.Call<Modules::Kernel32::GetCurrentDirectoryW>(Win32::DWORD(MAX_PATH), Buffer) == 0)
66 case SystemPath::USER:
68 struct AutoFreeBuffer {
70 wchar_t*
const FBuffer;
72 AutoFreeBuffer(
wchar_t*
const ABuffer) :
82 if (MM.Call<Modules::Shell::SHGetKnownFolderPath>(GUID{ 0xF1B32785, 0x6FBA, 0x4FCF, 0x9D, 0x55, 0x7B, 0x8E, 0x7F, 0x15, 0x70, 0x91 }, DWORD(0),
nullptr, &Buffer) != S_OK)
85 AutoFreeBuffer AFB(Buffer);
96 if (CheckDirectoryExists(As16) != 1) {
97 if (
Core().FModuleManager.Call<Modules::Kernel32::CreateDirectoryW>(As16.
WString(),
nullptr) == 0
105 if (
Core().FModuleManager.Call<Modules::Kernel32::RemoveDirectoryW>(As16.
WString()) == FALSE) {
106 const auto Error(
Core().FModuleManager.Call<Modules::Kernel32::GetLastError>());
108 case ERROR_FILE_NOT_FOUND:
110 case ERROR_DIR_NOT_EMPTY:
120 auto& MM(
Core().FModuleManager);
121 if (MM.Call<Modules::Kernel32::DeleteFileW>(As16.
WString()) == FALSE) {
122 const auto Error(MM.Call<Modules::Kernel32::GetLastError>());
124 case ERROR_FILE_NOT_FOUND:
126 case ERROR_ACCESS_DENIED: {
128 WIN32_FILE_ATTRIBUTE_DATA Attributes;
129 const auto Result(MM.Call<Modules::Kernel32::GetFileAttributesExW>(As16.
WString(), GetFileExInfoStandard, &Attributes));
131 Attributes.dwFileAttributes &= ~FILE_ATTRIBUTE_READONLY;
132 if (MM.Call<Modules::Kernel32::SetFileAttributesW>(As16.
WString(), Attributes.dwFileAttributes) != FALSE && MM.Call<Modules::Kernel32::DeleteFileW>(As16.
WString()) != FALSE)
145 wchar_t OutputBuffer[MAX_PATH];
146 if (
Core().FModuleManager.Call<Modules::ShellAPI::PathCanonicalizeW>(OutputBuffer, As16.
WString()) == FALSE)
153 const bool Local(&APath == &FPath);
163 FPath = std::move(APath);
167 WIN32_FILE_ATTRIBUTE_DATA Attributes;
168 const auto Result(
Core().FModuleManager.Call<Modules::Kernel32::GetFileAttributesExW>(APath.WString(), GetFileExInfoStandard, &Attributes));
171 return ((Attributes.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) > 0) ? 1 : 0;
175 const auto Result(CheckDirectoryExists(FWidePath));
177 const auto Error(
Core().FModuleManager.Call<Modules::Kernel32::GetLastError>());
178 if (Error == ERROR_ACCESS_DENIED || Error == ERROR_SHARING_VIOLATION)
188 wchar_t Buffer[MAX_PATH];
190 std::copy(FWidePath.WString(), FWidePath.WString() + FWidePath.RawLength(), Buffer);
194 for (
auto I(FWidePath.RawLength() / 2); I >= 0 ; --I)
195 if (Buffer[I] == L
'/') {
199 auto& MM(
Core().FModuleManager);
200 const auto Result1(MM.Call<Modules::ShellAPI::PathIsRootW>(Buffer));
201 if (Result1 != FALSE)
204 const auto Result2(MM.Call<Modules::ShellAPI::PathRemoveFileSpecW>(Buffer));
207 SetPath(UTF16::ToUTF8(Buffer));
211 const auto Result(
Core().FModuleManager.Call<Modules::ShellAPI::PathFindFileNameW>(const_cast<wchar_t*>(FWidePath.WString())));
214 return UTF16::ToUTF8(Result);
218 const auto File(
Core().FModuleManager.Call<Modules::ShellAPI::PathFindFileNameW>(const_cast<wchar_t*>(FWidePath.WString()))),
219 Extension(
Core().
FModuleManager.
Call<Modules::ShellAPI::PathFindExtensionW>(
const_cast<wchar_t*
>(FWidePath.WString())));
223 return UTF16::ToUTF8(
File);
225 wchar_t Buffer[MAX_PATH];
226 std::memset(Buffer, 0,
sizeof(Buffer));
227 std::copy(
File, Extension, Buffer);
229 return UTF16::ToUTF8(Buffer);
236 FOriginalPath(APath),
237 FPathListing(nullptr)
239 WIN32_FIND_DATA FindData;
245 const auto Error(
Core().FModuleManager.Call<Modules::Kernel32::GetLastError>());
247 case ERROR_FILE_NOT_FOUND:
249 case ERROR_ACCESS_DENIED:
264 WIN32_FIND_DATA FindData;
265 if (
Core().FModuleManager.Call<Modules::Kernel32::FindNextFileW>(FFindHandle, &FindData) == 0)
268 AssignOrRecurse(std::move(FindData));
274 auto FindData(std::move(AFindData));
275 Conversion = UTF16::ToUTF8(FindData.cFileName);
276 if (Conversion ==
Static(u8
".") || Conversion ==
Static(u8
"..")) {
void AssignOrRecurse(Win32::WIN32_FIND_DATA &&AFindData)
Assign the current data to FPathListing if it is not '.' or '..'.
A variable length UTF-8 string.
Template type for wrapping pointers and treating them as objects. Only works with CyberEngine interfa...
API::Interop::Context & Context(void) noexcept
Get the API's Context.
Failed to evaluate a Path.
static const char *const FTempPathName
The directory in the temp folder to use.
void operator++(void) finaloverride
Advance the iterator.
A string pointing to unchanging data in the stack above it or the data segment. Must have UTF-8 encod...
UTF-16 String enabled only under windows.
Platform::Modules::Manager FModuleManager
Loads and contains required modules.
Object< AObject > ConstructObject(AArgs &&...AArguments)
Allocates the Object specified by AObject using a specified Constructor.
SystemPath
Starting points for creating paths.
Used for manipulating Paths. Paths will always exist either as a file or directory. Paths are '/' delimited when forming though may not be while retrieving. File names ".." will ascend a directory and '.' represents a no-op.
A string could not be validated.
Mutex could not be created.
static UTF8 ToUTF8(const wchar_t *AWString)
Create a new UTF8 string given a wide char array.
const unsigned int FErrorCode
The assigned error code.
const System::Path & FOriginalPath
The Path of the directory being enumerated.
DirectoryEntry(const System::Path &APath)
Begin the directory listing operation of APath.
A previously valid path has become invalidated, most likely due to deletion.
Exceptions caused by external call failures or invalid external data. Only classifies ones that can p...
static void Equal(const AType &ALHS, const AType &ARHS) noexcept
Equivalence assertion function. May not be evaluated.
A heap has no block large enough for a requested allocation and expansion failed. ...
Allocator & FAllocator
The Allocator.
const wchar_t * WString(void) const noexcept
Get the underlying const wide char array.
Generic error for read failures. See functions for further documentation.
Precompiled header for inter-engine operations.
Win32::HANDLE FFindHandle
The Win32 find handle.
static const String::Static DirectorySeparatorChar(void) noexcept
Get the standardized UTF-8 directory separator string.
Engine::Core & Core(void) noexcept
Retrieve the Core singleton.
A system path could not be retrieved.
Exceptions that are thrown internally in the engine that the should never see, these are a superset o...
Tried to delete a non-empty directory.
ErrorCode
The error code of the exception.
Exceptions indicating an API contract violation. Should not be anticipated.
Template for defining the types of parameters for engine object constructors with multiple arguments...
#define UNREACHABLE
Used for hardcore unreachable code paths when Assert::HCF is not enough. Should generally be avoided ...
Generic error for write failures. See functions for further documentation.
~DirectoryEntry() finaloverride
See Default Constructors and Destructor.
An operation was attempted with an invalid enum code.