Subversion Repositories SvarDOS

Rev

Rev 1965 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1965 Rev 1968
Line 27... Line 27...
27
modify [ax bx dx]
27
modify [ax bx dx]
28
 
28
 
29
 
29
 
30
/* checks the health of a package (or all packages).
30
/* checks the health of a package (or all packages).
31
 * Returns 0 on success, non-zero otherwise */
31
 * Returns 0 on success, non-zero otherwise */
32
int healthcheck(unsigned char *buff4k, const char *pkgname, const char *dosdir, unsigned char extendedcheck) {
32
int healthcheck(unsigned char *buff15k, const char *pkgname, const char *dosdir, unsigned char extendedcheck) {
33
  char *crc, *ext;
33
  char *crc, *ext;
34
  FILE *flist, *fd;
34
  FILE *flist, *fd;
35
  unsigned long goodcrc, realcrc;
35
  unsigned long goodcrc, realcrc;
36
  unsigned short errcount = 0;
36
  unsigned short errcount = 0;
37
  DIR *dp = NULL;
37
  DIR *dp = NULL;
38
  struct dirent *ep;
38
  struct dirent *ep;
39
 
39
 
40
  if (pkgname == NULL) {
40
  if (pkgname == NULL) {
41
    sprintf(buff4k, "%s\\appinfo", dosdir);
41
    sprintf(buff15k, "%s\\appinfo", dosdir);
42
    dp = opendir(buff4k);
42
    dp = opendir(buff15k);
43
    if (dp == NULL) {
43
    if (dp == NULL) {
44
      output(svarlang_str(9, 0)); /* "ERROR: Could not access directory:" */
44
      output(svarlang_str(9, 0)); /* "ERROR: Could not access directory:" */
45
      outputnl(buff4k);
45
      outputnl(buff15k);
46
      return(-1);
46
      return(-1);
47
    }
47
    }
48
 
48
 
49
    AGAIN:
49
    AGAIN:
50
 
50
 
Line 69... Line 69...
69
   * pkgname is valid now so let's proceed with serious stuff *
69
   * pkgname is valid now so let's proceed with serious stuff *
70
   ************************************************************/
70
   ************************************************************/
71
 
71
 
72
  /* open the (legacy) listing file at %DOSDIR%\packages\pkgname.lst
72
  /* open the (legacy) listing file at %DOSDIR%\packages\pkgname.lst
73
   * if not exists then fall back to appinfo\pkgname.lsm */
73
   * if not exists then fall back to appinfo\pkgname.lsm */
74
  sprintf(buff4k, "%s\\appinfo\\%s.lsm", dosdir, pkgname);
74
  sprintf(buff15k, "%s\\appinfo\\%s.lsm", dosdir, pkgname);
75
  flist = fopen(buff4k, "rb");
75
  flist = fopen(buff15k, "rb");
76
  if (flist == NULL) {
76
  if (flist == NULL) {
77
    sprintf(buff4k, svarlang_str(4,0), pkgname); /* "Package %s is not installed, so not removed." */
77
    sprintf(buff15k, svarlang_str(4,0), pkgname); /* "Package %s is not installed, so not removed." */
78
    outputnl(buff4k);
78
    outputnl(buff15k);
79
    return(-1);
79
    return(-1);
80
  }
80
  }
81
 
81
 
82
  /* iterate over all files listed in pkgname.lsm */
82
  /* iterate over all files listed in pkgname.lsm */
83
  while (freadtokval(flist, buff4k, 4096, NULL, 0) == 0) {
83
  while (freadtokval(flist, buff15k, 15 * 1024, NULL, 0) == 0) {
84
 
84
 
85
    /* skip empty lines */
85
    /* skip empty lines */
86
    if (buff4k[0] == 0) continue;
86
    if (buff15k[0] == 0) continue;
87
 
87
 
88
    /* change all slash to backslash */
88
    /* change all slash to backslash */
89
    slash2backslash(buff4k);
89
    slash2backslash(buff15k);
90
 
90
 
91
    /* skip garbage */
91
    /* skip garbage */
92
    if ((buff4k[1] != ':') || (buff4k[2] != '\\')) continue;
92
    if ((buff15k[1] != ':') || (buff15k[2] != '\\')) continue;
93
 
93
 
94
    /* trim out CRC information and get the ptr to it (if present) */
94
    /* trim out CRC information and get the ptr to it (if present) */
95
    crc = trimfnamecrc(buff4k);
95
    crc = trimfnamecrc(buff15k);
96
    if (crc == NULL) continue;
96
    if (crc == NULL) continue;
97
 
97
 
98
    goodcrc = strtoul(crc, NULL, 16);
98
    goodcrc = strtoul(crc, NULL, 16);
-
 
99
    strlwr(buff15k); /* turn filename lower case - this is needed for aesthetics
-
 
100
    when printing errors, but also for matching extensions */
99
    ext = getfext(buff4k);
101
    ext = getfext(buff15k);
100
    strlwr(ext);
-
 
101
 
102
 
102
    /* skip non-executable files (unless healthcheck+) */
103
    /* skip non-executable files (unless healthcheck+) */
103
    if ((extendedcheck == 0) &&
104
    if ((extendedcheck == 0) &&
104
        (strcmp(ext, "bat") != 0) &&
105
        (strcmp(ext, "bat") != 0) &&
105
        (strcmp(ext, "bin") != 0) &&
106
        (strcmp(ext, "bin") != 0) &&
Line 111... Line 112...
111
        (strcmp(ext, "sys") != 0)) continue;
112
        (strcmp(ext, "sys") != 0)) continue;
112
 
113
 
113
    output("[");
114
    output("[");
114
    output(pkgname);
115
    output(pkgname);
115
    output("] ");
116
    output("] ");
116
    output(buff4k);
117
    output(buff15k);
117
 
118
 
118
    realcrc = CRC32_INITVAL;
119
    realcrc = CRC32_INITVAL;
119
    fd = fopen(buff4k, "rb");
120
    fd = fopen(buff15k, "rb");
120
    if (fd == NULL) {
121
    if (fd == NULL) {
121
      outputnl(": NOT FOUND");
122
      output(" ");
-
 
123
      outputnl(svarlang_str(11,1));
122
      continue;
124
      continue;
123
    }
125
    }
124
    for (;;) {
126
    for (;;) {
125
      unsigned short bufflen;
127
      unsigned short bufflen;
126
      bufflen = fread(buff4k, 1, 4096, fd);
128
      bufflen = fread(buff15k, 1, 15 * 1024, fd);
127
      if (bufflen == 0) break;
129
      if (bufflen == 0) break;
128
      crc32_feed(&realcrc, buff4k, bufflen);
130
      crc32_feed(&realcrc, buff15k, bufflen);
129
    }
131
    }
130
    fclose(fd);
132
    fclose(fd);
131
 
133
 
132
    crc32_finish(&realcrc);
134
    crc32_finish(&realcrc);
133
 
135
 
134
    if (goodcrc != realcrc) {
136
    if (goodcrc != realcrc) {
135
      sprintf(buff4k, ": %s", "BAD CRC");
137
      output(" ");
136
      outputnl(buff4k);
138
      outputnl(svarlang_str(11,0)); /* BAD CRC */
137
      errcount++;
139
      errcount++;
138
      continue;
140
      continue;
139
    }
141
    }
140
 
142
 
141
    clrcurline(80);
143
    clrcurline(80);
Line 150... Line 152...
150
  DONE:
152
  DONE:
151
 
153
 
152
  if (errcount == 0) {
154
  if (errcount == 0) {
153
    outputnl(svarlang_strid(0x0A00));
155
    outputnl(svarlang_strid(0x0A00));
154
  } else {
156
  } else {
155
    sprintf(buff4k, "%u errors.", errcount);
157
    sprintf(buff15k, svarlang_str(11,2), errcount);
156
    outputnl(buff4k);
158
    outputnl(buff15k);
157
  }
159
  }
158
  return(0);
160
  return(0);
159
}
161
}