dll加载路径错误

This commit is contained in:
2025-06-08 17:40:21 +08:00
parent 232ba1a5ae
commit 2298e69a1c
84 changed files with 4749 additions and 241 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ out
.eslintcache .eslintcache
*.log* *.log*
.idea .idea
resources/hardware_monitor

View File

@ -2,6 +2,11 @@ appId: com.electron.app
productName: hardware_monitorndefinedndefined productName: hardware_monitorndefinedndefined
directories: directories:
buildResources: build buildResources: build
extraResources:
- 'resources/hardware_monitor/hardware_monitor.node'
- 'resources/hardware_monitor/HidSharp.dll'
- 'resources/hardware_monitor/LibreHardwareManagerManaged2.dll'
- 'resources/hardware_monitor/LibreHardwareMonitorLib.dll'
files: files:
- '!**/.vscode/*' - '!**/.vscode/*'
- '!src/*' - '!src/*'

View File

@ -1,10 +1,35 @@
import { resolve } from 'path' import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite' import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import vue from '@vitejs/plugin-vue' import vue from '@vitejs/plugin-vue'
import * as fs from 'node:fs'
export default defineConfig({ export default defineConfig({
main: { main: {
plugins: [externalizeDepsPlugin()] plugins: [externalizeDepsPlugin(),
{
name: 'preserve-native-modules', closeBundle:() => {
const libDir=resolve('hardware_monitor_wrapper/build/Release/hardware_monitor.node')
const sourceDir = resolve('resources/hardware_monitor'); // node-gyp 编译生成的路径
const destDir = resolve( 'out');
fs.mkdirSync(destDir, { recursive: true });
fs.copyFileSync(
resolve(libDir),
resolve(destDir, "hardware_monitor.node")
);
let files=fs.readdirSync(resolve(sourceDir));
for(let i=0;i<files.length;i++){
fs.copyFileSync(
resolve(sourceDir, files[i]),
resolve(destDir, files[i])
);
}
}
}],
build:{
rollupOptions: {
external: ["../hardware_monitor.node"],
}
}
}, },
preload: { preload: {
plugins: [externalizeDepsPlugin()] plugins: [externalizeDepsPlugin()]

3
hardware_monitor_wrapper/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
build/
node_modules/
package-lock.json

View File

@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.15...3.31)
project(hardware_monitor)
add_compile_definitions(-DNAPI_VERSION=4)
file(GLOB SOURCE_FILES "your-source files-location-here")
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC})
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_JS_INC})
target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_JS_LIB})
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET)
# Generate node.lib
execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS})
endif()

View File

@ -0,0 +1,14 @@
{
"targets": [
{
"target_name": "hardware_monitor",
"sources": ["native/computer.cpp" , "native/cpu.cpp", "native/gpu.cpp", "native/memory.cpp", "native/storage.cpp", "native/monitor.cpp" ],
"include_dirs": ["./node_modules/node-addon-api", "./native/include"],
"libraries": ["-l../native/libs/LibreHardwareManagerManaged2.lib"],
"cflags": ["-fno-exceptions"],
"xcode_settings": {
"OTHER_CFLAGS": ["-fexceptions"]
}
}
]
}

View File

@ -0,0 +1,125 @@
#include <computer.h>
#include <IComputer.h>
#include <Visitor.h>
#include "include.h"
#include <iostream>
//回调函数在C#版本的DLL中我们需要实现IVisitor接口并将其引用传给Computer。
//由于没有办法在C++里实现C#接口考虑到IVisitor接口只包含函数因此我提供了IVisitor的默认实现
//其实现为调用以下四个回调函数它们的指针会被转换为C#委托供IVisitor的C#实现调用。
//注意!!哪怕提供空实现也要提供,要不然就不保证不出问题了。
void VisitComputerCallBack(IComputer& computer, Visitor* visitor)
{
computer.Traverse(visitor);
}
void VisitHardwareCallBack(Hardware& hardware, Visitor* visitor)
{
hardware.Update();
std::vector<Hardware> subHardwares = hardware.getSubHardware();
for (int i = 0; i < subHardwares.size(); i++) {
subHardwares[i].Accept(visitor);
}
}
void VisitSensorCallBack(Sensor& sensor, Visitor* visitor)
{
}
void VisitParameterCallBack(Parameter& parameter, Visitor* visitor)
{
}
void destroy(const Napi::CallbackInfo& info){
computer->Close();
computer=nullptr;
CoUninitialize();
}
// 使用智能指针管理资源
std::shared_ptr<Computer> computer;
std::shared_ptr<Visitor> visitor;
// 封装 COM 初始化/卸载
struct ComInitializer {
HRESULT hr;
ComInitializer() {
hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
}
~ComInitializer() {
if (SUCCEEDED(hr)) {
CoUninitialize();
}
}
};
void log(std::string log) {
std::ofstream logfile;
logfile.open("native_module.log", std::ios::app);
logfile << log << std::endl;
logfile.close();
}
// 安全的初始化函数
Napi::Object init(Napi::Env env, Napi::Object exports) {
log("Com initing");
ComInitializer comInit; // RAII 管理 COM 生命周期
// 检查 COM 初始化结果
if (FAILED(comInit.hr)) {
log("Com init fail");
_com_error err(comInit.hr);
Napi::Error::New(env, err.ErrorMessage()).ThrowAsJavaScriptException();
return exports;
}
log("Com inited");
computer = std::make_shared<Computer>();
computer->setCpuEnabled(true);
computer->setGpuEnabled(true);
computer.setGpuEnabled(true);
computer.setMotherboardEnabled(true);
computer.setStorageEnabled(true);
computer.setBatteryEnabled(true);
computer.setControllerEnabled(true);
computer.setMemoryEnabled(true);
computer.setNetworkEnabled(true);
computer.setPsuEnabled(true);
computer->Open();
log("Computer inited");
visitor = std::make_shared<Visitor>();
visitor->setVisitComputerCallBack(VisitComputerCallBack);
visitor->setVisitHardwareCallBack(VisitHardwareCallBack);
visitor->setVisitParameterCallBack(VisitParameterCallBack);
visitor->setVisitSensorCallBack(VisitSensorCallBack);
visitor->commit();
computer->Accept(visitor.get()); // 传递原始指针
log("Visitor inited");
// 导出函数
exports.Set(Napi::String::New(env,"cpu_name"), Napi::Function::New(env, cpu_name));
exports.Set(Napi::String::New(env,"cpu_load"), Napi::Function::New(env, cpu_load));
exports.Set(Napi::String::New(env,"cpu_power"), Napi::Function::New(env, cpu_power));
exports.Set(Napi::String::New(env,"cpu_speed"), Napi::Function::New(env, cpu_speed));
exports.Set(Napi::String::New(env,"cpu_temperature"), Napi::Function::New(env, cpu_temperature));
exports.Set(Napi::String::New(env,"cpu_voltage"), Napi::Function::New(env, cpu_voltage));
exports.Set(Napi::String::New(env,"current_gpu_status"), Napi::Function::New(env, current_gpu_status));
exports.Set(Napi::String::New(env,"mem_clock"), Napi::Function::New(env, mem_clock));
exports.Set(Napi::String::New(env,"mem_free_size"), Napi::Function::New(env, mem_free_size));
exports.Set(Napi::String::New(env,"mem_used_size"), Napi::Function::New(env, mem_used_size));
exports.Set(Napi::String::New(env,"mem_name"), Napi::Function::New(env, mem_name));
exports.Set(Napi::String::New(env,"mem_size"), Napi::Function::New(env, mem_size));
exports.Set(Napi::String::New(env,"vmem_free_size"), Napi::Function::New(env, vmem_free_size));
exports.Set(Napi::String::New(env,"vmem_used_size"), Napi::Function::New(env, vmem_used_size));
exports.Set(Napi::String::New(env,"current_disk_used"), Napi::Function::New(env, current_disk_used));
exports.Set(Napi::String::New(env,"disk_name"), Napi::Function::New(env, disk_name));
exports.Set(Napi::String::New(env,"monitor_info"), Napi::Function::New(env, monitor_info));
exports.Set(Napi::String::New(env,"destroy"), Napi::Function::New(env, destroy));
log("Export inited");
return exports;
}
NODE_API_MODULE(hardware_monitor, init)

View File

@ -0,0 +1,70 @@
#define NODE_ADDON_API_DISABLE_CPP_EXCEPTIONS
#include "include.h"
Napi::Value cpu_name(const Napi::CallbackInfo& info){
Napi::Env env = info.Env();
for (Hardware hardware:computer->getHardware()){
if(hardware.getHardwareType()==HardwareType::Cpu){
Napi::String str2= Napi::String::New(env, hardware.Name());
return str2;
}
}
return env.Null();
}
Napi::Array _cpu_data(const Napi::CallbackInfo& info,SensorType type){
Napi::Env env = info.Env();
Napi::Array vec;
int i=0;
for (Hardware hardware:computer->getHardware()){
if(hardware.getHardwareType()==HardwareType::Cpu){
for(Hardware sub:hardware.getSubHardware()){
for(Sensor sen:sub.getSensors()){
if(sen.getType()==type){
vec.Set<Napi::Number>(i,Napi::Number::New(env, sen.getValue()));
}
}
i++;
}
}
}
return vec;
}
Napi::Array cpu_speed(const Napi::CallbackInfo& info){
return _cpu_data(info,SensorType::Clock);
}
Napi::Value cpu_power(const Napi::CallbackInfo& info){
Napi::Env env = info.Env();
for (Hardware hardware:computer->getHardware()){
if(hardware.getHardwareType()==HardwareType::Cpu){
for(Sensor sen:hardware.getSensors()){
if(sen.getType()==SensorType::Power){
return Napi::Number::New(env, sen.getValue());
}
}
}
}
return env.Null();
}
Napi::Value cpu_voltage(const Napi::CallbackInfo& info){
Napi::Env env = info.Env();
for (Hardware hardware:computer->getHardware()){
if(hardware.getHardwareType()==HardwareType::Cpu){
for(Sensor sen:hardware.getSensors()){
if(sen.getType()==SensorType::Voltage){
return Napi::Number::New(env, sen.getValue());
}
}
}
}
return env.Null();
}
Napi::Value cpu_load(const Napi::CallbackInfo& info){
return _cpu_data(info,SensorType::Load);
}
Napi::Value cpu_temperature(const Napi::CallbackInfo& info){
return _cpu_data(info,SensorType::Temperature);
}

View File

@ -0,0 +1,30 @@
#include "include.h"
#include <string>
Napi::Array current_gpu_status(const Napi::CallbackInfo& info){
Napi::Env env = info.Env();
Napi::Array myarray=Napi::Array::New(env);
std::vector<Hardware> hardwares=computer->getHardware();
for (int i=0;i<hardwares.size();i++){
if(hardwares[i].getHardwareType()==HardwareType::GpuNvidia
|| hardwares[i].getHardwareType()==HardwareType::GpuAmd
|| hardwares[i].getHardwareType()==HardwareType::GpuIntel){
Napi::Object object=Napi::Object::New(env);
object.Set<Napi::String>("name", Napi::String::New(env, hardwares[i].Name()));
for(Sensor sen:hardwares[i].getSensors()){
if(sen.getType()==SensorType::Power){
object.Set<float>("power", sen.getValue());
}
else if(sen.getType()==SensorType::Load && (strcmp(sen.getName(),"GPU Core")==0)){
object.Set<float>("load", sen.getValue());
}
else if(sen.getType()==SensorType::Clock){
object.Set<float>("freq", sen.getValue());
}
}
myarray.Set(i,object);
}
}
return myarray;
}

View File

@ -0,0 +1,27 @@
#define NODE_ADDON_API_DISABLE_CPP_EXCEPTIONS
#include <napi.h>
#include "Computer.h"
#include "Hardware.h"
#include "HardwareType.h"
#include "Sensor.h"
#include <comdef.h>
#include <Wbemidl.h>
extern std::shared_ptr<Computer> computer;
Napi::Value cpu_name(const Napi::CallbackInfo& info);
Napi::Array cpu_speed(const Napi::CallbackInfo& info);
Napi::Value cpu_power(const Napi::CallbackInfo& info);
Napi::Value cpu_voltage(const Napi::CallbackInfo& info);
Napi::Value cpu_load(const Napi::CallbackInfo& info);
Napi::Value cpu_temperature(const Napi::CallbackInfo& info);
Napi::Array current_gpu_status(const Napi::CallbackInfo& info);
Napi::Value mem_used_size(const Napi::CallbackInfo& info);
Napi::Value vmem_used_size(const Napi::CallbackInfo& info);
Napi::Value mem_free_size(const Napi::CallbackInfo& info);
Napi::Value vmem_free_size(const Napi::CallbackInfo& info);
Napi::Value mem_clock(const Napi::CallbackInfo& info);
Napi::Value mem_size(const Napi::CallbackInfo& info);
Napi::String mem_name(const Napi::CallbackInfo& info);
Napi::Array disk_name(const Napi::CallbackInfo& info);
Napi::Array current_disk_used(const Napi::CallbackInfo& info);
Napi::Array monitor_info(const Napi::CallbackInfo& info);
Napi::Object init(Napi::Env env, Napi::Object exports);

View File

@ -0,0 +1,65 @@
#pragma once
#include "Settings.h"
#include "SMBios.h"
#include "Visitor.h"
#include "IComputer.h"
#include "Hardware.h"
#include <vector>
#include <memory>
#include "dll_macro.h"
struct innerComputer;
struct innerComputerInterface;
class DLL_API Computer : public IComputer{
public:
Computer();
Computer(Settings &settigs);
Computer(std::shared_ptr<innerComputer> inner);
~Computer() override;
bool isNull() const;
bool operator==(const Computer&) const;
std::vector<Hardware> getHardware() override;
bool isBatteryEnabled() override;
void setBatteryEnabled(bool);
bool isControllerEnabled() override;
void setControllerEnabled(bool);
bool isCpuEnabled() override;
void setCpuEnabled(bool);
bool isGpuEnabled() override;
void setGpuEnabled(bool);
bool isMemoryEnabled() override;
void setMemoryEnabled(bool);
bool isMotherboardEnabled() override;
void setMotherboardEnabled(bool);
bool isNetworkEnabled() override;
void setNetworkEnabled(bool);
bool isPsuEnabled() override;
void setPsuEnabled(bool);
bool isStorageEnabled() override;
void setStorageEnabled(bool);
SMBios getSMBios();
std::string GetReport() override;
void Accept(Visitor* visitor) override;
void Traverse(Visitor* visitor) override;
void Open();
void Close();
void Reset();
private:
std::shared_ptr<innerComputer> inner;
};

View File

@ -0,0 +1,30 @@
#pragma once
struct innerCsControl;
class Sensor;
#include "Identifier.h"
#include "dll_macro.h"
#include <memory>
enum CsControlMode
{
Undefined,
Software,
Default,
ObjectIsNull
};
class DLL_API CsControl
{
public:
CsControl(std::shared_ptr<innerCsControl> inner);
~CsControl();
bool isNull() const;
CsControlMode getCsControlMode();
Identifier getIdentifier();
float getMaxSoftwareValue();
float getMinSoftwareValue();
Sensor getSensor();
float getSoftwareValue();
void SetDefault();
void SetSoftware(float value);
private:
std::shared_ptr<innerCsControl> inner;
};

View File

@ -0,0 +1,25 @@
#include "pch.h"
#include "Group.h"
#include <msclr/marshal_cppstd.h>
#include "internals.h"
bool Group::isNull() const
{
if (inner == nullptr)
return true;
return ((inner->getInner()->Equals(nullptr))) ? false : true;
}
std::string Group::GetReport()
{
if (isNull()) {
return "";
}
return msclr::interop::marshal_as<std::string>(inner->getInner()->GetReport());
}
void Group::Close()
{
if (isNull()) {
return;
}
inner->getInner()->Close();
}

View File

@ -0,0 +1,15 @@
#pragma once
#include "dll_macro.h"
#include <string>
struct innerGroup;
class DLL_API Group {
public:
Group(std::shared_ptr<innerGroup> inner):inner(inner){}
virtual ~Group() {
}
bool isNull() const;
virtual std::string GetReport();
virtual void Close();
protected:
std::shared_ptr<innerGroup> inner;
};

View File

@ -0,0 +1,29 @@
#pragma once
#include "Hardware.h"
#include "dll_macro.h"
struct innerGroupAffinity;
namespace mikesolar {
template<typename T>
class List;
}
class DLL_API GroupAffinity
{
public:
GroupAffinity(unsigned short group, unsigned long mask);
GroupAffinity(std::shared_ptr<innerGroupAffinity> inner);
bool isNull() const;
static GroupAffinity Undifined();
static GroupAffinity Single(unsigned short group, int index);
unsigned short Group();
unsigned long Mask();
//public override bool Equals(object o)
int GetHashCode();
bool operator==(const GroupAffinity &other) const;
//static bool operator !=(GroupAffinity a1, GroupAffinity a2);
~GroupAffinity();
private:
std::shared_ptr<innerGroupAffinity> inner;
};

View File

@ -0,0 +1,33 @@
#pragma once
#include "dll_macro.h"
#include "HardwareType.h"
#include "Identifier.h"
#include <string>
#include <memory>
#include <vector>
class Sensor;
class Visitor;
struct innerHardware;
class DLL_API Hardware {
public:
Hardware(std::shared_ptr<innerHardware> inner);
Hardware(const Hardware& src);
bool isNull() const;
Hardware operator=(const Hardware& src) const{
return Hardware(src);
}
bool operator==(const Hardware& other) const;
HardwareType getHardwareType();
std::vector<Sensor> getSensors();
Hardware getParent();
std::vector<Hardware> getSubHardware();
void Update();
std::string Name();
std::string GetReport();
void Accept(Visitor* visitor);
void Traverse(Visitor* visitor);
Identifier getIdenifier();
~Hardware();
private:
std::shared_ptr<innerHardware> inner;
};

View File

@ -0,0 +1,19 @@
#pragma once
enum class HardwareType {
Motherboard,
SuperIO,
Cpu,
Memory,
GpuNvidia,
GpuAmd,
GpuIntel,
Storage,
Network,
Cooler,
EmbeddedController,
Psu,
Battery,
Other,
ObjectIsNull
};

View File

@ -0,0 +1,63 @@
#pragma once
#pragma once
#include "Settings.h"
#include "SMBios.h"
#include <vector>
#include "Hardware.h"
#include "IComputer.h"
#include "dll_macro.h"
class Visitor;
struct innerComputerInterface;
/**
* <20><>Ȼ<EFBFBD><C8BB>I<EFBFBD><49>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>Ϊ<EFBFBD>˺<EFBFBD>C#<23><EFBFBD><E0B1A3>һ<EFBFBD>£<EFBFBD><C2A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>dz<EFBFBD><C7B3><EFBFBD><EFBFBD><EFBFBD>
* <20><>Ӧ<EFBFBD>ñ<EFBFBD><C3B1>ֶ<EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD>Դӱ<D4B4><D3B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>ȡ
*/
class DLL_API IComputer {
public:
//<2F><>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>innerComputerInterface<63><65>ʵ<EFBFBD>ֵģ<D6B5>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5>͸ñ<CDB8><C3B1><EFBFBD><EFBFBD>ˡ<EFBFBD>
//<2F><>Ӧ<EFBFBD>ñ<EFBFBD><C3B1>ֶ<EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD>Դӱ<D4B4><D3B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>ȡ
IComputer(std::shared_ptr<innerComputerInterface> inner);
virtual bool operator==(const IComputer& other) const;
bool isNull() const;
virtual ~IComputer();
virtual std::vector<Hardware> getHardware();
virtual bool isBatteryEnabled();
virtual bool isControllerEnabled();
virtual bool isCpuEnabled();
virtual bool isGpuEnabled();
virtual bool isMemoryEnabled();
virtual bool isMotherboardEnabled();
virtual bool isNetworkEnabled();
virtual bool isPsuEnabled();
virtual bool isStorageEnabled();
virtual std::string GetReport();
virtual void Accept(Visitor* visitor);
virtual void Traverse(Visitor* visitor);
protected:
std::shared_ptr<innerComputerInterface> inner;
//<2F><>Ӧ<EFBFBD><D3A6><EFBFBD>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD>inner<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD>getter<65><72>setter<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><E3B6A8><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void setIComputerInner(std::shared_ptr<innerComputerInterface> inner) {
this->inner = inner;
}
std::shared_ptr<innerComputerInterface> getIComputerInner() const {
return inner;
}
};

View File

@ -0,0 +1,26 @@
#pragma once
#include "dll_macro.h"
#include <string>
#include <memory>
struct innerIdentifier;
class DLL_API Identifier {
public:
Identifier(std::shared_ptr<innerIdentifier> inner);
//Identifier(params string[] identifiers);
//Identifier(Identifier identifier, params string[] extensions)
int CompareTo(Identifier other);
//static void CheckIdentifiers(IEnumerable<string> identifiers)
std::string ToString();
int GetHashCode();
bool operator==(const Identifier& other) const;
bool operator!=(const Identifier& other) const;
bool operator<(const Identifier& id) const;
bool operator>(const Identifier& id) const;
bool isNull() const;
private:
std::shared_ptr<innerIdentifier> inner;
};

View File

@ -0,0 +1,26 @@
#pragma once
#include <string>
class Visitor;
#include "Identifier.h"
class Sensor;
#include "dll_macro.h"
struct innerParameter;
class DLL_API Parameter {
public:
Parameter(innerParameter* inner);
~Parameter();
bool isNull() const;
bool operator==(const Parameter& other) const;
float getDefaultValue();
std::string getDescription();
Identifier getIdentifier();
bool isDefault();
std::string getName();
Sensor getSensor();
float getValue();
void Accept(Visitor* visitor);
void Traverse(Visitor* visitor);
private:
innerParameter* inner;
};

View File

@ -0,0 +1,14 @@
#pragma once
#include "dll_macro.h"
#include <string>
struct innerParameterDescription;
class DLL_API ParameterDescription
{
public:
ParameterDescription(char* name, char* description, float defaultValue);
bool isNull() const;
std::string getName();
float getDefaultValue();
private:
std::shared_ptr<innerParameterDescription> inner;
};

View File

@ -0,0 +1,195 @@
#pragma once
#ifdef DLL_EXPORT
#define DLL_API __declspec(dllexport)
#else
#define DLL_API __declspec(dllimport)
#endif
#include <ctime>
#include <string>
#include <vector>
#include "SMBiosEnums.h"
struct innerBiosInformation;
struct innerSystemEnclosure;
struct innerSMBios;
struct innerSystemInformation;
struct innerBaseBoardInformation;
struct innerProcessorInformation;
struct innerCacheInformation;
struct innerMemoryDevice;
struct innerSMBios;
class DLL_API BiosInformation {
public:
BiosInformation(std::shared_ptr<innerBiosInformation> inner);
~BiosInformation();
bool isNull() const;
time_t getDate();
std::string getVendor();
std::string getVersion();
unsigned long long getSize();
private:
std::shared_ptr<innerBiosInformation> inner;
};
class DLL_API SystemInformation {
public:
SystemInformation(std::shared_ptr<innerSystemInformation> inner);
~SystemInformation();
bool isNull() const;
std::string getFamily();
std::string getManufacturerName();
std::string getProductName();
std::string getSerialNumber();
std::string getVersion();
SystemWakeUp WakeUp();
private:
std::shared_ptr<innerSystemInformation> inner;
};
class DLL_API SystemEnclosure {
public:
SystemEnclosure(std::shared_ptr<innerSystemEnclosure> inner);
~SystemEnclosure();
bool isNull() const;
std::string getAssetTag();
SystemEnclosureState getBootUpState();
bool getLockDetected();
void setLockDetected(bool locked);
std::string getManufacturerName();
unsigned char getPowerCords();
SystemEnclosureState getPowerSupplyState();
unsigned char getRackHeight();
SystemEnclosureSecurityStatus getSecurityStatus();
void setSecurityStatus(SystemEnclosureSecurityStatus status);
std::string getSerialNumber();
std::string getSKU();
SystemEnclosureState getThermalState();
SystemEnclosureType getType();
std::string Version();
private:
std::shared_ptr<innerSystemEnclosure> inner;
};
class DLL_API BaseBoardInformation {
public:
BaseBoardInformation(std::shared_ptr<innerBaseBoardInformation> inner);
~BaseBoardInformation();
bool isNull() const;
std::string getManufacturerName();
std::string getProductName();
std::string getSerialNumber();
std::string getVersion();
private:
std::shared_ptr<innerBaseBoardInformation> inner;
};
class DLL_API CSProcessorInformation {
public:
CSProcessorInformation(std::shared_ptr<innerProcessorInformation> inner);
~CSProcessorInformation();
bool isNull() const;
ProcessorCharacteristics getCharacteristics();
unsigned short getCoreCount();
unsigned short getCoreEnabled();
unsigned short getCurrentSpeed();
unsigned short getExternalClock();
ProcessorFamily getFamily();
unsigned short getHandle();
unsigned long long getId();
unsigned short getL1CacheHandle();
unsigned short getL2CacheHandle();
unsigned short getL3CacheHandle();
std::string getManufacturerName();
unsigned short getMaxSpeed();
ProcessorType getProcessorType();
std::string getSerial();
ProcessorSocket getSocket();
std::string getSocketDesignation();
unsigned short getThreadCount();
std::string getVersion();
private:
std::shared_ptr<innerProcessorInformation> inner;
};
class DLL_API CacheInformation
{
public:
CacheInformation(std::shared_ptr<innerCacheInformation> inner);
~CacheInformation();
bool isNull() const;
CacheAssociativity getAssociativity();
CacheDesignation getDesignation();
unsigned short getHandle();
unsigned short getSize();
private:
std::shared_ptr<innerCacheInformation> inner;
};
class DLL_API MemoryDevice
{
public:
MemoryDevice(std::shared_ptr<innerMemoryDevice> inner);
~MemoryDevice();
bool isNull() const;
std::string getBankLocator();
std::string getDeviceLocator();
std::string getManufacturerName();
std::string getPartNumber();
std::string getSerialNumber();
unsigned int getSize();
unsigned short getSpeed();
unsigned short getConfiguredSpeed();
unsigned short getConfiguredVoltage();
MemoryType getType();
private:
std::shared_ptr<innerMemoryDevice> inner;
};
class DLL_API SMBios
{
public:
SMBios();
~SMBios();
bool isNull() const;
SMBios(std::shared_ptr<innerSMBios>);
bool operator==(const SMBios& other) const;
BiosInformation getBios();
BaseBoardInformation getBoard();
std::vector<MemoryDevice> getMemoryDevice();
std::vector<CacheInformation> getProcessorCaches();
std::vector<CSProcessorInformation> getProcessors();
SystemInformation getSystem();
SystemEnclosure getSystemEnclosure();
std::string getGetReport();
private:
std::shared_ptr<innerSMBios> inner;
};

View File

@ -0,0 +1,460 @@
#pragma once
enum class SystemEnclosureSecurityStatus
{
Other = 1,
Unknown,
None,
ExternalInterfaceLockedOut,
ExternalInterfaceEnabled,
ObjectIsNull
};
enum class SystemEnclosureState
{
Other = 1,
Unknown,
Safe,
Warning,
Critical,
NonRecoverable,
ObjectIsNull
};
enum class SystemEnclosureType
{
Other = 1,
Unknown,
Desktop,
LowProfileDesktop,
PizzaBox,
MiniTower,
Tower,
Portable,
Laptop,
Notebook,
HandHeld,
DockingStation,
AllInOne,
SubNotebook,
SpaceSaving,
LunchBox,
MainServerChassis,
ExpansionChassis,
SubChassis,
BusExpansionChassis,
PeripheralChassis,
RaidChassis,
RackMountChassis,
SealedCasePc,
MultiSystemChassis,
CompactPci,
AdvancedTca,
Blade,
BladeEnclosure,
Tablet,
Convertible,
Detachable,
IoTGateway,
EmbeddedPc,
MiniPc,
StickPc,
ObjectIsNull
};
enum class ProcessorFamily
{
Other = 1,
Intel8086 = 3,
Intel80286 = 4,
Intel386,
Intel486,
Intel8087,
Intel80287,
Intel80387,
Intel80487,
IntelPentium,
IntelPentiumPro,
IntelPentiumII,
IntelPentiumMMX,
IntelCeleron,
IntelPentiumIIXeon,
IntelPentiumIII,
M1,
M2,
IntelCeleronM,
IntelPentium4HT,
AmdDuron = 24,
AmdK5,
AmdK6,
AmdK62,
AmdK63,
AmdAthlon,
Amd2900,
AmdK62Plus,
PowerPc,
PowerPc601,
PowerPc603,
PowerPc603Plus,
PowerPc604,
PowerPc620,
PowerPcx704,
PowerPc750,
IntelCoreDuo,
IntelCoreDuoMobile,
IntelCoreSoloMobile,
IntelAtom,
IntelCoreM,
IntelCoreM3,
IntelCoreM5,
IntelCoreM7,
Alpha,
Alpha21064,
Alpha21066,
Alpha21164,
Alpha21164Pc,
Alpha21164a,
Alpha21264,
Alpha21364,
AmdTurionIIUltraDualCoreMobileM,
AmdTurionDualCoreMobileM,
AmdAthlonIIDualCoreM,
AmdOpteron6100Series,
AmdOpteron4100Series,
AmdOpteron6200Series,
AmdOpteron4200Series,
AmdFxSeries,
Mips,
MipsR4000,
MipsR4200,
MipsR4400,
MipsR4600,
MipsR10000,
AmdCSeries,
AmdESeries,
AmdASeries,
AmdGSeries,
AmdZSeries,
AmdRSeries,
AmdOpteron4300Series,
AmdOpteron6300Series,
AmdOpteron3300Series,
AmdFireProSeries,
Sparc,
SuperSparc,
MicroSparcII,
MicroSparcIIep,
UltraSparc,
UltraSparcII,
UltraSparcIIi,
UltraSparcIII,
UltraSparcIIIi,
Motorola68040 = 96,
Motorola68xxx,
Motorola68000,
Motorola68010,
Motorola68020,
Motorola68030,
AmdAthlonX4QuadCore,
AmdOpteronX1000Series,
AmdOpteronX2000Series,
AmdOpteronASeries,
AmdOpteronX3000Series,
AmdZen,
Hobbit = 112,
CrusoeTm5000 = 120,
CrusoeTm3000,
EfficeonTm8000,
Weitek = 128,
IntelItanium = 130,
AmdAthlon64,
AmdOpteron,
AmdSempron,
AmdTurio64Mobile,
AmdOpteronDualCore,
AmdAthlon64X2DualCore,
AmdTurion64X2Mobile,
AmdOpteronQuadCore,
AmdOpteronThirdGen,
AmdPhenomFXQuadCore,
AmdPhenomX4QuadCore,
AmdPhenomX2DualCore,
AmdAthlonX2DualCore,
PaRisc,
PaRisc8500,
PaRisc8000,
PaRisc7300LC,
PaRisc7200,
PaRisc7100LC,
PaRisc7100,
V30 = 160,
IntelXeon3200QuadCoreSeries,
IntelXeon3000DualCoreSeries,
IntelXeon5300QuadCoreSeries,
IntelXeon5100DualCoreSeries,
IntelXeon5000DualCoreSeries,
IntelXeonLVDualCore,
IntelXeonULVDualCore,
IntelXeon7100Series,
IntelXeon5400Series,
IntelXeonQuadCore,
IntelXeon5200DualCoreSeries,
IntelXeon7200DualCoreSeries,
IntelXeon7300QuadCoreSeries,
IntelXeon7400QuadCoreSeries,
IntelXeon7400MultiCoreSeries,
IntelPentiumIIIXeon,
IntelPentiumIIISpeedStep,
IntelPentium4,
IntelXeon,
As400,
IntelXeonMP,
AmdAthlonXP,
AmdAthlonMP,
IntelItanium2,
IntelPentiumM,
IntelCeleronD,
IntelPentiumD,
IntelPentiumExtreme,
IntelCoreSolo,
IntelCore2Duo = 191,
IntelCore2Solo,
IntelCore2Extreme,
IntelCore2Quad,
IntelCore2ExtremeMobile,
IntelCore2DuoMobile,
IntelCore2SoloMobile,
IntelCoreI7,
IntelCeleronDualCore,
Ibm390,
PowerPcG4,
PowerPcG5,
Esa390G6,
ZArchitecture,
IntelCoreI5,
IntelCoreI3,
IntelCoreI9,
ViaC7M = 210,
ViaC7D,
ViaC7,
ViaEden,
IntelXeonMultiCore,
IntelXeon3xxxDualCoreSeries,
IntelXeon3xxxQuadCoreSeries,
ViaNano,
IntelXeon5xxxDualCoreSeries,
IntelXeon5xxxQuadCoreSeries,
IntelXeon7xxxDualCoreSeries = 221,
IntelXeon7xxxQuadCoreSeries,
IntelXeon7xxxMultiCoreSeries,
IntelXeon3400MultiCoreSeries,
AmdOpteron3000Series = 228,
AmdSempronII,
AmdOpteronQuadCoreEmbedded,
AmdPhenomTripleCore,
AmdTurionUltraDualCoreMobile,
AmdTurionDualCoreMobile,
AmdTurionDualCore,
AmdAthlonDualCore,
AmdSempronSI,
AmdPhenomII,
AmdAthlonII,
AmdOpteronSixCore,
AmdSempronM,
IntelI860 = 250,
IntelI960,
ArmV7 = 256,
ArmV8,
HitachiSh3,
HitachiSh4,
Arm,
StrongArm,
_686,
MediaGX,
MII,
WinChip,
Dsp,
VideoProcessor,
ObjectIsNull
};
/// <summary>
/// Processor characteristics based on <see href="https://www.dmtf.org/dsp/DSP0134">DMTF SMBIOS Reference Specification v.3.3.0, Chapter 7.5.9</see>.
/// </summary>
enum class ProcessorCharacteristics
{
None = 0,
_64BitCapable = 1,
MultiCore = 2,
HardwareThread = 4,
ExecuteProtection = 8,
EnhancedVirtualization = 16,
PowerPerformanceControl = 32,
_128BitCapable = 64,
ObjectIsNull
};
/// <summary>
/// Processor type based on <see href="https://www.dmtf.org/dsp/DSP0134">DMTF SMBIOS Reference Specification v.3.3.0, Chapter 7.5.1</see>.
/// </summary>
enum class ProcessorType
{
Other = 1,
Unknown,
CentralProcessor,
MathProcessor,
DspProcessor,
VideoProcessor,
ObjectIsNull
};
/// <summary>
/// Processor socket based on <see href="https://www.dmtf.org/dsp/DSP0134">DMTF SMBIOS Reference Specification v.3.3.0, Chapter 7.5.5</see>.
/// </summary>
enum class ProcessorSocket
{
Other = 1,
Unknown,
DaughterBoard,
ZifSocket,
PiggyBack,
None,
LifSocket,
Zif423 = 13,
A,
Zif478,
Zif754,
Zif940,
Zif939,
MPga604,
Lga771,
Lga775,
S1,
AM2,
F,
Lga1366,
G34,
AM3,
C32,
Lga1156,
Lga1567,
Pga988A,
Bga1288,
RPga088B,
Bga1023,
Bga1224,
Lga1155,
Lga1356,
Lga2011,
FS1,
FS2,
FM1,
FM2,
Lga20113,
Lga13563,
Lga1150,
Bga1168,
Bga1234,
Bga1364,
AM4,
Lga1151,
Bga1356,
Bga1440,
Bga1515,
Lga36471,
SP3,
SP3R2,
Lga2066,
Bga1510,
Bga1528,
Lga4189,
ObjectIsNull
};
/// <summary>
/// System wake-up type based on <see href="https://www.dmtf.org/dsp/DSP0134">DMTF SMBIOS Reference Specification v.3.3.0, Chapter 7.2.2</see>.
/// </summary>
enum class SystemWakeUp
{
Reserved,
Other,
Unknown,
ApmTimer,
ModemRing,
LanRemote,
PowerSwitch,
PciPme,
AcPowerRestored,
ObjectIsNull
};
/// <summary>
/// Cache associativity based on <see href="https://www.dmtf.org/dsp/DSP0134">DMTF SMBIOS Reference Specification v.3.3.0, Chapter 7.8.5</see>.
/// </summary>
enum class CacheAssociativity
{
Other = 1,
Unknown,
DirectMapped,
_2Way,
_4Way,
FullyAssociative,
_8Way,
_16Way,
_12Way,
_24Way,
_32Way,
_48Way,
_64Way,
_20Way,
ObjectIsNull
};
/// <summary>
/// Processor cache level.
/// </summary>
enum class CacheDesignation
{
Other,
L1,
L2,
L3,
ObjectIsNull
};
/// <summary>
/// Memory type.
/// </summary>
enum class MemoryType
{
Other = 0x01,
Unknown = 0x02,
DRAM = 0x03,
EDRAM = 0x04,
VRAM = 0x05,
SRAM = 0x06,
RAM = 0x07,
ROM = 0x08,
FLASH = 0x09,
EEPROM = 0x0a,
FEPROM = 0x0b,
EPROM = 0x0c,
CDRAM = 0x0d,
_3DRAM = 0x0e,
SDRAM = 0x0f,
SGRAM = 0x10,
RDRAM = 0x11,
DDR = 0x12,
DDR2 = 0x13,
DDR2_FBDIMM = 0x14,
DDR3 = 0x18,
FBD2 = 0x19,
DDR4 = 0x1a,
LPDDR = 0x1b,
LPDDR2 = 0x1c,
LPDDR3 = 0x1d,
LPDDR4 = 0x1e,
LogicalNonVolatileDevice = 0x1f,
HBM = 0x20,
HBM2 = 0x21,
DDR5 = 0x22,
LPDDR5 = 0x23,
ObjectIsNull
};

View File

@ -0,0 +1,83 @@
#pragma once
#include <ctime>
#include "Hardware.h"
#include "Identifier.h"
#include "Parameter.h"
#include <vector>
#include "Control.h"
#include "dll_macro.h"
class Visitor;
struct innerSensor;
class DLL_API SensorValue {
public:
SensorValue(float value, time_t time) {
this->value = value;
this->timestamp = time;
}
time_t getTimestamp() {
return timestamp;
}
bool operator==(const SensorValue& other) const {
return (this->value == other.value) && (this->timestamp == other.timestamp);
}
float getValue() {
return value;
}
private:
time_t timestamp;
float value;
};
enum class SensorType
{
Voltage, // V
Current, // A
Power, // W
Clock, // MHz
Temperature, // °C
Load, // %
Frequency, // Hz
Fan, // RPM
Flow, // L/h
Control, // %
Level, // %
Factor, // 1
Data, // GB = 2^30 Bytes
SmallData, // MB = 2^20 Bytes
Throughput, // B/s
TimeSpan, // Seconds
Energy, // milliwatt-hour (mWh)
Noise, // dBA
Conductivity, // µS/cm
Humidity, // %
ObjectIsNull
};
class DLL_API Sensor {
public:
Sensor(std::shared_ptr<innerSensor> inner);
~Sensor();
bool isNull() const;
bool operator==(const Sensor& other) const;
float getMax();//如果是null返回FLT_MIN即float最小值
float getMin();//如果是null返回FLT_MAX即float最大值
std::vector<SensorValue> getValues();
SensorType getType();
float getValue();
//需自行delete[]
char* getName();
std::vector<Parameter> getParameters();
time_t getTimeSpan();
void resetMin();
void resetMax();
void clearValues();
void Accept(Visitor* visitor);
void Traverse(Visitor* visitor);
Hardware getHardware();
Identifier getIdentifier();
bool isDefaultHidden();
int getIndex();
CsControl getControl();
private:
std::shared_ptr<innerSensor> inner;
};

View File

@ -0,0 +1,24 @@
#pragma once
#ifdef DLL_EXPORT
#define DLL_API __declspec(dllexport)
#else
#define DLL_API __declspec(dllimport)
#endif
#include <memory>
#include <string>
struct innerSettings;
class DLL_API Settings {
public:
Settings(std::shared_ptr<innerSettings>);
virtual bool isNull() const;
virtual bool Contains(char*);
virtual void SetValue(char*, char*);
virtual std::string GetValue(char*, char*);
virtual void Remove(char*);
virtual std::shared_ptr<innerSettings> getInner();
virtual void setInner(std::shared_ptr<innerSettings>);
private:
std::shared_ptr<innerSettings> inner=nullptr;
};

View File

@ -0,0 +1,36 @@
#pragma once
#include "dll_macro.h"
#include "IComputer.h"
#include "Hardware.h"
class Sensor;
#include "Parameter.h"
struct innerVisitor;
class VisitorCallBacks;
typedef void (*VisitComputerDelegate)(IComputer& computer, Visitor* visitor);
typedef void (*VisitHardwareDelegate)(Hardware& hardware, Visitor* visitor);
typedef void (*VisitSensorDelegate)(Sensor& sensor, Visitor* visitor);
typedef void (*VisitParameterDelegate)(Parameter& parameter, Visitor* visitor);
class DLL_API Visitor {
public:
Visitor();
void setVisitComputerCallBack(VisitComputerDelegate);
void setVisitHardwareCallBack(VisitHardwareDelegate);
void setVisitSensorCallBack(VisitSensorDelegate);
void setVisitParameterCallBack(VisitParameterDelegate);
void commit();
VisitComputerDelegate getVisitComputerCallBack();
VisitHardwareDelegate getVisitHardwareCallBack();
VisitSensorDelegate getVisitSensorCallBack();
VisitParameterDelegate getVisitParameterCallBack();
innerVisitor* getInner();
protected:
innerVisitor* inner;
VisitComputerDelegate visitComputerCallBack;
VisitHardwareDelegate visitHardwareCallBack;
VisitSensorDelegate visitSensorCallBack;
VisitParameterDelegate visitParameterCallBack;
};

View File

@ -0,0 +1,6 @@
#pragma once
#ifdef DLL_EXPORT
#define DLL_API __declspec(dllexport)
#else
#define DLL_API __declspec(dllimport)
#endif

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,17 @@
ImageRuntimeVersion: v4.0.30319
Assembly LibreHardwareManagerManaged2, Version=1.0.*, Culture=固定语言(固定国家/地区):
hash=SHA1, flags=PublicKey
Assembly mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089:
hash=None, flags=None
Assembly Aga.Controls, Version=1.7.*, Culture=固定语言(固定国家/地区):
hash=None, flags=None
Assembly LibreHardwareMonitorLib, Version=0.9.*, Culture=固定语言(固定国家/地区):
hash=None, flags=None
Assembly System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089:
hash=None, flags=None
Assembly System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089:
hash=None, flags=None
Assembly System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089:
hash=None, flags=None
Class LibreHardwareManagerManaged2.Class1: AutoLayout, AnsiClass, Class, Public, BeforeFieldInit
Void .ctor(): PrivateScope, Public, HideBySig, SpecialName, RTSpecialName

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 35 KiB

View File

@ -0,0 +1,134 @@
#include "include.h"
#pragma comment(lib, "wbemuuid.lib")
Napi::Value mem_used_size(const Napi::CallbackInfo& info){
Napi::Env env = info.Env();
for (Hardware hardware:computer->getHardware()){
if(hardware.getHardwareType()==HardwareType::Memory){
for(Sensor sen:hardware.getSensors()){
char *name=sen.getName();
if(sen.getType()==SensorType::Data && (strcmp(name, "Memory Used")==0)){
delete[] name;
return Napi::Number::New(env, sen.getValue());
}
delete[] name;
}
}
}
return env.Null();
}
Napi::Value vmem_used_size(const Napi::CallbackInfo& info){
Napi::Env env = info.Env();
for (Hardware hardware:computer->getHardware()){
if(hardware.getHardwareType()==HardwareType::Memory){
for(Sensor sen:hardware.getSensors()){
char *name=sen.getName();
if(sen.getType()==SensorType::Data && (strcmp(name, "Virtual Memory Used")==0)){
delete[] name;
return Napi::Number::New(env, sen.getValue());
}
delete[] name;
}
}
}
return env.Null();
}
Napi::Value mem_free_size(const Napi::CallbackInfo& info){
Napi::Env env = info.Env();
for (Hardware hardware:computer->getHardware()){
if(hardware.getHardwareType()==HardwareType::Memory){
for(Sensor sen:hardware.getSensors()){
char *name=sen.getName();
if(sen.getType()==SensorType::Data && (strcmp(name, "Memory Available")==0)){
delete[] name;
return Napi::Number::New(env, sen.getValue());
}
delete[] name;
}
}
}
return env.Null();
}
Napi::Value vmem_free_size(const Napi::CallbackInfo& info){
Napi::Env env = info.Env();
for (Hardware hardware:computer->getHardware()){
if(hardware.getHardwareType()==HardwareType::Memory){
for(Sensor sen:hardware.getSensors()){
char *name=sen.getName();
if(sen.getType()==SensorType::Data && (strcmp(name, "Virtual Memory Available")==0)){
delete[] name;
return Napi::Number::New(env, sen.getValue());
}
delete[] name;
}
}
}
return env.Null();
}
Napi::Value mem_clock(const Napi::CallbackInfo& info){
Napi::Env env = info.Env();
for (Hardware hardware:computer->getHardware()){
if(hardware.getHardwareType()==HardwareType::Memory){
for(Sensor sen:hardware.getSensors()){
if(sen.getType()==SensorType::Clock){
return Napi::Number::New(env, sen.getValue());
}
}
}
}
return env.Null();
}
Napi::Value mem_size(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
HRESULT hr;
IWbemLocator* pLoc = nullptr;
hr = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&pLoc);
IWbemServices* pSvc = nullptr;
hr = pLoc->ConnectServer(_bstr_t(L"ROOT\\CIMV2"), nullptr, nullptr, 0, NULL, 0, 0, &pSvc);
hr = CoSetProxyBlanket(pSvc, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, nullptr, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, nullptr, EOAC_NONE);
// 查询总容量
IEnumWbemClassObject* pEnumerator = nullptr;
hr = pSvc->ExecQuery(_bstr_t(L"WQL"), _bstr_t(L"SELECT Capacity FROM Win32_PhysicalMemory"), WBEM_FLAG_FORWARD_ONLY, nullptr, &pEnumerator);
ULONG uReturn = 0;
IWbemClassObject* pObj = nullptr;
DWORD totalCapacity = 0;
while (pEnumerator->Next(WBEM_INFINITE, 1, &pObj, &uReturn) == S_OK) {
VARIANT vtCapacity;
hr = pObj->Get(L"Capacity", 0, &vtCapacity, nullptr, nullptr);
totalCapacity += vtCapacity.ullVal / (1024 * 1024 * 1024); // 转换为GB
VariantClear(&vtCapacity);
pObj->Release();
}
pSvc->Release();
pLoc->Release();
return Napi::Number::New(env, totalCapacity);
}
Napi::String mem_name(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
for (Hardware hardware:computer->getHardware()){
if(hardware.getHardwareType()==HardwareType::Memory){
return Napi::String::New(env, hardware.Name());
}
}
return Napi::String::New(env, "");
}

View File

@ -0,0 +1,22 @@
#include "include.h"
#include <Windows.h>
#include <string.h>
Napi::Array monitor_info(const Napi::CallbackInfo& info){
Napi::Env env=info.Env();
int i=0;
DISPLAY_DEVICE device;
Napi::Array array;
for(int i=0;i<EnumDisplayDevices(NULL, i, &device, EDD_GET_DEVICE_INTERFACE_NAME);i++){
DEVMODE settings;
EnumDisplaySettings(device.DeviceName, ENUM_CURRENT_SETTINGS, &settings);
Napi::Object deviceObj;
deviceObj.Set<DWORD>("pixWidth",settings.dmPelsWidth);
deviceObj.Set<DWORD>("pixHeight",settings.dmPelsHeight);
deviceObj.Set<DWORD>("colorDepth",settings.dmBitsPerPel);
deviceObj.Set<DWORD>("freq",settings.dmDisplayFrequency);
array.Set<Napi::Object>(i, deviceObj);
}
i++;
return array;
}

View File

@ -0,0 +1,31 @@
#include "include.h"
Napi::Array disk_name(const Napi::CallbackInfo& info){
Napi::Env env = info.Env();
Napi::Array array;
int i=0;
for (Hardware hardware:computer->getHardware()){
if(hardware.getHardwareType()==HardwareType::Storage){
Napi::String str2= Napi::String::New(env,hardware.Name());
array.Set(i, str2);
i++;
}
}
return array;
}
Napi::Array current_disk_used(const Napi::CallbackInfo& info){
Napi::Env env = info.Env();
Napi::Array myarray=Napi::Array::New(env);
std::vector<Hardware> hardwares=computer->getHardware();
for (int i=0;i<hardwares.size();i++){
if(hardwares[i].getHardwareType()==HardwareType::Storage){
Napi::Object object=Napi::Object::New(env);
std::string name_str=hardwares[i].Name();
for(Sensor sen:hardwares[i].getSensors()){
if(sen.getType()==SensorType::Load && name_str=="Used Space"){
myarray.Set<float>(i, sen.getValue());
}
}
}
}
return myarray;
}

View File

@ -0,0 +1,18 @@
{
"name": "hardwaremonitor",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"install": "node-gyp configure && node-gyp build"
},
"private": true,
"keywords": [],
"author": "",
"license": "ISC",
"gypfile": true,
"description": "",
"dependencies": {
"node-addon-api": "^8.3.1"
}
}

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

51
index.js Normal file
View File

@ -0,0 +1,51 @@
"use strict";
const electron = require("electron");
const path = require("path");
const utils = require("@electron-toolkit/utils");
const hardware_monitor = require("./hardware_monitor.node");
const icon = path.join(__dirname, "../../resources/hardware_monitor/icon.png");
function handleQueryCpuName() {
return hardware_monitor.cpu_temperature();
}
function createWindow() {
const mainWindow = new electron.BrowserWindow({
width: 900,
height: 670,
show: false,
autoHideMenuBar: true,
...process.platform === "linux" ? { icon } : {},
webPreferences: {
preload: path.join(__dirname, "../preload/index.js"),
sandbox: false
}
});
mainWindow.on("ready-to-show", () => {
mainWindow.show();
});
mainWindow.webContents.setWindowOpenHandler((details) => {
electron.shell.openExternal(details.url);
return { action: "deny" };
});
if (utils.is.dev && process.env["ELECTRON_RENDERER_URL"]) {
mainWindow.loadURL(process.env["ELECTRON_RENDERER_URL"]);
} else {
mainWindow.loadFile(path.join(__dirname, "../renderer/index.html"));
}
}
electron.app.whenReady().then(() => {
electron.ipcMain.handle("queryCpuName", handleQueryCpuName);
utils.electronApp.setAppUserModelId("com.electron");
electron.app.on("browser-window-created", (_, window) => {
utils.optimizer.watchWindowShortcuts(window);
});
electron.ipcMain.on("ping", () => console.log("pong"));
createWindow();
electron.app.on("activate", function() {
if (electron.BrowserWindow.getAllWindows().length === 0) createWindow();
});
});
electron.app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
electron.app.quit();
}
});

609
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,7 @@
"typecheck:web": "vue-tsc --noEmit -p tsconfig.web.json --composite false", "typecheck:web": "vue-tsc --noEmit -p tsconfig.web.json --composite false",
"typecheck": "npm run typecheck:node && npm run typecheck:web", "typecheck": "npm run typecheck:node && npm run typecheck:web",
"start": "electron-vite preview", "start": "electron-vite preview",
"dev": "electron-vite dev", "dev": "cd hardware_monitor_wrapper && npx electron-rebuild -v 35.1.5 && cd .. && electron-vite dev",
"build": "npm run typecheck && electron-vite build", "build": "npm run typecheck && electron-vite build",
"postinstall": "electron-builder install-app-deps", "postinstall": "electron-builder install-app-deps",
"build:unpack": "npm run build && electron-builder --dir", "build:unpack": "npm run build && electron-builder --dir",
@ -23,6 +23,8 @@
"dependencies": { "dependencies": {
"@electron-toolkit/preload": "^3.0.1", "@electron-toolkit/preload": "^3.0.1",
"@electron-toolkit/utils": "^4.0.0", "@electron-toolkit/utils": "^4.0.0",
"@electron/rebuild": "^4.0.1",
"electron-log": "^5.4.0",
"vue-router": "^4.5.1" "vue-router": "^4.5.1"
}, },
"devDependencies": { "devDependencies": {

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -3,6 +3,8 @@ Assembly LibreHardwareManagerManaged2, Version=1.0.*, Culture=固定语言(固
hash=SHA1, flags=PublicKey hash=SHA1, flags=PublicKey
Assembly mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089: Assembly mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089:
hash=None, flags=None hash=None, flags=None
Assembly Aga.Controls, Version=1.7.*, Culture=固定语言(固定国家/地区):
hash=None, flags=None
Assembly LibreHardwareMonitorLib, Version=0.9.*, Culture=固定语言(固定国家/地区): Assembly LibreHardwareMonitorLib, Version=0.9.*, Culture=固定语言(固定国家/地区):
hash=None, flags=None hash=None, flags=None
Assembly System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089: Assembly System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089:

View File

@ -108,15 +108,8 @@
Support for the NZXT GRID+ V3 devices. Support for the NZXT GRID+ V3 devices.
</summary> </summary>
</member> </member>
<member name="T:LibreHardwareMonitor.Hardware.Controller.Nzxt.KrakenV2">
<summary>
Support for the Kraken X (X42, X52, X62 or X72) devices.
</summary>
</member>
<member name="T:LibreHardwareMonitor.Hardware.Controller.Nzxt.KrakenV3"> <member name="T:LibreHardwareMonitor.Hardware.Controller.Nzxt.KrakenV3">
<summary> Support for the KrakenZ devices from NZXT
Support for the KrakenZ devices.
</summary>
</member> </member>
<member name="M:LibreHardwareMonitor.Hardware.Cpu.CpuId.#ctor(System.Int32,System.Int32,LibreHardwareMonitor.Hardware.GroupAffinity)"> <member name="M:LibreHardwareMonitor.Hardware.Cpu.CpuId.#ctor(System.Int32,System.Int32,LibreHardwareMonitor.Hardware.GroupAffinity)">
<summary> <summary>
@ -152,19 +145,6 @@
Sets the default fan speed. Sets the default fan speed.
</summary> </summary>
</member> </member>
<member name="M:LibreHardwareMonitor.Hardware.Gpu.AmdGpu.GetAdlSensor(LibreHardwareMonitor.Interop.AtiAdlxx.ADLPMLogData,LibreHardwareMonitor.Interop.AtiAdlxx.ADLPMLogDataOutput,LibreHardwareMonitor.Interop.AtiAdlxx.ADLPMLogSensors,LibreHardwareMonitor.Hardware.Sensor,System.Single,System.Boolean)">
<summary>
Gets a sensor value.
</summary>
<param name="adlPMLogData">Current pmlog struct, used with pmlog-support/start.</param>
<param name="od8Log">Legacy pmlogdataoutput struct, used with ADL2_New_QueryPMLogData_Get.</param>
<param name="sensorType">Type of the sensor.</param>
<param name="sensor">The sensor.</param>
<param name="factor">The factor.</param>
<param name="reset">If set to <c>true</c>, resets the sensor value to <c>null</c>.</param>
<returns>true if sensor is supported, false otherwise</returns>
</member>
<member name="M:LibreHardwareMonitor.Hardware.Gpu.AmdGpu.GetODNTemperature(LibreHardwareMonitor.Interop.AtiAdlxx.ADLODNTemperatureType,LibreHardwareMonitor.Hardware.Sensor,System.Double,System.Double,System.Boolean)"> <member name="M:LibreHardwareMonitor.Hardware.Gpu.AmdGpu.GetODNTemperature(LibreHardwareMonitor.Interop.AtiAdlxx.ADLODNTemperatureType,LibreHardwareMonitor.Hardware.Sensor,System.Double,System.Double,System.Boolean)">
<summary> <summary>
Gets the OverdriveN temperature. Gets the OverdriveN temperature.
@ -175,6 +155,16 @@
<param name="scale">The scale.</param> <param name="scale">The scale.</param>
<param name="reset">If set to <c>true</c>, resets the sensor value to <c>null</c>.</param> <param name="reset">If set to <c>true</c>, resets the sensor value to <c>null</c>.</param>
</member> </member>
<member name="M:LibreHardwareMonitor.Hardware.Gpu.AmdGpu.GetPMLog(LibreHardwareMonitor.Interop.AtiAdlxx.ADLPMLogDataOutput,LibreHardwareMonitor.Interop.AtiAdlxx.ADLSensorType,LibreHardwareMonitor.Hardware.Sensor,System.Single,System.Boolean)">
<summary>
Gets a PMLog sensor value.
</summary>
<param name="data">The data.</param>
<param name="sensorType">Type of the sensor.</param>
<param name="sensor">The sensor.</param>
<param name="factor">The factor.</param>
<param name="reset">If set to <c>true</c>, resets the sensor value to <c>null</c>.</param>
</member>
<member name="M:LibreHardwareMonitor.Hardware.Gpu.AmdGpu.GetOD6Power(LibreHardwareMonitor.Interop.AtiAdlxx.ADLODNCurrentPowerType,LibreHardwareMonitor.Hardware.Sensor)"> <member name="M:LibreHardwareMonitor.Hardware.Gpu.AmdGpu.GetOD6Power(LibreHardwareMonitor.Interop.AtiAdlxx.ADLODNCurrentPowerType,LibreHardwareMonitor.Hardware.Sensor)">
<summary> <summary>
Gets the Overdrive6 power. Gets the Overdrive6 power.
@ -446,14 +436,6 @@
<param name="identifier">Base identifier being the beginning of the new one.</param> <param name="identifier">Base identifier being the beginning of the new one.</param>
<param name="extensions">Additional parts by which the base <see cref="T:LibreHardwareMonitor.Hardware.Identifier" /> will be extended.</param> <param name="extensions">Additional parts by which the base <see cref="T:LibreHardwareMonitor.Hardware.Identifier" /> will be extended.</param>
</member> </member>
<member name="M:LibreHardwareMonitor.Hardware.Identifier.#ctor(HidSharp.HidDevice)">
<summary>
Creates a new identifier instance based on the supplied <see cref="T:HidSharp.HidDevice" />.
If available the identifier will consist of the vendor-id, product-id and serial number of the HidDevice.
Alternatively a platform dependent identifier based on the usb device-path is generated.
</summary>
<param name="dev">The <see cref="T:HidSharp.HidDevice" /> this identifier will be created for.</param>
</member>
<member name="M:LibreHardwareMonitor.Hardware.Identifier.CompareTo(LibreHardwareMonitor.Hardware.Identifier)"> <member name="M:LibreHardwareMonitor.Hardware.Identifier.CompareTo(LibreHardwareMonitor.Hardware.Identifier)">
<inheritdoc /> <inheritdoc />
</member> </member>
@ -802,9 +784,6 @@
<member name="F:LibreHardwareMonitor.Hardware.Motherboard.Lpc.EC.EmbeddedController.ECSensor.TempTSensor"> <member name="F:LibreHardwareMonitor.Hardware.Motherboard.Lpc.EC.EmbeddedController.ECSensor.TempTSensor">
<summary>"T_Sensor" temperature sensor reading [℃]</summary> <summary>"T_Sensor" temperature sensor reading [℃]</summary>
</member> </member>
<member name="F:LibreHardwareMonitor.Hardware.Motherboard.Lpc.EC.EmbeddedController.ECSensor.TempTSensor2">
<summary>"T_Sensor 2" temperature sensor reading [℃]</summary>
</member>
<member name="F:LibreHardwareMonitor.Hardware.Motherboard.Lpc.EC.EmbeddedController.ECSensor.TempVrm"> <member name="F:LibreHardwareMonitor.Hardware.Motherboard.Lpc.EC.EmbeddedController.ECSensor.TempVrm">
<summary>VRM temperature [℃]</summary> <summary>VRM temperature [℃]</summary>
</member> </member>
@ -848,7 +827,7 @@
different for each motherboard model. different for each motherboard model.
</remarks> </remarks>
</member> </member>
<member name="T:LibreHardwareMonitor.Hardware.Motherboard.Lpc.IsaBridgeGigabyteController"> <member name="T:LibreHardwareMonitor.Hardware.Motherboard.Lpc.GigabyteController">
<summary> <summary>
This is a controller present on some Gigabyte motherboards for both Intel and AMD, that is in custom firmware This is a controller present on some Gigabyte motherboards for both Intel and AMD, that is in custom firmware
loaded onto the 2nd ITE EC. loaded onto the 2nd ITE EC.
@ -856,19 +835,19 @@
This class can disable it so that the regular IT87XX code can drive the fans. This class can disable it so that the regular IT87XX code can drive the fans.
</summary> </summary>
</member> </member>
<member name="F:LibreHardwareMonitor.Hardware.Motherboard.Lpc.IsaBridgeGigabyteController._controllerBaseAddress"> <member name="F:LibreHardwareMonitor.Hardware.Motherboard.Lpc.GigabyteController._controllerBaseAddress">
<summary> <summary>
Base address in PCI RAM that maps to the EC's RAM Base address in PCI RAM that maps to the EC's RAM
</summary> </summary>
</member> </member>
<member name="M:LibreHardwareMonitor.Hardware.Motherboard.Lpc.IsaBridgeGigabyteController.Enable(System.Boolean)"> <member name="M:LibreHardwareMonitor.Hardware.Motherboard.Lpc.GigabyteController.Enable(System.Boolean)">
<summary> <summary>
Enable/Disable Fan Control Enable/Disable Fan Control
</summary> </summary>
<param name="enabled"></param> <param name="enabled"></param>
<returns>true on success</returns> <returns>true on success</returns>
</member> </member>
<member name="M:LibreHardwareMonitor.Hardware.Motherboard.Lpc.IsaBridgeGigabyteController.Restore"> <member name="M:LibreHardwareMonitor.Hardware.Motherboard.Lpc.GigabyteController.Restore">
<summary> <summary>
Restore settings back to initial values Restore settings back to initial values
</summary> </summary>
@ -1471,9 +1450,7 @@
</member> </member>
<member name="P:LibreHardwareMonitor.Hardware.MemoryDevice.Size"> <member name="P:LibreHardwareMonitor.Hardware.MemoryDevice.Size">
<summary> <summary>
Gets the size of the memory device. Gets the size of the memory device. If the value is 0, no memory device is installed in the socket.
If the value is 0, no memory device is installed in the socket.
If the value is 0xFFFF, the size is unknown.
</summary> </summary>
</member> </member>
<member name="P:LibreHardwareMonitor.Hardware.MemoryDevice.Speed"> <member name="P:LibreHardwareMonitor.Hardware.MemoryDevice.Speed">
@ -1771,63 +1748,6 @@
There's no Linux XDisplay in Linux Console environment. There's no Linux XDisplay in Linux Console environment.
</summary> </summary>
</member> </member>
<member name="F:LibreHardwareMonitor.Interop.AtiAdlxx.ADLPMLogSupportInfo.usSensors">
list of sensors defined by ADL_PMLOG_SENSORS
</member>
<member name="F:LibreHardwareMonitor.Interop.AtiAdlxx.ADLPMLogSupportInfo.iReserved">
Reserved
</member>
<member name="F:LibreHardwareMonitor.Interop.AtiAdlxx.ADLPMLogStartInput.usSensors">
list of sensors defined by ADL_PMLOG_SENSORS
</member>
<member name="F:LibreHardwareMonitor.Interop.AtiAdlxx.ADLPMLogStartInput.ulSampleRate">
Sample rate in milliseconds
</member>
<member name="F:LibreHardwareMonitor.Interop.AtiAdlxx.ADLPMLogStartInput.iReserved">
Reserved
</member>
<member name="F:LibreHardwareMonitor.Interop.AtiAdlxx.ADLPMLogStartOutput.pLoggingAddress">
Pointer to memory address containing logging data
</member>
<member name="F:LibreHardwareMonitor.Interop.AtiAdlxx.ADLPMLogData.ulVersion">
Structure version
</member>
<member name="F:LibreHardwareMonitor.Interop.AtiAdlxx.ADLPMLogData.ulActiveSampleRate">
Current driver sample rate
</member>
<member name="F:LibreHardwareMonitor.Interop.AtiAdlxx.ADLPMLogData.ulLastUpdated">
Timestamp of last update
</member>
<member name="F:LibreHardwareMonitor.Interop.AtiAdlxx.ADLPMLogData.ulReserved">
Reserved
</member>
<member name="F:LibreHardwareMonitor.Interop.AtiAdlxx.ADLMemoryInfoX4.iMemorySize">
Memory size in bytes.
</member>
<member name="F:LibreHardwareMonitor.Interop.AtiAdlxx.ADLMemoryInfoX4.strMemoryType">
Memory type in string.
</member>
<member name="F:LibreHardwareMonitor.Interop.AtiAdlxx.ADLMemoryInfoX4.iMemoryBandwidth">
Highest default performance level Memory bandwidth in Mbytes/s
</member>
<member name="F:LibreHardwareMonitor.Interop.AtiAdlxx.ADLMemoryInfoX4.iHyperMemorySize">
HyperMemory size in bytes.
</member>
<member name="F:LibreHardwareMonitor.Interop.AtiAdlxx.ADLMemoryInfoX4.iInvisibleMemorySize">
Invisible Memory size in bytes.
</member>
<member name="F:LibreHardwareMonitor.Interop.AtiAdlxx.ADLMemoryInfoX4.iVisibleMemorySize">
Visible Memory size in bytes.
</member>
<member name="F:LibreHardwareMonitor.Interop.AtiAdlxx.ADLMemoryInfoX4.iVramVendorRevId">
Vram vendor ID
</member>
<member name="F:LibreHardwareMonitor.Interop.AtiAdlxx.ADLMemoryInfoX4.iMemoryBandwidthX2">
Memory Bandiwidth that is calculated and finalized on the driver side, grab and go.
</member>
<member name="F:LibreHardwareMonitor.Interop.AtiAdlxx.ADLMemoryInfoX4.iMemoryBitRateX2">
Memory Bit Rate that is calculated and finalized on the driver side, grab and go.
</member>
<member name="F:LibreHardwareMonitor.Interop.Kernel32.NVME_CRITICAL_WARNING.AvailableSpaceLow"> <member name="F:LibreHardwareMonitor.Interop.Kernel32.NVME_CRITICAL_WARNING.AvailableSpaceLow">
<summary> <summary>
If set to 1, then the available spare space has fallen below the threshold. If set to 1, then the available spare space has fallen below the threshold.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

View File

@ -1,11 +1,17 @@
import { app, shell, BrowserWindow, ipcMain } from 'electron' import { app, shell, BrowserWindow, ipcMain } from 'electron'
import { join } from 'path' import { join } from 'path'
import { electronApp, optimizer, is } from '@electron-toolkit/utils' import { electronApp, optimizer, is } from '@electron-toolkit/utils'
import icon from '../../resources/icon.png?asset' import icon from '../../resources/hardware_monitor/icon.png?asset'
import hardware_monitor from '../../resources/hardware_monitor/hardware_monitor.node' const log = require('electron-log');
console.log(log.transports.file.getFile().path);
log.transports.console.level = 'debug'
import hardware_monitor from '../hardware_monitor.node'
function handleQueryCpuName () { function handleQueryCpuName () {
hardware_monitor.cpu_name() return hardware_monitor.name()
} }
process.on('uncaughtException', (error) => {
log.error('未捕获异常:', error);
});
function createWindow(): void { function createWindow(): void {
// Create the browser window. // Create the browser window.
const mainWindow = new BrowserWindow({ const mainWindow = new BrowserWindow({
@ -42,7 +48,7 @@ function createWindow(): void {
// initialization and is ready to create browser windows. // initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs. // Some APIs can only be used after this event occurs.
app.whenReady().then(() => { app.whenReady().then(() => {
//ipcMain.handle('queryCpuName', handleQueryCpuName) ipcMain.handle('queryCpuName', handleQueryCpuName)
// Set app user model id for windows // Set app user model id for windows
electronApp.setAppUserModelId('com.electron') electronApp.setAppUserModelId('com.electron')