blob: 58d10a817855f920cf2ecfb4e160893f6e8106f9 (
plain)
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
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#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);
// 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.num_embedded_files());
// 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& path) const
{
for (const file_entry_t& entry : m_manifest.files)
{
if (entry.relative_path() == path)
{
return &entry;
}
}
return nullptr;
}
bool runner_t::locate(const pal::string_t& relative_path, pal::string_t& full_path) const
{
const bundle::runner_t* app = bundle::runner_t::app();
const bundle::file_entry_t* entry = app->probe(relative_path);
if (entry == nullptr)
{
full_path.clear();
return false;
}
// Currently, all files except deps.json and runtimeconfig.json are extracted to disk.
// The json files are not queried by the host using this method.
assert(entry->needs_extraction());
full_path.assign(app->extraction_path());
append_path(&full_path, relative_path.c_str());
return true;
}
|