From a31bab5aae10757f5029b00e39beb0e3815b92b1 Mon Sep 17 00:00:00 2001 From: Ginger Bill Date: Fri, 23 Sep 2016 14:59:58 +0100 Subject: Unicode file loading; push_allocator & push_context --- src/common.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'src/common.cpp') diff --git a/src/common.cpp b/src/common.cpp index bbad5b845..fb4223d9d 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -4,6 +4,47 @@ #include "string.cpp" +String get_module_dir(gbAllocator a) { + isize len = GetModuleFileNameW(NULL, NULL, 0); + if (len == 0) { + return make_string(NULL, 0); + } + gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&string_buffer_arena); + defer (gb_temp_arena_memory_end(tmp)); + + + wchar_t *text = gb_alloc_array(string_buffer_allocator, wchar_t, len+1); + + String16 str = {text, len}; + GetModuleFileNameW(NULL, text, len); + String path = string16_to_string(a, str); + for (isize i = path.len-1; i >= 0; i--) { + u8 c = path.text[i]; + if (c == '/' || c == '\\') { + break; + } + path.len--; + } + + return path; +} + +String path_to_fullpath(gbAllocator a, String s) { + gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&string_buffer_arena); + defer (gb_temp_arena_memory_end(tmp)); + + String16 string16 = string_to_string16(string_buffer_allocator, s); + + DWORD len = GetFullPathNameW(string16.text, 0, NULL, NULL); + if (len == 0) { + return make_string(NULL, 0); + } + wchar_t *text = gb_alloc_array(string_buffer_allocator, wchar_t, len+1); + GetFullPathNameW(string16.text, len, text, NULL); + text[len] = 0; + + return string16_to_string(a, make_string16(text, len)); +} struct BlockTimer { u64 start; -- cgit v1.2.3