Exemplo n.º 1
0
int
main (int argc, char * argv[])
{
  int i;
  int changedCount = 0;

  files = tr_new0 (const char*, argc);

  tr_setMessageLevel (TR_MSG_ERR);

  if (parseCommandLine (argc, (const char**)argv))
    return EXIT_FAILURE;

  if (showVersion)
    {
      fprintf (stderr, MY_NAME" "LONG_VERSION_STRING"\n");
      return EXIT_SUCCESS;
    }

  if (fileCount < 1)
    {
      fprintf (stderr, "ERROR: No torrent files specified.\n");
      tr_getopt_usage (MY_NAME, getUsage (), options);
      fprintf (stderr, "\n");
      return EXIT_FAILURE;
    }

  if (!add && !deleteme && !replace[0])
    {
      fprintf (stderr, "ERROR: Must specify -a, -d or -r\n");
      tr_getopt_usage (MY_NAME, getUsage (), options);
      fprintf (stderr, "\n");
      return EXIT_FAILURE;
    }

  for (i=0; i<fileCount; ++i)
    {
      tr_benc top;
      bool changed = false;
      const char * filename = files[i];

      printf ("%s\n", filename);

      if (tr_bencLoadFile (&top, TR_FMT_BENC, filename))
        {
          printf ("\tError reading file\n");
          continue;
        }

      if (deleteme != NULL)
        changed |= removeURL (&top, deleteme);

      if (add != NULL)
        changed = addURL (&top, add);

      if (replace[0] && replace[1])
        changed |= replaceURL (&top, replace[0], replace[1]);

      if (changed)
        {
          ++changedCount;
          tr_bencToFile (&top, TR_FMT_BENC, filename);
        }

      tr_bencFree (&top);
    }

  printf ("Changed %d files\n", changedCount);

  tr_free (files);
  return EXIT_SUCCESS;
}
Exemplo n.º 2
0
int
main (int argc, char * argv[])
{
  int i;
  int changedCount = 0;

#ifdef _WIN32
  tr_win32_make_args_utf8 (&argc, &argv);
#endif

  files = tr_new0 (const char*, argc);

  tr_logSetLevel (TR_LOG_ERROR);

  if (parseCommandLine (argc, (const char**)argv))
    return EXIT_FAILURE;

  if (showVersion)
    {
      fprintf (stderr, MY_NAME" "LONG_VERSION_STRING"\n");
      return EXIT_SUCCESS;
    }

  if (fileCount < 1)
    {
      fprintf (stderr, "ERROR: No torrent files specified.\n");
      tr_getopt_usage (MY_NAME, getUsage (), options);
      fprintf (stderr, "\n");
      return EXIT_FAILURE;
    }

  if (!add && !deleteme && !replace[0])
    {
      fprintf (stderr, "ERROR: Must specify -a, -d or -r\n");
      tr_getopt_usage (MY_NAME, getUsage (), options);
      fprintf (stderr, "\n");
      return EXIT_FAILURE;
    }

  for (i=0; i<fileCount; ++i)
    {
      tr_variant top;
      bool changed = false;
      const char * filename = files[i];
      tr_error * error = NULL;

      printf ("%s\n", filename);

      if (!tr_variantFromFile (&top, TR_VARIANT_FMT_BENC, filename, &error))
        {
          printf ("\tError reading file: %s\n", error->message);
          tr_error_free (error);
          continue;
        }

      if (deleteme != NULL)
        changed |= removeURL (&top, deleteme);

      if (add != NULL)
        changed = addURL (&top, add);

      if (replace[0] && replace[1])
        changed |= replaceURL (&top, replace[0], replace[1]);

      if (changed)
        {
          ++changedCount;
          tr_variantToFile (&top, TR_VARIANT_FMT_BENC, filename);
        }

      tr_variantFree (&top);
    }

  printf ("Changed %d files\n", changedCount);

  tr_free (files);
  return EXIT_SUCCESS;
}