MCPcopy Create free account
hub / github.com/comaps/comaps / Platform

Method Platform

libs/platform/platform_win.cpp:55–105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53} // namespace platform
54
55Platform::Platform()
56{
57 std::string path;
58 CHECK(GetPathToBinary(path), ("Can't get path to binary"));
59
60 // resources path:
61 // 1. try to use data folder in the same path as executable
62 // 2. if not found, try to use ..\..\..\data (for development only)
63 path.erase(path.find_last_of('\\'));
64 if (IsFileExistsByFullPath(path + "\\data\\"))
65 m_resourcesDir = path + "\\data\\";
66 else
67 {
68#ifndef RELEASE
69 path.erase(path.find_last_of('\\'));
70 path.erase(path.find_last_of('\\'));
71 if (IsFileExistsByFullPath(path + "\\data\\"))
72 m_resourcesDir = path + "\\data\\";
73#else
74 CHECK(false, ("Can't find resources directory"));
75#endif
76 }
77
78 // writable path:
79 // 1. the same as resources if we have write access to this folder
80 // 2. otherwise, use system-specific folder
81 auto const tmpFilePath = base::JoinPath(m_resourcesDir, "mapswithmetmptestfile");
82 try
83 {
84 FileWriter tmpfile(tmpFilePath);
85 tmpfile.Write("Hi from Alex!", 13);
86 m_writableDir = m_resourcesDir;
87 }
88 catch (RootException const &)
89 {
90 CHECK(GetUserWritableDir(m_writableDir), ("Can't get writable directory"));
91 }
92 FileWriter::DeleteFileX(tmpFilePath);
93
94 m_settingsDir = m_writableDir;
95 char pathBuf[MAX_PATH] = {0};
96 GetTempPathA(MAX_PATH, pathBuf);
97 m_tmpDir = pathBuf;
98
99 m_guiThread = std::make_unique<platform::GuiThread>();
100
101 LOG(LINFO, ("Resources Directory:", m_resourcesDir));
102 LOG(LINFO, ("Writable Directory:", m_writableDir));
103 LOG(LINFO, ("Tmp Directory:", m_tmpDir));
104 LOG(LINFO, ("Settings Directory:", m_settingsDir));
105}
106
107bool Platform::IsFileExistsByFullPath(std::string const & filePath)
108{

Callers

nothing calls this directly

Calls 6

GetPathToBinaryFunction · 0.85
JoinPathFunction · 0.85
GetUserWritableDirFunction · 0.85
DeleteFileXFunction · 0.85
eraseMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected