Subversion Repositories SvarDOS

Rev

Rev 1600 | Rev 1678 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1600 Rev 1601
1
/*
1
/*
2
 * This file is part of pkg (SvarDOS)
2
 * This file is part of pkg (SvarDOS)
3
 * Copyright (C) 2012-2023 Mateusz Viste
3
 * Copyright (C) 2012-2023 Mateusz Viste
4
 */
4
 */
5
 
5
 
6
#include <ctype.h>     /* toupper() */
6
#include <ctype.h>     /* toupper() */
7
#include <stdio.h>
7
#include <stdio.h>
8
#include <stdlib.h>    /* system() */
8
#include <stdlib.h>    /* system() */
9
#include <string.h>    /* strcpy() */
9
#include <string.h>    /* strcpy() */
10
#include <unistd.h>    /* read() */
10
#include <unistd.h>    /* read() */
11
#include <sys/types.h> /* struct utimbuf */
11
#include <sys/types.h> /* struct utimbuf */
12
 
12
 
13
#include "helpers.h"   /* slash2backslash() */
13
#include "helpers.h"   /* slash2backslash() */
14
#include "fileexst.h"
14
#include "fileexst.h"
15
#include "kprintf.h"
15
#include "kprintf.h"
16
#include "libunzip.h"  /* zip_listfiles()... */
16
#include "libunzip.h"  /* zip_listfiles()... */
17
#include "showinst.h"  /* pkg_loadflist() */
17
#include "showinst.h"  /* pkg_loadflist() */
18
#include "svarlang.lib\svarlang.h"
18
#include "svarlang.lib\svarlang.h"
19
 
19
 
20
#include "pkginst.h"   /* include self for control */
20
#include "pkginst.h"   /* include self for control */
21
 
21
 
22
 
22
 
23
/* validate a filename (8+3, no weird characters, etc). returns 0 on success,
23
/* validate a filename (8+3, no weird characters, etc). returns 0 on success,
24
 * nonzero otherwise. */
24
 * nonzero otherwise. */
25
static int validfilename(const char *fname) {
25
static int validfilename(const char *fname) {
26
  int i, i2;
26
  int i, i2;
27
  char *validchars = "!#$%&'()-@^_`{}~";
27
  char *validchars = "!#$%&'()-@^_`{}~";
28
  int elemlen = 0;
28
  int elemlen = 0;
29
  int elemmaxlen = 8; /* switches from 8 to 3 depending wheter I am analyzing
29
  int elemmaxlen = 8; /* switches from 8 to 3 depending wheter I am analyzing
30
                         a filename or an extension */
30
                         a filename or an extension */
31
  /* look for invalid chars in the entire string, and check the length of the
31
  /* look for invalid chars in the entire string, and check the length of the
32
   * element at the same time */
32
   * element at the same time */
33
  for (i = 0; fname[i] != 0; i++) {
33
  for (i = 0; fname[i] != 0; i++) {
34
    /* director separators are threated specially */
34
    /* director separators are threated specially */
35
    if (fname[i] == '\\') {
35
    if (fname[i] == '\\') {
36
      elemlen = 0;
36
      elemlen = 0;
37
      elemmaxlen = 8;
37
      elemmaxlen = 8;
38
      continue;
38
      continue;
39
    }
39
    }
40
    /* '.' switches the check into extension mode */
40
    /* '.' switches the check into extension mode */
41
    if (fname[i] == '.') {
41
    if (fname[i] == '.') {
42
      if (elemlen == 0) return(-1); /* a file must have a base name */
42
      if (elemlen == 0) return(-1); /* a file must have a base name */
43
      if (elemmaxlen == 3) return(-2); /* a file cannot have two extensions */
43
      if (elemmaxlen == 3) return(-2); /* a file cannot have two extensions */
44
      elemlen = 0;
44
      elemlen = 0;
45
      elemmaxlen = 3;
45
      elemmaxlen = 3;
46
      continue;
46
      continue;
47
    }
47
    }
48
    /* check that the element is not too long */
48
    /* check that the element is not too long */
49
    if (++elemlen > elemmaxlen) return(-3);
49
    if (++elemlen > elemmaxlen) return(-3);
50
    /* look for valid characters */
50
    /* look for valid characters */
51
    if ((fname[i] >= 'a') && (fname[i] <= 'z')) continue;
51
    if ((fname[i] >= 'a') && (fname[i] <= 'z')) continue;
52
    if ((fname[i] >= 'A') && (fname[i] <= 'Z')) continue;
52
    if ((fname[i] >= 'A') && (fname[i] <= 'Z')) continue;
53
    if ((fname[i] >= '0') && (fname[i] <= '9')) continue;
53
    if ((fname[i] >= '0') && (fname[i] <= '9')) continue;
54
    if ((fname[i] & 128) != 0) continue; /* high bytes are okay (NLS) */
54
    if ((fname[i] & 128) != 0) continue; /* high bytes are okay (NLS) */
55
    /* look for other valid characters */
55
    /* look for other valid characters */
56
    for (i2 = 0; validchars[i2] != 0; i2++) {
56
    for (i2 = 0; validchars[i2] != 0; i2++) {
57
      if (fname[i] == validchars[i2]) break;
57
      if (fname[i] == validchars[i2]) break;
58
    }
58
    }
59
    if (validchars[i2] != 0) continue;
59
    if (validchars[i2] != 0) continue;
60
    /* if we are here, then the character is invalid */
60
    /* if we are here, then the character is invalid */
61
    return(-4);
61
    return(-4);
62
  }
62
  }
63
  /* all checks passed */
63
  /* all checks passed */
64
  return(0);
64
  return(0);
65
}
65
}
66
 
66
 
67
 
67
 
68
/* returns 0 if pkgname is not installed, non-zero otherwise */
68
/* returns 0 if pkgname is not installed, non-zero otherwise */
69
int is_package_installed(const char *pkgname, const char *dosdir) {
69
int is_package_installed(const char *pkgname, const char *dosdir) {
70
  char fname[512];
70
  char fname[512];
71
  sprintf(fname, "%s\\packages\\%s.lst", dosdir, pkgname);
71
  sprintf(fname, "%s\\packages\\%s.lst", dosdir, pkgname);
72
  return(fileexists(fname)); /* file exists -> package is installed */
72
  return(fileexists(fname)); /* file exists -> package is installed */
73
}
73
}
74
 
74
 
75
 
75
 
76
/* checks that pkgname is NOT installed. return 0 on success, non-zero otherwise. */
76
/* checks that pkgname is NOT installed. return 0 on success, non-zero otherwise. */
77
static int validate_package_not_installed(const char *pkgname, const char *dosdir) {
77
static int validate_package_not_installed(const char *pkgname, const char *dosdir) {
78
  if (is_package_installed(pkgname, dosdir) != 0) {
78
  if (is_package_installed(pkgname, dosdir) != 0) {
79
    kitten_printf(3, 18, pkgname); /* "Package %s is already installed! You might want to use the 'update' action." */
79
    kitten_printf(3, 18, pkgname); /* "Package %s is already installed! You might want to use the 'update' action." */
80
    puts("");
80
    puts("");
81
    return(-1);
81
    return(-1);
82
  }
82
  }
83
  return(0);
83
  return(0);
84
}
84
}
85
 
85
 
86
 
86
 
87
/* find a filename in a flist linked list, and returns a pointer to it */
87
/* find a filename in a flist linked list, and returns a pointer to it */
88
static struct flist_t *findfileinlist(struct flist_t *flist, const char *fname) {
88
static struct flist_t *findfileinlist(struct flist_t *flist, const char *fname) {
89
  while (flist != NULL) {
89
  while (flist != NULL) {
90
    if (strcasecmp(flist->fname, fname) == 0) return(flist);
90
    if (strcasecmp(flist->fname, fname) == 0) return(flist);
91
    flist = flist->next;
91
    flist = flist->next;
92
  }
92
  }
93
  return(NULL);
93
  return(NULL);
94
}
94
}
95
 
95
 
96
 
96
 
97
/* prepare a package for installation. this is mandatory before actually installing it!
97
/* prepare a package for installation. this is mandatory before actually installing it!
98
 * returns a pointer to the zip file's index on success, NULL on failure. the **zipfd pointer is updated with a file descriptor to the open zip file to install. */
98
 * returns a pointer to the zip file's index on success, NULL on failure. the **zipfd pointer is updated with a file descriptor to the open zip file to install. */
99
struct ziplist *pkginstall_preparepackage(const char *pkgname, const char *zipfile, int flags, FILE **zipfd, const char *dosdir, const struct customdirs *dirlist) {
99
struct ziplist *pkginstall_preparepackage(const char *pkgname, const char *zipfile, int flags, FILE **zipfd, const char *dosdir, const struct customdirs *dirlist) {
100
  char fname[256];
100
  char fname[256];
101
  char appinfofile[256];
101
  char appinfofile[256];
102
  int appinfopresence;
102
  int appinfopresence;
103
  char *shortfile;
103
  char *shortfile;
104
  struct ziplist *ziplinkedlist = NULL, *curzipnode, *prevzipnode;
104
  struct ziplist *ziplinkedlist = NULL, *curzipnode, *prevzipnode;
105
  struct flist_t *flist = NULL;
105
  struct flist_t *flist = NULL;
106
 
106
 
107
  sprintf(appinfofile, "appinfo\\%s.lsm", pkgname); /* Prepare the appinfo/xxxx.lsm filename string for later use */
107
  sprintf(appinfofile, "appinfo\\%s.lsm", pkgname); /* Prepare the appinfo/xxxx.lsm filename string for later use */
108
 
108
 
109
  /* check if not already installed, if already here, print a message "you might want to use update instead"
109
  /* check if not already installed, if already here, print a message "you might want to use update instead"
110
   * of course this must not be done if we are in the process of upgrading said package */
110
   * of course this must not be done if we are in the process of upgrading said package */
111
  if (((flags & PKGINST_UPDATE) == 0) && (validate_package_not_installed(pkgname, dosdir) != 0)) {
111
  if (((flags & PKGINST_UPDATE) == 0) && (validate_package_not_installed(pkgname, dosdir) != 0)) {
112
    return(NULL);
112
    return(NULL);
113
  }
113
  }
114
 
114
 
115
  /* copy zip filename into fname */
115
  /* copy zip filename into fname */
116
  strcpy(fname, zipfile);
116
  strcpy(fname, zipfile);
117
 
117
 
118
  /* append an .SVP extension if not present */
118
  /* append an .SVP extension if not present */
119
  {
119
  {
120
    int slen = strlen(fname);
120
    int slen = strlen(fname);
121
    if ((slen > 3) && (fname[slen - 4] != '.')) strcat(fname, ".SVP");
121
    if ((slen < 4) || (fname[slen - 4] != '.')) strcat(fname, ".SVP");
122
  }
122
  }
123
 
123
 
124
  /* Now let's check the content of the zip file */
124
  /* Now let's check the content of the zip file */
125
 
125
 
126
  *zipfd = fopen(fname, "rb");
126
  *zipfd = fopen(fname, "rb");
127
  if (*zipfd == NULL) {
127
  if (*zipfd == NULL) {
128
    puts(svarlang_str(3, 8)); /* "ERROR: Invalid zip archive! Package not installed." */
128
    puts(svarlang_str(3, 8)); /* "ERROR: Invalid zip archive! Package not installed." */
129
    goto RAII;
129
    goto RAII;
130
  }
130
  }
131
  ziplinkedlist = zip_listfiles(*zipfd);
131
  ziplinkedlist = zip_listfiles(*zipfd);
132
  if (ziplinkedlist == NULL) {
132
  if (ziplinkedlist == NULL) {
133
    puts(svarlang_str(3, 8)); /* "ERROR: Invalid zip archive! Package not installed." */
133
    puts(svarlang_str(3, 8)); /* "ERROR: Invalid zip archive! Package not installed." */
134
    goto RAII;
134
    goto RAII;
135
  }
135
  }
136
  /* if updating, load the list of files belonging to the current package */
136
  /* if updating, load the list of files belonging to the current package */
137
  if ((flags & PKGINST_UPDATE) != 0) {
137
  if ((flags & PKGINST_UPDATE) != 0) {
138
    flist = pkg_loadflist(pkgname, dosdir);
138
    flist = pkg_loadflist(pkgname, dosdir);
139
  }
139
  }
140
  /* Verify that there's no collision with existing local files, look for the appinfo presence */
140
  /* Verify that there's no collision with existing local files, look for the appinfo presence */
141
  appinfopresence = 0;
141
  appinfopresence = 0;
142
  prevzipnode = NULL;
142
  prevzipnode = NULL;
143
  for (curzipnode = ziplinkedlist; curzipnode != NULL;) {
143
  for (curzipnode = ziplinkedlist; curzipnode != NULL;) {
144
    /* change all slashes to backslashes, and switch into all-lowercase */
144
    /* change all slashes to backslashes, and switch into all-lowercase */
145
    slash2backslash(curzipnode->filename);
145
    slash2backslash(curzipnode->filename);
146
    strlwr(curzipnode->filename);
146
    strlwr(curzipnode->filename);
147
    /* remove 'directory' ZIP entries to avoid false alerts about directory already existing */
147
    /* remove 'directory' ZIP entries to avoid false alerts about directory already existing */
148
    if ((curzipnode->flags & ZIP_FLAG_ISADIR) != 0) {
148
    if ((curzipnode->flags & ZIP_FLAG_ISADIR) != 0) {
149
      curzipnode->filename[0] = 0; /* mark it "empty", will be removed in a short moment */
149
      curzipnode->filename[0] = 0; /* mark it "empty", will be removed in a short moment */
150
    }
150
    }
151
    /* is it a "link file"? skip it - link files are no longer supported */
151
    /* is it a "link file"? skip it - link files are no longer supported */
152
    if (fdnpkg_strcasestr(curzipnode->filename, "links\\") == curzipnode->filename) {
152
    if (fdnpkg_strcasestr(curzipnode->filename, "links\\") == curzipnode->filename) {
153
      curzipnode->filename[0] = 0; /* in fact, I just mark the file as 'empty' on the filename - see later below */
153
      curzipnode->filename[0] = 0; /* in fact, I just mark the file as 'empty' on the filename - see later below */
154
    }
154
    }
155
 
155
 
156
    if (curzipnode->filename[0] == 0) { /* ignore empty filenames (maybe it was empty originally, or has been emptied because it's a dropped source or link) */
156
    if (curzipnode->filename[0] == 0) { /* ignore empty filenames (maybe it was empty originally, or has been emptied because it's a dropped source or link) */
157
      if (prevzipnode == NULL) {  /* take the item out of the list */
157
      if (prevzipnode == NULL) {  /* take the item out of the list */
158
        ziplinkedlist = curzipnode->nextfile;
158
        ziplinkedlist = curzipnode->nextfile;
159
        free(curzipnode); /* free the item */
159
        free(curzipnode); /* free the item */
160
        curzipnode = ziplinkedlist;
160
        curzipnode = ziplinkedlist;
161
      } else {
161
      } else {
162
        prevzipnode->nextfile = curzipnode->nextfile;
162
        prevzipnode->nextfile = curzipnode->nextfile;
163
        free(curzipnode); /* free the item */
163
        free(curzipnode); /* free the item */
164
        curzipnode = prevzipnode->nextfile;
164
        curzipnode = prevzipnode->nextfile;
165
      }
165
      }
166
      continue; /* go to the next item */
166
      continue; /* go to the next item */
167
    }
167
    }
168
    /* validate that the file has a valid filename (8+3, no shady chars...) */
168
    /* validate that the file has a valid filename (8+3, no shady chars...) */
169
    if (validfilename(curzipnode->filename) != 0) {
169
    if (validfilename(curzipnode->filename) != 0) {
170
      puts(svarlang_str(3, 23)); /* "ERROR: Package contains an invalid filename:" */
170
      puts(svarlang_str(3, 23)); /* "ERROR: Package contains an invalid filename:" */
171
      printf(" %s\n", curzipnode->filename);
171
      printf(" %s\n", curzipnode->filename);
172
      goto RAII_ERR;
172
      goto RAII_ERR;
173
    }
173
    }
174
    /* look out for collisions with already existing files (unless we are
174
    /* look out for collisions with already existing files (unless we are
175
     * updating the package and the local file belongs to it */
175
     * updating the package and the local file belongs to it */
176
    shortfile = computelocalpath(curzipnode->filename, fname, dosdir, dirlist);
176
    shortfile = computelocalpath(curzipnode->filename, fname, dosdir, dirlist);
177
    strcat(fname, shortfile);
177
    strcat(fname, shortfile);
178
    if ((findfileinlist(flist, fname) == NULL) && (fileexists(fname) != 0)) {
178
    if ((findfileinlist(flist, fname) == NULL) && (fileexists(fname) != 0)) {
179
      puts(svarlang_str(3, 9)); /* "ERROR: Package contains a file that already exists locally:" */
179
      puts(svarlang_str(3, 9)); /* "ERROR: Package contains a file that already exists locally:" */
180
      printf(" %s\n", fname);
180
      printf(" %s\n", fname);
181
      goto RAII_ERR;
181
      goto RAII_ERR;
182
    }
182
    }
183
    /* abort if any entry is encrypted */
183
    /* abort if any entry is encrypted */
184
    if ((curzipnode->flags & ZIP_FLAG_ENCRYPTED) != 0) {
184
    if ((curzipnode->flags & ZIP_FLAG_ENCRYPTED) != 0) {
185
      puts(svarlang_str(3, 20)); /* "ERROR: Package contains an encrypted file:" */
185
      puts(svarlang_str(3, 20)); /* "ERROR: Package contains an encrypted file:" */
186
      printf(" %s\n", curzipnode->filename);
186
      printf(" %s\n", curzipnode->filename);
187
      goto RAII_ERR;
187
      goto RAII_ERR;
188
    }
188
    }
189
    /* abort if any file is compressed with an unsupported method */
189
    /* abort if any file is compressed with an unsupported method */
190
    if ((curzipnode->compmethod != ZIP_METH_STORE) && (curzipnode->compmethod != ZIP_METH_DEFLATE)) { /* unsupported compression method */
190
    if ((curzipnode->compmethod != ZIP_METH_STORE) && (curzipnode->compmethod != ZIP_METH_DEFLATE)) { /* unsupported compression method */
191
      kitten_printf(8, 2, curzipnode->compmethod); /* "ERROR: Package contains a file compressed with an unsupported method (%d):" */
191
      kitten_printf(8, 2, curzipnode->compmethod); /* "ERROR: Package contains a file compressed with an unsupported method (%d):" */
192
      puts("");
192
      puts("");
193
      printf(" %s\n", curzipnode->filename);
193
      printf(" %s\n", curzipnode->filename);
194
      goto RAII_ERR;
194
      goto RAII_ERR;
195
    }
195
    }
196
    if (strcmp(curzipnode->filename, appinfofile) == 0) appinfopresence = 1;
196
    if (strcmp(curzipnode->filename, appinfofile) == 0) appinfopresence = 1;
197
    prevzipnode = curzipnode;
197
    prevzipnode = curzipnode;
198
    curzipnode = curzipnode->nextfile;
198
    curzipnode = curzipnode->nextfile;
199
  }
199
  }
200
  /* if appinfo file not found, this is not a real SvarDOS package */
200
  /* if appinfo file not found, this is not a real SvarDOS package */
201
  if (appinfopresence != 1) {
201
  if (appinfopresence != 1) {
202
    kitten_printf(3, 12, appinfofile); /* "ERROR: Package do not contain the %s file! Not a valid SvarDOS package." */
202
    kitten_printf(3, 12, appinfofile); /* "ERROR: Package do not contain the %s file! Not a valid SvarDOS package." */
203
    puts("");
203
    puts("");
204
    goto RAII_ERR;
204
    goto RAII_ERR;
205
  }
205
  }
206
 
206
 
207
  goto RAII;
207
  goto RAII;
208
 
208
 
209
  RAII_ERR:
209
  RAII_ERR:
210
  zip_freelist(&ziplinkedlist);
210
  zip_freelist(&ziplinkedlist);
211
  ziplinkedlist = NULL;
211
  ziplinkedlist = NULL;
212
  if ((zipfd != NULL) && (*zipfd != NULL)) {
212
  if ((zipfd != NULL) && (*zipfd != NULL)) {
213
    fclose(*zipfd);
213
    fclose(*zipfd);
214
    *zipfd = NULL;
214
    *zipfd = NULL;
215
  }
215
  }
216
 
216
 
217
  RAII:
217
  RAII:
218
  pkg_freeflist(flist);
218
  pkg_freeflist(flist);
219
  return(ziplinkedlist);
219
  return(ziplinkedlist);
220
}
220
}
221
 
221
 
222
 
222
 
223
/* look for a "warn" field in the package's LSM file and display it if found */
223
/* look for a "warn" field in the package's LSM file and display it if found */
224
static void display_warn_if_exists(const char *pkgname, const char *dosdir, char *buff, size_t buffsz) {
224
static void display_warn_if_exists(const char *pkgname, const char *dosdir, char *buff, size_t buffsz) {
225
  FILE *fd;
225
  FILE *fd;
226
  char *msgptr;
226
  char *msgptr;
227
  int warncount = 0, i;
227
  int warncount = 0, i;
228
 
228
 
229
  sprintf(buff, "%s\\appinfo\\%s.lsm", dosdir, pkgname);
229
  sprintf(buff, "%s\\appinfo\\%s.lsm", dosdir, pkgname);
230
  fd = fopen(buff, "rb");
230
  fd = fopen(buff, "rb");
231
  if (fd == NULL) return;
231
  if (fd == NULL) return;
232
 
232
 
233
  while (freadtokval(fd, buff, buffsz, &msgptr, ':') == 0) {
233
  while (freadtokval(fd, buff, buffsz, &msgptr, ':') == 0) {
234
    if (msgptr != NULL) {
234
    if (msgptr != NULL) {
235
      if (strcasecmp(buff, "warn") == 0) {
235
      if (strcasecmp(buff, "warn") == 0) {
236
        /* print a visual delimiter */
236
        /* print a visual delimiter */
237
        if (warncount == 0) {
237
        if (warncount == 0) {
238
          puts("");
238
          puts("");
239
          for (i = 0; i < 79; i++) putchar('*');
239
          for (i = 0; i < 79; i++) putchar('*');
240
          puts("");
240
          puts("");
241
        }
241
        }
242
        /* there may be more than one "warn" line */
242
        /* there may be more than one "warn" line */
243
        puts(msgptr);
243
        puts(msgptr);
244
        warncount++;
244
        warncount++;
245
      }
245
      }
246
    }
246
    }
247
  }
247
  }
248
 
248
 
249
  fclose(fd);
249
  fclose(fd);
250
 
250
 
251
  /* if one or more warn lines have been displayed then close with a delimiter again */
251
  /* if one or more warn lines have been displayed then close with a delimiter again */
252
  if (warncount > 0) {
252
  if (warncount > 0) {
253
    for (i = 0; i < 79; i++) putchar('*');
253
    for (i = 0; i < 79; i++) putchar('*');
254
    puts("");
254
    puts("");
255
  }
255
  }
256
 
256
 
257
}
257
}
258
 
258
 
259
 
259
 
260
/* install a package that has been prepared already. returns 0 on success,
260
/* install a package that has been prepared already. returns 0 on success,
261
 * or a negative value on error, or a positive value on warning */
261
 * or a negative value on error, or a positive value on warning */
262
int pkginstall_installpackage(const char *pkgname, const char *dosdir, const struct customdirs *dirlist, struct ziplist *ziplinkedlist, FILE *zipfd) {
262
int pkginstall_installpackage(const char *pkgname, const char *dosdir, const struct customdirs *dirlist, struct ziplist *ziplinkedlist, FILE *zipfd) {
263
  char buff[256];
263
  char buff[256];
264
  char fulldestfilename[256];
264
  char fulldestfilename[256];
265
  char packageslst[32];
265
  char packageslst[32];
266
  char *shortfile;
266
  char *shortfile;
267
  long filesextractedsuccess = 0, filesextractedfailure = 0;
267
  long filesextractedsuccess = 0, filesextractedfailure = 0;
268
  struct ziplist *curzipnode;
268
  struct ziplist *curzipnode;
269
  FILE *lstfd;
269
  FILE *lstfd;
270
 
270
 
271
  sprintf(packageslst, "packages\\%s.lst", pkgname); /* Prepare the packages/xxxx.lst filename string for later use */
271
  sprintf(packageslst, "packages\\%s.lst", pkgname); /* Prepare the packages/xxxx.lst filename string for later use */
272
 
272
 
273
  /* create the %DOSDIR%/packages directory, just in case it doesn't exist yet */
273
  /* create the %DOSDIR%/packages directory, just in case it doesn't exist yet */
274
  sprintf(buff, "%s\\packages\\", dosdir);
274
  sprintf(buff, "%s\\packages\\", dosdir);
275
  mkpath(buff);
275
  mkpath(buff);
276
 
276
 
277
  /* open the lst file */
277
  /* open the lst file */
278
  sprintf(buff, "%s\\%s", dosdir, packageslst);
278
  sprintf(buff, "%s\\%s", dosdir, packageslst);
279
  lstfd = fopen(buff, "wb"); /* opening it in binary mode, because I like to have control over line terminators (CR/LF) */
279
  lstfd = fopen(buff, "wb"); /* opening it in binary mode, because I like to have control over line terminators (CR/LF) */
280
  if (lstfd == NULL) {
280
  if (lstfd == NULL) {
281
    kitten_printf(3, 10, buff); /* "ERROR: Could not create %s!" */
281
    kitten_printf(3, 10, buff); /* "ERROR: Could not create %s!" */
282
    puts("");
282
    puts("");
283
    return(-2);
283
    return(-2);
284
  }
284
  }
285
 
285
 
286
  /* write list of files in zip into the lst, and create the directories structure */
286
  /* write list of files in zip into the lst, and create the directories structure */
287
  for (curzipnode = ziplinkedlist; curzipnode != NULL; curzipnode = curzipnode->nextfile) {
287
  for (curzipnode = ziplinkedlist; curzipnode != NULL; curzipnode = curzipnode->nextfile) {
288
    int unzip_result;
288
    int unzip_result;
289
    if ((curzipnode->flags & ZIP_FLAG_ISADIR) != 0) continue; /* skip directories */
289
    if ((curzipnode->flags & ZIP_FLAG_ISADIR) != 0) continue; /* skip directories */
290
    shortfile = computelocalpath(curzipnode->filename, buff, dosdir, dirlist); /* substitute paths to custom dirs */
290
    shortfile = computelocalpath(curzipnode->filename, buff, dosdir, dirlist); /* substitute paths to custom dirs */
291
    /* log the filename to packages\pkg.lst */
291
    /* log the filename to packages\pkg.lst */
292
    fprintf(lstfd, "%s%s\r\n", buff, shortfile);
292
    fprintf(lstfd, "%s%s\r\n", buff, shortfile);
293
    /* create the path, just in case it doesn't exist yet */
293
    /* create the path, just in case it doesn't exist yet */
294
    mkpath(buff);
294
    mkpath(buff);
295
    sprintf(fulldestfilename, "%s%s", buff, shortfile);
295
    sprintf(fulldestfilename, "%s%s", buff, shortfile);
296
    /* Now unzip the file */
296
    /* Now unzip the file */
297
    unzip_result = zip_unzip(zipfd, curzipnode, fulldestfilename);
297
    unzip_result = zip_unzip(zipfd, curzipnode, fulldestfilename);
298
    if (unzip_result != 0) {
298
    if (unzip_result != 0) {
299
      kitten_printf(8, 3, curzipnode->filename, fulldestfilename); /* "ERROR: failed extracting '%s' to '%s'!" */
299
      kitten_printf(8, 3, curzipnode->filename, fulldestfilename); /* "ERROR: failed extracting '%s' to '%s'!" */
300
      printf(" [%d]\n", unzip_result);
300
      printf(" [%d]\n", unzip_result);
301
      filesextractedfailure += 1;
301
      filesextractedfailure += 1;
302
    } else {
302
    } else {
303
      printf(" %s -> %s\n", curzipnode->filename, buff);
303
      printf(" %s -> %s\n", curzipnode->filename, buff);
304
      filesextractedsuccess += 1;
304
      filesextractedsuccess += 1;
305
    }
305
    }
306
  }
306
  }
307
  fclose(lstfd);
307
  fclose(lstfd);
308
 
308
 
309
  kitten_printf(3, 19, pkgname, filesextractedsuccess, filesextractedfailure); /* "Package %s installed: %ld files extracted, %ld errors." */
309
  kitten_printf(3, 19, pkgname, filesextractedsuccess, filesextractedfailure); /* "Package %s installed: %ld files extracted, %ld errors." */
310
  puts("");
310
  puts("");
311
 
311
 
312
  /* scan the LSM file for a "warn" message to display */
312
  /* scan the LSM file for a "warn" message to display */
313
  display_warn_if_exists(pkgname, dosdir, buff, sizeof(buff));
313
  display_warn_if_exists(pkgname, dosdir, buff, sizeof(buff));
314
 
314
 
315
  return(filesextractedfailure);
315
  return(filesextractedfailure);
316
}
316
}
317
 
317