From dbc576862ec1ee2d070f4ae2a0d63d94263bb373 Mon Sep 17 00:00:00 2001 From: DarN <82701459+DarNCelsius@users.noreply.github.com> Date: Mon, 26 Apr 2021 21:46:57 +0200 Subject: [PATCH] Made corrections Something like this? --- src/modules/wmtheme.c | 66 +++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/src/modules/wmtheme.c b/src/modules/wmtheme.c index a7ded49f4..ed9312741 100644 --- a/src/modules/wmtheme.c +++ b/src/modules/wmtheme.c @@ -1,4 +1,5 @@ #include "fastfetch.h" +#include "util/FFstrbuf.h" #include #define FF_WMTHEME_MODULE_NAME "WM Theme" @@ -38,7 +39,6 @@ static void printOpenbox(FFinstance* instance) { FFstrbuf absolutePath, theme; ffStrbufInitA(&absolutePath, 64); - ffStrbufInitA(&theme, 256); ffStrbufAppendS(&absolutePath, instance->state.passwd->pw_dir); ffStrbufAppendC(&absolutePath, '/'); @@ -55,45 +55,43 @@ static void printOpenbox(FFinstance* instance) size_t len = 0; FILE* file = fopen(absolutePath.chars, "r"); - if(file != NULL) + if(file == NULL) { - while(getline(&line, &len, file) != -1) - { - if(strstr(line, "") != 0) - break; - } - while(getline(&line, &len, file) != -1) - { - if(strstr(line, "") != 0) - { - ffStrbufAppendS(&theme, line); - ffStrbufRemoveStrings(&theme, 2, "", ""); - ffStrbufTrimRight(&theme, '\n'); - ffStrbufTrim(&theme, ' '); - break; - } - else if(strstr(line, "") != 0) // sanity check - break; - } - if(line != NULL) - free(line); - - fclose(file); - } - else ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't open \"%s\"", absolutePath.chars); - - if(theme.length == 0) - { - ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't find theme name in \"%s\"", absolutePath.chars); - - ffStrbufDestroy(&theme); ffStrbufDestroy(&absolutePath); - + return; } + + while(getline(&line, &len, file) != -1) + { + if(strstr(line, "") != 0) + break; + } + while(getline(&line, &len, file) != -1) + { + if(strstr(line, "") != 0) + { + ffStrbufInitA(&theme, 256); + ffStrbufAppendS(&theme, line); + ffStrbufRemoveStrings(&theme, 2, "", ""); + ffStrbufTrimRight(&theme, '\n'); + ffStrbufTrim(&theme, ' '); + break; + } + else if(strstr(line, "") != 0) // sanity check + break; + } + if(line != NULL) + free(line); - printWMTheme(instance, theme.chars); + fclose(file); + + + if(theme.length == 0) + ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't find theme name in \"%s\"", absolutePath.chars); + else + printWMTheme(instance, theme.chars); ffStrbufDestroy(&theme); ffStrbufDestroy(&absolutePath);