Subversion Repositories SvarDOS

Rev

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

Rev 242 Rev 244
1
/*
1
/*
2
 * PKGINST - SvarDOS package installer
2
 * PKGINST - SvarDOS package installer
3
 *
3
 *
4
 * PUBLISHED UNDER THE TERMS OF THE MIT LICENSE
4
 * PUBLISHED UNDER THE TERMS OF THE MIT LICENSE
5
 *
5
 *
6
 * COPYRIGHT (C) 2016-2021 MATEUSZ VISTE, ALL RIGHTS RESERVED.
6
 * COPYRIGHT (C) 2016-2021 MATEUSZ VISTE, ALL RIGHTS RESERVED.
7
 *
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining a
8
 * Permission is hereby granted, free of charge, to any person obtaining a
9
 * copy of this software and associated documentation files (the "Software"),
9
 * copy of this software and associated documentation files (the "Software"),
10
 * to deal in the Software without restriction, including without limitation
10
 * to deal in the Software without restriction, including without limitation
11
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
 * and/or sell copies of the Software, and to permit persons to whom the
12
 * and/or sell copies of the Software, and to permit persons to whom the
13
 * Software is furnished to do so, subject to the following conditions:
13
 * Software is furnished to do so, subject to the following conditions:
14
 *
14
 *
15
 * The above copyright notice and this permission notice shall be included in
15
 * The above copyright notice and this permission notice shall be included in
16
 * all copies or substantial portions of the Software.
16
 * all copies or substantial portions of the Software.
17
 *
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24
 * DEALINGS IN THE SOFTWARE.
24
 * DEALINGS IN THE SOFTWARE.
25
 */
25
 */
26
 
26
 
27
 
27
 
28
#include <stdio.h>    /* printf() */
28
#include <stdio.h>    /* printf() */
29
#include <stdlib.h>   /* malloc() and friends */
29
#include <stdlib.h>   /* malloc() and friends */
30
#include <string.h>   /* strcasecmp() */
30
#include <string.h>   /* strcasecmp() */
31
 
31
 
-
 
32
#include "kitten/kitten.h"
32
#include "kprintf.h"
33
#include "kprintf.h"
33
#include "libunzip.h"
34
#include "libunzip.h"
34
#include "pkginst.h"
35
#include "pkginst.h"
35
#include "pkgrem.h"
36
#include "pkgrem.h"
36
#include "showinst.h"
37
#include "showinst.h"
37
#include "version.h"
38
#include "version.h"
38
 
39
 
39
 
40
 
40
enum ACTIONTYPES {
41
enum ACTIONTYPES {
41
  ACTION_INSTALL,
42
  ACTION_INSTALL,
42
  ACTION_REMOVE,
43
  ACTION_REMOVE,
43
  ACTION_LISTFILES,
44
  ACTION_LISTFILES,
44
  ACTION_HELP
45
  ACTION_HELP
45
};
46
};
46
 
47
 
47
 
48
 
48
static int showhelp(void) {
49
static int showhelp(void) {
49
  printf("PKGINST ver " PVER " Copyright (C) " PDATE " Mateusz Viste\n"
50
  printf("PKGINST ver " PVER " Copyright (C) " PDATE " Mateusz Viste\n"
50
         "\n"
51
         "\n"
51
         "PKGINST is the package installer for SvarDOS.\n"
52
         "PKGINST is the package installer for SvarDOS.\n"
52
         "\n"
53
         "\n"
53
         "Usage: PKGINST install package.zip\n"
54
         "Usage: PKGINST install package.zip\n"
54
         "       PKGINST remove package\n"
55
         "       PKGINST remove package\n"
55
         "       PKGINST listfiles package\n"
56
         "       PKGINST listfiles package\n"
56
         "\n"
57
         "\n"
57
         "PKGINST is published under the MIT license. It uses a configuration file\n"
58
         "PKGINST is published under the MIT license. It uses a configuration file\n"
58
         "located at %%DOSDIR%%\\CFG\\PKGINST.CFG\n"
59
         "located at %%DOSDIR%%\\CFG\\PKGINST.CFG\n"
59
         );
60
         );
60
  return(1);
61
  return(1);
61
}
62
}
62
 
63
 
63
 
64
 
64
static enum ACTIONTYPES parsearg(int argc, char **argv) {
65
static enum ACTIONTYPES parsearg(int argc, char **argv) {
65
  /* I expect exactly 2 arguments (ie argc == 3) */
66
  /* I expect exactly 2 arguments (ie argc == 3) */
66
  if (argc != 3) return(ACTION_HELP);
67
  if (argc != 3) return(ACTION_HELP);
67
 
68
 
68
  /* look for valid actions */
69
  /* look for valid actions */
69
  if (strcasecmp(argv[1], "install") == 0) {
70
  if (strcasecmp(argv[1], "install") == 0) {
70
    return(ACTION_INSTALL);
71
    return(ACTION_INSTALL);
71
  } else if (strcasecmp(argv[1], "remove") == 0) {
72
  } else if (strcasecmp(argv[1], "remove") == 0) {
72
    return(ACTION_REMOVE);
73
    return(ACTION_REMOVE);
73
  } else if (strcasecmp(argv[1], "listfiles") == 0) {
74
  } else if (strcasecmp(argv[1], "listfiles") == 0) {
74
    return(ACTION_LISTFILES);
75
    return(ACTION_LISTFILES);
75
  } else {
76
  } else {
76
    return(ACTION_HELP);
77
    return(ACTION_HELP);
77
  }
78
  }
78
}
79
}
79
 
80
 
80
 
81
 
81
static int pkginst(const char *file, int flags, const char *dosdir, const struct customdirs *dirlist) {
82
static int pkginst(const char *file, int flags, const char *dosdir, const struct customdirs *dirlist) {
82
  char pkgname[32];
83
  char pkgname[32];
83
  int t, lastpathdelim = -1, u = 0;
84
  int t, lastpathdelim = -1, u = 0;
84
  struct ziplist *zipfileidx;
85
  struct ziplist *zipfileidx;
85
  FILE *zipfilefd;
86
  FILE *zipfilefd;
86
  for (t = 0; file[t] != 0; t++) {
87
  for (t = 0; file[t] != 0; t++) {
87
    if ((file[t] == '/') || (file[t] == '\\')) lastpathdelim = t;
88
    if ((file[t] == '/') || (file[t] == '\\')) lastpathdelim = t;
88
  }
89
  }
89
  /* copy the filename into pkgname (without path elements) */
90
  /* copy the filename into pkgname (without path elements) */
90
  for (t = lastpathdelim + 1; file[t] != 0; t++) pkgname[u++] = file[t];
91
  for (t = lastpathdelim + 1; file[t] != 0; t++) pkgname[u++] = file[t];
91
  pkgname[u] = 0; /* terminate the string */
92
  pkgname[u] = 0; /* terminate the string */
92
  /* truncate the file's extension (.zip) */
93
  /* truncate the file's extension (.zip) */
93
  for (t = u; t > 0; t--) {
94
  for (t = u; t > 0; t--) {
94
    if (pkgname[t] == '.') {
95
    if (pkgname[t] == '.') {
95
      pkgname[t] = 0;
96
      pkgname[t] = 0;
96
      break;
97
      break;
97
    }
98
    }
98
  }
99
  }
99
  /* prepare the zip file and install it */
100
  /* prepare the zip file and install it */
100
  zipfileidx = pkginstall_preparepackage(pkgname, file, flags, &zipfilefd, dosdir, dirlist);
101
  zipfileidx = pkginstall_preparepackage(pkgname, file, flags, &zipfilefd, dosdir, dirlist);
101
  if (zipfileidx != NULL) {
102
  if (zipfileidx != NULL) {
102
    int res = 0;
103
    int res = 0;
103
    if (pkginstall_installpackage(pkgname, dosdir, dirlist, zipfileidx, zipfilefd) != 0) res = 1;
104
    if (pkginstall_installpackage(pkgname, dosdir, dirlist, zipfileidx, zipfilefd) != 0) res = 1;
104
    fclose(zipfilefd);
105
    fclose(zipfilefd);
105
    return(res);
106
    return(res);
106
  } else {
107
  } else {
107
    fclose(zipfilefd);
108
    fclose(zipfilefd);
108
    return(1);
109
    return(1);
109
  }
110
  }
110
}
111
}
111
 
112
 
112
 
113
 
113
int main(int argc, char **argv) {
114
int main(int argc, char **argv) {
114
  int res, flags;
115
  int res = 1, flags;
115
  enum ACTIONTYPES action;
116
  enum ACTIONTYPES action;
116
  const char *dosdir;
117
  const char *dosdir;
117
  struct customdirs *dirlist;
118
  struct customdirs *dirlist;
118
 
119
 
-
 
120
  kittenopen("pkginst"); /* NLS init */
-
 
121
 
119
  action = parsearg(argc, argv);
122
  action = parsearg(argc, argv);
120
  if (action == ACTION_HELP) return(showhelp());
123
  if (action == ACTION_HELP) {
-
 
124
    showhelp();
-
 
125
    goto GAMEOVER;
-
 
126
  }
121
 
127
 
122
  /* read the DOSDIR environment variable */
128
  /* read the DOSDIR environment variable */
123
  dosdir = getenv("DOSDIR");
129
  dosdir = getenv("DOSDIR");
124
  if (dosdir == NULL) {
130
  if (dosdir == NULL) {
125
    kitten_puts(2, 2, "%DOSDIR% not set! You should make it point to the FreeDOS main directory.");
131
    kitten_puts(2, 2, "%DOSDIR% not set! You should make it point to the FreeDOS main directory.");
126
    kitten_puts(2, 3, "Example: SET DOSDIR=C:\\FDOS");
132
    kitten_puts(2, 3, "Example: SET DOSDIR=C:\\FDOS");
127
    return(-1);
133
    goto GAMEOVER;
128
  }
134
  }
129
 
135
 
130
  /* load configuration */
136
  /* load configuration */
131
  flags = 0;
137
  flags = 0;
132
  dirlist = NULL;
138
  dirlist = NULL;
133
  if (loadconf(dosdir, &dirlist, &flags) != 0) return(5);
139
  if (loadconf(dosdir, &dirlist, &flags) != 0) goto GAMEOVER;
134
 
140
 
135
  switch (action) {
141
  switch (action) {
136
    case ACTION_INSTALL:
142
    case ACTION_INSTALL:
137
      res = pkginst(argv[2], flags, dosdir, dirlist);
143
      res = pkginst(argv[2], flags, dosdir, dirlist);
138
      break;
144
      break;
139
    case ACTION_REMOVE:
145
    case ACTION_REMOVE:
140
      res = pkgrem(argv[2], dosdir);
146
      res = pkgrem(argv[2], dosdir);
141
      break;
147
      break;
142
    case ACTION_LISTFILES:
148
    case ACTION_LISTFILES:
143
      res = listfilesofpkg(argv[2], dosdir);
149
      res = listfilesofpkg(argv[2], dosdir);
144
      break;
150
      break;
145
    default:
151
    default:
146
      res = showhelp();
152
      res = showhelp();
147
      break;
153
      break;
148
  }
154
  }
149
 
155
 
-
 
156
  GAMEOVER:
-
 
157
  kittenclose(); /* NLS de-init */
150
  if (res != 0) return(1);
158
  if (res != 0) return(1);
151
  return(0);
159
  return(0);
152
}
160
}
153
 
161