Subversion Repositories SvarDOS

Rev

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

Rev 614 Rev 1678
Line 1... Line 1...
1
/*
1
/*
2
 * This file is part of the pkg (SvarDOS) project.
2
 * This file is part of the pkg (SvarDOS) project.
3
 * Copyright (C) Mateusz Viste 2012-2022
3
 * Copyright (C) Mateusz Viste 2012-2024
4
 */
4
 */
5
 
5
 
6
#include <ctype.h>    /* toupper() */
6
#include <ctype.h>    /* toupper() */
7
#include <stdio.h>
7
#include <stdio.h>
8
#include <string.h>    /* strlen() */
8
#include <string.h>    /* strlen() */
Line 68... Line 68...
68
  char buff[256];
68
  char buff[256];
69
  FILE *flist;
69
  FILE *flist;
70
  int lastdirsep;
70
  int lastdirsep;
71
  struct dirliststruct *dirlist = NULL; /* used to remember directories to remove */
71
  struct dirliststruct *dirlist = NULL; /* used to remember directories to remove */
72
 
72
 
73
  /* open the file %DOSDIR%\packages\pkgname.lst */
73
  /* open the (legacy) listing file at %DOSDIR%\packages\pkgname.lst
-
 
74
   * if not exists then fall back to appinfo\pkgname.lsm */
74
  sprintf(fpath, "%s\\packages\\%s.lst", dosdir, pkgname);
75
  sprintf(fpath, "%s\\packages\\%s.lst", dosdir, pkgname);
75
  flist = fopen(fpath, "rb");
76
  flist = fopen(fpath, "rb");
76
  if (flist == NULL) {
77
  if (flist == NULL) {
-
 
78
    sprintf(fpath, "%s\\appinfo\\%s.lsm", dosdir, pkgname);
-
 
79
    flist = fopen(fpath, "rb");
-
 
80
    if (flist == NULL) {
77
    kitten_printf(4, 0, pkgname); /* "Package %s is not installed, so not removed." */
81
      kitten_printf(4, 0, pkgname); /* "Package %s is not installed, so not removed." */
78
    puts("");
82
      puts("");
79
    return(-1);
83
      return(-1);
80
  }
84
    }
-
 
85
  }
81
 
86
 
82
  /* remove all files/folders listed in pkgname.lst but NOT pkgname.lst */
87
  /* remove all files/folders listed in pkgname.lsm but NOT pkgname.lsm */
83
  while (freadtokval(flist, buff, sizeof(buff), NULL, 0) == 0) {
88
  while (freadtokval(flist, buff, sizeof(buff), NULL, 0) == 0) {
84
    int x;
89
    int x;
-
 
90
 
-
 
91
    /* skip empty lines */
-
 
92
    if (buff[0] == 0) continue;
-
 
93
 
85
    slash2backslash(buff); /* change all slash to backslash */
94
    /* change all slash to backslash */
-
 
95
    slash2backslash(buff);
-
 
96
 
-
 
97
    /* skip garbage */
86
    if (buff[0] == 0) continue; /* skip empty lines */
98
    if ((buff[1] != ':') || (buff[2] != '\\')) continue;
-
 
99
 
-
 
100
    /* trim out CRC information (if present) */
-
 
101
    trimfnamecrc(buff);
87
 
102
 
88
    /* remember the path part for removal later */
103
    /* remember the path part for removal later */
89
    lastdirsep = -1;
104
    lastdirsep = -1;
90
    for (x = 1; buff[x] != 0; x++) {
105
    for (x = 1; buff[x] != 0; x++) {
91
      if ((buff[x] == '\\') && (buff[x - 1] != ':')) lastdirsep = x;
106
      if ((buff[x] == '\\') && (buff[x - 1] != ':')) lastdirsep = x;
Line 97... Line 112...
97
    }
112
    }
98
 
113
 
99
    /* if it's a directory, skip it */
114
    /* if it's a directory, skip it */
100
    if (buff[strlen(buff) - 1] == '\\') continue;
115
    if (buff[strlen(buff) - 1] == '\\') continue;
101
 
116
 
102
    /* do not delete pkgname.lst at this point - I am using it (will be deleted later) */
117
    /* do not delete pkgname.lst at this point because I am using it (will be
-
 
118
     * deleted later) */
103
    if (strcasecmp(buff, fpath) == 0) continue;
119
    if (strcasecmp(buff, fpath) == 0) continue;
104
 
120
 
105
    /* remove it */
121
    /* remove it */
106
    kitten_printf(4, 4, buff); /* "removing %s" */
122
    kitten_printf(4, 4, buff); /* "removing %s" */
107
    puts("");
123
    puts("");
108
    unlink(buff);
124
    unlink(buff);
109
  }
125
  }
110
 
126
 
111
  /* close the lst file */
127
  /* close the lsm file */
112
  fclose(flist);
128
  fclose(flist);
113
 
129
 
114
  /* iterate over dirlist and remove directories if empty, from longest to shortest */
130
  /* iterate over dirlist and remove directories if empty, from longest to shortest */
115
  while (dirlist != NULL) {
131
  while (dirlist != NULL) {
116
    struct dirliststruct *dirlistpos, *previousdir;
132
    struct dirliststruct *dirlistpos, *previousdir;
Line 133... Line 149...
133
    dirlist = dirlistpos->next;
149
    dirlist = dirlistpos->next;
134
    free(dirlistpos);
150
    free(dirlistpos);
135
  }
151
  }
136
 
152
 
137
  /* remove the lst file */
153
  /* remove the lst file */
-
 
154
  kitten_printf(4, 4, fpath); /* "removing %s" */
-
 
155
  puts("");
138
  unlink(fpath);
156
  unlink(fpath);
-
 
157
 
139
  kitten_printf(4, 5, pkgname); /* "Package %s has been removed." */
158
  kitten_printf(4, 5, pkgname); /* "Package %s has been removed." */
140
  puts("");
159
  puts("");
141
  return(0);
160
  return(0);
142
}
161
}