forked from maraf/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunner.cpp
More file actions
118 lines (93 loc) · 2.99 KB
/
runner.cpp
File metadata and controls
118 lines (93 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#include <memory>
#include "extractor.h"
#include "runner.h"
#include "trace.h"
#include "header.h"
#include "manifest.h"
#include "utils.h"
using namespace bundle;
// This method processes the bundle manifest.
// It also implements the extraction of files that cannot be directly processed from the bundle.
StatusCode runner_t::extract()
{
try
{
const char* addr = map_bundle();
// Set the Reader at header_offset
reader_t reader(addr, m_bundle_size, m_header_offset);
m_offset_in_file = reader.offset_in_file();
// Read the bundle header
m_header = header_t::read(reader);
m_deps_json.set_location(&m_header.deps_json_location());
m_runtimeconfig_json.set_location(&m_header.runtimeconfig_json_location());
// Read the bundle manifest
m_manifest = manifest_t::read(reader, m_header);
// Extract the files if necessary
if (m_manifest.files_need_extraction())
{
extractor_t extractor(m_header.bundle_id(), m_bundle_path, m_manifest);
m_extraction_path = extractor.extract(reader);
}
unmap_bundle(addr);
return StatusCode::Success;
}
catch (StatusCode e)
{
return e;
}
}
const file_entry_t* runner_t::probe(const pal::string_t &relative_path) const
{
for (const file_entry_t& entry : m_manifest.files)
{
if (entry.matches(relative_path))
{
assert(!entry.is_disabled());
return &entry;
}
}
return nullptr;
}
bool runner_t::probe(const pal::string_t& relative_path, int64_t* offset, int64_t* size, int64_t* compressedSize) const
{
const bundle::file_entry_t* entry = probe(relative_path);
// Do not report extracted entries - those should be reported through either TPA or resource paths
if (entry == nullptr || entry->needs_extraction())
{
return false;
}
assert(!entry->is_disabled());
assert(entry->offset() != 0);
*offset = entry->offset() + m_offset_in_file;
*size = entry->size();
*compressedSize = entry->compressedSize();
return true;
}
bool runner_t::locate(const pal::string_t& relative_path, pal::string_t& full_path, bool& extracted_to_disk) const
{
const bundle::file_entry_t* entry = probe(relative_path);
if (entry == nullptr)
{
full_path.clear();
return false;
}
assert(!entry->is_disabled());
extracted_to_disk = entry->needs_extraction();
full_path.assign(extracted_to_disk ? extraction_path() : base_path());
append_path(&full_path, relative_path.c_str());
return true;
}
bool runner_t::disable(const pal::string_t& relative_path)
{
for (file_entry_t& entry : m_manifest.files)
{
if (entry.matches(relative_path))
{
entry.disable();
return true;
}
}
return false;
}