|
|
@@ -0,0 +1,49 @@ |
|
|
#!/usr/bin/env ruby |
|
|
|
|
|
# Requires that you have ./bin/dcpTool from https://sourceforge.net/projects/dcptool/ |
|
|
|
|
|
require 'rubygems' |
|
|
require 'bundler/setup' |
|
|
require 'nokogiri' |
|
|
|
|
|
input_camera_model = ARGV[0] || "LEICA Q (Typ 116)" |
|
|
output_camera_model = ARGV[1] || "LEICA M10" |
|
|
|
|
|
input_dir = ARGV[2] || "./input" |
|
|
output_dir = ARGV[3] || "./output" |
|
|
|
|
|
def convert_profile_name(profile_name, input_camera_model, output_camera_model) |
|
|
File.basename(profile_name.gsub(/#{input_camera_model.gsub(/\(/, "\\(").gsub(/\)/, "\\)")}/, output_camera_model), ".dcp") |
|
|
end |
|
|
|
|
|
def replace_camera_model(xml_profile_filename, output_camera_model) |
|
|
profile_doc = Nokogiri::XML(File.read(xml_profile_filename)) |
|
|
profile_doc.xpath('//UniqueCameraModelRestriction').first.content = output_camera_model |
|
|
|
|
|
File.open(xml_profile_filename, "w+") { |file| file.write(profile_doc.to_xml) } |
|
|
end |
|
|
|
|
|
Dir.entries(input_dir).reject { |file| file =~ /^(\.|\.\.)$/ }.each do |existing_profile| |
|
|
converted_profile = convert_profile_name(existing_profile, input_camera_model, output_camera_model) |
|
|
existing_dcp_filename = File.join(input_dir, existing_profile) |
|
|
xml_filename = "#{File.join(output_dir, converted_profile)}.xml" |
|
|
|
|
|
decompile_command = "./bin/dcpTool -d '#{existing_dcp_filename}' '#{xml_filename}'" |
|
|
|
|
|
puts "Decompiling #{existing_dcp_filename} into XML" |
|
|
`#{decompile_command}` |
|
|
|
|
|
puts "Replacing camera model: #{input_camera_model} -> #{output_camera_model}" |
|
|
replace_camera_model(xml_filename, output_camera_model) |
|
|
|
|
|
|
|
|
converted_dcp_filename = "#{File.join(output_dir, converted_profile)}.dcp" |
|
|
recompile_command = "./bin/dcpTool -c '#{xml_filename}' '#{converted_dcp_filename}'" |
|
|
|
|
|
puts "Recompiling XML into #{converted_dcp_filename}" |
|
|
`#{recompile_command}` |
|
|
|
|
|
File.delete(xml_filename) |
|
|
|
|
|
puts |
|
|
end |