aboutsummaryrefslogtreecommitdiffstats
path: root/autoarchive/test-extract.c
blob: d122ca47ad22c2bee2edac918c0069826fa2f907 (plain) (blame)
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
/* vim: set sw=2 ts=2 sts=2 et: */

#include "autoar-extract.h"
#include <stdlib.h>

static void
my_handler_scanned (AutoarExtract *arextract,
                    guint files,
                    gpointer data)
{
  g_print ("Scanning OK, %d files to be extracted.\n", files);
}

static void
my_handler_decide_dest (AutoarExtract *arextract,
                        GFile *dest)
{
  char *path, *uri;
  path = g_file_get_path (dest);
  uri = g_file_get_uri (dest);
  g_print ("Destination Path: %s\n", path);
  g_print ("Destination URI: %s\n", uri);
  g_free (path);
  g_free (uri);
}

static void
my_handler_progress (AutoarExtract *arextract,
                     gdouble fraction_size,
                     gdouble fraction_files,
                     gpointer data)
{
  g_print ("\rProgress: Archive Size %.2lf %%, Files %.2lf %%",
           fraction_size * 100,
           fraction_files * 100);
}

static void
my_handler_error (AutoarExtract *arextract,
                  GError *error,
                  gpointer data)
{
  g_printerr ("\nError: %s\n", error->message);
  g_error_free (error);
  exit (1);
}

static void
my_handler_completed (AutoarExtract *arextract,
                      gpointer data)
{
  g_print ("\nCompleted!\n");
  exit (0);
}

int
main (int argc,
      char *argv[])
{
  AutoarExtract *arextract;

  if (argc < 3) {
    g_printerr ("Usage: %s archive_file output_dir\n", argv[0]);
    return 255;
  }

  arextract = autoar_extract_new (argv[1], argv[2]);
  g_signal_connect (arextract, "scanned", G_CALLBACK (my_handler_scanned), NULL);
  g_signal_connect (arextract, "decide-dest", G_CALLBACK (my_handler_decide_dest), NULL);
  g_signal_connect (arextract, "progress", G_CALLBACK (my_handler_progress), NULL);
  g_signal_connect (arextract, "error", G_CALLBACK (my_handler_error), NULL);
  g_signal_connect (arextract, "completed", G_CALLBACK (my_handler_completed), NULL);

  autoar_extract_start (arextract);

  return 0;
}