plptools
Loading...
Searching...
No Matches
sisfile.cpp
Go to the documentation of this file.
1/*
2 * This file is part of plptools.
3 *
4 * Copyright (C) 2002 Daniel Brahneborg <basic.chello@se>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * along with this program; if not, see <https://www.gnu.org/licenses/>.
18 */
19#include "config.h"
20
21#include "sisfile.h"
22#include "sislangrecord.h"
23#include "sisfilerecord.h"
24#include "sisreqrecord.h"
25#include "plpintl.h"
26
27#include <stdio.h>
28
30{
31 m_buf = 0;
32 m_ownBuffer = false;
33}
34
36{
37 if (m_ownBuffer)
38 delete[] m_buf;
39}
40
43{
44 return m_header.compareApp(&other->m_header);
45}
46
48SISFile::fillFrom(uint8_t* buf, off_t len)
49{
50 m_end = 0;
51 int ix = 0;
52 m_buf = buf;
53 SisRC rc = m_header.fillFrom(buf, &ix, len);
54 if (rc != SIS_OK)
55 {
56 printf(_("Could not read header, rc = %d\n"), rc);
57 return rc;
58 }
59 if (logLevel >= 2)
60 printf(_("Ate header, got ix = %d\n"), ix);
61 int n;
62
63 // Read languages.
64 //
68 for (int i = 0; i < n; ++i)
69 {
70 if (ix >= len)
71 return SIS_TRUNCATED;
72 rc = m_langRecords[i].fillFrom(buf, &ix, len);
73 if (rc != SIS_OK)
74 {
75 printf(_("Problem reading language record %d, rc = %d.\n"), i, rc);
76 return rc;
77 }
78 }
79 updateEnd(ix);
80
81 // Read requisites.
82 //
83 n = m_header.m_nreqs;
85 ix = m_header.m_reqPtr;
86 for (int i = 0; i < n; ++i)
87 {
88 if (ix >= len)
89 return SIS_TRUNCATED;
90 rc = m_reqRecords[i].fillFrom(buf, &ix, len, this);
91 if (rc != SIS_OK)
92 {
93 printf(_("Problem reading requisite record %d, rc = %d.\n"), i, rc);
94 return rc;
95 }
96 }
97 updateEnd(ix);
98
99 // Read component names, by language.
100 //
102 rc = m_componentRecord.fillFrom(buf, &ix, len, this);
103 updateEnd(ix);
105 if (rc != SIS_OK)
106 {
107 printf(_("Problem reading the name record, rc = %d.\n"), rc);
108 return rc;
109 }
110
111 // Read files.
112 //
113 n = m_header.m_nfiles;
115 ix = m_header.m_filesPtr;
116 SisRC myrc = SIS_OK;
117 for (int i = 0; i < n; ++i)
118 {
119 if (ix >= len)
120 return SIS_TRUNCATED;
121 rc = m_fileRecords[i].fillFrom(buf, &ix, len, this);
122 if (rc != SIS_OK)
123 {
124 printf(_("Problem reading file record %d, rc = %d.\n"), i, rc);
125 if (rc == SIS_TRUNCATEDDATA)
126 myrc = rc;
127 else
128 return rc;
129 }
130 }
131 updateEnd(ix);
132
133 return SIS_OK;
134}
135
136int
138{
140}
141
144{
145 return &langTable[m_langRecords[i].m_lang];
146}
147
148uint8_t*
150{
152}
153
154void
156{
157 m_header.setDrive(drive);
158}
159
160void
162{
163 m_header.setFiles(nFiles);
164}
165
166void
168{
170}
171
172void
174{
175 if (m_end < pos)
176 m_end = pos;
177}
SisRC fillFrom(uint8_t *buf, int *base, off_t len, SISFile *sisFile)
Populate the fields.
uint32_t getLastEnd()
Find out the end position for the last name in the file.
uint8_t * getName(int no)
Return the name for the given language.
uint32_t m_reqPtr
void setFiles(int nFiles)
Update the number of installed files, and patch the parsed buffer.
SisRC compareApp(SISFileHeader *other)
Compare uid and version number of this file, with another.
void setDrive(char drive)
Update the drive letter, and patch the parsed buffer.
uint32_t m_componentPtr
uint32_t m_languagePtr
Definition: sisfileheader.h:99
uint32_t m_filesPtr
SisRC fillFrom(uint8_t *buf, int *base, off_t len)
Populate the fields.
uint16_t m_nlangs
Definition: sisfileheader.h:87
uint16_t m_nreqs
Definition: sisfileheader.h:89
uint16_t m_installationLanguage
Definition: sisfileheader.h:90
uint16_t m_nfiles
Definition: sisfileheader.h:88
Information about a file component in a SIS file.
Definition: sisfilerecord.h:34
SisRC fillFrom(uint8_t *buf, int *base, off_t len, SISFile *sisFile)
Populate the fields.
The top level container of a SIS file.
Definition: sisfile.h:36
void setDrive(char drive)
Set the installed drive.
Definition: sisfile.cpp:155
SISFile()
Definition: sisfile.cpp:29
SisRC fillFrom(uint8_t *buf, off_t len)
Populate the fields.
Definition: sisfile.cpp:48
uint8_t * m_buf
Definition: sisfile.h:119
SISReqRecord * m_reqRecords
Definition: sisfile.h:111
void setFiles(int nFiles)
Set the number of installed files.
Definition: sisfile.cpp:161
SisRC compareApp(SISFile *other)
Compare uid and version number of this file, with another.
Definition: sisfile.cpp:42
virtual ~SISFile()
Definition: sisfile.cpp:35
bool m_ownBuffer
Definition: sisfile.h:117
SISLangRecord * m_langRecords
Definition: sisfile.h:109
SISFileRecord * m_fileRecords
Definition: sisfile.h:110
SISComponentNameRecord m_componentRecord
Definition: sisfile.h:115
SISFileHeader m_header
Definition: sisfile.h:108
void setLanguage(int lang)
Set the selected installation language.
Definition: sisfile.cpp:167
int getLanguage()
Return the currently selected installation language.
Definition: sisfile.cpp:137
uint32_t m_end
Definition: sisfile.h:121
void updateEnd(uint32_t pos)
Definition: sisfile.cpp:173
uint8_t * getName()
Get the name of this component, in the selected language.
Definition: sisfile.cpp:149
A simple language record, only containing the epoc specific 16 bit language number.
Definition: sislangrecord.h:30
SisRC fillFrom(uint8_t *buf, int *base, off_t len)
Populate the fields.
uint16_t m_lang
The language number.
Definition: sislangrecord.h:48
Information about an application that must be installed prior to the current one.
Definition: sisreqrecord.h:32
SisRC fillFrom(uint8_t *buf, int *base, off_t len, SISFile *sisFile)
Populate the fields.
#define _(String)
Definition: plpintl.h:35
LangTableEntry langTable[]
Definition: sistypes.cpp:73
int logLevel
Definition: sistypes.cpp:25
SisRC
Return Codes.
Definition: sistypes.h:29
@ SIS_OK
Definition: sistypes.h:30
@ SIS_TRUNCATEDDATA
Definition: sistypes.h:32
@ SIS_TRUNCATED
Definition: sistypes.h:31
Holder of a language entry, translating from language numbers to names.
Definition: sistypes.h:59