File: extract.c

package info (click to toggle)
orange 0.2-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,044 kB
  • ctags: 299
  • sloc: sh: 7,824; ansic: 2,419; makefile: 83
file content (94 lines) | stat: -rw-r--r-- 1,965 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* $Id: extract.c,v 1.2 2003/09/06 20:48:27 twogood Exp $ */
#define _BSD_SOURCE 1
#include "liborange_internal.h"
#include <libunshield.h>
#include <ctype.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>

bool orange_extract_is_cab(/*{{{*/
    const char* input_filename,
    const char* output_directory)
{
  bool success = false;
  Unshield* unshield = NULL;
  int i;
  int count;

  unshield = unshield_open(input_filename);
  if (!unshield)
    goto exit;
  
  count = unshield_file_count(unshield);

  if (count < 0)
    goto exit;

  if (!orange_make_sure_directory_exists(output_directory))
    goto exit;
  
  for (i = 0; i < count; i++)
  {
    char filename[256];
    char* p;

    if (unshield_file_is_valid(unshield, i))
    {
      snprintf(filename, sizeof(filename), "%s/%s", 
          output_directory, unshield_file_name(unshield, i));

      for (p = filename; *p != '\0'; p++)
        if (!isprint(*p))
          *p = '_';

      unshield_file_save(unshield, i, filename);
    }
  }

  success = true;
  
exit:
  unshield_close(unshield);
  return success;
}/*}}}*/

static bool orange_extract(const char* command)
{
  int status = system(command);

  return -1 != status && WIFEXITED(status) && WEXITSTATUS(status) == 0;
}

bool orange_extract_ms_cab(
    const char* input_filename,
    const char* output_directory)
{
  char command[1024];

  snprintf(command, sizeof(command), "cabextract -q -d \"%s\" \"%s\" 2>/dev/null",
      output_directory, input_filename);
  
  return orange_extract(command);
}

bool orange_extract_rar(
    const char* input_filename,
    const char* output_directory)
{
  bool success = false;
  return success;
}

bool orange_extract_zip(
    const char* input_filename,
    const char* output_directory)
{
  char command[1024];

  snprintf(command, sizeof(command), "unzip -o -qq -d \"%s\" \"%s\" 2>/dev/null",
      output_directory, input_filename);
  
  return orange_extract(command);
}