mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-26 11:00:48 +01:00
This was causing FEXServer to look in to global installed paths and local paths for things when FEXServer was started. Ensure it listens to FEX_PORTABLE so this doesn't occur. This also requires us to scan both data directories and config directories to find them.
34 lines
1.1 KiB
C++
34 lines
1.1 KiB
C++
// SPDX-License-Identifier: MIT
|
|
#pragma once
|
|
#include "Common/Config.h"
|
|
|
|
namespace FEX {
|
|
static inline FEX::Config::PortableInformation ReadPortabilityInformation() {
|
|
const FEX::Config::PortableInformation BadResult {false, {}};
|
|
const char* PortableConfig = getenv("FEX_PORTABLE");
|
|
if (!PortableConfig) {
|
|
return BadResult;
|
|
}
|
|
|
|
uint32_t Value {};
|
|
std::string_view PortableView {PortableConfig};
|
|
|
|
if (std::from_chars(PortableView.data(), PortableView.data() + PortableView.size(), Value).ec != std::errc {} || Value == 0) {
|
|
return BadResult;
|
|
}
|
|
|
|
// Read the FEXInterpreter path from `/proc/self/exe` which is always a symlink to the absolute path of the executable running.
|
|
// This way we can get the parent path that the application is executing from.
|
|
char SelfPath[PATH_MAX];
|
|
auto Result = readlink("/proc/self/exe", SelfPath, PATH_MAX);
|
|
if (Result == -1) {
|
|
return BadResult;
|
|
}
|
|
|
|
std::string_view SelfPathView {SelfPath, std::min<size_t>(PATH_MAX, Result)};
|
|
|
|
// Extract the absolute path from the FEXInterpreter path
|
|
return {true, fextl::string {SelfPathView.substr(0, SelfPathView.find_last_of('/') + 1)}};
|
|
}
|
|
} // namespace FEX
|