Added image loading
Added some string functions and macros Added path listing on windows Added assets
This commit is contained in:
@@ -13,4 +13,33 @@ function void FS_FileClose(OS_Handle file);
|
||||
function void FS_FileRead(OS_Handle file, void *ptr, U64 size, U64 offset);
|
||||
function void FS_FileWrite(OS_Handle file, void *ptr, U64 size, U64 offset);
|
||||
|
||||
typedef U32 FS_EntryType;
|
||||
enum {
|
||||
FS_ENTRY_TYPE_FILE = 0,
|
||||
FS_ENTRY_TYPE_DIR
|
||||
};
|
||||
|
||||
typedef struct FS_Entry FS_Entry;
|
||||
struct FS_Entry {
|
||||
FS_Entry *next;
|
||||
|
||||
FS_EntryType type;
|
||||
|
||||
Str8 path;
|
||||
Str8 basename;
|
||||
|
||||
U64 time;
|
||||
U64 size;
|
||||
};
|
||||
|
||||
typedef struct FS_List FS_List;
|
||||
struct FS_List {
|
||||
FS_Entry *first;
|
||||
FS_Entry *last;
|
||||
|
||||
U32 count;
|
||||
};
|
||||
|
||||
function FS_List FS_PathList(M_Arena *arena, Str8 path);
|
||||
|
||||
#endif // LD_OS_FILESYSTEM_H_
|
||||
|
||||
@@ -14,6 +14,19 @@ internal Str8 Win32_WideStr(M_Arena *arena, Str8 v) {
|
||||
return result;
|
||||
}
|
||||
|
||||
internal Str8 Win32_MultiByteStr(M_Arena *arena, LPWSTR wstr) {
|
||||
Str8 result = { 0 };
|
||||
|
||||
S32 nbytes = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, 0, 0, 0, 0);
|
||||
|
||||
result.count = nbytes - 1;
|
||||
result.data = M_ArenaPush(arena, U8, .count = nbytes);
|
||||
|
||||
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, (LPSTR) result.data, nbytes, 0, 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Virtual memory
|
||||
|
||||
U64 VM_PageSize() {
|
||||
|
||||
@@ -83,4 +83,39 @@ void FS_FileWrite(OS_Handle file, void *ptr, U64 size, U64 offset) {
|
||||
}
|
||||
}
|
||||
|
||||
FS_List FS_PathList(M_Arena *arena, Str8 path) {
|
||||
FS_List result = { 0 };
|
||||
|
||||
M_TempScope(1, &arena) {
|
||||
Str8 wpath = Win32_WideStr(temp.arena, Sf(temp.arena, "%.*s\\*", Sv(path)));
|
||||
|
||||
WIN32_FIND_DATAW find = { 0 };
|
||||
HANDLE hFind = FindFirstFileW((LPCWSTR) wpath.data, &find);
|
||||
|
||||
while (hFind != INVALID_HANDLE_VALUE) {
|
||||
if (find.cFileName[0] != L'.') {
|
||||
FS_Entry *entry = M_ArenaPush(arena, FS_Entry);
|
||||
|
||||
entry->type = (find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? FS_ENTRY_TYPE_DIR : FS_ENTRY_TYPE_FILE;
|
||||
|
||||
entry->basename = Win32_MultiByteStr(arena, find.cFileName);
|
||||
entry->path = Sf(arena, "%.*s/%.*s", Sv(path), Sv(entry->basename));
|
||||
|
||||
FILETIME *wt = &find.ftLastWriteTime;
|
||||
|
||||
entry->time = ((U64) wt->dwHighDateTime << 32) | ((U64) wt->dwLowDateTime);
|
||||
entry->size = ((U64) find.nFileSizeHigh << 32) | ((U64) find.nFileSizeLow);
|
||||
|
||||
SLL_Enqueue(result.first, result.last, entry);
|
||||
|
||||
result.count += 1;
|
||||
}
|
||||
|
||||
if (!FindNextFileW(hFind, &find)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user