
// WinSys.java
// Andrew Davison, ad@coe.psu.ac.th, Nov. 2022

/* Uses SystemInfo on Windows to get system configuration
   details. The data is stored in CSV format, which consists of
   two rows, one for the headers, one for the data. 
   ZUtils.buildMap() converts this into a map: headers->data

   SystemInfo details:
     * https://www.computerhope.com/systemin.htm
     * https://ss64.com/nt/systeminfo.html

    Usage:
      > compile WinSys.java
      > run WinSys
*/

import java.util.*;


public class WinSys
{
  public static void main(String[] args)
  {
    if (ZUtils.getOSType() != ZUtils.WINDOWS) {
      System.out.println("Not on Windows");
      return;
    }

    if ( ZUtils.cmdExit("systeminfo", "/?") != 0) {
      System.out.println("SystemInfo not present");
      return;
    }

    // collect systeminfo in CSV format
    String csvStr = ZUtils.cmdOut("systemInfo", "/fo", "csv");

    // build map of headers --> data
    TreeMap<String,String> sysMap = ZUtils.buildMap(csvStr);
    ZUtils.printMap(sysMap);   // comment this out if you don't want it

    // query the map
    String key = "BIOS Version";
    System.out.println("\n" + key + ": " + sysMap.get(key));

    key = "System Boot Time";
    System.out.println("\n" + key + ": " + sysMap.get(key));
  }
}  // end of WinSys class