Line 212... |
Line 212... |
212 |
|
212 |
|
213 |
|
213 |
|
214 |
/* install a package that has been prepared already. returns 0 on success,
|
214 |
/* install a package that has been prepared already. returns 0 on success,
|
215 |
* or a negative value on error, or a positive value on warning */
|
215 |
* or a negative value on error, or a positive value on warning */
|
216 |
int pkginstall_installpackage(const char *pkgname, const char *dosdir, const struct customdirs *dirlist, struct ziplist *ziplinkedlist, FILE *zipfd) {
|
216 |
int pkginstall_installpackage(const char *pkgname, const char *dosdir, const struct customdirs *dirlist, struct ziplist *ziplinkedlist, FILE *zipfd) {
|
217 |
char *buff;
|
217 |
char buff[256];
|
218 |
char *fulldestfilename;
|
218 |
char fulldestfilename[256];
|
219 |
char packageslst[64];
|
219 |
char packageslst[32];
|
220 |
char *shortfile;
|
220 |
char *shortfile;
|
221 |
long filesextractedsuccess = 0, filesextractedfailure = 0;
|
221 |
long filesextractedsuccess = 0, filesextractedfailure = 0;
|
222 |
struct ziplist *curzipnode;
|
222 |
struct ziplist *curzipnode;
|
223 |
FILE *lstfd;
|
223 |
FILE *lstfd;
|
224 |
|
224 |
|
225 |
sprintf(packageslst, "packages\\%s.lst", pkgname); /* Prepare the packages/xxxx.lst filename string for later use */
|
225 |
sprintf(packageslst, "packages\\%s.lst", pkgname); /* Prepare the packages/xxxx.lst filename string for later use */
|
226 |
|
226 |
|
227 |
buff = malloc(512);
|
- |
|
228 |
fulldestfilename = malloc(1024);
|
- |
|
229 |
if ((buff == NULL) || (fulldestfilename == NULL)) {
|
- |
|
230 |
kitten_printf(2, 14, "Out of memory! (%s)", "fulldestfilename");
|
- |
|
231 |
puts("");
|
- |
|
232 |
zip_freelist(&ziplinkedlist);
|
- |
|
233 |
free(buff);
|
- |
|
234 |
free(fulldestfilename);
|
- |
|
235 |
return(-1);
|
- |
|
236 |
}
|
- |
|
237 |
|
- |
|
238 |
/* create the %DOSDIR%/packages directory, just in case it doesn't exist yet */
|
227 |
/* create the %DOSDIR%/packages directory, just in case it doesn't exist yet */
|
239 |
sprintf(buff, "%s\\packages\\", dosdir);
|
228 |
sprintf(buff, "%s\\packages\\", dosdir);
|
240 |
mkpath(buff);
|
229 |
mkpath(buff);
|
241 |
|
230 |
|
242 |
/* open the lst file */
|
231 |
/* open the lst file */
|
243 |
sprintf(buff, "%s\\%s", dosdir, packageslst);
|
232 |
sprintf(buff, "%s\\%s", dosdir, packageslst);
|
244 |
lstfd = fopen(buff, "wb"); /* opening it in binary mode, because I like to have control over line terminators (CR/LF) */
|
233 |
lstfd = fopen(buff, "wb"); /* opening it in binary mode, because I like to have control over line terminators (CR/LF) */
|
245 |
if (lstfd == NULL) {
|
234 |
if (lstfd == NULL) {
|
246 |
kitten_printf(3, 10, "ERROR: Could not create %s!", buff);
|
235 |
kitten_printf(3, 10, "ERROR: Could not create %s!", buff);
|
247 |
puts("");
|
236 |
puts("");
|
248 |
zip_freelist(&ziplinkedlist);
|
- |
|
249 |
free(buff);
|
- |
|
250 |
free(fulldestfilename);
|
- |
|
251 |
return(-2);
|
237 |
return(-2);
|
252 |
}
|
238 |
}
|
253 |
|
239 |
|
254 |
/* write list of files in zip into the lst, and create the directories structure */
|
240 |
/* write list of files in zip into the lst, and create the directories structure */
|
255 |
for (curzipnode = ziplinkedlist; curzipnode != NULL; curzipnode = curzipnode->nextfile) {
|
241 |
for (curzipnode = ziplinkedlist; curzipnode != NULL; curzipnode = curzipnode->nextfile) {
|
256 |
int unzip_result;
|
242 |
int unzip_result;
|
257 |
if ((curzipnode->flags & ZIP_FLAG_ISADIR) != 0) continue; /* skip directories */
|
243 |
if ((curzipnode->flags & ZIP_FLAG_ISADIR) != 0) continue; /* skip directories */
|
258 |
if (strcasecmp(curzipnode->filename, packageslst) == 0) continue; /* skip silently the package.lst file, if found */
|
- |
|
259 |
shortfile = computelocalpath(curzipnode->filename, buff, dosdir, dirlist); /* substitute paths to custom dirs */
|
244 |
shortfile = computelocalpath(curzipnode->filename, buff, dosdir, dirlist); /* substitute paths to custom dirs */
|
260 |
/* log the filename to packages\pkg.lst (with original, unmapped drive) */
|
245 |
/* log the filename to packages\pkg.lst */
|
261 |
fprintf(lstfd, "%s%s\r\n", buff, shortfile);
|
246 |
fprintf(lstfd, "%s%s\r\n", buff, shortfile);
|
262 |
/* create the path, just in case it doesn't exist yet */
|
247 |
/* create the path, just in case it doesn't exist yet */
|
263 |
mkpath(buff);
|
248 |
mkpath(buff);
|
264 |
sprintf(fulldestfilename, "%s%s", buff, shortfile);
|
249 |
sprintf(fulldestfilename, "%s%s", buff, shortfile);
|
265 |
/* Now unzip the file */
|
250 |
/* Now unzip the file */
|
Line 273... |
Line 258... |
273 |
filesextractedsuccess += 1;
|
258 |
filesextractedsuccess += 1;
|
274 |
}
|
259 |
}
|
275 |
}
|
260 |
}
|
276 |
fclose(lstfd);
|
261 |
fclose(lstfd);
|
277 |
|
262 |
|
278 |
/* free the ziplist and close file descriptor */
|
- |
|
279 |
zip_freelist(&ziplinkedlist);
|
- |
|
280 |
free(buff);
|
- |
|
281 |
free(fulldestfilename);
|
- |
|
282 |
|
- |
|
283 |
kitten_printf(3, 19, "Package %s installed: %ld files extracted, %ld errors.", pkgname, filesextractedsuccess, filesextractedfailure);
|
263 |
kitten_printf(3, 19, "Package %s installed: %ld files extracted, %ld errors.", pkgname, filesextractedsuccess, filesextractedfailure);
|
284 |
puts("");
|
264 |
puts("");
|
285 |
return(filesextractedfailure);
|
265 |
return(filesextractedfailure);
|
286 |
}
|
266 |
}
|