override user directory on command line

master
Allen Webster 2021-05-07 16:56:24 -07:00
parent e3efa89293
commit fb4d181a3b
8 changed files with 655 additions and 625 deletions

View File

@ -52,6 +52,7 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings,
case 'f': action = CLAct_FontSize; break; case 'f': action = CLAct_FontSize; break;
case 'h': action = CLAct_FontUseHinting; --i; break; case 'h': action = CLAct_FontUseHinting; --i; break;
case 'U': action = CLAct_UserDirectory; break;
} }
} }
else if (arg[0] != 0){ else if (arg[0] != 0){
@ -137,6 +138,14 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings,
settings->use_hinting = plat_settings->use_hinting; settings->use_hinting = plat_settings->use_hinting;
action = CLAct_Nothing; action = CLAct_Nothing;
}break; }break;
case CLAct_UserDirectory:
{
if (i < argc){
plat_settings->user_directory = argv[i];
}
action = CLAct_Nothing;
}break;
} }
}break; }break;

28
4ed.h
View File

@ -28,16 +28,18 @@ struct Plat_Settings{
b8 maximize_window; b8 maximize_window;
b8 use_hinting; b8 use_hinting;
char *user_directory;
}; };
#define App_Read_Command_Line_Sig(name) \ #define App_Read_Command_Line_Sig(name) \
void *name(Thread_Context *tctx,\ void *name(Thread_Context *tctx,\
String_Const_u8 current_directory,\ String_Const_u8 current_directory,\
Plat_Settings *plat_settings,\ Plat_Settings *plat_settings,\
char ***files, \ char ***files, \
i32 **file_count,\ i32 **file_count,\
i32 argc, \ i32 argc, \
char **argv) char **argv)
typedef App_Read_Command_Line_Sig(App_Read_Command_Line); typedef App_Read_Command_Line_Sig(App_Read_Command_Line);
@ -48,10 +50,10 @@ struct Custom_API{
#define App_Init_Sig(name) \ #define App_Init_Sig(name) \
void name(Thread_Context *tctx, \ void name(Thread_Context *tctx, \
Render_Target *target, \ Render_Target *target, \
void *base_ptr, \ void *base_ptr, \
String_Const_u8 current_directory,\ String_Const_u8 current_directory,\
Custom_API api) Custom_API api)
typedef App_Init_Sig(App_Init); typedef App_Init_Sig(App_Init);
@ -77,9 +79,9 @@ struct Application_Step_Input{
#define App_Step_Sig(name) Application_Step_Result \ #define App_Step_Sig(name) Application_Step_Result \
name(Thread_Context *tctx, \ name(Thread_Context *tctx, \
Render_Target *target, \ Render_Target *target, \
void *base_ptr, \ void *base_ptr, \
Application_Step_Input *input) Application_Step_Input *input)
typedef App_Step_Sig(App_Step); typedef App_Step_Sig(App_Step);

View File

@ -180,7 +180,6 @@ struct File_Init{
enum Command_Line_Action{ enum Command_Line_Action{
CLAct_Nothing, CLAct_Nothing,
CLAct_Ignore, CLAct_Ignore,
CLAct_UserFile,
CLAct_CustomDLL, CLAct_CustomDLL,
CLAct_WindowSize, CLAct_WindowSize,
CLAct_WindowMaximize, CLAct_WindowMaximize,
@ -188,6 +187,7 @@ enum Command_Line_Action{
CLAct_WindowFullscreen, CLAct_WindowFullscreen,
CLAct_FontSize, CLAct_FontSize,
CLAct_FontUseHinting, CLAct_FontUseHinting,
CLAct_UserDirectory,
// //
CLAct_COUNT, CLAct_COUNT,
}; };

View File

@ -167,11 +167,6 @@ save_file_to_name(Thread_Context *tctx, Models *models, Editing_File *file, u8 *
return(result); return(result);
} }
internal b32
save_file(Thread_Context *tctx, Models *models, Editing_File *file){
return(save_file_to_name(tctx, models, file, 0));
}
//////////////////////////////// ////////////////////////////////
internal Buffer_Cursor internal Buffer_Cursor

View File

@ -1835,6 +1835,11 @@ main(int argc, char **argv){
}*/ }*/
} }
// NOTE(allen): setup user directory override
if (plat_settings.user_directory != 0){
lnx_override_user_directory = plat_settings.user_directory;
}
// NOTE(allen): load custom layer // NOTE(allen): load custom layer
System_Library custom_library = {}; System_Library custom_library = {};
Custom_API custom = {}; Custom_API custom = {};

File diff suppressed because it is too large Load Diff

View File

@ -1738,6 +1738,11 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
} }
} }
// NOTE(allen): setup user directory override
if (plat_settings.user_directory != 0){
w32_override_user_directory = SCu8((u8*)plat_settings.user_directory);
}
// NOTE(allen): load custom layer // NOTE(allen): load custom layer
System_Library custom_library = {}; System_Library custom_library = {};
Custom_API custom = {}; Custom_API custom = {};

View File

@ -125,6 +125,8 @@ system_memory_annotation_sig(){
extern "C" BOOL CALL_CONVENTION extern "C" BOOL CALL_CONVENTION
GetUserProfileDirectoryW(HANDLE hToken, LPWSTR lpProfileDir, LPDWORD lpcchSize); GetUserProfileDirectoryW(HANDLE hToken, LPWSTR lpProfileDir, LPDWORD lpcchSize);
global String_Const_u8 w32_override_user_directory = {};
internal internal
system_get_path_sig(){ system_get_path_sig(){
String_Const_u8 result = {}; String_Const_u8 result = {};
@ -155,13 +157,18 @@ system_get_path_sig(){
case SystemPath_UserDirectory: case SystemPath_UserDirectory:
{ {
HANDLE current_process_token = GetCurrentProcessToken(); if (w32_override_user_directory.size == 0){
DWORD size = 0; HANDLE current_process_token = GetCurrentProcessToken();
GetUserProfileDirectoryW(current_process_token, 0, &size); DWORD size = 0;
u16 *buffer_u16 = push_array(arena, u16, size); GetUserProfileDirectoryW(current_process_token, 0, &size);
if (GetUserProfileDirectoryW(current_process_token, (WCHAR*)buffer_u16, &size)){ u16 *buffer_u16 = push_array(arena, u16, size);
String8 path = string_u8_from_string_u16(arena, SCu16(buffer_u16, size), StringFill_NullTerminate).string; if (GetUserProfileDirectoryW(current_process_token, (WCHAR*)buffer_u16, &size)){
result = push_stringf(arena, "%.*s\\4coder\\", string_expand(path)); String8 path = string_u8_from_string_u16(arena, SCu16(buffer_u16, size), StringFill_NullTerminate).string;
result = push_stringf(arena, "%.*s\\4coder\\", string_expand(path));
}
}
else{
result = w32_override_user_directory;
} }
}break; }break;
} }