Introduce FFPlatform

This commit is contained in:
Linus Dierheimer
2023-01-15 15:57:26 +01:00
parent dd77ebe11e
commit a1d8e3e598
39 changed files with 622 additions and 560 deletions
-22
View File
@@ -1,22 +0,0 @@
#include "pwd.h"
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <shlobj.h>
struct passwd* ffGetPasswd()
{
static struct passwd res;
DWORD len = sizeof(res.pw_name);
GetUserNameA(res.pw_name, &len);
PWSTR pPath;
if(SUCCEEDED(SHGetKnownFolderPath(&FOLDERID_Profile, KF_FLAG_DEFAULT, NULL, &pPath)))
WideCharToMultiByte(CP_UTF8, 0, pPath, -1, res.pw_dir, sizeof(res.pw_dir), NULL, NULL); //res has been NULL inited
CoTaskMemFree(pPath);
for (char *current_pos = strchr(res.pw_dir, '\\'); current_pos; current_pos = strchr(current_pos + 1, '\\'))
*current_pos = '/';
return &res;
}
-22
View File
@@ -1,22 +0,0 @@
#pragma once
#ifndef FASTFETCH_INCLUDED_UTIL_PWD
#define FASTFETCH_INCLUDED_UTIL_PWD
#include <Lmcons.h>
#include <minwindef.h>
struct passwd
{
char pw_name[UNLEN + 1]; /* username */
// char *pw_passwd[1]; /* user password */
// int pw_uid; /* user ID */
// int pw_gid; /* group ID */
// char *pw_gecos; /* user information */
char pw_dir[MAX_PATH]; /* home directory */
// char *pw_shell; /* shell program */
};
struct passwd* ffGetPasswd();
#endif
+3 -1
View File
@@ -3,16 +3,18 @@
#ifndef FASTFETCH_INCLUDED_UNICODE_H
#define FASTFETCH_INCLUDED_UNICODE_H
#include "fastfetch.h"
#include "util/FFstrbuf.h"
#include <wchar.h>
void ffStrbufSetNWS(FFstrbuf* result, uint32_t length, const wchar_t* source);
static inline void ffStrbufSetWS(FFstrbuf* result, const wchar_t* source)
{
return ffStrbufSetNWS(result, (uint32_t)wcslen(source), source);
}
FFstrbuf ffStrbufCreateNWS(uint32_t length, const wchar_t* source);
static inline FFstrbuf ffStrbufCreateWS(const wchar_t* source)
{
return ffStrbufCreateNWS((uint32_t)wcslen(source), source);
-116
View File
@@ -1,116 +0,0 @@
#include "fastfetch.h"
#include "utsname.h"
#define WIN32_LEAN_AND_MEAN 1
#include <Windows.h>
static int detectSysname(struct utsname *name)
{
strncpy(name->sysname, "Windows_NT", UTSNAME_MAXLENGTH);
return 0;
}
static int detectNodename(struct utsname *name)
{
DWORD bufSize = UTSNAME_MAXLENGTH - 1;
if(!GetComputerNameExA(ComputerNameDnsFullyQualified, name->nodename, &bufSize))
return 1;
name->nodename[bufSize] = '\0';
return 0;
}
static int detectVersion(struct utsname *name)
{
HKEY hKey;
if(RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS)
return 1;
DWORD bufSize;
char currentVersion[32];
{
DWORD currentMajorVersionNumber;
DWORD currentMinorVersionNumber;
bufSize = sizeof(currentMajorVersionNumber);
if(RegGetValueW(hKey, NULL, L"CurrentMajorVersionNumber", RRF_RT_REG_DWORD, NULL, &currentMajorVersionNumber, &bufSize) == ERROR_SUCCESS &&
RegGetValueW(hKey, NULL, L"CurrentMinorVersionNumber", RRF_RT_REG_DWORD, NULL, &currentMinorVersionNumber, &bufSize) == ERROR_SUCCESS
)
snprintf(currentVersion, sizeof(currentVersion), "%u.%u", (unsigned)currentMajorVersionNumber, (unsigned)currentMinorVersionNumber);
else
{
bufSize = sizeof(currentVersion);
if(RegGetValueA(hKey, NULL, "CurrentVersion", RRF_RT_REG_SZ, NULL, currentVersion, &bufSize) != ERROR_SUCCESS)
strcpy(currentVersion, "0.0");
}
}
char currentBuildNumber[32];
bufSize = sizeof(currentBuildNumber);
if(RegGetValueA(hKey, NULL, "CurrentBuildNumber", RRF_RT_REG_SZ, NULL, currentBuildNumber, &bufSize) != ERROR_SUCCESS)
strcpy(currentBuildNumber, "0");
DWORD ubr;
bufSize = sizeof(ubr);
if(RegGetValueA(hKey, NULL, "UBR", RRF_RT_REG_DWORD, NULL, &ubr, &bufSize) != ERROR_SUCCESS || bufSize != sizeof(ubr))
ubr = 0;
snprintf(name->release, sizeof(name->release), "%s.%s.%u", currentVersion, currentBuildNumber, (unsigned)ubr);
bufSize = sizeof(name->version);
RegGetValueA(hKey, NULL, "DisplayVersion", RRF_RT_REG_SZ, NULL, name->version, &bufSize);
RegCloseKey(hKey);
return 0;
}
static int detectMachine(struct utsname *name)
{
// Get hardware info
SYSTEM_INFO sysInfo = {0};
GetNativeSystemInfo(&sysInfo);
// Set processor architecture
switch(sysInfo.wProcessorArchitecture)
{
case PROCESSOR_ARCHITECTURE_AMD64:
strcpy(name->machine, "x86_64");
break;
case PROCESSOR_ARCHITECTURE_IA64:
strcpy(name->machine, "ia64");
break;
case PROCESSOR_ARCHITECTURE_INTEL:
strcpy(name->machine, "x86");
break;
case PROCESSOR_ARCHITECTURE_ARM64:
strcpy(name->machine, "aarch64");
break;
case PROCESSOR_ARCHITECTURE_ARM:
strcpy(name->machine, "arm");
break;
case PROCESSOR_ARCHITECTURE_PPC:
strcpy(name->machine, "ppc");
break;
case PROCESSOR_ARCHITECTURE_MIPS:
strcpy(name->machine, "mips");
break;
case PROCESSOR_ARCHITECTURE_UNKNOWN:
default:
strcpy(name->machine, "unknown");
break;
}
return 0;
}
int uname(struct utsname *name)
{
memset(name, 0, sizeof(*name));
int sysnameResult = detectSysname(name);
int nodenameResult = detectNodename(name);
int versionResult = detectVersion(name);
int machineResult = detectMachine(name);
return sysnameResult || nodenameResult || versionResult || machineResult;
}
-19
View File
@@ -1,19 +0,0 @@
#pragma once
#ifndef FASTFETCH_INCLUDED_UTSNAME_H
#define FASTFETCH_INCLUDED_UTSNAME_H
#define UTSNAME_MAXLENGTH 256
struct utsname
{
char sysname[UTSNAME_MAXLENGTH]; // name of this implementation of the operating system
char nodename[UTSNAME_MAXLENGTH]; // name of this node within an implementation - dependent communications network
char release[UTSNAME_MAXLENGTH]; // current release level of this implementation
char version[UTSNAME_MAXLENGTH]; // current version level of this release
char machine[UTSNAME_MAXLENGTH]; // name of the hardware type on which the system is running
};
int uname(struct utsname *name);
#endif