Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factorize Win user folder function between files #2925

Merged
merged 4 commits into from
Oct 26, 2023
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
2 changes: 2 additions & 0 deletions libmamba/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ set(LIBMAMBA_SOURCES
${LIBMAMBA_SOURCE_DIR}/fs/filesystem.cpp
# C++ utility library
${LIBMAMBA_SOURCE_DIR}/util/string.cpp
${LIBMAMBA_SOURCE_DIR}/util/os_win.cpp
${LIBMAMBA_SOURCE_DIR}/util/path_manip.cpp
${LIBMAMBA_SOURCE_DIR}/util/url_manip.cpp
${LIBMAMBA_SOURCE_DIR}/util/url.cpp
Expand Down Expand Up @@ -226,6 +227,7 @@ set(LIBMAMBA_PUBLIC_HEADERS
${LIBMAMBA_INCLUDE_DIR}/mamba/util/graph.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/util/iterator.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/util/string.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/util/os_win.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/util/path_manip.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/util/url_manip.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/util/url.hpp
Expand Down
69 changes: 29 additions & 40 deletions libmamba/include/mamba/core/environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,49 @@
#ifndef MAMBA_CORE_ENVIRONMENT_HPP
#define MAMBA_CORE_ENVIRONMENT_HPP

#include <cassert>
#include <cstdlib>
#include <map>
#include <optional>
#include <string>
#include <vector>

#include "mamba/fs/filesystem.hpp"
#include "mamba/util/build.hpp"

#ifdef _WIN32
#include <Shlobj.h>
#endif
namespace mamba::env
{
[[nodiscard]] constexpr auto pathsep() -> const char*;

#ifndef _WIN32
#include <pwd.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <unistd.h>
#include <wordexp.h>
auto get(const std::string& key) -> std::optional<std::string>;
auto set(const std::string& key, const std::string& value) -> bool;
auto unset(const std::string& key) -> void;

extern "C"
{
extern char** environ;
}
#endif
auto which(const std::string& exe, const std::string& override_path = "") -> fs::u8path;
auto which(const std::string& exe, const std::vector<fs::u8path>& search_paths) -> fs::u8path;
auto copy() -> std::map<std::string, std::string>;
auto platform() -> std::string;
auto home_directory() -> fs::u8path;
auto user_config_dir() -> fs::u8path;
auto user_data_dir() -> fs::u8path;
auto user_cache_dir() -> fs::u8path;

namespace mamba
{
namespace env
auto expand_user(const fs::u8path& path) -> fs::u8path;
auto shrink_user(const fs::u8path& path) -> fs::u8path;

/********************
* Implementation *
********************/

constexpr auto pathsep() -> const char*
{
inline constexpr const char* pathsep()
if (util::on_win)
{
#ifdef _WIN32
return ";";
#else
}
else
{
return ":";
#endif
}

std::optional<std::string> get(const std::string& key);
bool set(const std::string& key, const std::string& value);
void unset(const std::string& key);

fs::u8path which(const std::string& exe, const std::string& override_path = "");
fs::u8path which(const std::string& exe, const std::vector<fs::u8path>& search_paths);
std::map<std::string, std::string> copy();
std::string platform();
fs::u8path home_directory();
fs::u8path user_config_dir();
fs::u8path user_data_dir();
fs::u8path user_cache_dir();

fs::u8path expand_user(const fs::u8path& path);
fs::u8path shrink_user(const fs::u8path& path);
}
}

}
#endif
22 changes: 12 additions & 10 deletions libmamba/include/mamba/core/menuinst.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
#include "mamba/fs/filesystem.hpp"

#include "transaction_context.hpp"
// Copyright (c) 2019, QuantStack and Mamba Contributors
//
// Distributed under the terms of the BSD 3-Clause License.
//
// The full license is in the file LICENSE, distributed with this software.

namespace mamba
{
class Context;
class TransactionContext;
namespace fs
{
class u8path;
}

void remove_menu_from_json(
const Context& context,
const fs::u8path& json_file,
Expand All @@ -14,11 +23,4 @@ namespace mamba
const fs::u8path& json_file,
TransactionContext* transaction_context
);
#ifdef _WIN32
namespace win
{
fs::u8path get_folder(const std::string& id);
}

#endif
}
27 changes: 27 additions & 0 deletions libmamba/include/mamba/util/os_win.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2023, QuantStack and Mamba Contributors
//
// Distributed under the terms of the BSD 3-Clause License.
//
// The full license is in the file LICENSE, distributed with this software.

#ifndef MAMBA_UTIL_OS_WIN_HPP
#define MAMBA_UTIL_OS_WIN_HPP

#include "mamba/fs/filesystem.hpp"


namespace mamba::util
{
enum class WindowsKnowUserFolder
{
Documents,
Profile,
Programs,
ProgramData,
LocalAppData,
RoamingAppData,
};

auto get_windows_known_user_folder(WindowsKnowUserFolder dir) -> fs::u8path;
}
#endif
Loading