Working on resource management stuff
This commit is contained in:
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user