| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#ifdef HAVE_CONFIG_H |
| 19 |
# include "config.h" |
| 20 |
#endif |
| 21 |
|
| 22 |
#include <glib/gi18n.h> |
| 23 |
|
| 24 |
#include "byzanzencoder.h" |
| 25 |
#include "byzanzserialize.h" |
| 26 |
|
| 27 |
static GOptionEntry entries[] = |
| 28 |
{ |
| 29 |
{ NULL } |
| 30 |
}; |
| 31 |
|
| 32 |
static void |
| 33 |
usage (void) |
| 34 |
{ |
| 35 |
g_print (_("usage: %s [OPTIONS] INFILE OUTFILE\n"), g_get_prgname ()); |
| 36 |
g_print (_(" %s --help\n"), g_get_prgname ()); |
| 37 |
} |
| 38 |
|
| 39 |
static void |
| 40 |
encoder_notify (ByzanzEncoder *encoder, GParamSpec *pspec, GMainLoop *loop) |
| 41 |
{ |
| 42 |
const GError *error; |
| 43 |
|
| 44 |
error = byzanz_encoder_get_error (encoder); |
| 45 |
if (error) { |
| 46 |
g_print ("%s\n", error->message); |
| 47 |
g_main_loop_quit (loop); |
| 48 |
} else if (!byzanz_encoder_is_running (encoder)) { |
| 49 |
g_main_loop_quit (loop); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
int |
| 54 |
main (int argc, char **argv) |
| 55 |
{ |
| 56 |
GOptionContext* context; |
| 57 |
GError *error = NULL; |
| 58 |
GFile *infile; |
| 59 |
GFile *outfile; |
| 60 |
GInputStream *instream; |
| 61 |
GOutputStream *outstream; |
| 62 |
GMainLoop *loop; |
| 63 |
ByzanzEncoder *encoder; |
| 64 |
|
| 65 |
g_set_prgname (argv[0]); |
| 66 |
#ifdef GETTEXT_PACKAGE |
| 67 |
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); |
| 68 |
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); |
| 69 |
textdomain (GETTEXT_PACKAGE); |
| 70 |
#endif |
| 71 |
|
| 72 |
context = g_option_context_new (_("process a Byzanz debug recording")); |
| 73 |
#ifdef GETTEXT_PACKAGE |
| 74 |
g_option_context_set_translation_domain(context, GETTEXT_PACKAGE); |
| 75 |
#endif |
| 76 |
|
| 77 |
g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); |
| 78 |
if (!g_option_context_parse (context, &argc, &argv, &error)) { |
| 79 |
g_print (_("Wrong option: %s\n"), error->message); |
| 80 |
usage (); |
| 81 |
g_error_free (error); |
| 82 |
return 1; |
| 83 |
} |
| 84 |
if (argc != 3) { |
| 85 |
usage (); |
| 86 |
return 0; |
| 87 |
} |
| 88 |
|
| 89 |
infile = g_file_new_for_commandline_arg (argv[1]); |
| 90 |
outfile = g_file_new_for_commandline_arg (argv[2]); |
| 91 |
loop = g_main_loop_new (NULL, FALSE); |
| 92 |
|
| 93 |
instream = G_INPUT_STREAM (g_file_read (infile, NULL, &error)); |
| 94 |
if (instream == NULL) { |
| 95 |
g_print ("%s\n", error->message); |
| 96 |
g_error_free (error); |
| 97 |
return 1; |
| 98 |
} |
| 99 |
outstream = G_OUTPUT_STREAM (g_file_replace (outfile, NULL, |
| 100 |
FALSE, G_FILE_CREATE_REPLACE_DESTINATION, NULL, &error)); |
| 101 |
if (outstream == NULL) { |
| 102 |
g_print ("%s\n", error->message); |
| 103 |
g_error_free (error); |
| 104 |
return 1; |
| 105 |
} |
| 106 |
encoder = byzanz_encoder_new (byzanz_encoder_get_type_from_file (outfile), |
| 107 |
instream, outstream, FALSE, NULL); |
| 108 |
|
| 109 |
g_signal_connect (encoder, "notify", G_CALLBACK (encoder_notify), loop); |
| 110 |
|
| 111 |
g_main_loop_run (loop); |
| 112 |
|
| 113 |
g_main_loop_unref (loop); |
| 114 |
g_object_unref (encoder); |
| 115 |
g_object_unref (instream); |
| 116 |
g_object_unref (outstream); |
| 117 |
g_object_unref (infile); |
| 118 |
g_object_unref (outfile); |
| 119 |
|
| 120 |
return 0; |
| 121 |
} |