2017-07-18 23:17:40 +00:00
/*
* Mr . 4 th Dimention - Allen Webster
*
* 18.07 .2017
*
* Shared logic for 4 coder initialization .
*
*/
// TOP
2017-07-18 23:41:28 +00:00
internal void
2019-10-01 02:06:21 +00:00
load_app_code ( Thread_Context * tctx ) {
2017-07-19 00:19:38 +00:00
App_Get_Functions * get_funcs = 0 ;
2019-10-01 02:06:21 +00:00
Scratch_Block scratch ( tctx , Scratch_Share ) ;
2019-08-16 15:01:17 +00:00
if ( system_load_library ( scratch , & libraries . app_code , " 4ed_app " , LoadLibrary_BinaryDirectory ) ) {
2017-07-19 00:19:38 +00:00
get_funcs = ( App_Get_Functions * ) system_get_proc ( & libraries . app_code , " app_get_functions " ) ;
}
else {
char msg [ ] = " Could not load '4ed_app. " DLL " '. This file should be in the same directory as the main '4ed' executable. " ;
2019-08-16 15:01:17 +00:00
system_error_box ( scratch , msg ) ;
2017-07-19 00:19:38 +00:00
}
if ( get_funcs ! = 0 ) {
app = get_funcs ( ) ;
}
else {
char msg [ ] = " Failed to get application code from '4ed_app. " DLL " '. " ;
2019-08-16 15:01:17 +00:00
system_error_box ( scratch , msg ) ;
2017-07-19 00:19:38 +00:00
}
}
2017-07-19 16:33:12 +00:00
global char custom_fail_version_msg [ ] = " Failed to load custom code due to missing version information or a version mismatch. Try rebuilding with buildsuper. " ;
global char custom_fail_missing_get_bindings_msg [ ] = " Failed to load custom code due to missing 'get_bindings' symbol. Try rebuilding with buildsuper. " ;
internal void
2019-10-01 02:06:21 +00:00
load_custom_code ( Thread_Context * tctx ) {
Scratch_Block scratch ( tctx , Scratch_Share ) ;
2017-07-19 16:33:12 +00:00
local_persist char * default_file = " custom_4coder " ;
local_persist Load_Library_Location locations [ ] = {
LoadLibrary_CurrentDirectory ,
LoadLibrary_BinaryDirectory ,
} ;
2018-11-20 08:18:54 +00:00
char * custom_files [ 3 ] = { } ;
2017-07-19 16:33:12 +00:00
if ( plat_settings . custom_dll ! = 0 ) {
custom_files [ 0 ] = plat_settings . custom_dll ;
if ( ! plat_settings . custom_dll_is_strict ) {
custom_files [ 1 ] = default_file ;
}
}
else {
custom_files [ 0 ] = default_file ;
}
char success_file [ 4096 ] ;
b32 has_library = false ;
for ( u32 i = 0 ; custom_files [ i ] ! = 0 & & ! has_library ; + + i ) {
char * file = custom_files [ i ] ;
for ( u32 j = 0 ; j < ArrayCount ( locations ) & & ! has_library ; + + j ) {
2019-08-16 15:01:17 +00:00
if ( system_load_library ( scratch , & libraries . custom , file , locations [ j ] , success_file , sizeof ( success_file ) ) ) {
2017-07-19 16:33:12 +00:00
has_library = true ;
success_file [ sizeof ( success_file ) - 1 ] = 0 ;
}
}
}
if ( ! has_library ) {
2019-08-16 15:01:17 +00:00
system_error_box ( scratch , " Did not find a library for the custom layer. " ) ;
2017-07-19 16:33:12 +00:00
}
custom_api . get_alpha_4coder_version = ( _Get_Version_Function * )
system_get_proc ( & libraries . custom , " get_alpha_4coder_version " ) ;
if ( custom_api . get_alpha_4coder_version = = 0 | | custom_api . get_alpha_4coder_version ( MAJOR , MINOR , PATCH ) = = 0 ) {
2019-08-16 15:01:17 +00:00
system_error_box ( scratch , custom_fail_version_msg ) ;
2017-07-19 16:33:12 +00:00
}
custom_api . get_bindings = ( Get_Binding_Data_Function * )
system_get_proc ( & libraries . custom , " get_bindings " ) ;
if ( custom_api . get_bindings = = 0 ) {
2019-08-16 15:01:17 +00:00
system_error_box ( scratch , custom_fail_missing_get_bindings_msg ) ;
2017-07-19 16:33:12 +00:00
}
2019-07-21 18:16:34 +00:00
//LOGF("Loaded custom file: %s\n", success_file);
2017-07-19 16:33:12 +00:00
}
2019-10-01 02:06:21 +00:00
internal void *
read_command_line ( Thread_Context * tctx , i32 argc , char * * argv ) {
Scratch_Block scratch ( tctx , Scratch_Share ) ;
2019-07-24 07:41:40 +00:00
String_Const_u8 curdir = sysfunc . get_current_path ( scratch ) ;
2019-06-01 23:58:28 +00:00
curdir = string_mod_replace_character ( curdir , ' \\ ' , ' / ' ) ;
2017-07-19 20:07:50 +00:00
char * * files = 0 ;
i32 * file_count = 0 ;
2019-10-01 02:06:21 +00:00
void * result = app . read_command_line ( tctx , & sysfunc , curdir , & plat_settings , & files , & file_count , argc , argv ) ;
2019-08-16 15:01:17 +00:00
sysshared_filter_real_files ( scratch , files , file_count ) ;
2019-10-01 02:06:21 +00:00
return ( result ) ;
2017-07-19 20:07:50 +00:00
}
2017-07-18 23:17:40 +00:00
// BOTTOM