forked from microsoft/cpprestsdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath.h
More file actions
89 lines (77 loc) · 2.17 KB
/
path.h
File metadata and controls
89 lines (77 loc) · 2.17 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
#pragma once
#include <algorithm>
#include <filesystem>
#include <fstream>
#include <string>
#include <iostream>
#include <fstream>
#include <cstdint>
#include <filesystem>
#include <windows.h>
#include "boost/filesystem.hpp" // includes all needed Boost.Filesystem declarations
class Path
{
public:
Path() = default;
explicit Path(const std::string& InFile)
{
char buf[1024];
GetModuleFileNameA(NULL, buf, 1024);
std::string ProgramPath(buf);
std::replace(ProgramPath.begin(), ProgramPath.end(), '\\', '/');
size_t pos = ProgramPath.find_last_of("/");
ProgramPath = ProgramPath.substr(0, pos + 1);
std::string assetPrefix;
#if ME_EDITOR
assetPrefix = "../../";
#endif
LocalPath = InFile;
std::replace(LocalPath.begin(), LocalPath.end(), '\\', '/');
size_t path = LocalPath.find(':');
if (path != std::string::npos)
{
FullPath = LocalPath;
}
else
{
FullPath = ProgramPath + assetPrefix + LocalPath;
}
path = LocalPath.rfind("Assets");
if (path != std::string::npos)
{
LocalPath = LocalPath.substr(path, LocalPath.size());
}
#if ME_EDITOR
if (!std::filesystem::exists(FullPath))
{
std::string tempPath = ProgramPath + assetPrefix + "Engine/" + LocalPath;
if (std::filesystem::exists(tempPath))
{
FullPath = std::move(tempPath);
assetPrefix = assetPrefix.append("Engine/");
}
}
#endif
// if (std::filesystem::is_regular_file((FullPath)))
if (boost::filesystem::is_regular_file(FullPath))
{
IsFile = true;
pos = FullPath.find_last_of("/");
Directory = FullPath.substr(0, pos + 1);
}
else
{
IsFolder = true;
Directory = FullPath;
}
#if ME_PLATFORM_UWP
std::replace(LocalPath.begin(), LocalPath.end(), '/', '\\');
#endif
}
~Path() {}
bool IsFile = false;
bool IsFolder = false;
std::string FullPath;
std::string LocalPath;
std::string Directory;
};