# Path: image_creator/util.py
# class FatalError(Exception):
#     """Fatal Error exception of snf-image-creator"""
#     pass


import tempfile
import os
import struct
import hivex
from image_creator.util import FatalError
            0 => IMAGE_STATE_COMPLETE
            1 => IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE
            2 => IMAGE_STATE_GENERALIZE_RESEAL_TO_AUDIT
            3 => IMAGE_STATE_SPECIALIZE_RESEAL_TO_OOBE
            4 => IMAGE_STATE_SPECIALIZE_RESEAL_TO_AUDIT
        For more information check here:
            http://technet.microsoft.com/en-us/library/hh824815.aspx
        """

        with self.open_hive('SOFTWARE') as hive:
            # Navigate to:
            #   SOFTWARE/Microsoft/Windows/CurrentVersion/Setup/State
            state = hive.root()
            for child in ('Microsoft', 'Windows', 'CurrentVersion',
                          'Setup', 'State'):
                state = hive.node_get_child(state, child)

            image_state = hive.node_get_value(state, 'ImageState')
            vtype, value = hive.value_value(image_state)
            assert vtype == 1L, \
                "ImageState field type (=%d) is not REG_SZ" % vtype

            value = value.decode('utf-16le')

            ret = 0
            for known_state in WINDOWS_SETUP_STATES:
                if value == known_state + '\x00':  # REG_SZ is null-terminated
                    return ret
                ret += 1


# Path: image_creator/util.py
# class FatalError(Exception):
#     """Fatal Error exception of snf-image-creator"""
#     pass


# Path: image_creator/distro/windows/registry.py
import tempfile
import os
import struct
import hivex
from image_creator.util import FatalError

            0 => IMAGE_STATE_COMPLETE
            1 => IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE
            2 => IMAGE_STATE_GENERALIZE_RESEAL_TO_AUDIT
            3 => IMAGE_STATE_SPECIALIZE_RESEAL_TO_OOBE
            4 => IMAGE_STATE_SPECIALIZE_RESEAL_TO_AUDIT
        For more information check here:
            http://technet.microsoft.com/en-us/library/hh824815.aspx
        """

        with self.open_hive('SOFTWARE') as hive:
            # Navigate to:
            #   SOFTWARE/Microsoft/Windows/CurrentVersion/Setup/State
            state = hive.root()
            for child in ('Microsoft', 'Windows', 'CurrentVersion',
                          'Setup', 'State'):
                state = hive.node_get_child(state, child)

            image_state = hive.node_get_value(state, 'ImageState')
            vtype, value = hive.value_value(image_state)
            assert vtype == 1L, \
                "ImageState field type (=%d) is not REG_SZ" % vtype

            value = value.decode('utf-16le')

            ret = 0
            for known_state in WINDOWS_SETUP_STATES:
                if value == known_state + '\x00':  # REG_SZ is null-terminated
                    return ret
                ret += 1


        raise FatalError("Unknown Windows Setup State: %s" % value)