/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.profesorfalken.jsensors.manager.windows;

/**
 *
 * @author Javier
 */
class PowerShellScriptHelper {
    static String dllImport() {
        return "[System.Reflection.Assembly]::LoadFile(\"c:\\OpenHardwareMonitorLib.dll\")"
                + " | Out-Null";
    }
    
    static String newComputerInstance() {
        StringBuilder code = new StringBuilder();
        
        code.append("$PC = New-Object OpenHardwareMonitor.Hardware.Computer");
        
        code.append("$PC.MainboardEnabled = $true");
        code.append("$PC.CPUEnabled = $true");
        code.append("$PC.RAMEnabled = $true");
        code.append("$PC.GPUEnabled = $true");
        code.append("$PC.FanControllerEnabled = $true");
        code.append("$PC.HDDEnabled = $true");

        return code.toString();
    }
    
    static String sensorsQueryLoop() {
        StringBuilder code = new StringBuilder();
        
        code.append("$PC.Open()");
        
        code.append("ForEach ($hw in $PC.Hardware)");
        code.append("{");
        code.append("$hw");
        code.append("$hw.Update()");
        code.append("ForEach ($subhw in $hw.SubHardware)");
        code.append("{");
        code.append("$subhw.Update()");
        code.append("}");
        code.append("ForEach ($sensor in $hw.Sensors)");
        code.append("{");
        code.append("$sensor");
        code.append("Write-Host \"\"");
        code.append("}");
        code.append("}");
        
        return code.toString();
    }
}

@@ -232,16 +232,127 @@
 ndows;%0A%0A
+import java.io.File;%0Aimport java.io.FileOutputStream;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0A%0A
 /**%0A *%0A 
@@ -496,74 +496,794 @@
 e(%5C%22
-c:%5C%5COpenHardwareMonitorLib.dll%5C%22)%22%0A                + %22 %7C Out-Null%22
+%22 + dllPath() + %22%5C%22)%22%0A                + %22 %7C Out-Null%22;%0A    %7D%0A    %0A    private static String dllPath() %7B%0A        String dllName = %22OpenHardwareMonitorLib.dll%22;%0A        InputStream in = PowerShellScriptHelper.class.getResourceAsStream(dllName);%0A        File tempFile;%0A        try %7B%0A            tempFile = File.createTempFile(dllName, %22%22);%0A            byte%5B%5D buffer = new byte%5B1024%5D;%0A            int read;%0A            FileOutputStream fos = new FileOutputStream(tempFile);            %0A            while((read = in.read(buffer)) != -1) %7B%0A                fos.write(buffer, 0, read);%0A            %7D%0A            fos.close();%0A            in.close();%0A        %7D catch (IOException ex) %7B%0A            //TODO: handle%0A            return %22%22;%0A        %7D%0A        %0A        return tempFile.getAbsolutePath()
 ;%0A  

Load dll path in script helper