Class: Yuki::VD
- Defined in:
- scripts/00000 Dependencies/00200 GameData(dep)/00900 Yuki__VD.rb
Overview
Class that helps to read Virtual Directories
In reading mode, the Virtual Directories can be loaded to RAM if MAX_SIZE >= VD.size
All the filenames inside the Yuki::VD has to be downcased filename in utf-8
Note : Encryption is up to the developper and no longer supported on the basic script
Constant Summary collapse
- DEBUG_ON =
Is the debug info on ?
ARGV.include?('debug-yuki-vd')
- MAX_SIZE =
The max size of the file that can be loaded in memory
10 * 1024 * 1024
- ALLOWED_MODES =
List of allowed modes
%i[read write update]
- POINTER_SIZE =
Size of the pointer at the begin of the file
4
- UNPACK_METHOD =
Unpack method of the pointer at the begin of the file
'L'
Instance Attribute Summary collapse
-
#filename ⇒ String
readonly
The filename of the current Yuki::VD.
Instance Method Summary collapse
-
#add_file(filename, ext_name = nil)
Add a file to the Yuki::VD.
-
#close
Close the VD.
-
#exists?(filename) ⇒ Boolean
Test if a file exists in the VD.
-
#get_filenames ⇒ Array<String>
Get all the filename.
-
#initialize(filename, mode) ⇒ VD
constructor
Create a new Yuki::VD file or load it.
-
#read_data(filename) ⇒ String?
Read a file data from the VD.
-
#write_data(filename, data)
Write a file with its data in the VD.
Constructor Details
#initialize(filename, mode) ⇒ VD
Create a new Yuki::VD file or load it
25 26 27 28 29 |
# File 'scripts/00000 Dependencies/00200 GameData(dep)/00900 Yuki__VD.rb', line 25 def initialize(filename, mode) @mode = mode = fix_mode(mode) @filename = filename send("initialize_#{mode}") end |
Instance Attribute Details
#filename ⇒ String (readonly)
Returns the filename of the current Yuki::VD.
11 12 13 |
# File 'scripts/00000 Dependencies/00200 GameData(dep)/00900 Yuki__VD.rb', line 11 def filename @filename end |
Instance Method Details
#add_file(filename, ext_name = nil)
Add a file to the Yuki::VD
63 64 65 66 |
# File 'scripts/00000 Dependencies/00200 GameData(dep)/00900 Yuki__VD.rb', line 63 def add_file(filename, ext_name = nil) sub_filename = ext_name ? "#{filename}.#{ext_name}" : filename write_data(filename, File.binread(sub_filename)) end |
#close
Close the VD
75 76 77 78 79 80 81 82 83 84 85 |
# File 'scripts/00000 Dependencies/00200 GameData(dep)/00900 Yuki__VD.rb', line 75 def close return unless @file if @mode != :read pos = [@file.pos].pack(UNPACK_METHOD) @file.write(Marshal.dump(@hash)) @file.pos = 0 @file.write(pos) end @file.close @file = nil end |
#exists?(filename) ⇒ Boolean
Test if a file exists in the VD
46 47 48 |
# File 'scripts/00000 Dependencies/00200 GameData(dep)/00900 Yuki__VD.rb', line 46 def exists?(filename) @hash[filename] != nil end |
#get_filenames ⇒ Array<String>
Get all the filename
70 71 72 |
# File 'scripts/00000 Dependencies/00200 GameData(dep)/00900 Yuki__VD.rb', line 70 def get_filenames @hash.keys end |
#read_data(filename) ⇒ String?
Read a file data from the VD
34 35 36 37 38 39 40 41 |
# File 'scripts/00000 Dependencies/00200 GameData(dep)/00900 Yuki__VD.rb', line 34 def read_data(filename) return nil unless @file pos = @hash[filename] return nil unless pos @file.pos = pos size = @file.read(POINTER_SIZE).unpack1(UNPACK_METHOD) return @file.read(size) end |
#write_data(filename, data)
Write a file with its data in the VD
53 54 55 56 57 58 |
# File 'scripts/00000 Dependencies/00200 GameData(dep)/00900 Yuki__VD.rb', line 53 def write_data(filename, data) return unless @file @hash[filename] = @file.pos @file.write([data.bytesize].pack(UNPACK_METHOD)) @file.write(data) end |