From 2f457584d84eb2a538ca267a81e0be3d46aca4af Mon Sep 17 00:00:00 2001 From: Fafabis Date: Thu, 6 May 2021 11:50:55 -0300 Subject: [PATCH] Properly update update-desktop-database --- src/d_protocol.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/d_protocol.c b/src/d_protocol.c index 76c7a46e3..bd6d799c5 100644 --- a/src/d_protocol.c +++ b/src/d_protocol.c @@ -10,6 +10,7 @@ /// \brief srb2kart:// protocol stuff #include +#include #include #include #if defined (__unix__) || defined (UNIXCOMMON) @@ -98,6 +99,7 @@ static boolean RegisterProtocols(const char *path) const char *homedir = pw->pw_dir; char buffer[255]; boolean alreadyexists = false; + boolean newfolder = false; struct stat sb; char *applicationsfolder = va("%s/.local/share/applications/", homedir); @@ -111,12 +113,8 @@ static boolean RegisterProtocols(const char *path) if (stat(applicationsfolder, &sb) == -1) { // location doesn't exist, so let's actually create it + newfolder = true; I_mkdir(applicationsfolder, 0755); - if (system(va("update-desktop-database %s", applicationsfolder)) != 1) - { - CONS_Alert(CONS_ERROR, "Unable to register protocols. Could not run call to run update-desktop-database.\n"); - return false; - } } desktopfile = fopen(va("%s/.local/share/applications/srb2kart-handler.desktop", homedir), "w"); @@ -138,15 +136,26 @@ static boolean RegisterProtocols(const char *path) if (!mimefile) I_Error("Unable to register protocols. Error opening mime file."); - while (fgets(buffer, 255, mimefile)) + while (fgets(buffer, 255, mimefile)) + { if (strncmp(buffer, "x-scheme-handler/srb2kart=srb2kart-handler.desktop;", 43)==0) { alreadyexists = true; break; } + } if (!alreadyexists) fprintf(mimefile, "x-scheme-handler/srb2kart=srb2kart-handler.desktop;\n"); + + if (newfolder) + { + if (system(va("update-desktop-database %s/.local/share/applications/", homedir)) == -1) + { + CONS_Alert(CONS_ERROR, "Unable to register protocols. Could not run call to run update-desktop-database sucessfully.\n"); + return false; + } + } #endif return true;