class Gnosis::Archive

Representation of an encrypted RGSS archive. This class provides a layer of abstraction over the archive itself, providing methods to help ease the traversal of encrypted archives and allow in-memory decryption of their contents.

Attributes

archive[R]

Full path to the encrypted archive this class represents. @return [String]

files[R]

Hash of files with associated encryption information. @return [Hash{String => Hash{Symbol => Number}}]

translator[R]

The translator instance in use by this archive representation. @return [Translator]

Public Class Methods

new(archive) click to toggle source

Instantiates a new {Archive Archive} representing an encrypted RGSS archive.

@raise [InvalidArchiveError] if the given archive is invalid @param [String] archive the relative path to an encrypted archive

# File lib/gnosis/archive.rb, line 26
def initialize(archive)
  @archive    = File.expand_path(archive)
  @translator = Translators.class_for(self)
  @files      = @translator.scan_files
end

Public Instance Methods

contents() click to toggle source

Convenience method for obtaining an array of all encrypted files within this RGSS archive representation.

@return [Array<String>] an array of files contained in the archive

# File lib/gnosis/archive.rb, line 36
def contents
  @files.keys
end
decrypt(file) { |data| ... } click to toggle source

Decrypts the given internal filename. The returned binary string may be converted into an IO object in memory via the StringIO class present in the Ruby standard library. Yields the decrypted binary data if a block is given.

@example Decrypt to StringIO

require 'stringio'
archive = Gnosis::Archive.new('path/to/Game.rgss3a')
io = StringIO.new(archive.decrypt('Graphics/Titles1/Title.png'))

@raise [Errno::ENOENT] if the given file does not exist in the archive @param [String] file internal path of encrypted file @return [String] the decrypted binary contents of the given file

# File lib/gnosis/archive.rb, line 69
def decrypt(file)
  data = @translator.decrypt(file)
  yield data if block_given?
  data
end
glob(pattern) { |result| ... } click to toggle source

Search for files within the encrypted archive with optional shell-style globbing. Yields the results of the given pattern if a block is given.

@note Globbing is performed via ‘File#fnmatch`.

@example Search with Globbing

archive = Gnosis::Archive.new('path/to/Game.rgss3a')
archive.glob('**/Title.png') # => ["Graphics/Titles1/Title.png"]

@param [String] pattern file name pattern @yield [result] an array of file names matching the given pattern @return [Array<String>] an array of file names matching the given pattern

@see www.ruby-doc.org/core-1.9.3/File.html#method-c-fnmatch

File.fnmatch

@see search

# File lib/gnosis/archive.rb, line 112
def glob(pattern)
  pattern.force_encoding('utf-8')
  result = @files.keys.select { |file| File.fnmatch?(pattern, file) }
  yield result if block_given?
  result
end
inspect()
Alias for: to_s
length()
Alias for: size
match(expression)
Alias for: search
size() click to toggle source

Convenience method for obtaining the number of encrypted files within this RGSS archive representation.

@return [Number] the number of files contained in the archive

# File lib/gnosis/archive.rb, line 44
def size
  contents.size
end
Also aliased as: length
to_s() click to toggle source

A representation of this {Archive Archive} as a string.

@return [String] representation of this {Archive Archive} as a string.

# File lib/gnosis/archive.rb, line 122
def to_s
  "#{type} Archive: #{contents.size} files"
end
Also aliased as: inspect
type() click to toggle source

Returns the type of archive represented by this {Archive Archive}.

@return [String] the type of archive represented

# File lib/gnosis/archive.rb, line 52
def type
  @translator.class.name.split(/::/).last
end