diff --git a/4ed.cpp b/4ed.cpp index 58af3909..a4a25098 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -2302,6 +2302,12 @@ App_Step_Sig(app_step){ "If you're new to 4coder there are some tutorials at http://4coder.net/tutorials.html\n" "\n" "Newest features:\n" + "-Support for rendering unicode characters\n" + "- isearch alpha-numeric word under cursor\n" + "- query replace alpha-numeric word under cursor\n" + "- toggle file bar\n" + "\n" + "New in alpha 4.0.17:\n" "-New support for extended ascii input.\n" "-Extended ascii encoded in buffers as utf8.\n" "-The custom layer now has a 'markers' API for tracking buffer positions across changes.\n" diff --git a/win32_4ed_file_track.cpp b/win32_4ed_file_track.cpp index d48e9f8f..16059580 100644 --- a/win32_4ed_file_track.cpp +++ b/win32_4ed_file_track.cpp @@ -327,31 +327,45 @@ get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, i32 } if (has_result){ - FILE_NOTIFY_INFORMATION *info = (FILE_NOTIFY_INFORMATION*)(listener.result + offset); + FILE_NOTIFY_INFORMATION *info = (FILE_NOTIFY_INFORMATION*)(((u8*)listener.result) + offset); i32 len = info->FileNameLength / 2; i32 dir_len = GetFinalPathNameByHandle_utf8(listener.dir, 0, 0, FILE_NAME_NORMALIZED); - i32 req_size = dir_len + 1 + len; + i32 req_size = dir_len + (len + 1)*2; *size = req_size; // TODO(allen): This check isn't really right, it should rely on the result from GetFinalPathNameByHandle_utf8. if (req_size < max){ - i32 pos = GetFinalPathNameByHandle_utf8(listener.dir, buffer, max, FILE_NAME_NORMALIZED); - buffer[pos++] = '\\'; + u32 path_pos = GetFinalPathNameByHandle_utf8(listener.dir, buffer, max, FILE_NAME_NORMALIZED); + buffer[path_pos++] = '\\'; - for (i32 i = 0; i < len; ++i, ++pos){ - buffer[pos] = (char)info->FileName[i]; - } + u32 name_max = max - path_pos; + u8 *name_buffer = buffer + path_pos; - if (buffer[0] == '\\'){ - for (i32 i = 0; i+4 < pos; ++i){ - buffer[i] = buffer[i+4]; + b32 convert_error = false; + u32 name_pos = (u32)utf16_to_utf8_minimal_checking(name_buffer, name_max, (u16*)info->FileName, len, &convert_error); + + if (name_pos < name_max){ + if (!convert_error){ + u32 pos = path_pos + name_pos; + *size = pos; + if (buffer[0] == '\\'){ + for (u32 i = 0; i+4 < pos; ++i){ + buffer[i] = buffer[i+4]; + } + *size -= 4; + } + result = FileTrack_Good; } - *size -= 4; + else{ + result = FileTrack_FileSystemError; + } + } + else{ + result = FileTrack_MemoryTooSmall; } - result = FileTrack_Good; } else{ // TODO(allen): Need some way to stash this result so that if the diff --git a/win32_utf8.cpp b/win32_utf8.cpp index a11d963f..40f31332 100644 --- a/win32_utf8.cpp +++ b/win32_utf8.cpp @@ -43,6 +43,7 @@ GetFinalPathNameByHandle_utf8(HANDLE file, u8 *file_path_out, DWORD path_max, DW if (file_path_out == 0){ result = GetFinalPathNameByHandleW(file, 0, 0, flags); + result *= 2; } else{ Partition *scratch = &shared_vars.scratch;