mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 09:33:39 +01:00
Terminal (Windows): detect warp version
This commit is contained in:
+45
-14
@@ -1,28 +1,59 @@
|
||||
#include "util/windows/version.h"
|
||||
#include "util/mallocHelper.h"
|
||||
#include "util/windows/unicode.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
bool ffGetFileVersion(const wchar_t* filePath, FFstrbuf* version)
|
||||
bool ffGetFileVersion(const wchar_t* filePath, const wchar_t* stringName, FFstrbuf* version)
|
||||
{
|
||||
DWORD handle;
|
||||
DWORD size = GetFileVersionInfoSizeW(filePath, &handle);
|
||||
if(size > 0)
|
||||
if (size > 0)
|
||||
{
|
||||
FF_AUTO_FREE void* versionData = malloc(size);
|
||||
if(GetFileVersionInfoW(filePath, handle, size, versionData))
|
||||
FF_AUTO_FREE void *versionData = malloc(size);
|
||||
if (GetFileVersionInfoW(filePath, handle, size, versionData))
|
||||
{
|
||||
VS_FIXEDFILEINFO* verInfo;
|
||||
UINT len;
|
||||
if(VerQueryValueW(versionData, L"\\", (void**)&verInfo, &len) && len && verInfo->dwSignature == 0xFEEF04BD)
|
||||
if (!stringName)
|
||||
{
|
||||
ffStrbufAppendF(version, "%u.%u.%u.%u",
|
||||
(unsigned)(( verInfo->dwProductVersionMS >> 16 ) & 0xffff),
|
||||
(unsigned)(( verInfo->dwProductVersionMS >> 0 ) & 0xffff),
|
||||
(unsigned)(( verInfo->dwProductVersionLS >> 16 ) & 0xffff),
|
||||
(unsigned)(( verInfo->dwProductVersionLS >> 0 ) & 0xffff)
|
||||
);
|
||||
return true;
|
||||
VS_FIXEDFILEINFO* verInfo;
|
||||
UINT len;
|
||||
if (VerQueryValueW(versionData, L"\\", (void **)&verInfo, &len) && len && verInfo->dwSignature == 0xFEEF04BD)
|
||||
{
|
||||
ffStrbufAppendF(version, "%u.%u.%u.%u",
|
||||
(unsigned)((verInfo->dwProductVersionMS >> 16) & 0xffff),
|
||||
(unsigned)((verInfo->dwProductVersionMS >> 0) & 0xffff),
|
||||
(unsigned)((verInfo->dwProductVersionLS >> 16) & 0xffff),
|
||||
(unsigned)((verInfo->dwProductVersionLS >> 0) & 0xffff));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
struct
|
||||
{
|
||||
WORD language;
|
||||
WORD codePage;
|
||||
}* translations;
|
||||
|
||||
UINT translationsLen;
|
||||
|
||||
if (VerQueryValueW(versionData, L"\\VarFileInfo\\Translation",
|
||||
(void **) &translations, &translationsLen) &&
|
||||
translationsLen >= sizeof(*translations))
|
||||
{
|
||||
wchar_t subBlock[128];
|
||||
snwprintf(subBlock, ARRAY_SIZE(subBlock), L"\\StringFileInfo\\%04x%04x\\%ls",
|
||||
translations[0].language, translations[0].codePage, stringName);
|
||||
|
||||
wchar_t* value;
|
||||
UINT valueLen;
|
||||
|
||||
if (VerQueryValueW(versionData, subBlock, (void **)&value, &valueLen) && valueLen > 0)
|
||||
{
|
||||
ffStrbufSetWS(version, value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
bool ffGetFileVersion(const wchar_t* filePath, FFstrbuf* version);
|
||||
|
||||
/**
|
||||
* @brief Retrieves a specific version string for a Windows file.
|
||||
*
|
||||
* This function gets a version string from a Windows file's version information.
|
||||
*
|
||||
* @param filePath The path to the file for which version information is requested.
|
||||
* @param stringName The name of the specific version string to retrieve (e.g., "FileVersion", "ProductVersion").
|
||||
* @param version Pointer to an FFstrbuf where the version string will be stored.
|
||||
*
|
||||
* @return true if the version string was successfully retrieved, false otherwise.
|
||||
*/
|
||||
bool ffGetFileVersion(const wchar_t* filePath, const wchar_t* stringName, FFstrbuf* version);
|
||||
|
||||
Reference in New Issue
Block a user