-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Expand file tree
/
Copy pathServerResourceMounter.cpp
More file actions
73 lines (59 loc) · 1.83 KB
/
Copy pathServerResourceMounter.cpp
File metadata and controls
73 lines (59 loc) · 1.83 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
#include "StdInc.h"
#include "ResourceManager.h"
#include "ServerResourceList.h"
#include <skyr/url.hpp>
#include <skyr/percent_encode.hpp>
class ServerResourceMounter : public fx::ResourceMounter
{
public:
ServerResourceMounter(fx::ResourceManager* manager)
: m_manager(manager)
{
}
virtual bool HandlesScheme(const std::string& scheme) override
{
return (scheme == "file");
}
virtual pplx::task<fwRefContainer<fx::Resource>> LoadResource(const std::string& uri) override
{
auto resourceList = m_manager->GetComponent<fx::resources::ServerResourceList>();
auto uriParsed = skyr::make_url(uri);
fwRefContainer<fx::Resource> resource;
if (uriParsed)
{
auto pathRef = uriParsed->pathname();
auto fragRef = *skyr::percent_decode(uriParsed->hash().substr(1));
if (!pathRef.empty() && !fragRef.empty())
{
#ifdef _WIN32
std::string pr = pathRef.substr(1);
#else
std::string pr = pathRef;
#endif
std::string error;
resource = m_manager->CreateResource(fragRef, this);
if (!resource->LoadFrom(*skyr::percent_decode(pr), &error))
{
// error matching LuaMetaDataLoader.cpp in citizen:resources:metadata:lua
if (error == "Could not open resource metadata file - no such file.")
{
resourceList->AddError(fx::resources::ScanMessageType::Warning, fragRef, "no_manifest", {});
}
else
{
resourceList->AddError(fx::resources::ScanMessageType::Error, fragRef, "load_failed", { error });
}
m_manager->RemoveResource(resource);
resource = nullptr;
}
}
}
return pplx::task_from_result<fwRefContainer<fx::Resource>>(resource);
}
private:
fx::ResourceManager* m_manager;
};
DLL_EXPORT fwRefContainer<fx::ResourceMounter> MakeServerResourceMounter(const fwRefContainer<fx::ResourceManager>& resman)
{
return new ServerResourceMounter(resman.GetRef());
}