Add get_basename, fix win32 build

std::string::substr likes to throw
pull/595/head
jackun 3 years ago
parent 67e5d790d1
commit 822e325d11
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

@ -12,8 +12,7 @@ static std::string get_proc_name() {
if (!proc_name.empty()) {
return proc_name;
}
const std::string p = get_exe_path();
return p.substr(p.find_last_of("/\\") + 1);
return get_basename(get_exe_path());
}
static std::vector<std::string> blacklist {

@ -18,6 +18,19 @@ std::string read_line(const std::string& filename)
return line;
}
std::string get_basename(const std::string&& path)
{
auto npos = path.find_last_of("/\\");
if (npos == std::string::npos)
return path;
if (npos < path.size() - 1)
return path.substr(npos + 1);
return path;
}
#ifdef __gnu_linux__
bool find_folder(const char* root, const char* prefix, std::string& dest)
{
struct dirent* dp;
@ -106,6 +119,11 @@ std::string read_symlink(const char * link)
return std::string(result, (count > 0) ? count : 0);
}
std::string read_symlink(const std::string&& link)
{
return read_symlink(link.c_str());
}
std::string get_exe_path()
{
return read_symlink("/proc/self/exe");
@ -180,3 +198,5 @@ std::string get_config_dir()
path += "/.config";
return path;
}
#endif // __gnu_linux__

@ -19,6 +19,8 @@ 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 read_symlink(const char * link);
std::string read_symlink(const std::string&& link);
std::string get_basename(const std::string&& path); //prefix so it doesn't conflict libgen
std::string get_exe_path();
std::string get_wine_exe_name(bool keep_ext = false);
std::string get_home_dir();

@ -3,14 +3,6 @@
#include <fstream>
#include <string>
std::string read_line(const std::string& filename)
{
std::string line;
std::ifstream file(filename);
std::getline(file, line);
return line;
}
bool find_folder(const char* root, const char* prefix, std::string& dest)
{
return false;

@ -373,6 +373,7 @@ void HudElements::ram(){
void HudElements::procmem()
{
#ifdef __gnu_linux__
const char* unit = nullptr;
if (!HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_procmem])
return;
@ -408,6 +409,7 @@ void HudElements::procmem()
ImGui::Text("%s", unit);
ImGui::PopFont();
}
#endif
}
void HudElements::fps(){

@ -53,6 +53,7 @@ vklayer_files = files(
'gpu.cpp',
'vulkan.cpp',
'blacklist.cpp',
'file_utils.cpp',
)
opengl_files = []
if ['windows', 'mingw'].contains(host_machine.system())
@ -72,7 +73,6 @@ endif
if is_unixy
vklayer_files += files(
'cpu.cpp',
'file_utils.cpp',
'memory.cpp',
'iostats.cpp',
'notify.cpp',

Loading…
Cancel
Save