Skip to content

Instantly share code, notes, and snippets.

@esavard
Created July 8, 2010 04:35
Show Gist options
  • Save esavard/467638 to your computer and use it in GitHub Desktop.
Save esavard/467638 to your computer and use it in GitHub Desktop.
exe_packager.rb : find all dependencies for a given EXE and package it in a zip file
# exe_packager.rb : find all dependencies for a given EXE and package it in
# a zip file
require 'csv'
require 'zip/zip'
require 'zippy'
ARGV.each do |exe_file|
short_filename = File.basename(exe_file, '.exe')
zip_filename = "#{short_filename}.zip"
puts "Creating package for program: #{short_filename}\n"
puts "======================================================="
#--------------------------------------
# Find dependencies of the program,
# and put them in a list
#--------------------------------------
puts "Checking EXE dependencies..."
system ("depends /c /f:1 /OC:out.csv #{exe_file}");
file_list = Array.new
CSV.foreach('out.csv') do |rec|
if rec[0].nil? then
# We don't need "standard" Windows DLL
unless rec[1].downcase.include?("c:\\windows") then
file_list.push(rec[1])
end
end
end
#--------------------------------------
# Save each dependencies with the exe
#--------------------------------------
Zippy.create zip_filename do |zip|
#TODO: Add an automatic changelog along with the file
#ex: zip['README'] = 'README.TXT'
file_list.each do |filename|
local_filename = File.basename(filename)
FileUtils.copy(filename, local_filename) unless File.file?(local_filename)
puts "Adding #{local_filename}..."
zip[local_filename] = File.open(local_filename)
end
puts "======================================================="
# Cleanup
File.delete('out.csv')
puts "\nDone!"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment