Skip to content

Commit b48da3e

Browse files
Pey-cryptocoderobe
authored andcommitted
This fixes the Copy and file overwritting problems
Checks the MD5 values of the files present in the directory
1 parent 880eb02 commit b48da3e

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/methods.rb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
require "./src/extract-7z"
99
require "./src/extract-polyglot"
1010
require "./src/extract-zlib"
11-
11+
require 'digest/md5'
12+
hash = {}
1213
module VBiosFinder
1314
class Main
1415
@extractions = []
@@ -65,6 +66,7 @@ def self.run file
6566
unless romdata.nil? || romdata['vendor'].nil? || romdata['device'].nil?
6667
puts "Found VBIOS for device #{romdata['vendor']}:#{romdata['device']}!".colorize(:green)
6768
new_filename = "vbios_#{romdata['vendor']}_#{romdata['device']}.rom"
69+
new_filename =check_cpy(new_filename,romdata)
6870
FileUtils.cp(mod, "#{outpath}/#{new_filename}")
6971
end
7072
rescue Terrapin::ExitStatusError => e
@@ -88,3 +90,21 @@ def self.run file
8890
end
8991
end
9092
end
93+
94+
95+
96+
def check_cpy(new_filename,romdata)
97+
count = 0
98+
Dir.glob('**/*',File::FNM_DOTMATCH).each do |f|
99+
key = Digest::MD5.hexdigest(IO.read(f)).to_sym
100+
if hash.has_key?(key) then hash[key].push(f) else hash[key] = [f] end
101+
end
102+
103+
hash.each_value do |a|
104+
next if a.length == 1
105+
count+= 1
106+
new_filename = "vbios_#{romdata['vendor']}_#{romdata['device']}_#{count}.rom"
107+
108+
return new_filename
109+
end
110+
end

0 commit comments

Comments
 (0)