From 383980279ceca45f9f73883e14c5b80f09274387 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Tue, 5 Nov 2024 20:56:17 -0500 Subject: [PATCH 1/5] ofAppUtils::ofGetAppName --- libs/openFrameworks/utils/ofFileUtils.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libs/openFrameworks/utils/ofFileUtils.h b/libs/openFrameworks/utils/ofFileUtils.h index c2ed03af9f3..d76261e16a9 100644 --- a/libs/openFrameworks/utils/ofFileUtils.h +++ b/libs/openFrameworks/utils/ofFileUtils.h @@ -446,6 +446,20 @@ class ofFilePath { static of::filesystem::path getCurrentExeDirFS(); static std::string getCurrentExeDir(); + /// Get the App name of the running binary + /// + /// \param strip_debug removes a trailing "Debug" if present + /// \returns the App name as native string + static auto getAppName(bool strip_debug = true) { + auto name = ofFilePath::getCurrentExePathFS().filename().native(); + if (strip_debug) { + if (name.size() > 5 && name.compare(name.size() - 5, 5, "Debug") == 0) { + name.erase(name.size() - 5); + } + } + return name; + } + /// Get the absolute path to the user's home directory. /// /// Mac OSX: /Users/ From d4f25c02b7dd7a5e71ce1c43504822ec0efa8f43 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Tue, 5 Nov 2024 21:22:49 -0500 Subject: [PATCH 2/5] fix wstring --- libs/openFrameworks/utils/ofFileUtils.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.h b/libs/openFrameworks/utils/ofFileUtils.h index d76261e16a9..92bc1caa1b7 100644 --- a/libs/openFrameworks/utils/ofFileUtils.h +++ b/libs/openFrameworks/utils/ofFileUtils.h @@ -450,10 +450,11 @@ class ofFilePath { /// /// \param strip_debug removes a trailing "Debug" if present /// \returns the App name as native string - static auto getAppName(bool strip_debug = true) { + static const auto getAppName(bool strip_debug = true) { auto name = ofFilePath::getCurrentExePathFS().filename().native(); + const std::filesystem::path::string_type debug_suffix = "Debug"; if (strip_debug) { - if (name.size() > 5 && name.compare(name.size() - 5, 5, "Debug") == 0) { + if (name.size() > 5 && name.compare(name.size() - 5, 5, debug_suffix) == 0) { name.erase(name.size() - 5); } } From f6002ab19edee6e16ede7b7d925b483aa9434e63 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Tue, 5 Nov 2024 21:44:50 -0500 Subject: [PATCH 3/5] getAppName() ensure size of stripped suffix --- libs/openFrameworks/utils/ofFileUtils.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.h b/libs/openFrameworks/utils/ofFileUtils.h index 92bc1caa1b7..af4d59b99b6 100644 --- a/libs/openFrameworks/utils/ofFileUtils.h +++ b/libs/openFrameworks/utils/ofFileUtils.h @@ -452,10 +452,11 @@ class ofFilePath { /// \returns the App name as native string static const auto getAppName(bool strip_debug = true) { auto name = ofFilePath::getCurrentExePathFS().filename().native(); - const std::filesystem::path::string_type debug_suffix = "Debug"; + typename std::filesystem::path::string_type debug_suffix = std::filesystem::path::string_type("Debug"); + auto dbsize = debug_suffix.size(); if (strip_debug) { - if (name.size() > 5 && name.compare(name.size() - 5, 5, debug_suffix) == 0) { - name.erase(name.size() - 5); + if (name.size() > dbsize && name.compare(name.size() -dbsize , dbsize, debug_suffix) == 0) { + name.erase(name.size() - dbsize); } } return name; From cfd9033573e71c7345d84e55a883b2eba075290a Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Tue, 5 Nov 2024 21:57:31 -0500 Subject: [PATCH 4/5] ofFilePath::getAppName() correct type for suffix --- libs/openFrameworks/utils/ofFileUtils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.h b/libs/openFrameworks/utils/ofFileUtils.h index af4d59b99b6..7cff57f977e 100644 --- a/libs/openFrameworks/utils/ofFileUtils.h +++ b/libs/openFrameworks/utils/ofFileUtils.h @@ -452,7 +452,7 @@ class ofFilePath { /// \returns the App name as native string static const auto getAppName(bool strip_debug = true) { auto name = ofFilePath::getCurrentExePathFS().filename().native(); - typename std::filesystem::path::string_type debug_suffix = std::filesystem::path::string_type("Debug"); + auto debug_suffix = std::filesystem::path("Debug").native(); auto dbsize = debug_suffix.size(); if (strip_debug) { if (name.size() > dbsize && name.compare(name.size() -dbsize , dbsize, debug_suffix) == 0) { From 79c89c653916e9711a22988f1032127a9b83e88d Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Fri, 8 Nov 2024 18:48:00 -0500 Subject: [PATCH 5/5] correct suffix for linux --- libs/openFrameworks/utils/ofFileUtils.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/openFrameworks/utils/ofFileUtils.h b/libs/openFrameworks/utils/ofFileUtils.h index 7cff57f977e..3e683c6ed34 100644 --- a/libs/openFrameworks/utils/ofFileUtils.h +++ b/libs/openFrameworks/utils/ofFileUtils.h @@ -452,7 +452,11 @@ class ofFilePath { /// \returns the App name as native string static const auto getAppName(bool strip_debug = true) { auto name = ofFilePath::getCurrentExePathFS().filename().native(); +#if defined(TARGET_OSX) auto debug_suffix = std::filesystem::path("Debug").native(); +#else + auto debug_suffix = std::filesystem::path("_debug").native(); +#endif auto dbsize = debug_suffix.size(); if (strip_debug) { if (name.size() > dbsize && name.compare(name.size() -dbsize , dbsize, debug_suffix) == 0) {