Skip to content

Commit 6ef4f62

Browse files
committed
Terminal (Windows): detect warp version
1 parent c038024 commit 6ef4f62

File tree

5 files changed

+71
-24
lines changed

5 files changed

+71
-24
lines changed

src/detection/terminalshell/terminalshell.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020
#include "util/windows/version.h"
2121
#include <windows.h>
2222

23-
static bool getFileVersion(const FFstrbuf* exePath, FFstrbuf* version)
23+
static bool getFileVersion(const FFstrbuf* exePath, const wchar_t* stringName, FFstrbuf* version)
2424
{
2525
wchar_t exePathW[PATH_MAX];
2626
int len = MultiByteToWideChar(CP_UTF8, 0, exePath->chars, (int)exePath->length, exePathW, ARRAY_SIZE(exePathW));
2727
if (len <= 0) return false;
28-
return ffGetFileVersion(exePathW, version);
28+
return ffGetFileVersion(exePathW, stringName, version);
2929
}
30+
3031
#elif __HAIKU__
3132
#include "util/haiku/version.h"
3233
#endif
@@ -98,7 +99,7 @@ static bool getShellVersionPwsh(FFstrbuf* exe, FFstrbuf* version)
9899
}
99100

100101
#ifdef _WIN32
101-
if(getFileVersion(exe, version))
102+
if(getFileVersion(exe, NULL, version))
102103
{
103104
ffStrbufSubstrBeforeLastC(version, '.');
104105
return true;
@@ -291,7 +292,7 @@ bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* exePath,
291292
if(ffStrEqualsIgnCase(exeName, "powershell") || ffStrEqualsIgnCase(exeName, "powershell_ise"))
292293
return getShellVersionWinPowerShell(exe, version);
293294

294-
return getFileVersion(exe, version);
295+
return getFileVersion(exe, NULL, version);
295296
#endif
296297

297298
return false;
@@ -737,7 +738,7 @@ static bool getTerminalVersionWindowsTerminal(FFstrbuf* exe, FFstrbuf* version)
737738
return true;
738739
}
739740

740-
return getFileVersion(exe, version);
741+
return getFileVersion(exe, NULL, version);
741742
}
742743

743744
static bool getTerminalVersionConEmu(FFstrbuf* exe, FFstrbuf* version)
@@ -747,7 +748,7 @@ static bool getTerminalVersionConEmu(FFstrbuf* exe, FFstrbuf* version)
747748
if(version->length)
748749
return true;
749750

750-
return getFileVersion(exe, version);
751+
return getFileVersion(exe, NULL, version);
751752
}
752753

753754
#endif
@@ -839,6 +840,9 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FF_MAYBE_UNUSED FFstrbuf* exe
839840
if(ffStrbufStartsWithIgnCaseS(processName, "ConEmu"))
840841
return getTerminalVersionConEmu(exe, version);
841842

843+
if(ffStrbufIgnCaseEqualS(processName, "warp.exe"))
844+
return getFileVersion(exe, L"ProductVersion", version);
845+
842846
#endif
843847

844848
#ifndef _WIN32
@@ -914,7 +918,7 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FF_MAYBE_UNUSED FFstrbuf* exe
914918

915919
#ifdef _WIN32
916920

917-
return getFileVersion(exe, version);
921+
return getFileVersion(exe, NULL, version);
918922

919923
#else
920924

src/detection/terminalshell/terminalshell_windows.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static void setShellInfoDetails(FFShellResult* result)
8787
if(wcsncmp(module.szModule, L"clink_dll_", strlen("clink_dll_")) == 0)
8888
{
8989
ffStrbufAppendS(&result->prettyName, " (with Clink ");
90-
ffGetFileVersion(module.szExePath, &result->prettyName);
90+
ffGetFileVersion(module.szExePath, NULL, &result->prettyName);
9191
ffStrbufAppendC(&result->prettyName, ')');
9292
break;
9393
}

src/detection/wm/wm_windows.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const char* ffDetectWMVersion(const FFstrbuf* wmName, FFstrbuf* result, FF_MAYBE
7979
wchar_t fullPath[MAX_PATH];
8080
wcscpy(fullPath, pPath);
8181
wcscat(fullPath, L"\\dwm.exe");
82-
ffGetFileVersion(fullPath, result);
82+
ffGetFileVersion(fullPath, NULL, result);
8383
}
8484
CoTaskMemFree(pPath);
8585
return NULL;

src/util/windows/version.c

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,59 @@
11
#include "util/windows/version.h"
22
#include "util/mallocHelper.h"
3+
#include "util/windows/unicode.h"
34

45
#include <windows.h>
56

6-
bool ffGetFileVersion(const wchar_t* filePath, FFstrbuf* version)
7+
bool ffGetFileVersion(const wchar_t* filePath, const wchar_t* stringName, FFstrbuf* version)
78
{
89
DWORD handle;
910
DWORD size = GetFileVersionInfoSizeW(filePath, &handle);
10-
if(size > 0)
11+
if (size > 0)
1112
{
12-
FF_AUTO_FREE void* versionData = malloc(size);
13-
if(GetFileVersionInfoW(filePath, handle, size, versionData))
13+
FF_AUTO_FREE void *versionData = malloc(size);
14+
if (GetFileVersionInfoW(filePath, handle, size, versionData))
1415
{
15-
VS_FIXEDFILEINFO* verInfo;
16-
UINT len;
17-
if(VerQueryValueW(versionData, L"\\", (void**)&verInfo, &len) && len && verInfo->dwSignature == 0xFEEF04BD)
16+
if (!stringName)
1817
{
19-
ffStrbufAppendF(version, "%u.%u.%u.%u",
20-
(unsigned)(( verInfo->dwProductVersionMS >> 16 ) & 0xffff),
21-
(unsigned)(( verInfo->dwProductVersionMS >> 0 ) & 0xffff),
22-
(unsigned)(( verInfo->dwProductVersionLS >> 16 ) & 0xffff),
23-
(unsigned)(( verInfo->dwProductVersionLS >> 0 ) & 0xffff)
24-
);
25-
return true;
18+
VS_FIXEDFILEINFO* verInfo;
19+
UINT len;
20+
if (VerQueryValueW(versionData, L"\\", (void **)&verInfo, &len) && len && verInfo->dwSignature == 0xFEEF04BD)
21+
{
22+
ffStrbufAppendF(version, "%u.%u.%u.%u",
23+
(unsigned)((verInfo->dwProductVersionMS >> 16) & 0xffff),
24+
(unsigned)((verInfo->dwProductVersionMS >> 0) & 0xffff),
25+
(unsigned)((verInfo->dwProductVersionLS >> 16) & 0xffff),
26+
(unsigned)((verInfo->dwProductVersionLS >> 0) & 0xffff));
27+
return true;
28+
}
29+
}
30+
else
31+
{
32+
struct
33+
{
34+
WORD language;
35+
WORD codePage;
36+
}* translations;
37+
38+
UINT translationsLen;
39+
40+
if (VerQueryValueW(versionData, L"\\VarFileInfo\\Translation",
41+
(void **) &translations, &translationsLen) &&
42+
translationsLen >= sizeof(*translations))
43+
{
44+
wchar_t subBlock[128];
45+
snwprintf(subBlock, ARRAY_SIZE(subBlock), L"\\StringFileInfo\\%04x%04x\\%ls",
46+
translations[0].language, translations[0].codePage, stringName);
47+
48+
wchar_t* value;
49+
UINT valueLen;
50+
51+
if (VerQueryValueW(versionData, subBlock, (void **)&value, &valueLen) && valueLen > 0)
52+
{
53+
ffStrbufSetWS(version, value);
54+
return true;
55+
}
56+
}
2657
}
2758
}
2859
}

src/util/windows/version.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
#include "fastfetch.h"
22

3-
bool ffGetFileVersion(const wchar_t* filePath, FFstrbuf* version);
3+
4+
/**
5+
* @brief Retrieves a specific version string for a Windows file.
6+
*
7+
* This function gets a version string from a Windows file's version information.
8+
*
9+
* @param filePath The path to the file for which version information is requested.
10+
* @param stringName The name of the specific version string to retrieve (e.g., "FileVersion", "ProductVersion").
11+
* @param version Pointer to an FFstrbuf where the version string will be stored.
12+
*
13+
* @return true if the version string was successfully retrieved, false otherwise.
14+
*/
15+
bool ffGetFileVersion(const wchar_t* filePath, const wchar_t* stringName, FFstrbuf* version);

0 commit comments

Comments
 (0)