'Obtains information on CHM archive.
This function checks the /#SYSTEM file inside the CHM archive to
obtain the index, home page, topics, encoding and title. It is called
from LoadCHM.'

def GetArchiveInfo(self):

    self.searchable = False
    self.lcid = None
    (result, ui) = chmlib.chm_resolve_object(self.file, '/#SYSTEM')
    if (result != chmlib.CHM_RESOLVE_SUCCESS):
        sys.stderr.write('GetArchiveInfo:    #SYSTEM    does    not    exist\n')
        return 0
    (size, text) = chmlib.chm_retrieve_object(self.file, ui, 4L, ui.length)
    if (size == 0):
        sys.stderr.write('GetArchiveInfo:    file    size    =    0\n')
        return 0
    buff = array.array('B', text)
    index = 0
    while (index < size):
        cursor = (buff[index] + (buff[(index + 1)] * 256))
        if (cursor == 0):
            index += 2
            cursor = (buff[index] + (buff[(index + 1)] * 256))
            index += 2
            self.topics = ('/' + text[index:((index + cursor) - 1)])
        elif (cursor == 1):
            index += 2
            cursor = (buff[index] + (buff[(index + 1)] * 256))
            index += 2
            self.index = ('/' + text[index:((index + cursor) - 1)])
        elif (cursor == 2):
            index += 2
            cursor = (buff[index] + (buff[(index + 1)] * 256))
            index += 2
            self.home = ('/' + text[index:((index + cursor) - 1)])
        elif (cursor == 3):
            index += 2
            cursor = (buff[index] + (buff[(index + 1)] * 256))
            index += 2
            self.title = text[index:((index + cursor) - 1)]
        elif (cursor == 4):
            index += 2
            cursor = (buff[index] + (buff[(index + 1)] * 256))
            index += 2
            self.lcid = (buff[index] + (buff[(index + 1)] * 256))
        elif (cursor == 6):
            index += 2
            cursor = (buff[index] + (buff[(index + 1)] * 256))
            index += 2
            tmp = text[index:((index + cursor) - 1)]
            if (not self.topics):
                tmp1 = (('/' + tmp) + '.hhc')
                tmp2 = (('/' + tmp) + '.hhk')
                (res1, ui1) = chmlib.chm_resolve_object(self.file, tmp1)
                (res2, ui2) = chmlib.chm_resolve_object(self.file, tmp2)
                if ((not self.topics) and (res1 == chmlib.CHM_RESOLVE_SUCCESS)):
                    self.topics = (('/' + tmp) + '.hhc')
                if ((not self.index) and (res2 == chmlib.CHM_RESOLVE_SUCCESS)):
                    self.index = (('/' + tmp) + '.hhk')
        elif (cursor == 16):
            index += 2
            cursor = (buff[index] + (buff[(index + 1)] * 256))
            index += 2
            self.encoding = text[index:((index + cursor) - 1)]
        else:
            index += 2
            cursor = (buff[index] + (buff[(index + 1)] * 256))
            index += 2
        index += cursor
    self.GetWindowsInfo()
    if (not self.lcid):
        self.lcid = extra.get_lcid(self.file)
    return 1
