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 'h': action = CLAct_FontUseHinting; --i; break;
case 'U': action = CLAct_UserDirectory; break;
}
}
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;
action = CLAct_Nothing;
}break;
case CLAct_UserDirectory:
{
if (i < argc){
plat_settings->user_directory = argv[i];
}
action = CLAct_Nothing;
}break;
}
}break;

2
4ed.h
View File

@ -28,6 +28,8 @@ struct Plat_Settings{
b8 maximize_window;
b8 use_hinting;
char *user_directory;
};
#define App_Read_Command_Line_Sig(name) \

View File

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

View File

@ -167,11 +167,6 @@ save_file_to_name(Thread_Context *tctx, Models *models, Editing_File *file, u8 *
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

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
System_Library custom_library = {};
Custom_API custom = {};

View File

@ -8,6 +8,8 @@
*
*/
global char *lnx_override_user_directory = 0;
internal String_Const_u8
system_get_path(Arena* arena, System_Path_Code path_code){
String_Const_u8 result = {};
@ -45,10 +47,15 @@ system_get_path(Arena* arena, System_Path_Code path_code){
case SystemPath_UserDirectory:
{
if (lnx_override_user_directory == 0){
char *home_cstr = getenv("HOME");
if (home_cstr != 0){
result = push_u8_stringf(arena, "%s/.4coder/", home_cstr);
}
}
else{
result = SCu8((u8*)lnx_override_user_directory);
}
}break;
}

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
System_Library custom_library = {};
Custom_API custom = {};

View File

@ -125,6 +125,8 @@ system_memory_annotation_sig(){
extern "C" BOOL CALL_CONVENTION
GetUserProfileDirectoryW(HANDLE hToken, LPWSTR lpProfileDir, LPDWORD lpcchSize);
global String_Const_u8 w32_override_user_directory = {};
internal
system_get_path_sig(){
String_Const_u8 result = {};
@ -155,6 +157,7 @@ system_get_path_sig(){
case SystemPath_UserDirectory:
{
if (w32_override_user_directory.size == 0){
HANDLE current_process_token = GetCurrentProcessToken();
DWORD size = 0;
GetUserProfileDirectoryW(current_process_token, 0, &size);
@ -163,6 +166,10 @@ system_get_path_sig(){
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;
}
return(result);