Fix mouse, fix allocator in file iter, GetCFiles
This commit is contained in:
@@ -99,8 +99,6 @@ bool IsValid(const FileIter &it) {
|
||||
}
|
||||
|
||||
void Advance(FileIter *it) {
|
||||
if (it->temp.arena) EndTemp(it->temp);
|
||||
it->temp = BeginTemp(it->arena);
|
||||
while (FindNextFileW(it->w32->handle, &it->w32->data) != 0) {
|
||||
WIN32_FIND_DATAW *data = &it->w32->data;
|
||||
|
||||
@@ -109,11 +107,11 @@ void Advance(FileIter *it) {
|
||||
if (data->cFileName[0] == '.' && data->cFileName[1] == 0) continue;
|
||||
|
||||
it->is_directory = data->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
|
||||
it->filename = ToString(*it->arena, (char16_t *)data->cFileName, WideLength((char16_t *)data->cFileName));
|
||||
it->filename = ToString(it->allocator, (char16_t *)data->cFileName, WideLength((char16_t *)data->cFileName));
|
||||
const char *is_dir = it->is_directory ? "/" : "";
|
||||
const char *separator = it->path.data[it->path.len - 1] == '/' ? "" : "/";
|
||||
it->relative_path = Format(*it->arena, "%.*s%s%.*s%s", FmtString(it->path), separator, FmtString(it->filename), is_dir);
|
||||
it->absolute_path = GetAbsolutePath(*it->arena, it->relative_path);
|
||||
it->relative_path = Format(it->allocator, "%.*s%s%.*s%s", FmtString(it->path), separator, FmtString(it->filename), is_dir);
|
||||
it->absolute_path = GetAbsolutePath(it->allocator, it->relative_path);
|
||||
it->is_valid = true;
|
||||
|
||||
if (it->is_directory) {
|
||||
@@ -127,19 +125,17 @@ void Advance(FileIter *it) {
|
||||
DWORD error = GetLastError();
|
||||
Assert(error == ERROR_NO_MORE_FILES);
|
||||
FindClose(it->w32->handle);
|
||||
Dealloc(it->allocator, &it->arena);
|
||||
}
|
||||
|
||||
FileIter IterateFiles(Allocator alo, String path) {
|
||||
FileIter it = {0};
|
||||
it.allocator = alo;
|
||||
it.arena = AllocArena(alo, MiB(2));
|
||||
it.path = path;
|
||||
|
||||
String modified_path = Format(*it.arena, "%.*s\\*", FmtString(path));
|
||||
String16 modified_path16 = ToString16(*it.arena, modified_path);
|
||||
String modified_path = Format(it.allocator, "%.*s\\*", FmtString(path));
|
||||
String16 modified_path16 = ToString16(it.allocator, modified_path);
|
||||
|
||||
it.w32 = AllocType(*it.arena, Win32_FileIter);
|
||||
it.w32 = AllocType(it.allocator, Win32_FileIter);
|
||||
it.w32->handle = FindFirstFileW((wchar_t *)modified_path16.data, &it.w32->data);
|
||||
if (it.w32->handle == INVALID_HANDLE_VALUE) {
|
||||
it.is_valid = false;
|
||||
|
||||
Reference in New Issue
Block a user