Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Common/Cpp/Filesystem/FilePath.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Path{
m_path.clear();
}


public:
// Implicit conversion to the C++ std::filesystem::path so it can be passed to other library functions.
operator const std::filesystem::path&() const{
Expand All @@ -62,6 +63,7 @@ class Path{
return m_path;
}


public:
bool empty() const{
return m_path.empty();
Expand Down Expand Up @@ -109,12 +111,18 @@ class Path{
return m_path.extension();
}

Path lexically_normal() const{
return m_path.lexically_normal();
}


public:
Path& replace_extension(const Path& replacement){
m_path.replace_extension(replacement);
return *this;
}


public:
friend bool operator==(const Path& x, const Path& y){
return x.m_path == y.m_path;
Expand All @@ -130,6 +138,7 @@ class Path{

friend std::ostream& operator<<(std::ostream& stream, const Path& x);


private:
std::filesystem::path m_path;
};
Expand Down
4 changes: 4 additions & 0 deletions Common/Cpp/Filesystem/Filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ namespace Filesystem{



Path absolute(const Path& path){
return std::filesystem::absolute(path.stdpath());
}

bool exists(const Path& path){
return std::filesystem::exists(path.stdpath());
}
Expand Down
2 changes: 2 additions & 0 deletions Common/Cpp/Filesystem/Filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ namespace PokemonAutomation{
namespace Filesystem{


Path absolute(const Path& path);

// Whether a path exists.
bool exists(const Path& path);

Expand Down
6 changes: 5 additions & 1 deletion Common/Cpp/Strings/StringTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ namespace PokemonAutomation{
namespace StringTools{


std::string replace(const std::string& str, const std::string& desired, const std::string& replace_with){
std::string replace(
const std::string& str,
const std::string& desired,
const std::string& replace_with
){
std::string ret;
size_t index = 0;
while (index < str.size()){
Expand Down
6 changes: 5 additions & 1 deletion Common/Cpp/Strings/StringTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ namespace PokemonAutomation{
namespace StringTools{


std::string replace(const std::string& str, const std::string& desired, const std::string& replace_with);
std::string replace(
const std::string& str,
const std::string& desired,
const std::string& replace_with
);

// Trim leading and trailing white spaces
std::string strip(const std::string& str);
Expand Down
12 changes: 8 additions & 4 deletions SerialPrograms/Source/CommonFramework/GlobalAutoPaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifdef __linux__
#include <cstdlib>
#include <fstream>
#include "Common/Cpp/Strings/StringTools.h"
#include "Common/Cpp/Filesystem/FileIO.h"
#endif

Expand Down Expand Up @@ -60,6 +61,7 @@ namespace{




Filesystem::Path get_application_base_dir_path(){
#if defined(__linux__)
// Check for AppImage environment variables to find the root directory, if running as an AppImage.
Expand Down Expand Up @@ -93,10 +95,12 @@ Filesystem::Path get_application_base_dir_path(){
if (pre.size() < 5 || post.size() < 2){
continue;
}
QString mountPoint = pre[4].replace(QStringLiteral("\\040"), QStringLiteral(" "));
QString source = post[1].replace(QStringLiteral("\\040"), QStringLiteral(" "));
if (mountPoint == QString::fromUtf8(app_dir) && source.endsWith(QStringLiteral(".AppImage"))){
return QDir::cleanPath(QFileInfo(source).dir().absolutePath()).toStdString();
std::string mount_point = StringTools::replace(pre[4].toStdString(), "\\040", " ");
std::string source = StringTools::replace(post[1].toStdString(), "\\040", " ");
if (mount_point == app_dir && source.ends_with(".AppImage")){
Filesystem::Path dir_path = Filesystem::Path(source).parent_path();
Filesystem::Path abs_path = Filesystem::absolute(dir_path);
return abs_path.lexically_normal();
}
}
}
Expand Down
Loading