MCPcopy Create free account
hub / github.com/Norbyte/bg3se / LoadExternalFile

Function LoadExternalFile

BG3Extender/Extender/Shared/ScriptHelpers.cpp:55–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55std::optional<STDString> LoadExternalFile(std::string_view path, PathRootType root)
56{
57 if (!IsSafeRelativePath(STDString(path))) {
58 return {};
59 }
60
61 if (root == PathRootType::Data) {
62 auto reader = GetStaticSymbols().MakeFileReader(path, root);
63 if (reader.IsLoaded()) {
64 return reader.ToString();
65 }
66 } else {
67 auto absolutePath = GetPathForExternalIo(path, root);
68 if (!absolutePath) return {};
69
70 std::ifstream f(absolutePath->c_str(), std::ios::in | std::ios::binary);
71 if (f.good()) {
72 STDString body;
73 f.seekg(0, std::ios::end);
74 body.resize((unsigned)f.tellg());
75 f.seekg(0, std::ios::beg);
76 f.read(body.data(), body.size());
77 return body;
78 }
79 }
80
81 return {};
82}
83
84bool CreateParentDirectoryRecursive(std::wstring_view path)
85{

Callers 1

LoadFontMethod · 0.85

Calls 8

IsSafeRelativePathFunction · 0.85
GetPathForExternalIoFunction · 0.85
MakeFileReaderMethod · 0.80
IsLoadedMethod · 0.80
ToStringMethod · 0.45
resizeMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected