Fix memory only being available for Intel (#1887)
* Current implementation of PawnIo.LoadModuleFromResource swallows exceptions instead of throwing them like it has been previously. It also returns a not-null PawnIo object. RAMSPDToolkitDriver has been catching exception, returning false for LoadModule and checking if returned object is null. Therefore the return for a failed loaded module was true where it should have been false. Returning null from PawnIo.LoadModuleFromResource in catch block fixes this issue. * Add IsValid property for PawnIo and check in RAMSPDToolkitDriver. Remove null return. * Update RAMSPDToolkit to newest version. Fixes bug in .NET Framework and changed PawnIO interface due to adjusted Piix4 detection. Add new Data sensor. * Rename property.
This commit is contained in:
@@ -1,30 +1,49 @@
|
||||
using RAMSPDToolkit.I2CSMBus.Interop.PawnIO;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RAMSPDToolkit.I2CSMBus.Interop.PawnIO;
|
||||
using RAMSPDToolkit.Windows.Driver.Interfaces;
|
||||
|
||||
namespace LibreHardwareMonitor;
|
||||
|
||||
internal class RAMSPDToolkitDriver : IPawnIODriver
|
||||
internal sealed class RAMSPDToolkitDriver : IPawnIODriver
|
||||
{
|
||||
internal class PawnIOModule : IPawnIOModule, IDisposable
|
||||
{
|
||||
public PawnIOModule(PawnIo.PawnIo pawnIO)
|
||||
{
|
||||
_pawnIO = pawnIO;
|
||||
}
|
||||
|
||||
PawnIo.PawnIo _pawnIO;
|
||||
|
||||
public int Execute(string name, long[] inBuffer, uint inSize, long[] outBuffer, uint outSize, out uint returnSize)
|
||||
=> _pawnIO.ExecuteHr(name, inBuffer, inSize, outBuffer, outSize, out returnSize);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_pawnIO != null)
|
||||
{
|
||||
_pawnIO.Close();
|
||||
_pawnIO = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const string I801ModuleFilename = "SmbusI801.bin";
|
||||
const string Piix4ModuleFilename = "SmbusPIIX4.bin";
|
||||
const string Nct6793ModuleFilename = "SmbusNCT6793.bin";
|
||||
|
||||
private PawnIo.PawnIo _pawnIO;
|
||||
private List<PawnIOModule> _pawnIOModules = new();
|
||||
|
||||
public bool IsOpen => true;
|
||||
|
||||
public int Execute(string name, long[] inBuffer, uint inSize, long[] outBuffer, uint outSize, out uint returnSize)
|
||||
{
|
||||
return _pawnIO.ExecuteHr(name, inBuffer, inSize, outBuffer, outSize, out returnSize);
|
||||
}
|
||||
|
||||
public bool Load()
|
||||
{
|
||||
//Not required
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool LoadModule(PawnIOSMBusIdentifier pawnIOSMBusIdentifier)
|
||||
public IPawnIOModule LoadModule(PawnIOSMBusIdentifier pawnIOSMBusIdentifier)
|
||||
{
|
||||
string moduleResourceFilename = pawnIOSMBusIdentifier switch
|
||||
{
|
||||
@@ -36,23 +55,39 @@ internal class RAMSPDToolkitDriver : IPawnIODriver
|
||||
|
||||
if (moduleResourceFilename == null)
|
||||
{
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
PawnIOModule pawnIOModule = null;
|
||||
|
||||
try
|
||||
{
|
||||
_pawnIO = PawnIo.PawnIo.LoadModuleFromResource(typeof(RAMSPDToolkitDriver).Assembly, $"{nameof(LibreHardwareMonitor)}.Resources.PawnIO.{moduleResourceFilename}");
|
||||
var pawnIO = PawnIo.PawnIo.LoadModuleFromResource(typeof(RAMSPDToolkitDriver).Assembly, $"{nameof(LibreHardwareMonitor)}.Resources.PawnIO.{moduleResourceFilename}");
|
||||
|
||||
if (pawnIO.IsLoaded)
|
||||
{
|
||||
pawnIOModule = new PawnIOModule(pawnIO);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
return _pawnIO != null;
|
||||
if (pawnIOModule != null)
|
||||
{
|
||||
_pawnIOModules.Add(pawnIOModule);
|
||||
return pawnIOModule;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Unload()
|
||||
{
|
||||
_pawnIO.Close();
|
||||
_pawnIOModules.ForEach(p => p.Dispose());
|
||||
_pawnIOModules.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user