From eff08276073a832615591ec7671d4f8721611414 Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Thu, 6 Aug 2026 14:14:51 -0600 Subject: [PATCH] hook up initial installation detection, in case program is manually installed externally --- src/linux/shell/linux_shell.c | 74 +++++++++++++++++++++-------------- src/raddbg/raddbg_core.c | 5 ++- src/shell/shell.h | 2 +- 3 files changed, 49 insertions(+), 32 deletions(-) diff --git a/src/linux/shell/linux_shell.c b/src/linux/shell/linux_shell.c index 6b935fea..06ce8320 100644 --- a/src/linux/shell/linux_shell.c +++ b/src/linux/shell/linux_shell.c @@ -127,9 +127,10 @@ sh_open_in_browser(String8 url) } } -internal void -sh_install_or_uninstall_self(B32 install) +internal B32 +sh_install_or_uninstall_self(B32 write, B32 install) { + B32 install_state = 0; Temp scratch = scratch_begin(0, 0); //- rjf: unpack context @@ -159,42 +160,55 @@ sh_install_or_uninstall_self(B32 install) } #endif - //- rjf: install -> write info - if(install) + //- rjf: if writing -> do mutation + if(write) { - //- rjf: write icon - write_data_to_file_path(icon_path, lnx_sh_logo_file_bytes); + //- rjf: install -> write info + if(install) + { + //- rjf: write icon + write_data_to_file_path(icon_path, lnx_sh_logo_file_bytes); + + //- rjf: write .desktop file + String8 desktop_file_data = str8f(scratch.arena, + "[Desktop Entry]\n" + "Type=Application\n" + "Version=" BUILD_VERSION_STRING_LITERAL "\n" + "Name=" BUILD_TITLE "\n" + "Comment=" BUILD_TITLE_STRING_LITERAL "\n" + "Exec=%S\n" + "%s%S%s" // (optional icon) + "Terminal=%s\n" + "Categories=Utility;Development;", + get_process_info()->binary_file_path, + has_icon ? "Icon=" : "", + has_icon ? icon_path : s(""), + has_icon ? "\n" : "", + BUILD_CONSOLE_INTERFACE ? "true" : "false"); + write_data_to_file_path(desktop_file_path, desktop_file_data); + + //- rjf: make symlink in binary path to this exe + make_directory(str8_chop_last_slash(symlink_path)); + symlink((char *)get_process_info()->binary_file_path.str, (char *)symlink_path.str); + } - //- rjf: write .desktop file - String8 desktop_file_data = str8f(scratch.arena, - "[Desktop Entry]\n" - "Type=Application\n" - "Version=" BUILD_VERSION_STRING_LITERAL "\n" - "Name=" BUILD_TITLE "\n" - "Comment=" BUILD_TITLE_STRING_LITERAL "\n" - "Exec=%S\n" - "%s%S%s" // (optional icon) - "Terminal=%s\n" - "Categories=Utility;Development;", - get_process_info()->binary_file_path, - has_icon ? "Icon=" : "", - has_icon ? icon_path : s(""), - has_icon ? "\n" : "", - BUILD_CONSOLE_INTERFACE ? "true" : "false"); - write_data_to_file_path(desktop_file_path, desktop_file_data); + //- rjf: uninstall -> delete files + else + { + delete_file_at_path(icon_path); + delete_file_at_path(desktop_file_path); + unlink((char *)symlink_path.str); + } - //- rjf: make symlink in binary path to this exe - make_directory(str8_chop_last_slash(symlink_path)); - symlink((char *)get_process_info()->binary_file_path.str, (char *)symlink_path.str); + install_state = install; } - //- rjf: uninstall -> delete files + //- rjf: do reading -> check if installation state exists else { - delete_file_at_path(icon_path); - delete_file_at_path(desktop_file_path); - unlink((char *)symlink_path.str); + install_state = file_path_exists(desktop_file_path); } scratch_end(scratch); + return install_state; } diff --git a/src/raddbg/raddbg_core.c b/src/raddbg/raddbg_core.c index e7ae1924..2f32ef27 100644 --- a/src/raddbg/raddbg_core.c +++ b/src/raddbg/raddbg_core.c @@ -11486,6 +11486,9 @@ rd_init(CmdLine *cmdln) scratch_end(scratch); } + // rjf: check initial installation status + rd_state->installed = sh_install_or_uninstall_self(0, 0); + ProfEnd(); scratch_end(scratch); } @@ -13208,7 +13211,7 @@ rd_frame(void) B32 last_installed = rd_state->installed; if(installed != last_installed) { - sh_install_or_uninstall_self(installed); + sh_install_or_uninstall_self(1, installed); rd_state->installed = installed; } diff --git a/src/shell/shell.h b/src/shell/shell.h index c5828db0..4c1a2dc7 100644 --- a/src/shell/shell.h +++ b/src/shell/shell.h @@ -11,6 +11,6 @@ internal void sh_message(B32 error, String8 title, String8 message); internal String8 sh_pick_file(Arena *arena, String8 title, String8 initial_path); internal void sh_show_in_file_browser(String8 path); internal void sh_open_in_browser(String8 url); -internal void sh_install_or_uninstall_self(B32 install); +internal B32 sh_install_or_uninstall_self(B32 write, B32 install); #endif // SHELL_H