Move Wine exe name code from config.cpp to get_wine_exe_name(...)

pull/109/head
jackun 4 years ago
parent cf17f70dab
commit 25b0adfbf9
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

@ -50,26 +50,9 @@ void parseConfigFile(overlay_params& params) {
// find executable's path when run in Wine
if (!env_config.empty() && (basename == "wine-preloader" || basename == "wine64-preloader")) {
std::string line;
std::ifstream stream("/proc/self/cmdline");
while (std::getline(stream, line, '\0'))
{
if (!line.empty()
&& ((n = line.find_last_of("/\\")) != std::string::npos)
&& n < line.size() - 1) // have at least one character
{
auto dot = line.find_last_of('.');
if (dot < n)
dot = line.size();
paths.push_back(env_config + mangohud_dir + "wine-" + line.substr(n + 1, dot - n - 1) + ".conf");
break;
}
else if (ends_with(line, ".exe", true))
{
auto dot = line.find_last_of('.');
paths.push_back(env_config + mangohud_dir + "wine-" + line.substr(0, dot) + ".conf");
break;
}
std::string name;
if (get_wine_exe_name(name)) {
paths.push_back(env_config + mangohud_dir + "wine-" + name + ".conf");
}
}
}

@ -106,6 +106,33 @@ std::string get_exe_path()
return std::string(result, (count > 0) ? count : 0);
}
bool get_wine_exe_name(std::string& name, bool keep_ext)
{
std::string line;
std::ifstream cmdline("/proc/self/cmdline");
auto n = std::string::npos;
while (std::getline(cmdline, line, '\0'))
{
if (!line.empty()
&& ((n = line.find_last_of("/\\")) != std::string::npos)
&& n < line.size() - 1) // have at least one character
{
auto dot = keep_ext ? std::string::npos : line.find_last_of('.');
if (dot < n)
dot = line.size();
name = line.substr(n + 1, dot - n - 1);
return true;
}
else if (ends_with(line, ".exe", true))
{
auto dot = keep_ext ? std::string::npos : line.find_last_of('.');
name = line.substr(0, dot);
return true;
}
}
return false;
}
std::string get_home_dir()
{
std::string path;

@ -16,6 +16,7 @@ std::vector<std::string> ls(const char* root, const char* prefix = nullptr, LS_F
bool file_exists(const std::string& path);
bool dir_exists(const std::string& path);
std::string get_exe_path();
bool get_wine_exe_name(std::string& name, bool keep_ext = false);
std::string get_home_dir();
std::string get_data_dir();
std::string get_config_dir();

Loading…
Cancel
Save