diff --git a/src/detection/terminalfont/terminalfont_windows.c b/src/detection/terminalfont/terminalfont_windows.c index 6a68bb6a5..7e1d5c8cb 100644 --- a/src/detection/terminalfont/terminalfont_windows.c +++ b/src/detection/terminalfont/terminalfont_windows.c @@ -1,4 +1,5 @@ #include "common/properties.h" +#include "common/io.h" #include "detection/terminalshell/terminalshell.h" #include "terminalfont.h" @@ -73,10 +74,64 @@ exit: RegCloseKey(hKey); } +static void detectConEmu(const FFinstance* instance, FFTerminalFontResult* terminalFont) +{ + FF_UNUSED(instance) + + //https://conemu.github.io/en/ConEmuXml.html#search-sequence + FFstrbuf path; + ffStrbufInit(&path); + + FFstrbuf fontName; + ffStrbufInit(&fontName); + + FFstrbuf fontSize; + ffStrbufInit(&fontSize); + + const char* paths[] = { "ConEmuDir", "ConEmuBaseDir", "APPDATA" }; + for (uint32_t i = 0; i < sizeof(paths) / sizeof(paths[0]); ++i) + { + ffStrbufSetS(&path, getenv(paths[i])); + if(path.length > 0) + { + ffStrbufAppendS(&path, "/ConEmu.xml"); + if(ffParsePropFileValues(path.chars, 2, (FFpropquery[]){ + {"error, "Failed to parse ConEmu.xml"); + return; + } + + if(fontName.length > 0) + ffStrbufSubstrBeforeLastC(&fontName, '"'); + else + ffStrbufAppendS(&fontName, "Consola"); + + if(fontSize.length > 0) + ffStrbufSubstrBeforeLastC(&fontSize, '"'); + else + ffStrbufAppendS(&fontSize, "14"); + + ffFontInitValues(&terminalFont->font, fontName.chars, fontSize.chars); + + ffStrbufDestroy(&fontName); + ffStrbufDestroy(&fontSize); +} + void ffDetectTerminalFontPlatform(const FFinstance* instance, const FFTerminalShellResult* terminalShell, FFTerminalFontResult* terminalFont) { if(ffStrbufIgnCaseCompS(&terminalShell->terminalProcessName, "mintty") == 0) detectMintty(instance, terminalFont); else if(ffStrbufIgnCaseCompS(&terminalShell->terminalProcessName, "conhost.exe") == 0) detectConhost(instance, terminalFont); + else if(ffStrbufStartsWithIgnCaseS(&terminalShell->terminalProcessName, "ConEmuC")) + detectConEmu(instance, terminalFont); }