From 9862c8b926576ee8b74d14556f73e9a1f1e12138 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Fri, 30 Jun 2017 18:54:06 -0400 Subject: [PATCH] cleaned up the binary path getter on win32 --- 4ed_system.h | 4 ++- platform_all/4ed_system_shared.cpp | 8 +++++- platform_all/4ed_system_shared.h | 6 +++-- platform_win32/win32_4ed.cpp | 39 ++++++++++++++---------------- platform_win32/win32_4ed_fonts.cpp | 2 +- 5 files changed, 33 insertions(+), 26 deletions(-) diff --git a/4ed_system.h b/4ed_system.h index 26bdc454..c4d83767 100644 --- a/4ed_system.h +++ b/4ed_system.h @@ -199,7 +199,7 @@ typedef Sys_Acquire_Lock_Sig(System_Acquire_Lock); #define Sys_Release_Lock_Sig(name) void name(i32 id) typedef Sys_Release_Lock_Sig(System_Release_Lock); -// needed for custom layer +// memory #define Sys_Memory_Allocate_Sig(name) void* name(umem size) typedef Sys_Memory_Allocate_Sig(System_Memory_Allocate); @@ -209,6 +209,7 @@ typedef Sys_Memory_Set_Protection_Sig(System_Memory_Set_Protection); #define Sys_Memory_Free_Sig(name) void name(void *ptr, umem size) typedef Sys_Memory_Free_Sig(System_Memory_Free); +// file system #define Sys_File_Exists_Sig(name) b32 name(char *filename, i32 len) typedef Sys_File_Exists_Sig(System_File_Exists); @@ -218,6 +219,7 @@ typedef Sys_Directory_CD_Sig(System_Directory_CD); #define Sys_Get_4ed_Path_Sig(name) int32_t name(char *out, i32 capacity) typedef Sys_Get_4ed_Path_Sig(System_Get_4ed_Path); +// behavior and appearance options #define Sys_Show_Mouse_Cursor_Sig(name) void name(i32 show) typedef Sys_Show_Mouse_Cursor_Sig(System_Show_Mouse_Cursor); diff --git a/platform_all/4ed_system_shared.cpp b/platform_all/4ed_system_shared.cpp index 958a418d..1cd05ac1 100644 --- a/platform_all/4ed_system_shared.cpp +++ b/platform_all/4ed_system_shared.cpp @@ -16,6 +16,12 @@ // Standard implementation of file system stuff based on the file track layer. // +internal i32 +system_get_binary_path_string(String *out){ + out->size = system_get_4ed_path(out->str, out->memory_size); + return(out->size); +} + internal void init_shared_vars(){ umem scratch_size = KB(128); @@ -206,7 +212,7 @@ internal b32 sysshared_to_binary_path(String *out_filename, char *filename){ b32 translate_success = 0; i32 max = out_filename->memory_size; - i32 size = system_get_binary_path(out_filename); + i32 size = system_get_binary_path_string(out_filename); if (size > 0 && size < max-1){ out_filename->size = size; if (append_sc(out_filename, filename) && terminate_with_null(out_filename)){ diff --git a/platform_all/4ed_system_shared.h b/platform_all/4ed_system_shared.h index cb7edab5..33593f1b 100644 --- a/platform_all/4ed_system_shared.h +++ b/platform_all/4ed_system_shared.h @@ -25,10 +25,12 @@ struct File_Data{ global File_Data null_file_data = {0}; #define Sys_File_Can_Be_Made_Sig(name) b32 name(u8 *filename) -#define Sys_Get_Binary_Path_Sig(name) i32 name(String *out) - internal Sys_File_Can_Be_Made_Sig(system_file_can_be_made); + +#if 0 +#define Sys_Get_Binary_Path_Sig(name) i32 name(String *out) internal Sys_Get_Binary_Path_Sig(system_get_binary_path); +#endif struct Shared_Vars{ File_Track_System track; diff --git a/platform_win32/win32_4ed.cpp b/platform_win32/win32_4ed.cpp index 4e32636f..89c36ba6 100644 --- a/platform_win32/win32_4ed.cpp +++ b/platform_win32/win32_4ed.cpp @@ -211,6 +211,23 @@ struct Win32_Vars{ global Win32_Vars win32vars; global Application_Memory memory_vars; +// +// 4ed path +// + +internal +Sys_Get_4ed_Path_Sig(system_get_4ed_path){ + i32 result_size = 0; + i32 size = GetModuleFileName_utf8(0, (u8*)out, capacity); + if (size < capacity - 1){ + String str = make_string(out, size); + remove_last_folder(&str); + terminate_with_null(&str); + result_size = str.size; + } + return(result_size); +} + // // Logging // @@ -220,7 +237,7 @@ Sys_Log_Sig(system_log){ if (win32vars.settings.use_log){ u8 space[4096]; String str = make_fixed_width_string(space); - system_get_binary_path(&str); + str.size = system_get_4ed_path(str.str, str.memory_size); append_sc(&str, "4coder_log.txt"); terminate_with_null(&str); HANDLE file = CreateFile_utf8(space, GENERIC_WRITE, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); @@ -1037,19 +1054,6 @@ Win32DirectoryExists(char *path){ return(attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_DIRECTORY)); } -internal -Sys_Get_Binary_Path_Sig(system_get_binary_path){ - i32 result = 0; - i32 size = GetModuleFileName_utf8(0, (u8*)out->str, out->memory_size); - if (size < out->memory_size-1){ - out->size = size; - remove_last_folder(out); - terminate_with_null(out); - result = out->size; - } - return(result); -} - internal Sys_File_Exists_Sig(system_file_exists){ char full_filename_space[1024]; @@ -1112,13 +1116,6 @@ Sys_Directory_CD_Sig(system_directory_cd){ return(result); } -internal -Sys_Get_4ed_Path_Sig(system_get_4ed_path){ - String str = make_string_cap(out, 0, capacity); - int32_t size = system_get_binary_path(&str); - return(size); -} - /* NOTE(casey): This follows Raymond Chen's prescription for fullscreen toggling, see: diff --git a/platform_win32/win32_4ed_fonts.cpp b/platform_win32/win32_4ed_fonts.cpp index 2e286483..0ce23fcb 100644 --- a/platform_win32/win32_4ed_fonts.cpp +++ b/platform_win32/win32_4ed_fonts.cpp @@ -112,7 +112,7 @@ Sys_Font_Init_Sig(system_font_init){ u32 dir_max = KB(32); u8 *directory = push_array(scratch, u8, dir_max); String dir_str = make_string_cap(directory, 0, dir_max); - u32 dir_len = system_get_binary_path(&dir_str); + u32 dir_len = system_get_binary_path_string(&dir_str); Assert(dir_len < dir_max); set_last_folder_sc(&dir_str, "fonts", '\\');