/*
 * 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 de.nplusc.izc.InstallPak;

import de.nplusc.izc.tools.IOtools.FileTK;
import de.nplusc.izc.tools.IOtools.registryReader;
import de.nplusc.izc.tools.baseTools.Detectors;

/**
 *
 * @author LH
 */
public class SharedUtils
{
    public static  boolean checkCondition(String condition)
    {
        boolean conditionsClear = false;

        if (condition.equalsIgnoreCase("IsWin8"))
        {
            conditionsClear = Detectors.detectIsWin8();
        }
        if (condition.equalsIgnoreCase("Is64Bit") && !conditionsClear)
        {
            conditionsClear = Detectors.detect64bitWinon7and8();
        }
        if (condition.equalsIgnoreCase("IsWinXP") && !conditionsClear)
        {
            conditionsClear = Detectors.detectWInXP();
        }
        if (condition.equalsIgnoreCase("IsWin7") && !conditionsClear)
        {
            conditionsClear = Detectors.detectWin7();
        }
        if (condition.startsWith("PathExists:"))
        {
            conditionsClear = FileTK.checkDirExist(condition.substring(11));//kann zum Erkennen beliebiger Programme genutzt werden
        }
        if (condition.startsWith("RegKeyExists:"))
        {
            // prüft Registryeinträge//sollte hinter ne CheckWIndows geglemmt werden
            conditionsClear = registryReader.checkExistenceOfRegKey(condition.substring(13));
            if (!conditionsClear)
            {
                conditionsClear = registryReader.checkExistenceOfRegKeyEntry(condition.substring(13));
            }
        }
        return conditionsClear;
    }

    public static boolean detectInstall(String detecString)
    {
        if (detecString.substring(0, 7).equalsIgnoreCase("File://"))
        {
            String detecpart = detecString.substring(7);
            if (FileTK.checkDirExist(detecpart))
            {
                return true;
            }
        }
        if (detecString.substring(0, 6).equalsIgnoreCase("Reg://"))
        {
            String detecpart = detecString.substring(6);
            if (registryReader.checkExistenceOfRegKey(detecpart) || registryReader.checkExistenceOfRegKeyEntry(detecpart))
            {
                return true;
            }
        }
        return false;
    }

    private SharedUtils()
    {
    }
}
