This commit is contained in:
Igor Pavlov
2021-11-28 19:01:13 -08:00
committed by fn ⌃ ⌥
parent 585698650f
commit d789d4137d
88 changed files with 5996 additions and 1875 deletions

View File

@@ -26,6 +26,14 @@ static INT_PTR APIENTRY DialogProcedure(HWND dialogHWND, UINT message, WPARAM wP
return FALSE;
if (message == WM_INITDIALOG)
dialog->Attach(dialogHWND);
/* MSDN: The dialog box procedure should return
TRUE - if it processed the message
FALSE - if it did not process the message
If the dialog box procedure returns FALSE,
the dialog manager performs the default dialog operation in response to the message.
*/
try { return BoolToBOOL(dialog->OnMessage(message, wParam, lParam)); }
catch(...) { return TRUE; }
}
@@ -39,6 +47,7 @@ bool CDialog::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
case WM_NOTIFY: return OnNotify((UINT)wParam, (LPNMHDR) lParam);
case WM_TIMER: return OnTimer(wParam, lParam);
case WM_SIZE: return OnSize(wParam, LOWORD(lParam), HIWORD(lParam));
case WM_DESTROY: return OnDestroy();
case WM_HELP: OnHelp(); return true;
/*
OnHelp(

View File

@@ -31,6 +31,12 @@ public:
bool SetItemText(int itemID, LPCTSTR s)
{ return BOOLToBool(SetDlgItemText(_window, itemID, s)); }
bool SetItemTextA(int itemID, LPCSTR s)
{ return BOOLToBool(SetDlgItemTextA(_window, itemID, s)); }
bool SetItemText_Empty(int itemID)
{ return SetItemText(itemID, TEXT("")); }
#ifndef _UNICODE
bool SetItemText(int itemID, LPCWSTR s)
{
@@ -51,6 +57,12 @@ public:
*/
#endif
bool GetItemText(int itemID, UString &s)
{
CWindow window(GetItem(itemID));
return window.GetText(s);
}
bool SetItemInt(int itemID, UINT value, bool isSigned)
{ return BOOLToBool(SetDlgItemInt(_window, itemID, value, BoolToBOOL(isSigned))); }
bool GetItemInt(int itemID, bool isSigned, UINT &value)
@@ -65,6 +77,13 @@ public:
HWND GetNextTabItem(HWND control, bool previous)
{ return GetNextDlgTabItem(_window, control, BoolToBOOL(previous)); }
LRESULT SendMsg_NextDlgCtl(WPARAM wParam, LPARAM lParam)
{ return SendMsg(WM_NEXTDLGCTL, wParam, lParam); }
LRESULT SendMsg_NextDlgCtl_HWND(HWND hwnd) { return SendMsg_NextDlgCtl((WPARAM)hwnd, TRUE); }
LRESULT SendMsg_NextDlgCtl_CtlId(int id) { return SendMsg_NextDlgCtl_HWND(GetItem(id)); }
LRESULT SendMsg_NextDlgCtl_Next() { return SendMsg_NextDlgCtl(0, FALSE); }
LRESULT SendMsg_NextDlgCtl_Prev() { return SendMsg_NextDlgCtl(1, FALSE); }
bool MapRect(LPRECT rect)
{ return BOOLToBool(MapDialogRect(_window, rect)); }
@@ -92,6 +111,7 @@ public:
virtual bool OnCommand(WPARAM wParam, LPARAM lParam);
virtual bool OnCommand(int code, int itemID, LPARAM lParam);
virtual bool OnSize(WPARAM /* wParam */, int /* xSize */, int /* ySize */) { return false; }
virtual bool OnDestroy() { return false; }
/*
#ifdef UNDER_CE

View File

@@ -19,6 +19,14 @@ namespace NError {
static bool MyFormatMessage(DWORD errorCode, UString &message)
{
#ifndef _SFX
if ((HRESULT)errorCode == MY_HRES_ERROR__INTERNAL_ERROR)
{
message = "Internal Error: The failure in hardware (RAM or CPU), OS or program";
return true;
}
#endif
#ifdef _WIN32
LPVOID msgBuf;

View File

@@ -3,6 +3,7 @@
#include "StdAfx.h"
#include <wchar.h>
// #include <stdio.h>
#ifndef _UNICODE
#include "../Common/StringConvert.h"
@@ -17,12 +18,27 @@ namespace NWindows {
namespace NRegistry {
#define MYASSERT(expr) // _ASSERTE(expr)
#define MY_ASSUME(expr)
/*
static void Error()
{
#ifdef _CONSOLE
printf("\nregistry error\n");
#else
MessageBoxW(0, L"registry error", L"", 0);
// exit(1);
#endif
}
#define MY_ASSUME(expr) { if (!(expr)) Error(); }
*/
LONG CKey::Create(HKEY parentKey, LPCTSTR keyName,
LPTSTR keyClass, DWORD options, REGSAM accessMask,
LPSECURITY_ATTRIBUTES securityAttributes, LPDWORD disposition) throw()
{
MYASSERT(parentKey != NULL);
MY_ASSUME(parentKey != NULL);
DWORD dispositionReal;
HKEY key = NULL;
LONG res = RegCreateKeyEx(parentKey, keyName, 0, keyClass,
@@ -39,7 +55,7 @@ LONG CKey::Create(HKEY parentKey, LPCTSTR keyName,
LONG CKey::Open(HKEY parentKey, LPCTSTR keyName, REGSAM accessMask) throw()
{
MYASSERT(parentKey != NULL);
MY_ASSUME(parentKey != NULL);
HKEY key = NULL;
LONG res = RegOpenKeyEx(parentKey, keyName, 0, accessMask, &key);
if (res == ERROR_SUCCESS)
@@ -66,7 +82,7 @@ LONG CKey::Close() throw()
// winNT to be deleted must not have subkeys
LONG CKey::DeleteSubKey(LPCTSTR subKeyName) throw()
{
MYASSERT(_object != NULL);
MY_ASSUME(_object != NULL);
return RegDeleteKey(_object, subKeyName);
}
@@ -101,14 +117,14 @@ static inline bool UINT32ToBool(UInt32 value) { return (value != 0); }
LONG CKey::DeleteValue(LPCTSTR name) throw()
{
MYASSERT(_object != NULL);
MY_ASSUME(_object != NULL);
return ::RegDeleteValue(_object, name);
}
#ifndef _UNICODE
LONG CKey::DeleteValue(LPCWSTR name)
{
MYASSERT(_object != NULL);
MY_ASSUME(_object != NULL);
if (g_IsNT)
return ::RegDeleteValueW(_object, name);
return DeleteValue(name == 0 ? 0 : (LPCSTR)GetSystemString(name));
@@ -117,7 +133,7 @@ LONG CKey::DeleteValue(LPCWSTR name)
LONG CKey::SetValue(LPCTSTR name, UInt32 value) throw()
{
MYASSERT(_object != NULL);
MY_ASSUME(_object != NULL);
return RegSetValueEx(_object, name, 0, REG_DWORD,
(const BYTE *)&value, sizeof(UInt32));
}
@@ -130,7 +146,7 @@ LONG CKey::SetValue(LPCTSTR name, bool value) throw()
LONG CKey::SetValue(LPCTSTR name, LPCTSTR value) throw()
{
MYASSERT(value != NULL);
MYASSERT(_object != NULL);
MY_ASSUME(_object != NULL);
return RegSetValueEx(_object, name, 0, REG_SZ,
(const BYTE *)value, ((DWORD)lstrlen(value) + 1) * sizeof(TCHAR));
}
@@ -139,7 +155,7 @@ LONG CKey::SetValue(LPCTSTR name, LPCTSTR value) throw()
LONG CKey::SetValue(LPCTSTR name, const CSysString &value)
{
MYASSERT(value != NULL);
MYASSERT(_object != NULL);
MY_ASSUME(_object != NULL);
return RegSetValueEx(_object, name, NULL, REG_SZ,
(const BYTE *)(const TCHAR *)value, (value.Len() + 1) * sizeof(TCHAR));
}
@@ -150,7 +166,7 @@ LONG CKey::SetValue(LPCTSTR name, const CSysString &value)
LONG CKey::SetValue(LPCWSTR name, LPCWSTR value)
{
MYASSERT(value != NULL);
MYASSERT(_object != NULL);
MY_ASSUME(_object != NULL);
if (g_IsNT)
return RegSetValueExW(_object, name, 0, REG_SZ,
(const BYTE * )value, (DWORD)((wcslen(value) + 1) * sizeof(wchar_t)));
@@ -164,7 +180,7 @@ LONG CKey::SetValue(LPCWSTR name, LPCWSTR value)
LONG CKey::SetValue(LPCTSTR name, const void *value, UInt32 size) throw()
{
MYASSERT(value != NULL);
MYASSERT(_object != NULL);
MY_ASSUME(_object != NULL);
return RegSetValueEx(_object, name, 0, REG_BINARY,
(const BYTE *)value, size);
}

View File

@@ -153,6 +153,10 @@ public:
{
return Semaphore_Create(&_object, initCount, maxCount);
}
WRes OptCreateInit(UInt32 initCount, UInt32 maxCount)
{
return Semaphore_OptCreateInit(&_object, initCount, maxCount);
}
WRes Release() { return Semaphore_Release1(&_object); }
WRes Release(UInt32 releaseCount) { return Semaphore_ReleaseN(&_object, releaseCount); }
WRes Lock() { return Semaphore_Wait(&_object); }

View File

@@ -12,12 +12,12 @@
#else
#include <unistd.h>
#include <sys/utsname.h>
#ifdef __APPLE__
#include <sys/sysctl.h>
#elif !defined(_AIX)
#include <sys/auxv.h>
#ifdef MY_CPU_ARM_OR_ARM64
@@ -25,13 +25,56 @@
#endif
#endif
#ifdef __linux__
#include "../Windows/FileIO.h"
#endif
#endif // WIN32
#include "SystemInfo.h"
#include "System.h"
using namespace NWindows;
#ifdef __linux__
static bool ReadFile_to_Buffer(CFSTR fileName, CByteBuffer &buf)
{
NWindows::NFile::NIO::CInFile file;
if (!file.Open(fileName))
return false;
/*
UInt64 size;
if (!file.GetLength(size))
{
// GetLength() doesn't work "/proc/cpuinfo"
return false;
}
if (size >= ((UInt32)1 << 29))
return false;
*/
size_t size = 0;
size_t addSize = ((size_t)1 << 12);
for (;;)
{
// printf("\nsize = %d\n", (unsigned)size);
buf.ChangeSize_KeepData(size + addSize, size);
size_t processed;
if (!file.ReadFull(buf + size, addSize, processed))
return false;
if (processed == 0)
{
buf.ChangeSize_KeepData(size, size);
return true;
}
size += processed;
addSize *= 2;
}
}
#endif
#ifndef __APPLE__
static void PrintHex(AString &s, UInt64 v)
{
@@ -56,7 +99,7 @@ static void PrintCpuChars(AString &s, UInt32 v)
}
static void x86cpuid_to_String(const Cx86cpuid &c, AString &s)
static void x86cpuid_to_String(const Cx86cpuid &c, AString &s, AString &ver)
{
s.Empty();
@@ -87,13 +130,10 @@ static void x86cpuid_to_String(const Cx86cpuid &c, AString &s)
s.Trim();
}
s.Add_Space_if_NotEmpty();
{
char temp[32];
ConvertUInt32ToHex(c.ver, temp);
s += '(';
s += temp;
s += ')';
ver += temp;
}
}
@@ -402,18 +442,52 @@ void GetSysInfo(AString &s1, AString &s2)
void GetCpuName(AString &s);
void GetCpuName(AString &s)
static void AddBracedString(AString &dest, AString &src)
{
s.Empty();
if (!src.IsEmpty())
{
AString s;
s += '(';
s += src;
s += ')';
dest.Add_OptSpaced(s);
}
}
struct CCpuName
{
AString CpuName;
AString Revision;
AString Microcode;
AString LargePages;
void Fill();
void Get_Revision_Microcode_LargePages(AString &s)
{
s.Empty();
AddBracedString(s, Revision);
AddBracedString(s, Microcode);
s.Add_OptSpaced(LargePages);
}
};
void CCpuName::Fill()
{
CpuName.Empty();
Revision.Empty();
Microcode.Empty();
LargePages.Empty();
AString &s = CpuName;
#ifdef MY_CPU_X86_OR_AMD64
{
Cx86cpuid cpuid;
if (x86cpuid_CheckAndRead(&cpuid))
{
AString s2;
x86cpuid_to_String(cpuid, s2);
s += s2;
x86cpuid_to_String(cpuid, s, Revision);
}
else
{
@@ -484,11 +558,10 @@ void GetCpuName(AString &s)
}
if (res[0] == ERROR_SUCCESS || res[1] == ERROR_SUCCESS)
{
s.Add_OptSpaced("(");
for (int i = 0; i < 2; i++)
{
if (i == 1)
s += "->";
Microcode += "->";
if (res[i] != ERROR_SUCCESS)
continue;
const CByteBuffer &buf = bufs[i];
@@ -497,13 +570,12 @@ void GetCpuName(AString &s)
UInt32 high = GetUi32(buf);
if (high != 0)
{
PrintHex(s, high);
s += ".";
PrintHex(Microcode, high);
Microcode += ".";
}
PrintHex(s, GetUi32(buf + 4));
PrintHex(Microcode, GetUi32(buf + 4));
}
}
s += ")";
}
}
}
@@ -511,7 +583,7 @@ void GetCpuName(AString &s)
#ifdef _7ZIP_LARGE_PAGES
Add_LargePages_String(s);
Add_LargePages_String(LargePages);
#endif
}
@@ -532,13 +604,10 @@ void AddCpuFeatures(AString &s)
// s += TypeToString2(k_PF, ARRAY_SIZE(k_PF), i);
}
}
s.Add_Space_if_NotEmpty();
s += "f:";
s.Add_OptSpaced("f:");
PrintHex(s, flags);
#else // _WIN32
#ifdef __APPLE__
#elif defined(__APPLE__)
{
UInt32 v = 0;
if (My_sysctlbyname_Get_UInt32("hw.pagesize", &v) == 0)
@@ -549,10 +618,46 @@ void AddCpuFeatures(AString &s)
}
}
#elif !defined(_AIX)
#else
s.Add_Space_if_NotEmpty();
s += "hwcap:";
const long v = sysconf(_SC_PAGESIZE);
if (v != -1)
{
s.Add_Space_if_NotEmpty();
s += "PageSize:";
s.Add_UInt32((UInt32)(v >> 10));
s += "KB";
}
#if !defined(_AIX)
#ifdef __linux__
CByteBuffer buf;
if (ReadFile_to_Buffer("/sys/kernel/mm/transparent_hugepage/enabled", buf))
// if (ReadFile_to_Buffer("/proc/cpuinfo", buf))
{
s.Add_OptSpaced("THP:");
AString s2;
s2.SetFrom_CalcLen((const char *)(const void *)(const Byte *)buf, (unsigned)buf.Size());
const int pos = s2.Find('[');
if (pos >= 0)
{
const int pos2 = s2.Find(']', pos + 1);
if (pos2 >= 0)
{
s2.DeleteFrom(pos2);
s2.DeleteFrontal(pos + 1);
}
}
s += s2;
}
// else throw CSystemException(MY_SRes_HRESULT_FROM_WRes(errno));
#endif
s.Add_OptSpaced("hwcap:");
{
unsigned long h = getauxval(AT_HWCAP);
PrintHex(s, h);
@@ -561,6 +666,9 @@ void AddCpuFeatures(AString &s)
if (h & HWCAP_SHA1) s += ":SHA1";
if (h & HWCAP_SHA2) s += ":SHA2";
if (h & HWCAP_AES) s += ":AES";
if (h & HWCAP_ASIMD) s += ":ASIMD";
#elif defined(MY_CPU_ARM)
if (h & HWCAP_NEON) s += ":NEON";
#endif
}
@@ -580,9 +688,8 @@ void AddCpuFeatures(AString &s)
#endif
}
}
#endif
#endif // _WIN32
#endif // _AIX
#endif // _WIN32
}
@@ -609,11 +716,11 @@ static BOOL My_RtlGetVersion(OSVERSIONINFOEXW *vi)
#endif
void GetSystemInfoText(AString &sRes)
void GetOsInfoText(AString &sRes)
{
{
{
AString s;
sRes.Empty();
AString s;
#ifdef _WIN32
#ifndef UNDER_CE
// OSVERSIONINFO vi;
@@ -634,16 +741,16 @@ void GetSystemInfoText(AString &sRes)
s += " SP:"; s.Add_UInt32(vi.wServicePackMajor);
s += "."; s.Add_UInt32(vi.wServicePackMinor);
}
s += " Suite:"; PrintHex(s, vi.wSuiteMask);
s += " Type:"; s.Add_UInt32(vi.wProductType);
// s += " Suite:"; PrintHex(s, vi.wSuiteMask);
// s += " Type:"; s.Add_UInt32(vi.wProductType);
// s += " "; s += GetOemString(vi.szCSDVersion);
}
/*
{
s += " OEMCP:";
s.Add_UInt32(GetOEMCP());
s += " ACP:";
s.Add_UInt32(GetACP());
s += " OEMCP:"; s.Add_UInt32(GetOEMCP());
s += " ACP:"; s.Add_UInt32(GetACP());
}
*/
#endif
#else // _WIN32
@@ -666,8 +773,14 @@ void GetSystemInfoText(AString &sRes)
#endif // _WIN32
sRes += s;
sRes.Add_LF();
}
}
void GetSystemInfoText(AString &sRes)
{
GetOsInfoText(sRes);
sRes.Add_LF();
{
AString s, s1, s2;
@@ -712,5 +825,73 @@ void GetSystemInfoText(AString &sRes)
}
#endif
*/
}
void GetCpuName(AString &s);
void GetCpuName(AString &s)
{
CCpuName cpuName;
cpuName.Fill();
s = cpuName.CpuName;
AString s2;
cpuName.Get_Revision_Microcode_LargePages(s2);
s.Add_OptSpaced(s2);
}
void GetCpuName_MultiLine(AString &s);
void GetCpuName_MultiLine(AString &s)
{
CCpuName cpuName;
cpuName.Fill();
s = cpuName.CpuName;
AString s2;
cpuName.Get_Revision_Microcode_LargePages(s2);
if (!s2.IsEmpty())
{
s.Add_LF();
s += s2;
}
}
void GetCompiler(AString &s)
{
#ifdef __VERSION__
s += __VERSION__;
#endif
#ifdef __GNUC__
s += " GCC ";
s.Add_UInt32(__GNUC__);
s += '.';
s.Add_UInt32(__GNUC_MINOR__);
s += '.';
s.Add_UInt32(__GNUC_PATCHLEVEL__);
#endif
#ifdef __clang__
s += " CLANG ";
s.Add_UInt32(__clang_major__);
s += '.';
s.Add_UInt32(__clang_minor__);
#endif
#ifdef __xlC__
s += " XLC ";
s.Add_UInt32(__xlC__ >> 8);
s += '.';
s.Add_UInt32(__xlC__ & 0xFF);
#ifdef __xlC_ver__
s += '.';
s.Add_UInt32(__xlC_ver__ >> 8);
s += '.';
s.Add_UInt32(__xlC_ver__ & 0xFF);
#endif
#endif
#ifdef _MSC_VER
s += " MSC ";
s.Add_UInt32(_MSC_VER);
#endif
}

View File

@@ -5,8 +5,14 @@
#include "../Common/MyString.h"
void GetCpuName_MultiLine(AString &s);
void GetOsInfoText(AString &sRes);
void GetSystemInfoText(AString &s);
void PrintSize_KMGT_Or_Hex(AString &s, UInt64 v);
void Add_LargePages_String(AString &s);
void GetCompiler(AString &s);
#endif