mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-31 18:13:38 +01:00
util: add a helper function to convert wide strings (Windows)
This commit is contained in:
@@ -449,6 +449,7 @@ elseif(WIN32)
|
||||
src/util/windows/getline.c
|
||||
src/util/windows/pwd.c
|
||||
src/util/windows/register.c
|
||||
src/util/windows/unicode.c
|
||||
src/util/windows/utsname.c
|
||||
src/util/windows/wmi.cpp
|
||||
)
|
||||
@@ -546,6 +547,7 @@ elseif(WIN32)
|
||||
PRIVATE "ws2_32"
|
||||
PRIVATE "ntdll"
|
||||
PRIVATE "version"
|
||||
PRIVATE "setupapi"
|
||||
)
|
||||
if(USE_WIN_NTAPI)
|
||||
target_compile_definitions(libfastfetch PRIVATE FF_USE_WIN_NTAPI)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
extern "C" {
|
||||
#include "os.h"
|
||||
#include "util/windows/unicode.h"
|
||||
}
|
||||
#include "util/windows/wmi.hpp"
|
||||
|
||||
@@ -36,11 +37,7 @@ static const char* getOsNameByWinbrand(FFstrbuf* osName)
|
||||
return "GetProcAddress(BrandingFormatString) failed";
|
||||
|
||||
const wchar_t* rawName = BrandingFormatString(L"%WINDOWS_LONG%");
|
||||
int size_needed = WideCharToMultiByte(CP_UTF8, 0, rawName, -1, nullptr, 0, nullptr, nullptr);
|
||||
ffStrbufEnsureFree(osName, (uint32_t)size_needed);
|
||||
WideCharToMultiByte(CP_UTF8, 0, rawName, -1, osName->chars, size_needed, nullptr, nullptr);
|
||||
osName->length = (uint32_t)size_needed;
|
||||
osName->chars[size_needed] = '\0';
|
||||
ffWcharToUtf8(rawName, osName);
|
||||
GlobalFree((HGLOBAL)rawName);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#include "unicode.h"
|
||||
|
||||
void ffWcharToUtf8(const wchar_t* input, FFstrbuf* result)
|
||||
{
|
||||
int len = (int)wcslen(input);
|
||||
if(len <= 0)
|
||||
{
|
||||
ffStrbufClear(result);
|
||||
return;
|
||||
}
|
||||
|
||||
int size_needed = WideCharToMultiByte(CP_UTF8, 0, input, len, NULL, 0, NULL, NULL);
|
||||
ffStrbufEnsureFree(result, (uint32_t)size_needed);
|
||||
WideCharToMultiByte(CP_UTF8, 0, input, len, result->chars, size_needed, NULL, NULL);
|
||||
result->length = (uint32_t)size_needed;
|
||||
result->chars[size_needed] = '\0';
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef FASTFETCH_INCLUDED_UNICODE_H
|
||||
#define FASTFETCH_INCLUDED_UNICODE_H
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
void ffWcharToUtf8(const wchar_t* input, FFstrbuf* result);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user