#!/usr/bin/ruby
require File.expand_path(File.dirname(__FILE__)) + '/../lib/flame_channel_parser'
require 'optparse'
require "update_hints"

op = OptionParser.new
op.banner = "Usage: framecurve_to_flame /usr/discreet/projects/ExpensiveDildo/timewarp/shot2_tw.framecurve.txt"
op.parse!

fc_path = ARGV.shift
fail("No input file path provided.") unless fc_path
fail("File %s does not exist." % fc_path) unless File.exist?(fc_path)

curve = Framecurve::Parser.new.parse(fc_path)
v = Framecurve::Validator.new
v.validate(curve)
if v.any_errors?
  v.errors.each do | error |
    $stderr.puts "Framecurve file was faulty: #{error}"
  end
end

FlameChannelParser::FramecurveWriters::Base.with_each_writer do | writer_class |
  filename = [fc_path, writer_class.extension].join
  File.open(filename, "wb") do | f |
    writer_class.new.run_export_from_framecurve(f, curve)
  end
end

UpdateHints.version_check("flame_channel_parser", FlameChannelParser::VERSION, $stderr)
