Subversion Repositories SvarDOS

Rev

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

Rev 219 Rev 228
Line 1... Line 1...
1
/*
1
/*
2
 * This file is part of FDNPKG
2
 * This file is part of PKGINST (SvarDOS)
3
 * Copyright (C) 2013-2017 Mateusz Viste. All rights reserved.
3
 * Copyright (C) 2013-2021 Mateusz Viste. All rights reserved.
4
 */
4
 */
5
 
5
 
6
#include <stdio.h>
6
#include <stdio.h>
7
#include <ctype.h>    /* tolower() */
7
#include <ctype.h>    /* tolower() */
8
#include <stdlib.h>   /* atoi(), qsort() - not using it after all, redefining it manually later */
8
#include <stdlib.h>   /* atoi(), qsort() - not using it after all, redefining it manually later */
9
#include <string.h>   /* strlen() */
9
#include <string.h>   /* strlen() */
10
#include <sys/types.h>
10
#include <sys/types.h>
11
 
-
 
12
/* opendir() and friends */
11
#include <direct.h> /* opendir() and friends */
13
#ifdef __WATCOMC__
-
 
14
  #include <direct.h>
-
 
15
#else
-
 
16
  #include <dirent.h>
-
 
17
#endif
-
 
18
 
12
 
19
#include "fdnpkg.h"   /* PKGINST_UPDATE */
13
#include "fdnpkg.h"   /* PKGINST_UPDATE */
20
#include "fileexst.h"
14
#include "fileexst.h"
21
#include "getdelim.h"
15
#include "getdelim.h"
22
#include "helpers.h"  /* fdnpkg_strcasestr(), slash2backslash()... */
16
#include "helpers.h"  /* fdnpkg_strcasestr(), slash2backslash()... */
Line 37... Line 31...
37
  char **s2 = (char **)str2;
31
  char **s2 = (char **)str2;
38
  return(strcasecmp(*s1, *s2));
32
  return(strcasecmp(*s1, *s2));
39
}
33
}
40
 
34
 
41
 
35
 
42
/* clears current line */
-
 
43
static void clrline(void) {
-
 
44
  printf("\r                                                                            \r");
-
 
45
}
-
 
46
 
-
 
47
 
-
 
48
static int loadinstpkglist(char **packagelist, char **packagelist_ver, int packagelist_maxlen, char *filterstr, char *dosdir) {
36
static int loadinstpkglist(char **packagelist, char **packagelist_ver, int packagelist_maxlen, char *filterstr, char *dosdir) {
49
  DIR *dp;
37
  DIR *dp;
50
  int packagelist_len = 0, x;
38
  int packagelist_len = 0, x;
51
  struct dirent *ep;
39
  struct dirent *ep;
52
  #define verstr_maxlen 64
40
  #define verstr_maxlen 64
Line 110... Line 98...
110
    printf("%s %s\n", packagelist[x], packagelist_ver[x]);
98
    printf("%s %s\n", packagelist[x], packagelist_ver[x]);
111
  }
99
  }
112
}
100
}
113
 
101
 
114
 
102
 
115
/* displays the list of available updates for local packages (or a single package if pkg is not NULL). Returns 0 if some updates are found, non zero otherwise. */
-
 
116
int checkupdates(char *dosdir, struct pkgdb *pkgdb, char **repolist, char *pkg, char *tempdir, int flags, struct customdirs *dirlist, char *proxy, int proxyport, char *downloadingstring, char *mapdrv) {
-
 
117
  struct pkgdb *curpkg;
-
 
118
  struct pkgrepo *currepo;
-
 
119
  char *packagelist[packagelist_maxlen];
-
 
120
  char *packagelist_ver[packagelist_maxlen];
-
 
121
  int packagelist_len, x, foundupdate = 0, totalupdatesfound = 0;
-
 
122
  int packages_updated = 0, packages_updatefailed = 0;
-
 
123
  packagelist_len = loadinstpkglist(packagelist, packagelist_ver, packagelist_maxlen, NULL, dosdir);
-
 
124
  for (x = 0; x < packagelist_len; x++) {
-
 
125
    if (pkg != NULL) {
-
 
126
      if (strcasecmp(pkg, packagelist[x]) != 0) continue; /* if we got asked for a specific package, skip all other packages. */
-
 
127
    } else { /* else display a progress so slower PCs don't think we are freezed */
-
 
128
      long percprogress = x; /* long, just in case we have more than 3'200 packages installed... */
-
 
129
      percprogress *= 100;
-
 
130
      percprogress /= packagelist_len;
-
 
131
      kitten_printf(10, 7, "Looking for updates...");
-
 
132
      printf(" %ld%% (%s)        \r", percprogress, packagelist[x]); /* empty spaces trailing for flushing the previous content on the line */
-
 
133
    }
-
 
134
    for (curpkg = pkgdb; curpkg != NULL; curpkg = curpkg->nextpkg) { /* iterate through packages */
-
 
135
      if (strcasecmp(curpkg->name, packagelist[x]) == 0) {
-
 
136
        foundupdate = 0;
-
 
137
        for (currepo = curpkg->repolist; currepo != NULL; currepo = currepo->nextrepo) { /* check for possible newer version in every repo */
-
 
138
          if (isversionnewer(packagelist_ver[x], currepo->version) > 0) { /* isversionnewer() returns 1 if version is newer */
-
 
139
            if (foundupdate == 0) {
-
 
140
              foundupdate = 1;
-
 
141
              totalupdatesfound += 1;
-
 
142
              if (pkg == NULL) {
-
 
143
                clrline();
-
 
144
                kitten_printf(10, 0, "%s (local version: %s)", packagelist[x], packagelist_ver[x]);
-
 
145
                puts("");
-
 
146
              }
-
 
147
            }
-
 
148
            if (pkg == NULL) {
-
 
149
              clrline();
-
 
150
              printf("  ");
-
 
151
              kitten_printf(10, 1, "version %s at %s", currepo->version, repolist[currepo->repo]);
-
 
152
              puts("");
-
 
153
            }
-
 
154
          }
-
 
155
        }
-
 
156
        /* actually upgrade the package, if requested so */
-
 
157
        if (foundupdate != 0) {
-
 
158
          if (flags & PKGINST_UPDATE) {
-
 
159
            FILE *zipfilefd;
-
 
160
            struct ziplist *zipfileidx;
-
 
161
            char buffmem1k[1024];
-
 
162
            clrline();
-
 
163
            kitten_printf(10, 3, "An update of '%s' has been found. Update in progress...", packagelist[x]);
-
 
164
            puts("");
-
 
165
            packages_updatefailed += 1; /* increment the updatefailed counter - later we will decrement it if we're okay */
-
 
166
            zipfileidx = pkginstall_preparepackage(pkgdb, packagelist[x], tempdir, NULL, flags, repolist, &zipfilefd, proxy, proxyport, downloadingstring, dosdir, dirlist, buffmem1k, mapdrv);
-
 
167
            if (zipfileidx != NULL) {
-
 
168
              if (pkgrem(packagelist[x], dosdir, mapdrv) != 0) {
-
 
169
                /* ooops, package removal failed... */
-
 
170
                zip_freelist(&zipfileidx);
-
 
171
              } else {  /* pkgrem == 0 */
-
 
172
                pkginstall_installpackage(packagelist[x], dosdir, dirlist, zipfileidx, zipfilefd, mapdrv);
-
 
173
                packages_updated += 1;
-
 
174
                packages_updatefailed -= 1; /* decrement the updatefailed counter to leverage the fact we incremented it without reason earlier */
-
 
175
              }
-
 
176
              fclose(zipfilefd);
-
 
177
            }
-
 
178
          }
-
 
179
          puts(""); /* add a line feed to visually separate packages */
-
 
180
        }
-
 
181
        break; /* get out of the loop to get over the next local package */
-
 
182
      }
-
 
183
    }
-
 
184
  }
-
 
185
  if (pkg == NULL) {
-
 
186
    clrline();
-
 
187
    kitten_printf(10, 5, "%d package update(s) found.", totalupdatesfound);
-
 
188
    puts("");
-
 
189
    if (flags & PKGINST_UPDATE) {
-
 
190
      kitten_printf(10, 4, "%d package(s) updated, %d package(s) failed.", packages_updated, packages_updatefailed);
-
 
191
      puts("");
-
 
192
    }
-
 
193
  }
-
 
194
  if (foundupdate != 0) {
-
 
195
    return(0);
-
 
196
  } else {
-
 
197
    return(-1);
-
 
198
  }
-
 
199
}
-
 
200
 
-
 
201
 
-
 
202
/* frees a linked list of filenames */
103
/* frees a linked list of filenames */
203
void pkg_freeflist(struct flist_t *flist) {
104
void pkg_freeflist(struct flist_t *flist) {
204
  while (flist != NULL) {
105
  while (flist != NULL) {
205
    struct flist_t *victim = flist;
106
    struct flist_t *victim = flist;
206
    flist = flist->next;
107
    flist = flist->next;