# -*- coding: utf-8 -*-
from setuphelpers import *
import platform

def install():
    bin_name = glob.glob("CrystalDiskInfo*.exe")[0]

    install_exe_if_needed(
        bin_name,
        silentflags="/silent /verysilent",
        key="CrystalDiskInfo_is1",
        min_version=control.get_software_version(),
    )

def audit():
    audit_status = "ERROR"

    # Interact differently with Luti
    if params.get("running_as_luti"):
        return "OK"

    app_path = ""

    if iswinarm():
        app_path = makepath(programfiles, "CrystalDiskInfo", "DiskInfoA64.exe")
    elif is32():
        app_path = makepath(programfiles, "CrystalDiskInfo", "DiskInfo32.exe")
    elif iswin64():
        app_path = makepath(programfiles, "CrystalDiskInfo", "DiskInfo64.exe")
    run('"%s" /CopyExit' % app_path)

    with open("C:/Program Files/CrystalDiskInfo/DiskInfo.txt", "r") as f:
        for ligne in f:
            if "Health Status" in ligne:
                if "Bon" in ligne:
                    audit_status = "OK"

    return audit_status

def iswinarm():
    return platform.machine()=='ARM64'