Pues vereis, esque soy programador de Visual Basic 6 y para un pryecto me hace falta un script de ruby, en mi proyecto. Por eso pregunto si alguien es tan amable de traducirme este codigo (que esta en ruby) a vb6, o darme algunas ideas aclaratorias, pues no se lo que hace:
Código:
require 'fileutils'
require 'zlib'
# set this to false if you want to keep spaces in filenames
# PROTIP: you don't
SPACES_TO_UNDERSCORES = true
unless ARGV[0] and ARGV[1]
puts "Usage: scriptdb2rbfiles source dest"
puts " source: Path of Scripts.rxdata file to convert"
puts " dest : Path of the folder where the scripts will be added."
puts " The folder will be created if it doesn't exist yet."
exit
end
# setup source
source = String.new
source << ARGV[0]
source.gsub! '\\', '/' # \ to /
raise "Cannot find source file" unless File.exists? source
# setup destination
dest = String.new
dest << ARGV[1]
dest.gsub! '\\', '/' # \ to /
dest = dest + '/' unless '/' == dest[dest.length - 1, 1] # add trailing slash
FileUtils.mkdir dest unless File.directory? dest
raise "Cannot create destination folder" unless File.directory? dest
# load database
database = File.open(source, 'rb') { |f| Marshal.load f }
# prevent overwriting import_all_in_original_order.rb
iaioo_path = dest + 'import_all_in_original_order.rb'
raise('Destination file ' + iaioo_path + ' already exists. Aborting conversion.') if File.exists? iaioo_path
# prevent overwriting the rest
database.each do |script|
path = dest + script[1] + '.rb'
raise('Destination file ' + path + ' already exists. Aborting conversion.') if File.exists? path
end
# Conversion
database.each do |script|
path = dest + script[1] + '.rb'
path.gsub! ' ', '_' if SPACES_TO_UNDERSCORES
script_text = Zlib::Inflate.inflate(script[2])
# On my test setup, this step is required if you don't want an additional newline
# to be added between each line of your scripts. Things may be different on other platforms.
# TODO: figure this issue out.
script_text .gsub! "\r\n", "\n"
File.open(path, 'w') {|file| file.write(script_text) }
end
# Now let's write a script that will import them in the original order
index_script = String.new
database.each do |script|
filename = SPACES_TO_UNDERSCORES ? (script[1].gsub ' ', '_' ) : script[1]
index_script << "require '#{filename}.rb'\n"
end
File.open(iaioo_path , 'w') {|file| file.write index_script}
Les agradeceria algo de ayuda con esto, que es vital para mi proyecto, y estoy muy perdido pues reconozco que ruby es un tema que se me escapa por completo. Gracias de antemano.