asar coverage - build #179


src/asar/
File: src/asar/virtualfile.h
Date: 2024-01-28 20:21:42
Lines:
3/3
100.0%
Functions:
1/1
100.0%
Branches:
1/2
50.0%

Line Branch Exec Source
1 #if !defined(ASAR_VIRTUALFILE_H)
2 #define ASAR_VIRTUALFILE_H
3
4 #include "autoarray.h"
5 #include "assocarr.h"
6 #include "libstr.h"
7
8 // RPG Hacker: A virtual file system which can work with physical files
9 // as well as in-memory files.
10
11 typedef void* virtual_file_handle;
12 static const virtual_file_handle INVALID_VIRTUAL_FILE_HANDLE = nullptr;
13
14 enum virtual_file_error
15 {
16 vfe_none,
17
18 vfe_doesnt_exist,
19 vfe_access_denied,
20 vfe_not_regular_file,
21 vfe_unknown,
22
23 vfe_num_errors
24 };
25
26 struct memory_buffer
27 {
28 const void* data;
29 size_t length;
30 };
31
32 363 class virtual_filesystem
33 {
34 public:
35 void initialize(const char** include_paths, size_t num_include_paths);
36 void destroy();
37
38 virtual_file_handle open_file(const char* path, const char* base_path);
39 void close_file(virtual_file_handle file_handle);
40
41 size_t read_file(virtual_file_handle file_handle, void* out_buffer, size_t pos, size_t num_bytes);
42
43 size_t get_file_size(virtual_file_handle file_handle);
44
45 bool is_path_absolute(const char* path);
46
47 string create_absolute_path(const char* base, const char* target);
48
49 void add_memory_file(const char* name, const void* buffer, size_t length);
50
51 63 inline virtual_file_error get_last_error()
52 {
53
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
117 return m_last_error;
54 }
55
56 private:
57 enum virtual_file_type
58 {
59 vft_physical_file,
60 vft_memory_file
61 };
62
63 virtual_file_type get_file_type_from_path(const char* path);
64
65 assocarr<memory_buffer> m_memory_files;
66 autoarray<string> m_include_paths;
67 virtual_file_error m_last_error;
68 };
69
70 #endif
71