Subversion Repositories SvarDOS

Rev

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

Rev 1889 Rev 1963
Line 23... Line 23...
23
  FILE *fd;
23
  FILE *fd;
24
  int r = 0;
24
  int r = 0;
25
 
25
 
26
  fd = fopen(zipfile, "rb");
26
  fd = fopen(zipfile, "rb");
27
  if (fd == NULL) {
27
  if (fd == NULL) {
28
    puts(svarlang_str(10, 1)); /* "ERROR: Failed to open the archive file" */
28
    outputnl(svarlang_str(10, 1)); /* "ERROR: Failed to open the archive file" */
29
    return(1);
29
    return(1);
30
  }
30
  }
31
 
31
 
32
  zlist = zip_listfiles(fd);
32
  zlist = zip_listfiles(fd);
33
  if (zlist == NULL) {
33
  if (zlist == NULL) {
34
    puts(svarlang_str(10, 2)); /* "ERROR: Invalid ZIP archive" */
34
    outputnl(svarlang_str(10, 2)); /* "ERROR: Invalid ZIP archive" */
35
    fclose(fd);
35
    fclose(fd);
36
    return(-1);
36
    return(-1);
37
  }
37
  }
38
 
38
 
39
  if (listonly != 0) {
39
  if (listonly != 0) {
40
    /* just list the files inside the archive */
40
    /* just list the files inside the archive */
41
    for (znode = zlist; znode != NULL; znode = znode->nextfile) {
41
    for (znode = zlist; znode != NULL; znode = znode->nextfile) {
42
      puts(znode->filename);
42
      outputnl(znode->filename);
43
    }
43
    }
44
  } else {
44
  } else {
45
    /* examine the list of zipped files - make sure that no file currently
45
    /* examine the list of zipped files - make sure that no file currently
46
     * exists and that files are neither encrypted nor compressed with an
46
     * exists and that files are neither encrypted nor compressed with an
47
     * unsupported method */
47
     * unsupported method */
Line 53... Line 53...
53
      mkpath(znode->filename);
53
      mkpath(znode->filename);
54
      /* if a dir, we good already */
54
      /* if a dir, we good already */
55
      if (znode->flags == ZIP_FLAG_ISADIR) goto OK;
55
      if (znode->flags == ZIP_FLAG_ISADIR) goto OK;
56
      /* file already exists? */
56
      /* file already exists? */
57
      if (fileexists(znode->filename) != 0) {
57
      if (fileexists(znode->filename) != 0) {
58
        puts(svarlang_str(10, 3)); /* "ERROR: File already exists" */
58
        outputnl(svarlang_str(10, 3)); /* "ERROR: File already exists" */
59
        r = 1;
59
        r = 1;
60
        continue;
60
        continue;
61
      }
61
      }
62
      /* uncompress */
62
      /* uncompress */
63
      zres = zip_unzip(fd, znode, znode->filename);
63
      zres = zip_unzip(fd, znode, znode->filename);
64
      if (zres != 0) {
64
      if (zres != 0) {
65
        kitten_printf(10, 4, "ERROR: unzip failure (%d)", zres);
65
        kitten_printf(10, 4, "ERROR: unzip failure (%d)", zres);
66
        puts("");
66
        outputnl("");
67
        continue;
67
        continue;
68
      }
68
      }
69
      OK:
69
      OK:
70
      puts(svarlang_str(10, 0)); /* "OK" */
70
      outputnl(svarlang_str(10, 0)); /* "OK" */
71
    }
71
    }
72
  }
72
  }
73
 
73
 
74
  zip_freelist(&zlist);
74
  zip_freelist(&zlist);
75
  fclose(fd);
75
  fclose(fd);