Subversion Repositories SvarDOS

Rev

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

Rev 226 Rev 236
Line 1... Line 1...
1
/*
1
/*
2
 * FDINST - lightweigth FreeDOS package installer
2
 * PKGINST - lightweigth SvarDOS package installer
3
 * Copyright (C) 2015-2017 Mateusz Viste
3
 * Copyright (C) 2015-2021 Mateusz Viste
4
 *
4
 *
5
 * Permission is hereby granted, free of charge, to any person obtaining a
5
 * Permission is hereby granted, free of charge, to any person obtaining a
6
 * copy of this software and associated documentation files (the "Software"),
6
 * copy of this software and associated documentation files (the "Software"),
7
 * to deal in the Software without restriction, including without limitation
7
 * to deal in the Software without restriction, including without limitation
8
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
Line 71... Line 71...
71
    return(ACTION_HELP);
71
    return(ACTION_HELP);
72
  }
72
  }
73
}
73
}
74
 
74
 
75
 
75
 
76
static int pkginst(char *file, int flags, char *dosdir, char *tempdir, struct customdirs *dirlist) {
76
static int pkginst(const char *file, int flags, const char *dosdir, struct customdirs *dirlist) {
77
  char pkgname[32];
77
  char pkgname[32];
78
  int t, lastpathdelim = -1, u = 0;
78
  int t, lastpathdelim = -1, u = 0;
79
  char *buffmem1k;
-
 
80
  struct ziplist *zipfileidx;
79
  struct ziplist *zipfileidx;
81
  FILE *zipfilefd;
80
  FILE *zipfilefd;
82
  for (t = 0; file[t] != 0; t++) {
81
  for (t = 0; file[t] != 0; t++) {
83
    if ((file[t] == '/') || (file[t] == '\\')) lastpathdelim = t;
82
    if ((file[t] == '/') || (file[t] == '\\')) lastpathdelim = t;
84
  }
83
  }
Line 90... Line 89...
90
    if (pkgname[t] == '.') {
89
    if (pkgname[t] == '.') {
91
      pkgname[t] = 0;
90
      pkgname[t] = 0;
92
      break;
91
      break;
93
    }
92
    }
94
  }
93
  }
95
  /* allocate some memory for pkginst_preparepackage() to do its job */
-
 
96
  buffmem1k = malloc(1024);
-
 
97
  if (buffmem1k == NULL) {
-
 
98
    puts("ERROR: Out of memory");
-
 
99
    return(1);
-
 
100
  }
-
 
101
  /* prepare the zip file and install it */
94
  /* prepare the zip file and install it */
102
  zipfileidx = pkginstall_preparepackage(pkgname, file, flags, &zipfilefd, dosdir, dirlist, buffmem1k);
95
  zipfileidx = pkginstall_preparepackage(pkgname, file, flags, &zipfilefd, dosdir, dirlist);
103
  free(buffmem1k);
-
 
104
  if (zipfileidx != NULL) {
96
  if (zipfileidx != NULL) {
105
    int res = 0;
97
    int res = 0;
106
    if (pkginstall_installpackage(pkgname, dosdir, dirlist, zipfileidx, zipfilefd) != 0) res = 1;
98
    if (pkginstall_installpackage(pkgname, dosdir, dirlist, zipfileidx, zipfilefd) != 0) res = 1;
107
    fclose(zipfilefd);
99
    fclose(zipfilefd);
108
    return(res);
100
    return(res);
Line 114... Line 106...
114
 
106
 
115
 
107
 
116
int main(int argc, char **argv) {
108
int main(int argc, char **argv) {
117
  int res, flags;
109
  int res, flags;
118
  enum ACTIONTYPES action;
110
  enum ACTIONTYPES action;
119
  char *dosdir, *tempdir, *cfgfile;
111
  char *dosdir, *cfgfile;
120
  struct customdirs *dirlist;
112
  struct customdirs *dirlist;
121
 
113
 
122
  action = parsearg(argc, argv);
114
  action = parsearg(argc, argv);
123
  if (action == ACTION_HELP) return(showhelp());
115
  if (action == ACTION_HELP) return(showhelp());
124
 
116
 
Line 128... Line 120...
128
    puts("ERROR: Out of memory");
120
    puts("ERROR: Out of memory");
129
    return(1);
121
    return(1);
130
  }
122
  }
131
 
123
 
132
  /* read all necessary environment variables */
124
  /* read all necessary environment variables */
133
  if (readenv(&dosdir, &tempdir, cfgfile, 256) != 0) {
125
  if (readenv(&dosdir, cfgfile, 256) != 0) {
134
    free(cfgfile);
126
    free(cfgfile);
135
    return(1);
127
    return(1);
136
  }
128
  }
137
 
129
 
138
  /* load configuration */
130
  /* load configuration */
Line 144... Line 136...
144
  free(cfgfile);
136
  free(cfgfile);
145
  cfgfile = NULL;
137
  cfgfile = NULL;
146
 
138
 
147
  switch (action) {
139
  switch (action) {
148
    case ACTION_INSTALL:
140
    case ACTION_INSTALL:
149
      res = pkginst(argv[2], flags, dosdir, tempdir, dirlist);
141
      res = pkginst(argv[2], flags, dosdir, dirlist);
150
      break;
142
      break;
151
    case ACTION_REMOVE:
143
    case ACTION_REMOVE:
152
      res = pkgrem(argv[2], dosdir);
144
      res = pkgrem(argv[2], dosdir);
153
      break;
145
      break;
154
    default:
146
    default: