From 70d4e0c40f262c9cd1d05ca725c8f103c09e59cf Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Sat, 31 Jan 2026 18:23:00 -0600 Subject: [PATCH] WWMix: added support for replacing entries that are duplicates --- lib/ww_mix.rb | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/ww_mix.rb b/lib/ww_mix.rb index 97f7d18..ea546f7 100644 --- a/lib/ww_mix.rb +++ b/lib/ww_mix.rb @@ -228,27 +228,34 @@ class W3DHub @encrypted end - def add_file(path:) + def add_file(path:, replace: false) return false unless File.exist?(path) return false if File.directory?(path) - info = EntryInfoHeader.new(0, 0, File.size(path)) - @entries << Entry.new(name: File.basename(path), path: path, info: info) - - true + entry = Entry.new(name: File.basename(path), path: path, info: EntryInfoHeader.new(0, 0, File.size(path))) + add_entry(entry: entry, replace: replace) end - def add_blob(path:, blob:) + def add_blob(path:, blob:, replace: false) info = EntryInfoHeader.new(0, 0, blob.size) - @entries << Entry.new(name: File.basename(path), path: path, info: info, blob: blob) + entry = Entry.new(name: File.basename(path), path: path, info: info, blob: blob) into.crc32 = @entries.last.calculate_crc32 - true + add_entry(entry: entry, replace: replace) end - def add_entry(entry:) - @entries << entry + def add_entry(entry:, replace: false) + duplicate = @entries.find { |e| e.name.upcase == entry.name.upcase } + if duplicate + if replace + @entries.delete(duplicate) + else + return false + end + end + + @entries << entry true end