Class: StarCitizen::Pak

Inherits:
Object
  • Object
show all
Defined in:
lib/starcitizen/pak.rb

Overview

A .pak file. Located in /CitizenClient/Data

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Pak

Returns a new instance of Pak.

Parameters:

  • name (String)

    Name of the .pak file.



15
16
17
18
# File 'lib/starcitizen/pak.rb', line 15

def initialize name
  @name = name
  @path = "#{StarCitizen::Config.game_path}/CitizenClient/Data/#{name}.pak"
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/starcitizen/pak.rb', line 12

def name
  @name
end

Instance Method Details

#extract(path, **kwargs) ⇒ Object

Extract a file from the package.

Examples:

# Extract defaultProfile.xml
package.extract 'Libs/Config/defaultProfile.xml'

Parameters:

  • path (String)

    Path of the file inside the package.

  • kwargs (Hash)

    a customizable set of options

Options Hash (**kwargs):

  • :output_dir (String) — default: '.'

    File is extracted to this directory.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/starcitizen/pak.rb', line 26

def extract path, **kwargs
  output_dir = kwargs.fetch :output_dir, '.'
  
  Zip::File.open(@path) do |files|
    pak_file = files.glob(path).first
    
    FileUtils.mkdir_p output_dir
    FileUtils.chdir output_dir do
      filename = path.split('/').last
      File.delete filename if File.exists? filename
      pak_file.extract pak_file.name.split('/').last
    end
  end
end