1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
/** -*-c++-*-
* $Id$
*
* This file is part of plptools.
*
* Copyright (C) 2002 Daniel Brahneborg <basic.chello@se>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "sisfile.h"
#include "sislangrecord.h"
#include "sisfilerecord.h"
#include "sisreqrecord.h"
#include "plpintl.h"
#include <stdio.h>
SISFile::SISFile()
{
m_buf = 0;
m_ownBuffer = false;
}
SISFile::~SISFile()
{
if (m_ownBuffer)
delete[] m_buf;
}
SisRC
SISFile::compareApp(SISFile* other)
{
return m_header.compareApp(&other->m_header);
}
SisRC
SISFile::fillFrom(uint8_t* buf, off_t len)
{
m_end = 0;
int ix = 0;
m_buf = buf;
SisRC rc = m_header.fillFrom(buf, &ix, len);
if (rc != SIS_OK)
{
printf(_("Could not read header, rc = %d\n"), rc);
return rc;
}
if (logLevel >= 2)
printf(_("Ate header, got ix = %d\n"), ix);
int n;
// Read languages.
//
n = m_header.m_nlangs;
m_langRecords = new SISLangRecord[n];
ix = m_header.m_languagePtr;
for (int i = 0; i < n; ++i)
{
if (ix >= len)
return SIS_TRUNCATED;
rc = m_langRecords[i].fillFrom(buf, &ix, len);
if (rc != SIS_OK)
{
printf(_("Problem reading language record %d, rc = %d.\n"), i, rc);
return rc;
}
}
updateEnd(ix);
// Read requisites.
//
n = m_header.m_nreqs;
m_reqRecords = new SISReqRecord[n];
ix = m_header.m_reqPtr;
for (int i = 0; i < n; ++i)
{
if (ix >= len)
return SIS_TRUNCATED;
rc = m_reqRecords[i].fillFrom(buf, &ix, len, this);
if (rc != SIS_OK)
{
printf(_("Problem reading requisite record %d, rc = %d.\n"), i, rc);
return rc;
}
}
updateEnd(ix);
// Read component names, by language.
//
ix = m_header.m_componentPtr;
rc = m_componentRecord.fillFrom(buf, &ix, len, this);
updateEnd(ix);
updateEnd(m_componentRecord.getLastEnd());
if (rc != SIS_OK)
{
printf(_("Problem reading the name record, rc = %d.\n"), rc);
return rc;
}
// Read files.
//
n = m_header.m_nfiles;
m_fileRecords = new SISFileRecord[n];
ix = m_header.m_filesPtr;
SisRC myrc = SIS_OK;
for (int i = 0; i < n; ++i)
{
if (ix >= len)
return SIS_TRUNCATED;
rc = m_fileRecords[i].fillFrom(buf, &ix, len, this);
if (rc != SIS_OK)
{
printf(_("Problem reading file record %d, rc = %d.\n"), i, rc);
if (rc == SIS_TRUNCATEDDATA)
myrc = rc;
else
return rc;
}
}
updateEnd(ix);
return SIS_OK;
}
int
SISFile::getLanguage()
{
return m_header.m_installationLanguage;
}
LangTableEntry*
SISFile::getLanguage(int i)
{
return &langTable[m_langRecords[i].m_lang];
}
uint8_t*
SISFile::getName()
{
return m_componentRecord.getName(m_header.m_installationLanguage);
}
void
SISFile::setDrive(char drive)
{
m_header.setDrive(drive);
}
void
SISFile::setFiles(int nFiles)
{
m_header.setFiles(nFiles);
}
void
SISFile::setLanguage(int lang)
{
m_header.m_installationLanguage = lang;
}
void
SISFile::updateEnd(uint32_t pos)
{
if (m_end < pos)
m_end = pos;
}
|