From 083c859424c0542d3aa64d6ae3e0754601384991 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sat, 27 Jan 2018 14:46:52 +0000 Subject: [PATCH 1/5] [gitignore] Add .vscode --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index dfef7810..46652594 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ lib/ +## Visual Studio Code +.vscode/ + ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. ## From 431e280ce5e89a6f0643dd5a7ed04f4c74509e57 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sat, 27 Jan 2018 14:47:25 +0000 Subject: [PATCH 2/5] Fix user home directory implementation for posix Should be /home/ted/.config/OpenLoco by default. --- src/openloco/platform/platform.posix.cpp | 27 ++++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/openloco/platform/platform.posix.cpp b/src/openloco/platform/platform.posix.cpp index 882374c0..4e31626a 100644 --- a/src/openloco/platform/platform.posix.cpp +++ b/src/openloco/platform/platform.posix.cpp @@ -21,7 +21,8 @@ int main(int argc, const char** argv) static std::string GetEnvironmentVariable(const std::string& name) { - return getenv(name.c_str()); + auto result = getenv(name.c_str()); + return result == nullptr ? std::string() : result; } uint32_t openloco::platform::get_time() @@ -31,23 +32,35 @@ uint32_t openloco::platform::get_time() return spec.tv_nsec / 1000000; } -fs::path openloco::platform::get_user_directory() +static fs::path get_home_directory() { - std::string path; auto pw = getpwuid(getuid()); if (pw != nullptr) { - path = pw->pw_dir; + return pw->pw_dir; } else { - path = GetEnvironmentVariable("HOME"); + return GetEnvironmentVariable("HOME"); } +} + +fs::path openloco::platform::get_user_directory() +{ + auto path = fs::path(GetEnvironmentVariable("XDG_CONFIG_HOME")); if (path.empty()) { - path = "/"; + path = get_home_directory(); + if (path.empty()) + { + path = "/"; + } + else + { + path = path / fs::path(".config"); + } } - return path; + return path / fs::path("OpenLoco"); } #if !(defined(__APPLE__) && defined(__MACH__)) From cabe4b083a21ebcab4dcce5fc94c9f8710ca0656 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sat, 27 Jan 2018 15:22:09 +0000 Subject: [PATCH 3/5] Ignore exceptions in find_similar_file --- src/openloco/envionment.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/openloco/envionment.cpp b/src/openloco/envionment.cpp index 8edb5366..3d98a831 100644 --- a/src/openloco/envionment.cpp +++ b/src/openloco/envionment.cpp @@ -125,16 +125,24 @@ namespace openloco::environment */ static fs::path find_similar_file(const fs::path& path) { - auto expectedFilename = path.filename().generic_string(); - auto directory = path.parent_path(); - for (auto& item : fs::directory_iterator(directory)) + try { - auto& p = item.path(); - if (utility::iequals(p.filename().generic_string(), expectedFilename)) + auto expectedFilename = path.filename().generic_string(); + auto directory = path.parent_path(); + for (auto& item : fs::directory_iterator(directory)) { - return p; + auto& p = item.path(); + if (utility::iequals(p.filename().generic_string(), expectedFilename)) + { + return p; + } } } + catch (const std::exception&) + { + // Ignore errors when searching, most common will be that the + // parent directory does not exist + } return fs::path(); } #endif // _WIN32 From 38353c768df228a37bdc7f620433e51c8be280bb Mon Sep 17 00:00:00 2001 From: Ted John Date: Sat, 27 Jan 2018 16:08:51 +0000 Subject: [PATCH 4/5] Add cli prompt for posix --- src/openloco/platform/platform.posix.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/openloco/platform/platform.posix.cpp b/src/openloco/platform/platform.posix.cpp index 4e31626a..99032c8c 100644 --- a/src/openloco/platform/platform.posix.cpp +++ b/src/openloco/platform/platform.posix.cpp @@ -3,6 +3,7 @@ #include "../interop/interop.hpp" #include "../openloco.h" #include "platform.h" +#include #include #include @@ -66,7 +67,10 @@ fs::path openloco::platform::get_user_directory() #if !(defined(__APPLE__) && defined(__MACH__)) std::string openloco::platform::prompt_directory(const std::string& title) { - return "/"; + std::string input; + std::cout << "Type your Locomotion path: "; + std::cin >> input; + return input; } #endif From 00866dba9fde0aca98a32672d779144efcd74a08 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sat, 27 Jan 2018 16:09:04 +0000 Subject: [PATCH 5/5] Fix new directory permissions --- src/openloco/config.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/openloco/config.cpp b/src/openloco/config.cpp index 6888806a..99f40a73 100644 --- a/src/openloco/config.cpp +++ b/src/openloco/config.cpp @@ -78,7 +78,13 @@ namespace openloco::config if (!fs::is_directory(dir)) { fs::create_directories(configPath.parent_path()); - fs::permissions(dir, fs::perms::owner_read | fs::perms::owner_write | fs::perms::group_read | fs::perms::others_read); + // clang-format off + fs::permissions( + dir, + fs::perms::owner_all | + fs::perms::group_read | fs::perms::group_exec | + fs::perms::others_read | fs::perms::others_exec); + // clang-format on } #ifdef _OPENLOCO_USE_BOOST_FS_