Working on resource management stuff

This commit is contained in:
Krzosa Karol
2024-07-23 22:33:01 +02:00
parent 4cb892133f
commit 1528ecac52
12 changed files with 167 additions and 287 deletions

View File

@@ -555,7 +555,7 @@ void Remove(Array<T> *arr, T &item) {
template <class T>
void UnorderedRemove(Array<T> *arr, T &item) {
Assert(arr->len > 0);
Assert(&item >= arr->begin && &item < arr->end);
Assert((&item >= arr->begin()) && (&item < arr->end()));
item = arr->data[--arr->len];
}

View File

@@ -28,6 +28,9 @@ bool InitOS();
String GetExePath(Allocator allocator);
String GetExeDir(Allocator allocator);
bool FileExists(String path);
bool IsDir(String path);
bool IsFile(String path);
struct Process {
bool is_valid;

View File

@@ -276,3 +276,26 @@ String GetExeDir(Allocator allocator) {
path = Copy(allocator, path);
return path;
}
bool FileExists(String path) {
wchar_t wbuff[1024];
CreateWidecharFromChar(wbuff, Lengthof(wbuff), path.data, path.len);
DWORD attribs = GetFileAttributesW(wbuff);
bool result = attribs == INVALID_FILE_ATTRIBUTES ? false : true;
return result;
}
bool IsDir(String path) {
wchar_t wbuff[1024];
CreateWidecharFromChar(wbuff, Lengthof(wbuff), path.data, path.len);
DWORD dwAttrib = GetFileAttributesW(wbuff);
return dwAttrib != INVALID_FILE_ATTRIBUTES && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY);
}
bool IsFile(String path) {
wchar_t wbuff[1024];
CreateWidecharFromChar(wbuff, Lengthof(wbuff), path.data, path.len);
DWORD dwAttrib = GetFileAttributesW(wbuff);
bool is_file = (dwAttrib & FILE_ATTRIBUTE_DIRECTORY) == 0;
return dwAttrib != INVALID_FILE_ATTRIBUTES && is_file;
}