class Distillery::Storage
Constants
- GAMES_DIR
Hidden games directory
- ROMS_DIR
Hidden ROMs directory
Attributes
roms[R]
Public Class Methods
new(vault)
click to toggle source
# File lib/distillery/storage.rb, line 16 def initialize(vault) @roms = vault end
Public Instance Methods
build_games(dat, vault, &block)
click to toggle source
# File lib/distillery/storage.rb, line 52 def build_games(dat, vault, &block) dat.games.each {|game| puts "Building: #{game}" game.roms.each {|rom| # Find in the matching ROM in the storage vault # Note that in the vault: # - the same ROM can be present multiple time # - all checksums are defined match = Array(vault.match(rom)).uniq {|r| r.cksum(FS_CHECKSUM) } # Sanity check if match.size > 1 # Due to weak ROM definition in DAT file puts "- multiple matching ROMs for #{rom} (IGNORING)" next elsif match.size == 0 # Sadly we don't have this ROM puts "- no mathing ROM for #{rom} (IGNORING)" next end # Get vault ROM vrom = match.first # Call block block.call(game.name, vrom, rom.path.entry) } } end
build_games_archives(dir, dat, vault, type = '7z', pristine: false)
click to toggle source
# File lib/distillery/storage.rb, line 96 def build_games_archives(dir, dat, vault, type = '7z', pristine: false) # Normalize to lower case type = type.downcase # Directory Dir.unlink(dir) if pristine # Create clean env if requested Dir.mkdir(dir) unless Dir.exist?(dir) # Ensure directory exists # Ensure we support this type of archive if ! ROMArchive::EXTENSIONS.include?(type) raise ArgumentError, "unsupported type (#{type})" end # Build game archives build_games(dat, vault) {|game, rom, dst| file = File.join(dir, "#{game}.#{type}") Distillery::Archiver.for(file).writer(dst) {|o| rom.reader {|i| while data = i.read(32 * 1024) o.write(data) end } } } end
build_games_directories(dir, dat, vault, pristine: false, force: false)
click to toggle source
# File lib/distillery/storage.rb, line 84 def build_games_directories(dir, dat, vault, pristine: false, force: false) # Directory Dir.unlink(dir) if pristine # Create clean env if requested Dir.mkdir(dir) unless Dir.exist?(dir) # Ensure directory exists # Build game directories build_games(dat, vault) {|game, rom, dst| rom.copy(File.join(dir, game, dst)) } end
build_roms_directory(dest, pristine: false, force: false, delete: false)
click to toggle source
# File lib/distillery/storage.rb, line 42 def build_roms_directory(dest, pristine: false, force: false, delete: false) block = if delete proc {|rom| rom.delete! } end @roms.save(dest, part: :rom, subdir: true, pristine: pristine, force: force, &block) self end
each() { |r| ... }
click to toggle source
# File lib/distillery/storage.rb, line 25 def each block_given? ? @roms.each {|r| yield(r) } : @roms.each end
headered()
click to toggle source
# File lib/distillery/storage.rb, line 21 def headered @roms.headered end
index(type = nil, separator = nil)
click to toggle source
# File lib/distillery/storage.rb, line 30 def index(type = nil, separator = nil) type ||= ROM::FS_CHECKSUM each.map {|rom| hash = rom.cksum(type, :hex) file = case path = rom.path when ROM::Path::Archive then path.to_s(separator) else path.to_s end [ hash, file ] } end
rename(dat)
click to toggle source
# File lib/distillery/storage.rb, line 124 def rename(dat) @roms.each {|rom| # Skip if ROM is not present in DAT ? if (m = dat.roms.match(rom)).nil? puts "No DAT rom matching <#{rom}>" next end # Find new rom name name = if m.size == 1 # Easy, take the DAT rom name if different next if m.first.name == rom.name m.first.name else # Find name in the DAT, that is not currently present # in our vault for this rom. match_name = m.map {|r| r.name } roms_name = @roms.match(rom).map {|r| r.name} lst_name = match_name - roms_name # Check if all DAT names are present in our vault, # but perhaps we have an extra name to be removed if lst_name.empty? if (roms_name - match_name).include?(rom.name) rom.delete! end next end # Use the first name lst_name.first end # Apply new name. (Will be a no-op if same name) rom.rename(name) {|old_name, new_name| puts " < #{old_name}" puts " > #{new_name}" } } end