aboutsummaryrefslogtreecommitdiffstats
path: root/sisinstall/sisinstaller.cpp
blob: efd0bfe8ea58725f437e8074a18d9e58ffc87f09 (plain)
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#include "sisinstaller.h"

#include "sisfile.h"
#include "sisfilerecord.h"
#include "sisreqrecord.h"
#include "psion.h"

#include <unistd.h>
#include <stdio.h>

void
SISInstaller::setPsion(Psion* psion)
{
	m_psion = psion;
}

void
SISInstaller::run(SISFile* file, uchar* buf)
{
	run(file, buf, 0);
}

void
SISInstaller::run(SISFile* file, uchar* buf, SISFile* parent)
{
	int n;
	int lang;
	if (parent == 0)
		{
		n = file->m_header.m_nlangs;
		if (n == 1)
			{
			printf("You have only one language: %s\n",
				   file->getLanguage(0)->m_name);
			lang = 0;
			}
		else
			{
			printf("Select a language (%d alternatives):\n", n);
			for (int i = 0; i < n; ++i)
				{
				printf(" %d. %s\n", i, file->getLanguage(i)->m_name);
				}
			lang = 0;
			}
		}
	else
		{
		lang = parent->getLanguage();
		printf("Forcing language to %d\n", lang);
		}
	file->setLanguage(lang);
	printf("Installing component: `%s'\n", file->getName());

	// Check Requisites.
	//
	n = file->m_header.m_nreqs;
	printf("Found %d requisites, of some sort.\n", n);
	for (int i = 0; i < n; ++i)
		{
		SISReqRecord* reqRecord = &file->m_reqRecords[i];
		printf(" Check if app with uid %08x exists with version >= %d.%d\n",
		   reqRecord->m_uid,
		   reqRecord->m_major,
		   reqRecord->m_minor);
		}

	// Check previous version.
	//
	printf(
  "Checking if this app (uid %08x) exists with a version less than %d.%d.\n",
		   file->m_header.m_uid1,
		   file->m_header.m_major,
		   file->m_header.m_minor);

	// Install file components.
	//
	n = file->m_header.m_nfiles;
	printf("Found %d files.\n", n);
	char drive = (parent == 0) ? 0 : parent->m_header.m_installationDrive;
	file->m_header.m_installationFiles = 0;
	int firstFile = -1;
	while (n-- > 0)
		{
		SISFileRecord* fileRecord = &file->m_fileRecords[n];
		int ix = 0;
		if (fileRecord->m_flags & 1)
			ix = lang;
		char ch;
#if 0
		printf("FirstFile = %d, ptr = %d, length = %d\n",
			   firstFile,
			   fileRecord->m_filePtrs[ix],
			   fileRecord->m_fileLengths[ix]);
#endif
		if ((firstFile == -1) ||
			(firstFile >= fileRecord->m_filePtrs[ix]))
			firstFile = fileRecord->m_filePtrs[ix];

//		 We can only do this if we search all files...
//		 fileRecord->m_filePtrs[ix] + fileRecord->m_fileLengths[ix]

		switch (fileRecord->m_fileType)
			{
			case 0:
				if (buf[fileRecord->m_destPtr] == '!')
					{
					if (drive == 0)
						{
#if 0
						u_int32_t devbits = 0;
						Enum<rfsv::errs> res;
						if ((res = m_psion->m_rfsv->devlist(devbits)) == rfsv::E_PSI_GEN_NONE)
							{
							for (int i = 0; i < 26; i++)
								{
								PlpDrive plpdrive;
								if ((devbits & 1) != 0)
									{
									u_int32_t mediaType = plpdrive.getMediaType();
									if ((mediaType == 3) || (mediaType == 5))
										{
										printf("%c: %d bytes free\n", 'A' + i, plpdrive.getSpace());
										}
									}
								devbits >>= 1;
								}
							}
#endif
						printf("Please select a drive\n");
						read(0, &ch, 1);
						if (ch >= 'a' && ch <= 'z')
							drive = ch;
						else
							drive = 'c';
						}
					file->m_header.m_installationDrive = drive;
					}
				printf("Copying %d bytes to %.*s\n",
					   fileRecord->m_fileLengths[ix],
					   fileRecord->m_destLength,
					   buf + fileRecord->m_destPtr);
				break;
			case 1:
				printf("Info:\n%.*s\n",
					   fileRecord->m_fileLengths[ix],
					   buf + fileRecord->m_filePtrs[ix]);
				switch (fileRecord->m_fileDetails)
					{
					case 0:
						printf("Continue\n");
//						read(0, &ch, 1);
						break;
					case 1:
						printf("Skip next file? Yes/No\n");
//						read(0, &ch, 1);
						break;
					case 2:
						printf("[Continue installation?] Yes/No\n");
//						read(0, &ch, 1);
						break;
					}
				break;
			case 2:
				{
				printf("Recursive sis file...\n");
				SISFile sisFile;
				uchar* buf2 = buf + fileRecord->m_filePtrs[ix];
				sisFile.fillFrom(buf2);
				SISInstaller installer;
				installer.run(&sisFile, buf2, file);
				if (0 == file->m_header.m_installationDrive)
					drive =
						file->m_header.m_installationDrive = 
						sisFile.m_header.m_installationDrive;
				break;
				}
			case 3:
				printf("Run %.*s during installation/remove\n",
					   fileRecord->m_destLength, buf + fileRecord->m_destPtr);
				break;
			case 4:
				printf("Running the app will create %.*s\n",
					   fileRecord->m_destLength, buf + fileRecord->m_destPtr);
				break;
			}

		file->m_header.m_installationFiles++;
		}
	printf("Installed %d files of %d, cutting at offset %d\n",
		   file->m_header.m_installationFiles,
		   file->m_header.m_nfiles,
		   firstFile);

	// Set the new shortened size somewhere.
	//

	// Copy the updated sis file to the epoc machine.
	//

}