woodruffw / screenfetch-c

A rewrite of screenFetch in C.
MIT License
73 stars 17 forks source link

MSYS2 compatibility #25

Closed darealshinji closed 8 years ago

woodruffw commented 8 years ago

Minor nit: Could you amend the commit to explain why we redefine REG_QUERY_V for MSYS targets?

Something like this would be good:

win32/detect: MSYS2 compatibility.

Conditionally define REG_QUERY_V because [reasons].

Other than that, this looks good. Thanks!

darealshinji commented 8 years ago

I've added a description.

woodruffw commented 8 years ago

Thanks; merged.

darealshinji commented 8 years ago

I was thinking, maybe the whole popen() part could be replaced with a different solution, like this:

#include <libgen.h>  /* basename(3) */

[...]

void detect_wm_theme(void)
{
    char theme[MAX_STRLEN] = "Unknown";
    HKEY hkey;
    DWORD str_size = MAX_STRLEN;

    RegOpenKey(HKEY_CURRENT_USER,
            "Software\\Microsoft\\Windows\\CurrentVersion\\Themes", &hkey);
    RegQueryValueEx(hkey, "CurrentTheme", 0, NULL, (BYTE *) theme,
            &str_size);

    if (!STREQ(theme, "Unknown"))
    {
        snprintf(theme, MAX_STRLEN, "%s", basename(theme));
        char *end = theme + strlen(theme)-6;
        if (STREQ(end, ".theme"))
            theme[strlen(theme)-6] = 0;
    }
    snprintf(wm_theme_str, MAX_STRLEN, "%s", theme);

    return;
}
woodruffw commented 8 years ago

Try b22f62a. It's pretty much line-for-line what you had above.

darealshinji commented 8 years ago

Works in Cygwin and MSYS2. But you have two little mistakes in there:

--- a/src/plat/win32/detect.c
+++ b/src/plat/win32/detect.c
@@ -427,7 +427,7 @@ void detect_wm_theme(void)
        RegOpenKey(HKEY_CURRENT_USER,
                "Software\\Microsoft\\Windows\\CurrentVersion\\Themes", &hkey);
        RegQueryValueEx(hkey, "CurrentTheme", 0, NULL, (BYTE *) tmp_theme,
-               &str_size)
+               &str_size);

        /* if we successfully retrieved a theme from the registry */
        if (!STREQ(tmp_theme, "Unknown"))
@@ -438,7 +438,7 @@ void detect_wm_theme(void)
                /* if our retrieved theme ends with .theme, truncate it */
                if (STREQ(suffix, ".theme"))
                {
-                       tmp_theme[strlen(theme) - 6] = '\0';
+                       tmp_theme[strlen(tmp_theme) - 6] = '\0';
                }
        }
woodruffw commented 8 years ago

Thanks for the catch! I'll merge this now.