summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2024-03-09 23:02:17 +0100
committerAki <please@ignore.pl>2024-03-09 23:02:17 +0100
commite1606f9bbc45e7ba57c461dc1ca4d4a86c5d76dd (patch)
treed13c968b28d8f9a076b7fed0d6f098fc448ce87c
parenteced12a69603e23d6869f92a2d5302f4605354ba (diff)
downloadstarshatter-e1606f9bbc45e7ba57c461dc1ca4d4a86c5d76dd.zip
starshatter-e1606f9bbc45e7ba57c461dc1ca4d4a86c5d76dd.tar.gz
starshatter-e1606f9bbc45e7ba57c461dc1ca4d4a86c5d76dd.tar.bz2
Replaced MachineInfo with stripped cross-platform solution
It could easily handle more, but is there really need for it? Having some information about the machine in logs is nice, but with the current state of affairs most of errors are coming from bad pointer uses than anything else... InfoEx is STATIC, because it seems FoundationEx can cause multiple definitions in scenarios like this.
-rw-r--r--CMakeLists.txt1
-rw-r--r--InfoEx/CMakeLists.txt13
-rw-r--r--InfoEx/include/InfoEx.h27
-rw-r--r--InfoEx/src/description.cpp53
-rw-r--r--InfoEx/src/directx_other.cpp22
-rw-r--r--InfoEx/src/directx_win32.cpp28
-rw-r--r--InfoEx/test/description.cpp17
-rw-r--r--InfoEx/test/directx.cpp11
-rw-r--r--StarsEx/CMakeLists.txt2
-rw-r--r--StarsEx/GameWinDX9.cpp5
-rw-r--r--StarsEx/Joystick.cpp8
-rw-r--r--StarsEx/MachineInfo.cpp823
-rw-r--r--StarsEx/MachineInfo.h41
-rw-r--r--StarsEx/NetLobbyServer.cpp6
-rw-r--r--Starserver/CMakeLists.txt2
-rw-r--r--Starserver/Main.cpp16
-rw-r--r--Starserver/NetAdminServer.cpp1
-rw-r--r--Starshatter/CMakeLists.txt2
-rw-r--r--Starshatter/Main.cpp21
-rw-r--r--contrib/CMakeLists.txt3
-rw-r--r--contrib/infoware/1.current.patch30
-rw-r--r--contrib/infoware/CMakeLists.txt6
22 files changed, 243 insertions, 895 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8b29d20..4b3575c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -23,6 +23,7 @@ add_subdirectory(contrib)
add_subdirectory(data)
add_subdirectory(DefinitionEx)
add_subdirectory(FoundationEx)
+add_subdirectory(InfoEx)
if(MSVC)
add_subdirectory(Magic2)
endif()
diff --git a/InfoEx/CMakeLists.txt b/InfoEx/CMakeLists.txt
new file mode 100644
index 0000000..dab78ff
--- /dev/null
+++ b/InfoEx/CMakeLists.txt
@@ -0,0 +1,13 @@
+project(InfoEx)
+add_library(${PROJECT_NAME} STATIC src/description.cpp)
+target_include_directories(${PROJECT_NAME} PUBLIC include/)
+if(WIN32)
+ target_sources(${PROJECT_NAME} PRIVATE src/directx_win32.cpp)
+else()
+ target_sources(${PROJECT_NAME} PRIVATE src/directx_other.cpp)
+endif()
+target_link_libraries(${PROJECT_NAME} PUBLIC FoundationEx PRIVATE iware::infoware)
+add_executable(${PROJECT_NAME}_test test/description.cpp test/directx.cpp)
+generate_emulator(${PROJECT_NAME}_test)
+target_link_libraries(${PROJECT_NAME}_test PRIVATE ${PROJECT_NAME} GTest::gtest_main)
+gtest_discover_tests(${PROJECT_NAME}_test DISCOVERY_TIMEOUT 60)
diff --git a/InfoEx/include/InfoEx.h b/InfoEx/include/InfoEx.h
new file mode 100644
index 0000000..7ea7bf8
--- /dev/null
+++ b/InfoEx/include/InfoEx.h
@@ -0,0 +1,27 @@
+#pragma once
+
+#include <Text.h>
+
+
+namespace InfoEx
+{
+
+
+Text ShortDescription();
+Text LongDescription();
+
+
+enum struct DXVersion : int
+{
+ None,
+ Dx7 = 7,
+ Dx8,
+ Dx9,
+ Future,
+};
+
+
+DXVersion DirectX();
+
+
+} // namespace InfoEx
diff --git a/InfoEx/src/description.cpp b/InfoEx/src/description.cpp
new file mode 100644
index 0000000..5635de5
--- /dev/null
+++ b/InfoEx/src/description.cpp
@@ -0,0 +1,53 @@
+#include <InfoEx.h>
+
+#include <infoware/infoware.hpp>
+
+#include <Text.h>
+
+
+namespace
+{
+
+
+static constexpr const char* prefixes[] {"", "k", "M", "G", "T", "P", "E", "Z", "Y", "R", "Q"};
+
+
+Text
+HumanReadable(long double value, const char* unit)
+{
+ int magnitude = 0;
+ while (value > 1000) {
+ value /= 1000;
+ magnitude++;
+ }
+ return Text::format("%.2Lf %s%s", value, prefixes[magnitude], unit);
+}
+
+
+} // namespace
+
+
+namespace InfoEx
+{
+
+
+Text
+ShortDescription()
+{
+ return iware::system::OS_info().full_name.data();
+}
+
+
+Text
+LongDescription()
+{
+ return Text::format(
+ "OS: %s\nPhysical memory: %s\nCPU: %s\nCPU frequency: %s",
+ iware::system::OS_info().full_name.data(),
+ HumanReadable(iware::system::memory().physical_total, "B").data(),
+ iware::cpu::model_name().data(),
+ HumanReadable(iware::cpu::frequency(), "Hz").data());
+}
+
+
+} // namespace InfoEx
diff --git a/InfoEx/src/directx_other.cpp b/InfoEx/src/directx_other.cpp
new file mode 100644
index 0000000..75d1d39
--- /dev/null
+++ b/InfoEx/src/directx_other.cpp
@@ -0,0 +1,22 @@
+#ifndef _WIN32
+
+#include <InfoEx.h>
+
+#include <Text.h>
+
+
+namespace InfoEx
+{
+
+
+DXVersion
+DirectX()
+{
+ return DXVersion::None;
+}
+
+
+} // namespace InfoEx
+
+
+#endif // _WIN32
diff --git a/InfoEx/src/directx_win32.cpp b/InfoEx/src/directx_win32.cpp
new file mode 100644
index 0000000..4ade30b
--- /dev/null
+++ b/InfoEx/src/directx_win32.cpp
@@ -0,0 +1,28 @@
+#ifdef _WIN32
+
+#include <InfoEx.h>
+
+#include <windows.h>
+
+#include <Text.h>
+
+
+namespace InfoEx
+{
+
+
+DXVersion
+DirectX()
+{
+ auto lib = LoadLibrary("D3D9.DLL");
+ if (lib == nullptr)
+ return DXVersion::None;
+ FreeLibrary(lib);
+ return DXVersion::Dx9;
+}
+
+
+} // namespace InfoEx
+
+
+#endif // _WIN32
diff --git a/InfoEx/test/description.cpp b/InfoEx/test/description.cpp
new file mode 100644
index 0000000..e9f5120
--- /dev/null
+++ b/InfoEx/test/description.cpp
@@ -0,0 +1,17 @@
+#include <gtest/gtest.h>
+
+#include <iostream>
+
+#include <InfoEx.h>
+
+
+TEST(InfoEx, ShortDescription)
+{
+ std::cout << InfoEx::ShortDescription() << std::endl;
+}
+
+
+TEST(InfoEx, LongDescription)
+{
+ std::cout << InfoEx::LongDescription() << std::endl;
+}
diff --git a/InfoEx/test/directx.cpp b/InfoEx/test/directx.cpp
new file mode 100644
index 0000000..1e3444c
--- /dev/null
+++ b/InfoEx/test/directx.cpp
@@ -0,0 +1,11 @@
+#include <gtest/gtest.h>
+
+#include <iostream>
+
+#include <InfoEx.h>
+
+
+TEST(InfoEx, DirectX)
+{
+ std::cout << static_cast<int>(InfoEx::DirectX()) << std::endl;
+}
diff --git a/StarsEx/CMakeLists.txt b/StarsEx/CMakeLists.txt
index 1bacde7..99ccabe 100644
--- a/StarsEx/CMakeLists.txt
+++ b/StarsEx/CMakeLists.txt
@@ -123,7 +123,6 @@ add_library(
LoadScreen.cpp
Locale_ss.cpp
MCIWave.cpp
- MachineInfo.cpp
MapView.cpp
Menu.cpp
MenuDlg.cpp
@@ -284,6 +283,7 @@ target_link_libraries(
PUBLIC Png::png
PUBLIC Opcode
PRIVATE Sha1
+ PRIVATE InfoEx
)
target_compile_definitions(
StarsEx
diff --git a/StarsEx/GameWinDX9.cpp b/StarsEx/GameWinDX9.cpp
index bbf61c3..9f5595d 100644
--- a/StarsEx/GameWinDX9.cpp
+++ b/StarsEx/GameWinDX9.cpp
@@ -9,12 +9,13 @@
#include <stdio.h>
#include <string.h>
+#include <InfoEx.h>
+
#include "Bitmap.h"
#include "Clock.h"
#include "Color.h"
#include "DataLoader.h"
#include "Game.h"
-#include "MachineInfo.h"
#include "Panic.h"
#include "Screen.h"
#include "Types.h"
@@ -88,7 +89,7 @@ GameWinDX9::Init(HINSTANCE hi, HINSTANCE hpi, LPSTR cmdline, int nCmdShow)
status = INIT_FAILED;
}
- if (status == OK && MachineInfo::GetDirectXVersion() < MachineInfo::DX_9) {
+ if (status == OK && InfoEx::DirectX() < InfoEx::DXVersion::Dx9) {
Panic::Panic(" Insufficient DirectX detected (Dx9 IS REQUIRED)");
status = INIT_FAILED;
}
diff --git a/StarsEx/Joystick.cpp b/StarsEx/Joystick.cpp
index 8679c10..b4166a1 100644
--- a/StarsEx/Joystick.cpp
+++ b/StarsEx/Joystick.cpp
@@ -11,9 +11,11 @@
Joystick Input class
*/
-#include "GameWinDX9.h"
#include "Joystick.h"
-#include "MachineInfo.h"
+
+#include <InfoEx.h>
+
+#include "GameWinDX9.h"
#include "Types.h"
#define DIRECTINPUT_VERSION 0x0800
@@ -79,7 +81,7 @@ Joystick::Joystick()
inv_axis[2] = false;
inv_axis[3] = false;
- if (MachineInfo::GetDirectXVersion() < MachineInfo::DX_7) {
+ if (InfoEx::DirectX() < InfoEx::DXVersion::Dx7) {
Print("Joystick: DI7 not found, using multimedia library\n");
pdi = 0;
pdev = 0;
diff --git a/StarsEx/MachineInfo.cpp b/StarsEx/MachineInfo.cpp
deleted file mode 100644
index 64552ba..0000000
--- a/StarsEx/MachineInfo.cpp
+++ /dev/null
@@ -1,823 +0,0 @@
-/* Starshatter: The Open Source Project
- Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors
- Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
- Copyright (c) 1997-2006, Destroyer Studios LLC.
-
- AUTHOR: John DiCamillo
-
-
- OVERVIEW
- ========
- Collect and Display Machine, OS, and Driver Information
-*/
-
-#include <chrono>
-
-#include "MachineInfo.h"
-#include "Utils.h"
-
-#define DIRECTINPUT_VERSION 0x0700
-
-#include <stdio.h>
-#include <ddraw.h>
-#include <d3d9.h>
-#include <dinput.h>
-#include <winver.h>
-
-// +--------------------------------------------------------------------+
-
-static int cpu_class=-1;
-static int cpu_speed=-1;
-static int platform=-1;
-static int dx_version=-1;
-static int total_ram=-1;
-
-static OSVERSIONINFO os_ver = { sizeof(OSVERSIONINFO) };
-static SYSTEM_INFO cpu_info;
-static MEMORYSTATUS mem_info = { sizeof(MEMORYSTATUS) };
-
-// +--------------------------------------------------------------------+
-
-const char*
-MachineInfo::GetShortDescription()
-{
- static char desc[256];
-
- static const char* cpu_names[] = {
- "8088",
- "8086",
- "80286",
- "80386",
- "80486",
- "Pentium",
- "Pentium II",
- "Pentium 3",
- "Pentium 4"
- };
-
- static const char* os_names[] = {
- "DOS",
- "Windows 95",
- "Windows 98",
- "Windows NT",
- "Windows 2000",
- "Windows XP",
- "Windows XP x64",
- "Windows Vista",
- "Windows Seven",
- "Future Windows"
- };
-
- int cpu_index = GetCpuClass();
- if (cpu_index < 0) cpu_index = 0;
- else if (cpu_index > 8) cpu_index = 8;
-
- int os_index = GetPlatform();
- if (os_index < 0) os_index = 0;
-
- sprintf_s(desc, "%s %d MHz %d MB RAM %s",
- cpu_names[cpu_index],
- GetCpuSpeed(),
- GetTotalRam(),
- os_names[os_index]);
-
- return desc;
-}
-
-// +--------------------------------------------------------------------+
-
-static void DescribeCpuMake();
-static void DescribeOwner95();
-static void DescribeOwnerNT();
-static void DescribeDrivers95(const char* sType);
-static void DescribeDriversNT(const char* sType);
-static void DescribeDriverVersion(const char* file);
-static void DescribeDXVersion(const char* component);
-
-// wait for at least target_time,
-// return the exact amount of time actually waited:
-
-static double SpinWait(double target_time)
-{
- double actual_time = 0;
-
- LARGE_INTEGER ifreq;
- LARGE_INTEGER cnt1;
- LARGE_INTEGER cnt2;
-
- QueryPerformanceFrequency(&ifreq);
- double freq = (double) ifreq.QuadPart;
-
- QueryPerformanceCounter(&cnt1);
-
- do {
- QueryPerformanceCounter(&cnt2);
-
- double delta = (double) (cnt2.QuadPart - cnt1.QuadPart);
- actual_time = delta / freq;
- }
- while (actual_time < target_time);
-
- return actual_time;
-}
-
-static double CalcCpuSpeed()
-{
- const auto before = std::chrono::high_resolution_clock::now();
-
- double seconds = SpinWait(0.1);
-
- const auto after = std::chrono::high_resolution_clock::now();
- const std::chrono::duration<double> diff = after - before;
- double clocks = diff.count();
-
- return (clocks/seconds);
-}
-
-/****************************************************************************
-*
-* GetDXVersion
-*
-* This function returns
-* 0 Insufficient DirectX installed
-* 9 At least DirectX 9 installed.
-*
-****************************************************************************/
-
-DWORD GetDXVersion()
-{
- HRESULT hr = 0;
- HINSTANCE DDHinst = 0;
- LPDIRECT3D9 d3d9 = 0;
- OSVERSIONINFO osVer = { sizeof(OSVERSIONINFO) };
-
- // First get the windows platform
-
- if (!GetVersionEx(&osVer))
- return 0;
-
- // NT versions do not support DirectX 9
- if (osVer.dwPlatformId == VER_PLATFORM_WIN32_NT) {
- if (osVer.dwMajorVersion <= 4)
- return 0;
- }
-
- DDHinst = LoadLibrary("D3D9.DLL");
- if (DDHinst == 0) {
- return 0;
- }
-
- FreeLibrary(DDHinst);
- return 9;
-}
-
-
-// +--------------------------------------------------------------------+
-
-int
-MachineInfo::GetCpuClass()
-{
- if (cpu_class < 0) {
- GetSystemInfo(&cpu_info);
-
- if (cpu_info.wProcessorArchitecture != PROCESSOR_ARCHITECTURE_INTEL ||
- cpu_info.dwProcessorType < PROCESSOR_INTEL_PENTIUM)
- Print("INCOMPATIBLE CPU TYPE!\n");
-
- if (GetPlatform() < OS_WINNT)
- cpu_class = CPU_P5;
-
- else
- cpu_class = cpu_info.wProcessorLevel;
- }
-
- return cpu_class;
-}
-
-// +--------------------------------------------------------------------+
-
-int
-MachineInfo::GetCpuSpeed()
-{
- if (cpu_speed < 0) {
- cpu_speed = (int) (CalcCpuSpeed() / 1e6);
- }
-
- return cpu_speed;
-}
-
-// +--------------------------------------------------------------------+
-
-int
-MachineInfo::GetTotalRam()
-{
- if (total_ram < 0) {
- GlobalMemoryStatus(&mem_info);
- total_ram = (int) (mem_info.dwTotalPhys/(1024*1024)) + 1;
- }
-
- return total_ram;
-}
-
-// +--------------------------------------------------------------------+
-
-int
-MachineInfo::GetPlatform()
-{
- if (platform < 0) {
- GetVersionEx(&os_ver);
-
- switch (os_ver.dwPlatformId) {
- default:
- case VER_PLATFORM_WIN32s:
- case VER_PLATFORM_WIN32_WINDOWS: {
- char msg[256];
- sprintf_s(msg, "Invalid Operating System Platform: %d\n", os_ver.dwPlatformId); //-V576
- Print(msg);
- }
- break;
-
- case VER_PLATFORM_WIN32_NT:
- if (os_ver.dwMajorVersion == 4)
- platform = OS_WINNT;
- else if (os_ver.dwMajorVersion == 5 && os_ver.dwMinorVersion == 0)
- platform = OS_WIN2K;
- else if (os_ver.dwMajorVersion == 5 && os_ver.dwMinorVersion == 1)
- platform = OS_WINXP;
- else if (os_ver.dwMajorVersion == 5 && os_ver.dwMinorVersion == 2)
- platform = OS_WINXP64;
- else if (os_ver.dwMajorVersion == 6 && os_ver.dwMinorVersion == 0)
- platform = OS_WINVISTA;
- else if (os_ver.dwMajorVersion == 6 && os_ver.dwMinorVersion == 1)
- platform = OS_WINSEVEN;
- else if (os_ver.dwMajorVersion >= 6)
- platform = OS_WINFUTURE;
-
- else {
- platform = OS_INVALID;
-
- Print("Invalid Operating System Platform (NT-series): %d.%d\n", os_ver.dwMajorVersion, os_ver.dwMinorVersion);
- }
-
- break;
- }
- }
-
- return platform;
-}
-
-// +--------------------------------------------------------------------+
-
-int
-MachineInfo::GetDirectXVersion()
-{
- if (dx_version < 0) {
- dx_version = GetDXVersion();
- }
-
- return dx_version;
-}
-
-// +--------------------------------------------------------------------+
-
-void
-MachineInfo::DescribeMachine()
-{
- GetPlatform();
- GetCpuClass();
-
- Print("+====================================================================+\n");
- Print("| |\n");
-
- char txt[256];
-
- switch (platform) {
- case OS_WIN95:
- sprintf_s(txt, "Windows 95 version %d.%d.%d %s", //-V576
- os_ver.dwMajorVersion,
- os_ver.dwMinorVersion,
- LOWORD(os_ver.dwBuildNumber),
- os_ver.szCSDVersion);
- break;
-
- case OS_WIN98:
- sprintf_s(txt, "Windows 98 version %d.%d.%d %s", //-V576
- os_ver.dwMajorVersion,
- os_ver.dwMinorVersion,
- LOWORD(os_ver.dwBuildNumber),
- os_ver.szCSDVersion);
- break;
-
- case OS_WINNT:
- sprintf_s(txt, "Windows NT %d.%d (Build %d) %s", //-V576
- os_ver.dwMajorVersion,
- os_ver.dwMinorVersion,
- os_ver.dwBuildNumber,
- os_ver.szCSDVersion);
- break;
-
- case OS_WIN2K:
- sprintf_s(txt, "Windows 2000 %d.%d (Build %d) %s", //-V576
- os_ver.dwMajorVersion,
- os_ver.dwMinorVersion,
- os_ver.dwBuildNumber,
- os_ver.szCSDVersion);
-
- case OS_WINXP:
- sprintf_s(txt, "Windows XP %d.%d (Build %d) %s", //-V576
- os_ver.dwMajorVersion,
- os_ver.dwMinorVersion,
- os_ver.dwBuildNumber,
- os_ver.szCSDVersion);
- break;
- case OS_WINXP64:
- sprintf_s(txt, "Windows XP x64 %d.%d (Build %d) %s", //-V576
- os_ver.dwMajorVersion,
- os_ver.dwMinorVersion,
- os_ver.dwBuildNumber,
- os_ver.szCSDVersion);
- break;
- case OS_WINVISTA:
- sprintf_s(txt, "Windows Vista %d.%d (Build %d) %s", //-V576
- os_ver.dwMajorVersion,
- os_ver.dwMinorVersion,
- os_ver.dwBuildNumber,
- os_ver.szCSDVersion);
- break;
- case OS_WINSEVEN:
- sprintf_s(txt, "Windows 7 %d.%d (Build %d) %s", //-V576
- os_ver.dwMajorVersion,
- os_ver.dwMinorVersion,
- os_ver.dwBuildNumber,
- os_ver.szCSDVersion);
- break;
- case OS_WINFUTURE:
- sprintf_s(txt, "Windows from the future %d.%d (Build %d) %s", //-V576
- os_ver.dwMajorVersion,
- os_ver.dwMinorVersion,
- os_ver.dwBuildNumber,
- os_ver.szCSDVersion);
- break;
-
- default:
- sprintf_s(txt, "Unknown Operating System Platform");
- break;
- }
-
- Print("| %-66s |\n", txt);
- Print("| |\n");
-
- if (platform == OS_WIN95 || platform == OS_WIN98)
- DescribeOwner95();
- else
- DescribeOwnerNT();
-
- sprintf_s(txt, "CPUs Detected: %d CPU Level: %d.%d.%d CPU Speed: %d", //-V576
- cpu_info.dwNumberOfProcessors,
- cpu_info.wProcessorLevel,
- cpu_info.wProcessorRevision >> 8,
- cpu_info.wProcessorRevision & 0xff,
- GetCpuSpeed() + 1);
-
- Print("| %-66s |\n", txt);
- DescribeCpuMake();
-
- GlobalMemoryStatus(&mem_info);
- total_ram = (int) (mem_info.dwTotalPhys/(1024*1024)) + 1;
- int swap_max = (int) (mem_info.dwTotalPageFile/(1024*1024));
- int swap_avail = (int) (mem_info.dwAvailPageFile/(1024*1024));
-
- sprintf_s(txt, "%d MB RAM %d MB Max Swap %d MB Avail Swap",
- total_ram, swap_max, swap_avail);
-
-
- Print("| %-66s |\n", txt);
-
- Print("| |\n");
- Print("| DirectX %d installed. |\n",
- GetDirectXVersion());
- DescribeDXVersion("DDRAW");
- DescribeDXVersion("D3DIM");
- DescribeDXVersion("DINPUT");
- DescribeDXVersion("DPLAY");
- DescribeDXVersion("DSOUND");
- DescribeDXVersion("DMUSIC");
- DescribeDXVersion("DSHOW");
- Print("| |\n");
-
-
- if (platform == OS_WIN95 || platform == OS_WIN98) {
- DescribeDrivers95("Display");
- DescribeDrivers95("Media");
- DescribeDrivers95("Monitor");
- DescribeDrivers95("Multimedia");
- }
- else {
- DescribeDriversNT("");
- }
-
- Print("+====================================================================+\n");
- Print("\n");
-}
-
-// +--------------------------------------------------------------------+
-
-static void DescribeCpuMake()
-{
- HKEY hkWin;
- char sProcessor[256] = "";
- char sMMXInfo[256] = "";
- char sVendor[256] = "";
- DWORD dwSize;
-
- if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
- "Hardware\\Description\\System\\CentralProcessor\\0",
- 0,
- KEY_READ,
- &hkWin) == ERROR_SUCCESS) {
-
- dwSize = 256;
- RegQueryValueEx(hkWin,
- "Identifier",
- NULL,
- NULL,
- (LPBYTE) sProcessor,
- &dwSize);
-
- dwSize = 256;
- RegQueryValueEx(hkWin,
- "MMXIdentifier",
- NULL,
- NULL,
- (LPBYTE) sMMXInfo,
- &dwSize);
-
- dwSize = 256;
- RegQueryValueEx(hkWin,
- "VendorIdentifier",
- NULL,
- NULL,
- (LPBYTE) sVendor,
- &dwSize);
-
- RegCloseKey(hkWin);
- }
-
- if (sProcessor[0]) Print("| %-66s |\n", sProcessor);
- if (sMMXInfo[0]) Print("| %-66s |\n", sMMXInfo);
- if (sVendor[0]) Print("| %-66s |\n", sVendor);
-
- if (sProcessor[0] || sMMXInfo[0] || sVendor[0])
- Print("| |\n");
-}
-
-// +--------------------------------------------------------------------+
-
-static void DescribeOwner95()
-{
- HKEY hkWin;
- char sRegisteredOwner[256] = "";
- char sRegisteredOrganization[256] = "";
- DWORD dwSize;
-
- if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
- "SOFTWARE\\Microsoft\\Windows\\CurrentVersion",
- 0,
- KEY_READ,
- &hkWin) == ERROR_SUCCESS) {
-
- dwSize = 256;
- RegQueryValueEx(hkWin,
- "RegisteredOwner",
- NULL,
- NULL,
- (LPBYTE) sRegisteredOwner,
- &dwSize);
-
- dwSize = 256;
- RegQueryValueEx(hkWin,
- "RegisteredOrganization",
- NULL,
- NULL,
- (LPBYTE) sRegisteredOrganization,
- &dwSize);
-
- RegCloseKey(hkWin);
- }
- else {
- Print("Could not access registered owner\n");
- }
-
- if (sRegisteredOwner[0]) {
- char txt[256];
- sprintf_s(txt, "Registered Owner: %s, %s", sRegisteredOwner, sRegisteredOrganization);
- Print("| %-66s |\n", txt);
- Print("| |\n");
- }
-}
-
-static void DescribeOwnerNT()
-{
- HKEY hkWin;
- char sRegisteredOwner[256] = "";
- char sRegisteredOrganization[256] = "";
- DWORD dwSize;
-
- if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
- "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
- 0,
- KEY_READ,
- &hkWin) == ERROR_SUCCESS) {
-
- dwSize = 256;
- RegQueryValueEx(hkWin,
- "RegisteredOwner",
- NULL,
- NULL,
- (LPBYTE) sRegisteredOwner,
- &dwSize);
-
- dwSize = 256;
- RegQueryValueEx(hkWin,
- "RegisteredOrganization",
- NULL,
- NULL,
- (LPBYTE) sRegisteredOrganization,
- &dwSize);
-
- RegCloseKey(hkWin);
- }
- else {
- Print("Could not access registered owner\n");
- }
-
- if (sRegisteredOwner[0]) {
- char txt[256];
- sprintf_s(txt, "Registered Owner: %s, %s", sRegisteredOwner, sRegisteredOrganization);
- Print("| %-66s |\n", txt);
- Print("| |\n");
- }
-}
-
-// +--------------------------------------------------------------------+
-
-static void DescribeDrivers95(const char* sType)
-{
- HKEY hkWin, hkSub;
- int nKey = 0;
- char sKey[256];
- char sSub[256];
- char sDriver[256];
- char txt[256];
- DWORD dwSize;
- int worked;
-
- // describe the video driver(s):
- do {
- worked = 0;
-
- sprintf_s(sKey, "System\\CurrentControlSet\\Services\\Class\\%s\\%04X", sType, nKey);
- sprintf_s(sSub, "System\\CurrentControlSet\\Services\\Class\\%s\\%04X\\DEFAULT", sType, nKey);
-
- if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
- sKey,
- 0,
- KEY_READ,
- &hkWin) == ERROR_SUCCESS) {
-
- dwSize = 256;
- RegQueryValueEx(hkWin,
- "DriverDesc",
- NULL,
- NULL,
- (LPBYTE) sDriver,
- &dwSize);
-
- if (sDriver[0]) {
- sprintf_s(txt, "* %s", sDriver);
- Print("| %-66s |\n", txt);
- worked = 1;
- }
-
- // try to find the driver file name:
- if (worked) {
- ZeroMemory(sDriver, sizeof(sDriver));
-
- dwSize = 256;
- DWORD err = RegQueryValueEx(hkWin, "Driver", NULL, NULL, (LPBYTE) sDriver, &dwSize);
-
- if (err != ERROR_SUCCESS) {
- dwSize = 256;
- err = RegQueryValueEx(hkWin, "DeviceDriver", NULL, NULL, (LPBYTE) sDriver, &dwSize);
- }
-
- if (err != ERROR_SUCCESS) {
- dwSize = 256;
- err = RegQueryValueEx(hkWin, "drv", NULL, NULL, (LPBYTE) sDriver, &dwSize);
- }
-
- if (err != ERROR_SUCCESS) {
- if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
- sSub,
- 0,
- KEY_READ,
- &hkSub) == ERROR_SUCCESS) {
-
- dwSize = 256;
- err = RegQueryValueEx(hkSub, "drv", NULL, NULL, (LPBYTE) sDriver, &dwSize);
-
- RegCloseKey(hkSub);
- }
- }
-
- // if we found it, try to display version info:
- if (err == ERROR_SUCCESS) {
- DescribeDriverVersion(sDriver);
- }
-
- Print("| |\n");
- }
-
- RegCloseKey(hkWin);
- }
-
- nKey++;
- }
- while (worked);
-}
-
-static void DescribeDriversNT(const char* sType)
-{
- Print("| |\n");
-
- HKEY hkWin;
- char sVideo[256] = "";
- char sDriver[256] = "";
- DWORD dwSize = 0;
-
- // find the pointer to the video driver:
- if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
- "HARDWARE\\DEVICEMAP\\VIDEO",
- 0,
- KEY_READ,
- &hkWin) == ERROR_SUCCESS) {
-
- dwSize = 256;
- RegQueryValueEx(hkWin,
- "\\Device\\Video0",
- NULL,
- NULL,
- (LPBYTE) sVideo,
- &dwSize);
-
- RegCloseKey(hkWin);
- }
-
- // follow the pointer and get the driver description:
- if (dwSize && sVideo[0]) {
- const char* sLeader = "\\REGISTRY\\Machine\\";
- int nLeader = strlen(sLeader);
-
- if (_strnicmp(sVideo, sLeader, nLeader) == 0) {
- if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
- sVideo + nLeader,
- 0,
- KEY_READ,
- &hkWin) == ERROR_SUCCESS) {
-
- dwSize = 256;
- RegQueryValueEx(hkWin,
- "Device Description",
- NULL,
- NULL,
- (LPBYTE) sDriver,
- &dwSize);
-
- RegCloseKey(hkWin);
- }
- }
- }
-
- if (sDriver[0]) {
- Print("| %-66s |\n", sDriver);
- Print("| |\n");
- }
-}
-
-// +--------------------------------------------------------------------+
-
-static char sTranslation[16];
-
-static void GetTranslation(const LPBYTE pBlock)
-{
- LPBYTE sData = NULL;
- UINT lenData = 0;
-
- if (VerQueryValue(pBlock, "\\VarFileInfo\\Translation",
- (LPVOID*) &sData, &lenData)) {
-
- if (lenData && sData) {
- sprintf_s(sTranslation, "%02X%02X%02X%02X", sData[1], sData[0], sData[3], sData[2]);
- }
- }
-}
-
-void DisplayVersionString(const LPBYTE pBlock, LPTSTR sSection)
-{
- char txt[256];
- char sFullSection[256];
-
- sprintf_s(sFullSection, "\\StringFileInfo\\%s\\%s", sTranslation, sSection);
-
- LPBYTE sData = NULL;
- UINT lenData = 0;
- DWORD dwErr = 0;
-
- if (VerQueryValue(pBlock, sFullSection, (LPVOID*) &sData, &lenData)) {
- if (lenData && sData) {
- sprintf_s(txt, "%-16s %s", sSection, sData);
- Print("| %-60s |\n", txt);
- }
- }
-}
-
-static void DescribeDriverVersion(const char* file)
-{
- DWORD dwHandle = 0;
- TCHAR szFile[512];
-
- strcpy_s(szFile, file);
-
- int nBytes = GetFileVersionInfoSize(szFile, &dwHandle);
-
- if (nBytes <= 0) {
- char szWinDir[256];
- GetSystemDirectory(szWinDir, 256);
- sprintf_s(szFile, "%s\\%s", szWinDir, file);
-
- nBytes = GetFileVersionInfoSize(szFile, &dwHandle);
-
- if (nBytes <= 0)
- return;
- }
-
- LPBYTE pBlock = new BYTE[nBytes];
-
- if (pBlock && GetFileVersionInfo(szFile, dwHandle, nBytes, (LPVOID) pBlock)) {
- GetTranslation(pBlock);
- DisplayVersionString(pBlock, "CompanyName");
- // DisplayVersionString(pBlock, "FileDescription");
- DisplayVersionString(pBlock, "FileVersion");
- // DisplayVersionString(pBlock, "InternalName");
- // DisplayVersionString(pBlock, "LegalCopyright");
- // DisplayVersionString(pBlock, "OriginalFilename");
- // DisplayVersionString(pBlock, "ProductName");
- // DisplayVersionString(pBlock, "ProductVersion");
- // DisplayVersionString(pBlock, "Comments");
- // DisplayVersionString(pBlock, "LegalTrademarks");
- // DisplayVersionString(pBlock, "PrivateBuild");
- // DisplayVersionString(pBlock, "SpecialBuild");
- }
-
- delete [] pBlock;
-}
-
-static void DescribeDXVersion(const char* component)
-{
- DWORD dwHandle = 0;
- char szFile[512];
- char szWinDir[512];
-
- GetSystemDirectory(szWinDir, 512);
-
- sprintf_s(szFile, "%s\\%s.dll", szWinDir, component);
-
- int nBytes = GetFileVersionInfoSize(szFile, &dwHandle);
-
- if (nBytes <= 0) {
- return;
- }
-
- LPBYTE pBlock = new BYTE[nBytes];
-
- if (pBlock && GetFileVersionInfo(szFile, dwHandle, nBytes, (LPVOID) pBlock)) {
- GetTranslation(pBlock);
-
- char txt[256];
- char sFullSection[256];
- LPBYTE sData = NULL;
- UINT lenData = 0;
- DWORD dwErr = 0;
-
- sprintf_s(sFullSection, "\\StringFileInfo\\%s\\FileVersion", sTranslation);
-
- if (VerQueryValue(pBlock, sFullSection, (LPVOID*) &sData, &lenData)) {
- if (lenData && sData) {
- sprintf_s(txt, "%-8s%s", component, sData);
- Print("| %-64s |\n", txt);
- }
- }
- }
-
- delete [] pBlock;
-} \ No newline at end of file
diff --git a/StarsEx/MachineInfo.h b/StarsEx/MachineInfo.h
deleted file mode 100644
index 01e4bda..0000000
--- a/StarsEx/MachineInfo.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/* Starshatter: The Open Source Project
- Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors
- Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
- Copyright (c) 1997-2006, Destroyer Studios LLC.
-
- AUTHOR: John DiCamillo
-
-
- OVERVIEW
- ========
- Collect and Display Machine, OS, and Driver Information
-*/
-
-#ifndef MachineInfo_h
-#define MachineInfo_h
-
-#include "Types.h"
-
-// +--------------------------------------------------------------------+
-
-class MachineInfo
-{
-public:
- enum { CPU_INVALID, CPU_P5=5, CPU_P6=6, CPU_P7=7, CPU_PLUS };
- enum { OS_INVALID, OS_WIN95, OS_WIN98, OS_WINNT, OS_WIN2K, OS_WINXP, OS_WINXP64, OS_WINVISTA, OS_WINSEVEN, OS_WINFUTURE };
- enum { DX_NONE, DX_3=3, DX_5=5, DX_6=6, DX_7=7, DX_8=8, DX_9=9, DX_PLUS };
-
- static int GetCpuClass();
- static int GetCpuSpeed();
- static int GetTotalRam();
- static int GetPlatform();
- static int GetDirectXVersion();
-
- static void DescribeMachine();
-
- static const char* GetShortDescription();
-};
-
-// +--------------------------------------------------------------------+
-
-#endif // MachineInfo_h \ No newline at end of file
diff --git a/StarsEx/NetLobbyServer.cpp b/StarsEx/NetLobbyServer.cpp
index 371310f..2039fff 100644
--- a/StarsEx/NetLobbyServer.cpp
+++ b/StarsEx/NetLobbyServer.cpp
@@ -12,6 +12,9 @@
*/
#include "NetLobbyServer.h"
+
+#include <InfoEx.h>
+
#include "NetServerConfig.h"
#include "NetClientConfig.h"
#include "NetBrokerClient.h"
@@ -36,7 +39,6 @@
#include "NetHost.h"
#include "NetMsg.h"
-#include "MachineInfo.h"
#include "Clock.h"
#include "FormatUtil.h"
#include "VersionInfo.h"
@@ -838,7 +840,7 @@ NetLobbyServer::DoServerInfo(NetPeer* peer, Text s)
gameport = server_config->GetGamePort();
sprintf_s(buffer, "info \"%s\" version \"%s\" mode %d users %d host %s port %d",
- MachineInfo::GetShortDescription(),
+ InfoEx::ShortDescription().data(),
versionInfo,
GetStatus(),
NumUsers(),
diff --git a/Starserver/CMakeLists.txt b/Starserver/CMakeLists.txt
index 43e3d29..e492234 100644
--- a/Starserver/CMakeLists.txt
+++ b/Starserver/CMakeLists.txt
@@ -13,7 +13,7 @@ target_include_directories(
)
target_link_libraries(
Starserver
- PRIVATE StarsEx
+ PRIVATE StarsEx InfoEx
)
install(
TARGETS Starserver
diff --git a/Starserver/Main.cpp b/Starserver/Main.cpp
index 0063060..a92df86 100644
--- a/Starserver/Main.cpp
+++ b/Starserver/Main.cpp
@@ -4,12 +4,13 @@
Copyright (c) 1997-2006, Destroyer Studios LLC.
*/
-#include "MachineInfo.h"
-#include "NetLayer.h"
-#include "Panic.h"
-#include "StarServer.h"
-#include "Token.h"
-#include "Utils.h"
+#include <InfoEx.h>
+#include <NetLayer.h>
+#include <Panic.h>
+#include <StarServer.h>
+#include <Token.h>
+#include <Utils.h>
+#include <VersionInfo.h>
int dump_missions = 0;
@@ -19,7 +20,8 @@ int
main(int argc, char * argv[])
{
AssignErrLog(fopen("serverlog.txt", "wb"));
- MachineInfo::DescribeMachine();
+ Print("Starserver %s\n", versionInfo);
+ Print("%s\n\n", InfoEx::LongDescription().data());
int result = 1;
try {
NetLayer net;
diff --git a/Starserver/NetAdminServer.cpp b/Starserver/NetAdminServer.cpp
index 7e82801..190931b 100644
--- a/Starserver/NetAdminServer.cpp
+++ b/Starserver/NetAdminServer.cpp
@@ -25,7 +25,6 @@
#include "DataLoader.h"
#include "FormatUtil.h"
-#include "MachineInfo.h"
#include "VersionInfo.h"
// +-------------------------------------------------------------------+
diff --git a/Starshatter/CMakeLists.txt b/Starshatter/CMakeLists.txt
index e73a639..892a10f 100644
--- a/Starshatter/CMakeLists.txt
+++ b/Starshatter/CMakeLists.txt
@@ -9,7 +9,7 @@ target_include_directories(
)
target_link_libraries(
Starshatter
- PRIVATE StarsEx
+ PRIVATE StarsEx InfoEx
)
add_version_file(Starshatter.rc Starshatter.rc.conf)
target_sources(
diff --git a/Starshatter/Main.cpp b/Starshatter/Main.cpp
index f2417e9..beda5d0 100644
--- a/Starshatter/Main.cpp
+++ b/Starshatter/Main.cpp
@@ -6,6 +6,7 @@
AUTHOR: John DiCamillo
*/
+#include <InfoEx.h>
#include "Starshatter.h"
#include "HUDView.h"
@@ -21,7 +22,6 @@
#include "Color.h"
#include "DataLoader.h"
#include "Pcx.h"
-#include "MachineInfo.h"
#include "Encrypt.h"
#include "FormatUtil.h"
#include "Panic.h"
@@ -29,23 +29,22 @@
#include "Random.h"
#include "VersionInfo.h"
-// +--------------------------------------------------------------------+
-// WinMain
-// +--------------------------------------------------------------------+
-extern int VD3D_describe_things;
-int dump_missions = 0;
+extern int VD3D_describe_things;
+int dump_missions = 0;
-static void PrintLogHeader()
+
+static void
+PrintLogHeader()
{
Text sTime = FormatTimeString();
-
Print("+====================================================================+\n");
Print("| STARSHATTER %-25s%29s |\n", versionInfo, sTime.data());
-
- MachineInfo::DescribeMachine();
+ Print("+====================================================================+\n\n");
+ Print("%s\n\n", InfoEx::LongDescription().data());
}
+
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
@@ -125,5 +124,3 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
return result;
}
-
-
diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt
index 2f35927..6094770 100644
--- a/contrib/CMakeLists.txt
+++ b/contrib/CMakeLists.txt
@@ -2,11 +2,12 @@ include(ApplyPatch)
include(FetchContent)
include(MakeAvailable)
add_subdirectory(gtest)
+add_subdirectory(infoware)
add_subdirectory(libpng)
add_subdirectory(ogg)
add_subdirectory(vorbis)
add_subdirectory(zlib)
-make_available(gtest libpng ogg vorbis zlib)
+make_available(gtest infoware libpng ogg vorbis zlib)
add_subdirectory(Opcode)
add_subdirectory(sha1)
install(
diff --git a/contrib/infoware/1.current.patch b/contrib/infoware/1.current.patch
new file mode 100644
index 0000000..9ef31bc
--- /dev/null
+++ b/contrib/infoware/1.current.patch
@@ -0,0 +1,30 @@
+diff '--color=auto' -ru a/CMakeLists.txt b/CMakeLists.txt
+--- a/CMakeLists.txt 2024-03-09 23:00:40.101308564 +0100
++++ b/CMakeLists.txt 2024-03-09 22:59:36.067973296 +0100
+@@ -84,7 +84,7 @@
+ find_package(Git)
+ endif()
+
+-set(INFOWARE_PCI_DATA_DIR infoware_generated CACHE PATH "Output directory for the PCI ids generator")
++set(INFOWARE_PCI_DATA_DIR "${CMAKE_CURRENT_BINARY_DIR}/infoware_generated" CACHE PATH "Output directory for the PCI ids generator")
+ set(INFOWARE_PCI_DATA_HPP pci_data.hpp)
+ set(INFOWARE_PCI_DATA_GEN "${INFOWARE_PCI_DATA_DIR}/${INFOWARE_PCI_DATA_HPP}")
+ set(infoware_pci_ids_error "\
+@@ -132,13 +132,13 @@
+ else()
+ include(ExternalProject)
+ ExternalProject_Add(infoware_generate_pcis
+- SOURCE_DIR ${CMAKE_SOURCE_DIR}
+- PREFIX ${CMAKE_BINARY_DIR}/pci_generator
+- BINARY_DIR ${CMAKE_BINARY_DIR}/pci_generator
++ SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}
++ PREFIX ${CMAKE_CURRENT_BINARY_DIR}/pci_generator
++ BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/pci_generator
+ BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target infoware_generate_pcis
+ INSTALL_COMMAND ""
+ BUILD_ALWAYS ON
+- CMAKE_ARGS -DINFOWARE_PCI_DATA_DIR:PATH=${CMAKE_BINARY_DIR}/${INFOWARE_PCI_DATA_DIR})
++ CMAKE_ARGS -DINFOWARE_PCI_DATA_DIR:PATH=${CMAKE_CURRENT_BINARY_DIR}/${INFOWARE_PCI_DATA_DIR})
+ endif()
+ add_dependencies(infoware infoware_generate_pcis)
+
diff --git a/contrib/infoware/CMakeLists.txt b/contrib/infoware/CMakeLists.txt
new file mode 100644
index 0000000..81c7b4b
--- /dev/null
+++ b/contrib/infoware/CMakeLists.txt
@@ -0,0 +1,6 @@
+FetchContent_Declare(
+ infoware
+ URL https://github.com/ThePhD/infoware/archive/e469b86.tar.gz
+ URL_HASH SHA1=e844ae80c5ca3f6b944571130ac3795c96a4e9ab
+ PATCH_COMMAND ${CMAKE_COMMAND} -D "PATCH_FILE=${CMAKE_CURRENT_SOURCE_DIR}/1.current.patch" -P ${PATCH_SCRIPT}
+ DOWNLOAD_EXTRACT_TIMESTAMP No)