MCPcopy Create free account
hub / github.com/Autodesk/Aurora / getModulePath

Function getModulePath

Libraries/Foundation/Source/Utilities.cpp:89–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87}
88
89std::string getModulePath()
90{
91#if defined(WIN32)
92 char path[MAX_PATH + 1];
93
94 DWORD pathSize = _MAX_PATH;
95 if (path == nullptr)
96 return std::string();
97
98 // Get a handle to the module that this static function lives in.
99 HMODULE hModule = nullptr;
100 GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCTSTR)getModulePath, &hModule);
101
102 DWORD size = GetModuleFileNameA(hModule, path, pathSize);
103 if (size == 0 || size == pathSize)
104 {
105 AU_FAIL("Failed to get module path.");
106 }
107 std::string tempBuf(path);
108
109#else
110 Dl_info info;
111 std::string tempBuf("/");
112 if (dladdr((void*)getModulePath, &info))
113 {
114 tempBuf += info.dli_fname;
115 }
116 else
117 {
118 AU_FAIL("Failed to get module path.");
119 }
120#endif
121
122 size_t charOffset = tempBuf.find('/');
123 while (charOffset != std::string::npos)
124 {
125 tempBuf.replace(charOffset, 1, "\\");
126 charOffset = tempBuf.find('/');
127 }
128
129 // runTimeDir contains path up to executable name
130 // Remove the executable name.
131 charOffset = tempBuf.rfind(L'\\');
132 if (charOffset != std::string::npos)
133 tempBuf.erase(charOffset + 1, (tempBuf.length() - charOffset) - 1);
134 return tempBuf;
135}
136
137} // namespace Foundation
138} // namespace Aurora

Callers 5

TEST_FFunction · 0.85
TEST_FFunction · 0.85
initializeMethod · 0.85
PTSceneMethod · 0.85
writeStringToFileFunction · 0.85

Calls

no outgoing calls

Tested by 2

TEST_FFunction · 0.68
TEST_FFunction · 0.68