Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiue233 committed Dec 10, 2023
1 parent f138599 commit 773424b
Show file tree
Hide file tree
Showing 65 changed files with 1,057 additions and 0 deletions.
Binary file not shown.
Binary file added LegionInfoDLL/.vs/LegionInfoDLL/v17/.suo
Binary file not shown.
73 changes: 73 additions & 0 deletions LegionInfoDLL/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;

namespace LegionInfoDLL
{
public static class Fan
{
public static int GetFanSpeed(int fanID)
{
var speed = -1;
try// Get the client's SMS_Client class.
{
speed = Call("root\\WMI",
$"SELECT * FROM LENOVO_FAN_METHOD",
"Fan_GetCurrentFanSpeed",
new Dictionary<string, object>() { { "FanID", fanID } },
pdc => Convert.ToInt32(pdc["CurrentFanSpeed"].Value));
}
catch (Exception ignore)
{
return -1;
}
return speed;
}

private static T Call<T>(string scope, FormattableString query, string methodName, Dictionary<string, object> methodParams, Func<PropertyDataCollection, T> converter)
{
try
{
var queryFormatted = query.ToString(WMIPropertyValueFormatter.Instance);

var mos = new ManagementObjectSearcher(scope, queryFormatted);
var managementObject = mos.Get().Cast<ManagementBaseObject>().FirstOrDefault() ?? throw new InvalidOperationException("No results in query");

var mo = (ManagementObject)managementObject;
var methodParamsObject = mo.GetMethodParameters(methodName);
foreach (var pair in methodParams)
methodParamsObject[pair.Key] = pair.Value;

var resultProperties = mo.InvokeMethod(methodName, methodParamsObject, new InvokeMethodOptions());
var result = converter(resultProperties.Properties);
return result;
}
catch (ManagementException ex)
{
throw new ManagementException($"Call failed: {ex.Message}. [scope={scope}, query={query}, methodName={methodName}]", ex);
}
}

private class WMIPropertyValueFormatter : IFormatProvider, ICustomFormatter
{
public static readonly WMIPropertyValueFormatter Instance = new WMIPropertyValueFormatter();

private WMIPropertyValueFormatter() { }

public object GetFormat(Type formatType)
{
if (formatType == typeof(ICustomFormatter))
return this;

throw new InvalidOperationException("Invalid type of formatted");
}

public string Format(string format, object arg, IFormatProvider formatProvider)
{
var stringArg = arg?.ToString()?.Replace("\\", "\\\\");
return stringArg ?? string.Empty;
}
}
}
}
68 changes: 68 additions & 0 deletions LegionInfoDLL/LegionInfoDLL.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{C37E94F1-73B0-4FB1-9AAE-F5D533785F9D}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>LegionInfoDLL</RootNamespace>
<AssemblyName>LegionInfoDLL</AssemblyName>
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Management" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
31 changes: 31 additions & 0 deletions LegionInfoDLL/LegionInfoDLL.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34322.80
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LegionInfoDLL", "LegionInfoDLL.csproj", "{C37E94F1-73B0-4FB1-9AAE-F5D533785F9D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C37E94F1-73B0-4FB1-9AAE-F5D533785F9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C37E94F1-73B0-4FB1-9AAE-F5D533785F9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C37E94F1-73B0-4FB1-9AAE-F5D533785F9D}.Debug|x64.ActiveCfg = Debug|x64
{C37E94F1-73B0-4FB1-9AAE-F5D533785F9D}.Debug|x64.Build.0 = Debug|x64
{C37E94F1-73B0-4FB1-9AAE-F5D533785F9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C37E94F1-73B0-4FB1-9AAE-F5D533785F9D}.Release|Any CPU.Build.0 = Release|Any CPU
{C37E94F1-73B0-4FB1-9AAE-F5D533785F9D}.Release|x64.ActiveCfg = Release|x64
{C37E94F1-73B0-4FB1-9AAE-F5D533785F9D}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {53FA2AAC-8B47-4775-811D-4A12899625A0}
EndGlobalSection
EndGlobal
36 changes: 36 additions & 0 deletions LegionInfoDLL/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("LegionInfoDLL")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LegionInfoDLL")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("c37e94f1-73b0-4fb1-9aae-f5d533785f9d")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Binary file added LegionInfoDLL/bin/Debug/LegionInfoDLL.pdb
Binary file not shown.
Binary file added LegionInfoDLL/bin/x64/Debug/LegionInfoDLL.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5f6e7e3d846851f5ef04a1bb0e5300da5eceff0ee74dd83a7cb3dff536718092
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
D:\projects\vs\LegionInfoDLL\bin\Debug\LegionInfoDLL.dll
D:\projects\vs\LegionInfoDLL\bin\Debug\LegionInfoDLL.pdb
D:\projects\vs\LegionInfoDLL\obj\Debug\LegionInfoDLL.csproj.AssemblyReference.cache
D:\projects\vs\LegionInfoDLL\obj\Debug\LegionInfoDLL.csproj.CoreCompileInputs.cache
D:\projects\vs\LegionInfoDLL\obj\Debug\LegionInfoDLL.dll
D:\projects\vs\LegionInfoDLL\obj\Debug\LegionInfoDLL.pdb
Binary file added LegionInfoDLL/obj/Debug/LegionInfoDLL.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a961d9b8077c5584f75c109fee4e71700d1a6717be6a6d7609b7fde947f9621c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
D:\projects\vs\LegionInfoDLL\bin\x64\Debug\LegionInfoDLL.dll
D:\projects\vs\LegionInfoDLL\bin\x64\Debug\LegionInfoDLL.pdb
D:\projects\vs\LegionInfoDLL\obj\x64\Debug\LegionInfoDLL.csproj.AssemblyReference.cache
D:\projects\vs\LegionInfoDLL\obj\x64\Debug\LegionInfoDLL.csproj.CoreCompileInputs.cache
D:\projects\vs\LegionInfoDLL\obj\x64\Debug\LegionInfoDLL.dll
D:\projects\vs\LegionInfoDLL\obj\x64\Debug\LegionInfoDLL.pdb
Binary file added LegionInfoDLL/obj/x64/Debug/LegionInfoDLL.pdb
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 added LegionInfoPlugin/.vs/LegionInfoPlugin/v17/.suo
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions LegionInfoPlugin/InfoItem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "pch.h"
#include "InfoItem.h"

InfoItem::InfoItem(){}
34 changes: 34 additions & 0 deletions LegionInfoPlugin/InfoItem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once
#include "PluginInterface.h"
#include <string>

class InfoItem : public IPluginItem
{
public:
InfoItem();

const wchar_t* GetItemName() const override {
return itemName;
}
const wchar_t* GetItemId() const override {
return itemId;
}
const wchar_t* GetItemLableText() const override {
return itemLableText;
}
const wchar_t* GetItemValueText() const override {
return itemValueText.c_str();
}
const wchar_t* GetItemValueSampleText() const override {
return itemValueSampleText;
}
bool IsCustomDraw() const override {
return false;
}

const wchar_t* itemName;
const wchar_t* itemId;
const wchar_t* itemLableText;
std::wstring itemValueText;
const wchar_t* itemValueSampleText;
};
31 changes: 31 additions & 0 deletions LegionInfoPlugin/LegionInfoPlugin.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34322.80
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LegionInfoPlugin", "LegionInfoPlugin.vcxproj", "{14E138BC-22AB-45E8-9341-6E8D9291EF40}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{14E138BC-22AB-45E8-9341-6E8D9291EF40}.Debug|x64.ActiveCfg = Debug|x64
{14E138BC-22AB-45E8-9341-6E8D9291EF40}.Debug|x64.Build.0 = Debug|x64
{14E138BC-22AB-45E8-9341-6E8D9291EF40}.Debug|x86.ActiveCfg = Debug|Win32
{14E138BC-22AB-45E8-9341-6E8D9291EF40}.Debug|x86.Build.0 = Debug|Win32
{14E138BC-22AB-45E8-9341-6E8D9291EF40}.Release|x64.ActiveCfg = Release|x64
{14E138BC-22AB-45E8-9341-6E8D9291EF40}.Release|x64.Build.0 = Release|x64
{14E138BC-22AB-45E8-9341-6E8D9291EF40}.Release|x86.ActiveCfg = Release|Win32
{14E138BC-22AB-45E8-9341-6E8D9291EF40}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1D7324D2-C76F-4107-A4E9-7DD4017740C0}
EndGlobalSection
EndGlobal
Loading

0 comments on commit 773424b

Please sign in to comment.