Subversion Repositories SvarDOS

Rev

Rev 1963 | Rev 1966 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1963 Rev 1964
Line 31... Line 31...
31
 
31
 
32
#include "svarlang.lib/svarlang.h"
32
#include "svarlang.lib/svarlang.h"
33
#include "healthck.h"
33
#include "healthck.h"
34
#include "crc32.h"
34
#include "crc32.h"
35
#include "helpers.h"
35
#include "helpers.h"
36
#include "kprintf.h"
-
 
37
#include "libunzip.h"
36
#include "libunzip.h"
38
#include "pkginst.h"
37
#include "pkginst.h"
39
#include "pkgrem.h"
38
#include "pkgrem.h"
40
#include "showinst.h"
39
#include "showinst.h"
41
#include "unzip.h"
40
#include "unzip.h"
Line 107... Line 106...
107
    return(ACTION_HELP);
106
    return(ACTION_HELP);
108
  }
107
  }
109
}
108
}
110
 
109
 
111
 
110
 
112
static int pkginst(const char *file, int flags, const char *dosdir, const struct customdirs *dirlist, char bootdrive) {
111
static int pkginst(const char *file, int flags, const char *dosdir, const struct customdirs *dirlist, char bootdrive, unsigned char *buff15k) {
113
  char pkgname[9];
112
  char pkgname[9];
114
  int res = 1;
113
  int res = 1;
115
  struct ziplist *zipfileidx;
114
  struct ziplist *zipfileidx;
116
  FILE *zipfilefd;
115
  FILE *zipfilefd;
117
 
116
 
Line 124... Line 123...
124
 
123
 
125
    /* remove the old version of the package if we are UPDATING it */
124
    /* remove the old version of the package if we are UPDATING it */
126
    res = 0;
125
    res = 0;
127
    if (flags & PKGINST_UPDATE) res = pkgrem(pkgname, dosdir);
126
    if (flags & PKGINST_UPDATE) res = pkgrem(pkgname, dosdir);
128
 
127
 
129
    if (res == 0) res = pkginstall_installpackage(pkgname, dosdir, dirlist, zipfileidx, zipfilefd, bootdrive);
128
    if (res == 0) res = pkginstall_installpackage(pkgname, dosdir, dirlist, zipfileidx, zipfilefd, bootdrive, buff15k);
130
    zip_freelist(&zipfileidx);
129
    zip_freelist(&zipfileidx);
131
  }
130
  }
132
 
131
 
133
  fclose(zipfilefd);
132
  fclose(zipfilefd);
134
  return(res);
133
  return(res);
135
}
134
}
136
 
135
 
137
 
136
 
138
/* pkg crc32 file */
137
/* pkg crc32 file */
139
static int crcfile(const char *fname) {
138
static int crcfile(const char *fname, unsigned char *buff4k) {
140
  FILE *fd;
139
  FILE *fd;
141
  unsigned long crc;
140
  unsigned long crc;
142
  unsigned char buff[512];
-
 
143
  unsigned int len;
141
  unsigned int len;
144
 
142
 
145
  fd = fopen(fname, "rb");
143
  fd = fopen(fname, "rb");
146
  if (fd == NULL) {
144
  if (fd == NULL) {
147
    outputnl(svarlang_str(10, 1)); /* failed to open file */
145
    outputnl(svarlang_str(10, 1)); /* failed to open file */
148
    return(1);
146
    return(1);
149
  }
147
  }
150
 
148
 
151
  crc = crc32_init();
149
  crc = CRC32_INITVAL;
152
 
150
 
153
  for (;;) {
151
  for (;;) {
154
    len = fread(buff, 1, sizeof(buff), fd);
152
    len = fread(buff4k, 1, 4096, fd);
155
    if (len == 0) break;
153
    if (len == 0) break;
156
    crc32_feed(&crc, buff, len);
154
    crc32_feed(&crc, buff4k, len);
157
  }
155
  }
158
  fclose(fd);
156
  fclose(fd);
159
 
157
 
160
  crc32_finish(&crc);
158
  crc32_finish(&crc);
161
 
159
 
162
  printf("%08lX", crc);
160
  crc32tostring(buff4k, crc);
163
  outputnl("");
161
  outputnl(buff4k);
164
 
162
 
165
  return(0);
163
  return(0);
166
}
164
}
167
 
165
 
168
 
166
 
169
int main(int argc, char **argv) {
167
int main(int argc, char **argv) {
-
 
168
  static unsigned char buff15k[15 * 1024];
170
  int res = 1;
169
  int res = 1;
171
  enum ACTIONTYPES action;
170
  enum ACTIONTYPES action;
172
  const char *dosdir;
171
  const char *dosdir;
173
  struct customdirs *dirlist;
172
  struct customdirs *dirlist;
174
  char bootdrive;
173
  char bootdrive;
Line 179... Line 178...
179
  switch (action) {
178
  switch (action) {
180
    case ACTION_HELP:
179
    case ACTION_HELP:
181
      res = showhelp();
180
      res = showhelp();
182
      goto GAMEOVER;
181
      goto GAMEOVER;
183
    case ACTION_UNZIP:
182
    case ACTION_UNZIP:
184
      res = unzip(argv[2], 0);
183
      res = unzip(argv[2], 0, buff15k);
185
      goto GAMEOVER;
184
      goto GAMEOVER;
186
    case ACTION_LISTZIP:
185
    case ACTION_LISTZIP:
187
      res = unzip(argv[2], 1);
186
      res = unzip(argv[2], 1, buff15k);
188
      goto GAMEOVER;
187
      goto GAMEOVER;
189
    case ACTION_CRC32:
188
    case ACTION_CRC32:
190
      res = crcfile(argv[2]);
189
      res = crcfile(argv[2], buff15k);
191
      goto GAMEOVER;
190
      goto GAMEOVER;
192
  }
191
  }
193
 
192
 
194
  /* read the DOSDIR environment variable */
193
  /* read the DOSDIR environment variable */
195
  dosdir = getenv("DOSDIR");
194
  dosdir = getenv("DOSDIR");
Line 203... Line 202...
203
  if (loadconf(dosdir, &dirlist, &bootdrive) != 0) goto GAMEOVER;
202
  if (loadconf(dosdir, &dirlist, &bootdrive) != 0) goto GAMEOVER;
204
 
203
 
205
  switch (action) {
204
  switch (action) {
206
    case ACTION_UPDATE:
205
    case ACTION_UPDATE:
207
    case ACTION_INSTALL:
206
    case ACTION_INSTALL:
208
      res = pkginst(argv[2], (action == ACTION_UPDATE)?PKGINST_UPDATE:0, dosdir, dirlist, bootdrive);
207
      res = pkginst(argv[2], (action == ACTION_UPDATE)?PKGINST_UPDATE:0, dosdir, dirlist, bootdrive, buff15k);
209
      break;
208
      break;
210
    case ACTION_REMOVE:
209
    case ACTION_REMOVE:
211
      res = pkgrem(argv[2], dosdir);
210
      res = pkgrem(argv[2], dosdir);
212
      break;
211
      break;
213
    case ACTION_LISTFILES:
212
    case ACTION_LISTFILES:
Line 216... Line 215...
216
    case ACTION_LISTLOCAL:
215
    case ACTION_LISTLOCAL:
217
      res = showinstalledpkgs((argc == 3)?argv[2]:NULL, dosdir);
216
      res = showinstalledpkgs((argc == 3)?argv[2]:NULL, dosdir);
218
      break;
217
      break;
219
    case ACTION_HEALTHCHECK:
218
    case ACTION_HEALTHCHECK:
220
    case ACTION_HEALTHCHECKEXT:
219
    case ACTION_HEALTHCHECKEXT:
221
      res = healthcheck((argc == 3)?argv[2]:NULL, dosdir, (action == ACTION_HEALTHCHECKEXT)?1:0);
220
      res = healthcheck(buff15k, (argc == 3)?argv[2]:NULL, dosdir, (action == ACTION_HEALTHCHECKEXT)?1:0);
222
      break;
221
      break;
223
    default:
222
    default:
224
      res = showhelp();
223
      res = showhelp();
225
      break;
224
      break;
226
  }
225
  }