-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
273 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
modules/core/antara/gaming/core/antara.core.real.path.tests.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/****************************************************************************** | ||
* Copyright © 2013-2019 The Komodo Platform Developers. * | ||
* * | ||
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * | ||
* the top-level directory of this distribution for the individual copyright * | ||
* holder information and the developer policies on copyright and licensing. * | ||
* * | ||
* Unless otherwise agreed in a custom licensing agreement, no part of the * | ||
* Komodo Platform software, including this file may be copied, modified, * | ||
* propagated or distributed except according to the terms contained in the * | ||
* LICENSE file * | ||
* * | ||
* Removal or modification of this copyright notice is prohibited. * | ||
* * | ||
******************************************************************************/ | ||
|
||
#include <doctest/doctest.h> | ||
#include "antara/gaming/core/real.path.hpp" | ||
|
||
namespace antara::gaming::core::tests | ||
{ | ||
TEST_CASE("binary_real_path not empty") | ||
{ | ||
auto result = binary_real_path().string(); | ||
MESSAGE("binary real path " << result); | ||
CHECK_FALSE(result.empty()); | ||
} | ||
|
||
TEST_CASE("assets_real_path not empty") | ||
{ | ||
auto result = assets_real_path().string(); | ||
MESSAGE("assets real path " << result); | ||
CHECK_FALSE(result.empty()); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
modules/core/antara/gaming/core/details/emscripten/real.path.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/****************************************************************************** | ||
* Copyright © 2013-2019 The Komodo Platform Developers. * | ||
* * | ||
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * | ||
* the top-level directory of this distribution for the individual copyright * | ||
* holder information and the developer policies on copyright and licensing. * | ||
* * | ||
* Unless otherwise agreed in a custom licensing agreement, no part of the * | ||
* Komodo Platform software, including this file may be copied, modified, * | ||
* propagated or distributed except according to the terms contained in the * | ||
* LICENSE file * | ||
* * | ||
* Removal or modification of this copyright notice is prohibited. * | ||
* * | ||
******************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <filesystem> | ||
|
||
namespace antara::gaming::core::details | ||
{ | ||
std::filesystem::path binary_real_path() noexcept | ||
{ | ||
return std::filesystem::current_path(); | ||
} | ||
|
||
std::filesystem::path assets_real_path() noexcept | ||
{ | ||
return binary_real_path() / "assets"; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
modules/core/antara/gaming/core/details/linux/real.path.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/****************************************************************************** | ||
* Copyright © 2013-2019 The Komodo Platform Developers. * | ||
* * | ||
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * | ||
* the top-level directory of this distribution for the individual copyright * | ||
* holder information and the developer policies on copyright and licensing. * | ||
* * | ||
* Unless otherwise agreed in a custom licensing agreement, no part of the * | ||
* Komodo Platform software, including this file may be copied, modified, * | ||
* propagated or distributed except according to the terms contained in the * | ||
* LICENSE file * | ||
* * | ||
* Removal or modification of this copyright notice is prohibited. * | ||
* * | ||
******************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <filesystem> | ||
#include <string> | ||
#include <unistd.h> //! getpid() | ||
|
||
namespace antara::gaming::core::details | ||
{ | ||
std::filesystem::path binary_real_path() noexcept | ||
{ | ||
return std::filesystem::read_symlink("/proc/" + std::to_string(getpid()) + "/exe"); | ||
} | ||
|
||
std::filesystem::path assets_real_path() noexcept | ||
{ | ||
return binary_real_path().parent_path().parent_path() / "share/assets/"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/****************************************************************************** | ||
* Copyright © 2013-2019 The Komodo Platform Developers. * | ||
* * | ||
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * | ||
* the top-level directory of this distribution for the individual copyright * | ||
* holder information and the developer policies on copyright and licensing. * | ||
* * | ||
* Unless otherwise agreed in a custom licensing agreement, no part of the * | ||
* Komodo Platform software, including this file may be copied, modified, * | ||
* propagated or distributed except according to the terms contained in the * | ||
* LICENSE file * | ||
* * | ||
* Removal or modification of this copyright notice is prohibited. * | ||
* * | ||
******************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <mach-o/dyld.h> | ||
#include <climits> | ||
#include <string> | ||
#include <filesystem> | ||
#include <array> | ||
|
||
namespace antara::gaming::core::details | ||
{ | ||
static std::string &replace_all_mute(std::string &s, | ||
const std::string &from, const std::string &to) noexcept | ||
{ | ||
if (!from.empty()) | ||
for (std::size_t pos = 0; (pos = s.find(from, pos) + 1); pos += to.size()) | ||
s.replace(--pos, from.size(), to); | ||
return s; | ||
} | ||
|
||
static std::string replace_all_copy(std::string s, | ||
const std::string &from, const std::string &to) noexcept | ||
{ | ||
return replace_all_mute(s, from, to); | ||
} | ||
|
||
std::filesystem::path binary_real_path() noexcept | ||
{ | ||
std::array<char, PATH_MAX + 1> dir_name_buffer{}; | ||
auto size = static_cast<uint32_t>(dir_name_buffer.size()); | ||
[[maybe_unused]] int result = _NSGetExecutablePath(dir_name_buffer.data(), &size); | ||
assert(result == 0); | ||
std::string tmp_path(dir_name_buffer.data()); | ||
auto final_path = replace_all_copy(tmp_path, "./", ""); | ||
return std::filesystem::path(final_path); | ||
} | ||
|
||
std::filesystem::path assets_real_path() noexcept | ||
{ | ||
return binary_real_path().parent_path().parent_path() / "Resources/assets"; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
modules/core/antara/gaming/core/details/windows/real.path.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/****************************************************************************** | ||
* Copyright © 2013-2019 The Komodo Platform Developers. * | ||
* * | ||
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * | ||
* the top-level directory of this distribution for the individual copyright * | ||
* holder information and the developer policies on copyright and licensing. * | ||
* * | ||
* Unless otherwise agreed in a custom licensing agreement, no part of the * | ||
* Komodo Platform software, including this file may be copied, modified, * | ||
* propagated or distributed except according to the terms contained in the * | ||
* LICENSE file * | ||
* * | ||
* Removal or modification of this copyright notice is prohibited. * | ||
* * | ||
******************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <windows.h> //! HMODULE, GetModuleHandleW, GetModuleFileNameW | ||
#include <filesystem> | ||
#include <string> | ||
|
||
namespace nephtys::resources::details | ||
{ | ||
std::filesystem::path binary_real_path() noexcept | ||
{ | ||
HMODULE hModule = GetModuleHandleW(NULL); | ||
assert(hModule != nullptr); | ||
WCHAR path[MAX_PATH]; | ||
auto result = GetModuleFileNameW(hModule, path, MAX_PATH); | ||
return std::filesystem::path(path); | ||
} | ||
|
||
std::filesystem::path assets_real_path() noexcept | ||
{ | ||
return binary_real_path().parent_path() / "assets"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/****************************************************************************** | ||
* Copyright © 2013-2019 The Komodo Platform Developers. * | ||
* * | ||
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * | ||
* the top-level directory of this distribution for the individual copyright * | ||
* holder information and the developer policies on copyright and licensing. * | ||
* * | ||
* Unless otherwise agreed in a custom licensing agreement, no part of the * | ||
* Komodo Platform software, including this file may be copied, modified, * | ||
* propagated or distributed except according to the terms contained in the * | ||
* LICENSE file * | ||
* * | ||
* Removal or modification of this copyright notice is prohibited. * | ||
* * | ||
******************************************************************************/ | ||
|
||
#include "antara/gaming/core/real.path.hpp" | ||
|
||
#ifdef _WIN32 | ||
|
||
#include "antara/gaming/core/details/windows/real.path.hpp" | ||
|
||
#elif __APPLE__ | ||
|
||
#include "antara/gaming/core/details/osx/real.path.hpp" | ||
|
||
#elif __linux__ | ||
|
||
#include "nephtys/resources/details/linux/real.path.hpp" | ||
|
||
#elif EMSCRIPTEN | ||
#include "antara/gaming/core/details/emscripten/real.path.hpp" | ||
#endif | ||
|
||
namespace antara::gaming::core | ||
{ | ||
std::filesystem::path binary_real_path() noexcept | ||
{ | ||
return details::binary_real_path(); | ||
} | ||
|
||
std::filesystem::path assets_real_path() noexcept | ||
{ | ||
return details::assets_real_path(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/****************************************************************************** | ||
* Copyright © 2013-2019 The Komodo Platform Developers. * | ||
* * | ||
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * | ||
* the top-level directory of this distribution for the individual copyright * | ||
* holder information and the developer policies on copyright and licensing. * | ||
* * | ||
* Unless otherwise agreed in a custom licensing agreement, no part of the * | ||
* Komodo Platform software, including this file may be copied, modified, * | ||
* propagated or distributed except according to the terms contained in the * | ||
* LICENSE file * | ||
* * | ||
* Removal or modification of this copyright notice is prohibited. * | ||
* * | ||
******************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <filesystem> | ||
|
||
namespace antara::gaming::core | ||
{ | ||
std::filesystem::path binary_real_path() noexcept; | ||
std::filesystem::path assets_real_path() noexcept; | ||
} |