-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Expand file tree
/
Copy pathfxr_resolver.cpp
More file actions
66 lines (55 loc) · 2.14 KB
/
Copy pathfxr_resolver.cpp
File metadata and controls
66 lines (55 loc) · 2.14 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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// C++ wrappers around the C fxr_resolver_* APIs in fxr_resolver.c. The C++
// surface stays the same; each member just marshals between pal::string_t and
// pal_char_t*. try_get_existing_fxr remains a C++ function because
// pal::get_loaded_library is a templated helper that only has a C++ caller.
#include "fxr_resolver.h"
#include <pal.h>
#include <trace.h>
#include <utils.h>
#include <stdlib.h>
bool fxr_resolver::try_get_path(const pal::string_t& root_path, pal::string_t* out_dotnet_root, pal::string_t* out_fxr_path)
{
return try_get_path(root_path, search_location_default, nullptr, out_dotnet_root, out_fxr_path);
}
bool fxr_resolver::try_get_path(
const pal::string_t& root_path,
search_location search,
/*opt*/ pal::string_t* app_relative_dotnet_root,
/*out*/ pal::string_t* out_dotnet_root,
/*out*/ pal::string_t* out_fxr_path)
{
pal_char_t* dotnet_root_c = nullptr;
pal_char_t* fxr_path_c = nullptr;
bool ok = ::fxr_resolver_try_get_path(
root_path.c_str(),
static_cast<fxr_search_location>(search),
app_relative_dotnet_root != nullptr ? app_relative_dotnet_root->c_str() : nullptr,
&dotnet_root_c,
&fxr_path_c);
if (ok)
{
out_dotnet_root->assign(dotnet_root_c);
out_fxr_path->assign(fxr_path_c);
}
free(dotnet_root_c);
free(fxr_path_c);
return ok;
}
bool fxr_resolver::try_get_path_from_dotnet_root(const pal::string_t& dotnet_root, pal::string_t* out_fxr_path)
{
pal_char_t* fxr_path_c = nullptr;
bool ok = ::fxr_resolver_try_get_path_from_dotnet_root(dotnet_root.c_str(), &fxr_path_c);
if (ok)
out_fxr_path->assign(fxr_path_c);
free(fxr_path_c);
return ok;
}
bool fxr_resolver::try_get_existing_fxr(pal::dll_t* out_fxr, pal::string_t* out_fxr_path)
{
if (!pal::get_loaded_library(LIBFXR_NAME, "hostfxr_main", out_fxr, out_fxr_path))
return false;
trace::verbose(_X("Found previously loaded library %s [%s]."), LIBFXR_NAME, out_fxr_path->c_str());
return true;
}