All Downloads are FREE. Search and download functionalities are using the official Maven repository.

oshi.hardware.platform.windows.WindowsFirmware Maven / Gradle / Ivy

There is a newer version: 3.4.0
Show newest version
/**
 * Oshi (https://github.com/dblock/oshi)
 *
 * Copyright (c) 2010 - 2016 The Oshi Project Team
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Maintainers:
 * dblock[at]dblock[dot]org
 * widdis[at]gmail[dot]com
 * enrico.bianchi[at]gmail[dot]com
 *
 * Contributors:
 * https://github.com/dblock/oshi/graphs/contributors
 */
package oshi.hardware.platform.windows;

import java.time.Instant;
import java.time.ZoneOffset;
import java.util.List;
import java.util.Map;

import oshi.hardware.common.AbstractFirmware;
import oshi.util.platform.windows.WmiUtil;
import oshi.util.platform.windows.WmiUtil.ValueType;

/**
 * Firmware data obtained from WMI
 * 
 * @author SchiTho1 [at] Securiton AG
 */
final class WindowsFirmware extends AbstractFirmware {

    private static final long serialVersionUID = 1L;

    private static final ValueType[] BIOS_TYPES = { ValueType.STRING, ValueType.STRING, ValueType.STRING,
            ValueType.STRING, ValueType.DATETIME };

    WindowsFirmware() {
        init();
    }

    private void init() {

        final Map> win32BIOS = WmiUtil.selectObjectsFrom(null, "Win32_BIOS",
                "Manufacturer,Name,Description,Version,ReleaseDate", "where PrimaryBIOS=true", BIOS_TYPES);

        final List manufacturers = win32BIOS.get("Manufacturer");
        if (manufacturers != null && manufacturers.size() == 1) {
            setManufacturer((String) manufacturers.get(0));
        }

        final List names = win32BIOS.get("Name");
        if (names != null && names.size() == 1) {
            setName((String) names.get(0));
        }

        final List descriptions = win32BIOS.get("Description");
        if (descriptions != null && descriptions.size() == 1) {
            setDescription((String) descriptions.get(0));
        }

        final List version = win32BIOS.get("Version");
        if (version != null && version.size() == 1) {
            setVersion((String) version.get(0));
        }

        final List releaseDate = win32BIOS.get("ReleaseDate");
        if (releaseDate != null && releaseDate.size() == 1) {
            setReleaseDate(Instant.ofEpochMilli((Long) releaseDate.get(0)).atZone(ZoneOffset.UTC).toLocalDate());
        }
    }
}