Class: Keyhole::Archive

Inherits:
Zip::ZipFile
  • Object
show all
Defined in:
lib/keyhole/archive.rb

Constant Summary collapse

DAE_CACHE_PATH =
File.join(Floorplanner.config['dae_cache_path'],'dae')
IMG_CACHE_PATH =
File.join(Floorplanner.config['dae_cache_path'],'textures')

Instance Method Summary collapse

Instance Method Details

#dae_path(asset_id) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/keyhole/archive.rb', line 6

def dae_path(asset_id)
  FileUtils.mkdir_p DAE_CACHE_PATH
  dae = entries.select{|e| e.name.match(/\.dae$/)}.first
  @relative_dae_path = dae.name
  @dae_path = File.join(
    DAE_CACHE_PATH,
    "#{asset_id}_#{File.basename(dae.name)}"
  )
  dae.extract(@dae_path) unless File.exists?(@dae_path)
  @dae_path
end

#destroyObject



32
33
34
# File 'lib/keyhole/archive.rb', line 32

def destroy
  File.unlink(@dae_path)
end

#image_path(asset_id, relative_to_dae, relative_out = false) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/keyhole/archive.rb', line 18

def image_path(asset_id,relative_to_dae,relative_out=false)
  FileUtils.mkdir_p IMG_CACHE_PATH
  img_path = File.join(File.dirname(@relative_dae_path),relative_to_dae)
  target_path = File.join(IMG_CACHE_PATH,asset_id)
  tex_path = File.join(target_path,File.basename(img_path))

  unless File.exists?(tex_path)
    FileUtils.mkdir_p target_path
    zip_image = entries.select{|e| e.name.match(File.basename(img_path)) }.first
    extract( zip_image , tex_path )
  end
  relative_out ? '../textures'+tex_path.gsub(IMG_CACHE_PATH,'') : tex_path
end