#include "dvd_load_ifo.h"
#include "config.h"
#include "msg.h"
#include "ka_mem.h"
#include "ka_log.h"
#include "ro_file.h"
#include <string.h>
#include "input/ka_indvd.h"

ka_config_t config;
uint32_t fn_time[10];

typedef struct
{
  ka_input_t* pInput;
  int useCDFS;

  dvd_desc_t* dvd;
} data_t;

int main(int argc,char *argv[])
{
  ka_error_t errorBlock;
  data_t data;

  memset(&data, 0, sizeof(data));
  ka_allowStdOut();
  config.debug = 0x3fffffff;

  if (!msg_open("KinoIRes:Messages"))
    report_error(-1, "Cannot open Messages file");

  if (argc < 2)
    report_error(-1, "Syntax: dvdcopy (<path> | ::CDFS<x>)");

  data.pInput = ka_new_indvd(&errorBlock);
  if (!data.pInput)
    goto error;

  dvd_desc_load(data.pInput, argv[1], &data.dvd, 1);
  if (!data.dvd)
    goto error;

  goto done;

error:
  printf("%s\n", &errorBlock.errmess[0]);

done:
  if (data.pInput) ka_delete_input(&data.pInput);

  return 0;
}
