forked from focus-creative-games/il2cpp_plus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRuntime.cpp
More file actions
72 lines (61 loc) · 1.64 KB
/
Runtime.cpp
File metadata and controls
72 lines (61 loc) · 1.64 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
#include "il2cpp-config.h"
#include "os/Path.h"
#include "os/Environment.h"
#include "utils/Runtime.h"
#include "utils/PathUtils.h"
#include "utils/StringUtils.h"
#include "utils/Environment.h"
#if defined(RUNTIME_MONO)
extern "C"
{
#include <mono/metadata/unity-utils.h>
}
#endif
namespace il2cpp
{
namespace utils
{
NORETURN void Runtime::Abort()
{
os::Environment::Abort();
}
static std::string s_DataDirFallback;
#if !defined(RUNTIME_MONO)
static std::string s_DataDir;
void Runtime::SetDataDir(const char *path)
{
s_DataDir = path;
}
#endif
std::string Runtime::GetDataDir()
{
#if !IL2CPP_TINY_WITHOUT_DEBUGGER
#if defined(RUNTIME_MONO)
// use explicit value if set
char* dataDirCS = mono_unity_get_data_dir();
if (dataDirCS)
{
std::string dataDir(dataDirCS, strlen(dataDirCS));
if (dataDir.size() > 0)
return dataDir;
}
#else
// use explicit value if set
if (s_DataDir.size() > 0)
return s_DataDir;
#endif
std::string executablePath = os::Path::GetExecutablePath();
if (!executablePath.empty())
return PathUtils::Combine(PathUtils::DirectoryName(executablePath), StringView<char>(IL2CPP_DEFAULT_DATA_DIR_PATH_STR));
if (s_DataDirFallback.size() == 0 && Environment::GetNumMainArgs() > 0)
{
std::string main = StringUtils::Utf16ToUtf8(Environment::GetMainArgs()[0]);
s_DataDirFallback = PathUtils::DirectoryName(main);
}
return s_DataDirFallback;
#else
return std::string();
#endif
}
} // utils
} // il2cpp