16#define GETTEXT_DOMAIN "wesnoth-lib"
27#if !defined(_WIN32) && !defined(__APPLE__)
28#include <boost/filesystem.hpp>
42#define WIN32_LEAN_AND_MEAN
50#define ERR_DU LOG_STREAM(err, log_desktop)
51#define LOG_DU LOG_STREAM(info, log_desktop)
52#define DBG_DU LOG_STREAM(debug, log_desktop)
60void enumerate_storage_devices(std::vector<path_info>& res)
64 const DWORD drive_table = GetLogicalDrives();
66 for(
unsigned n = 0;
n < 26; ++
n) {
67 if((drive_table >>
n) & 1) {
68 std::string u8drive =
"A:";
71 LOG_DU <<
"enumerate_win32_drives(): " << u8drive <<
" is reported to be present";
73 wchar_t drive[] = L
"A:\\";
76 const DWORD label_bufsize = MAX_PATH + 1;
77 wchar_t label[label_bufsize] { 0 };
79 if(GetVolumeInformation(drive,
label, label_bufsize,
nullptr,
nullptr,
nullptr,
nullptr, 0) == 0) {
81 const DWORD err = GetLastError();
82 LOG_DU <<
"enumerate_win32_drives(): GetVolumeInformation() failed (" << err <<
")";
88 res.push_back({u8drive, unicode_cast<std::string>(std::wstring{
label}), u8drive +
'\\'});
92#elif defined(__APPLE__)
96 res.push_back({{
N_(
"filesystem_path_system^Volumes"),
GETTEXT_DOMAIN },
"",
"/Volumes"});
100 namespace bsys = boost::system;
101 namespace bfs = boost::filesystem;
109 std::vector<std::string> candidates {
"/media",
"/mnt" };
112 if(
const passwd* pw = getpwuid(geteuid()); pw && pw->pw_name && pw->pw_name[0]) {
113 candidates.emplace(candidates.begin(),
"/run/media/");
114 candidates.front() += pw->pw_name;
117 for(
const auto& mnt : candidates) {
120 if(bfs::is_directory(mnt,
e) && !bfs::is_empty(mnt,
e) && !
e) {
121 DBG_DU <<
"enumerate_mount_parents(): " << mnt <<
" appears to be a non-empty dir";
122 res.push_back({mnt,
"", mnt});
135bool have_path(
const std::vector<path_info>& pathset,
const std::string& path)
137 for(
const auto& pinfo : pathset) {
138 if(pinfo.path == path) {
146inline std::string pretty_path(
const std::string& path)
151inline config get_bookmarks_config()
159inline void commit_bookmarks_config(
config&
cfg)
173 const passwd*
const pwd = getpwuid(geteuid());
175 if(!pwd || !pwd->pw_dir || !*pwd->pw_dir) {
183 wchar_t profile_path[MAX_PATH];
184 HRESULT res = SHGetFolderPath(
nullptr, CSIDL_PROFILE,
nullptr, SHGFP_TYPE_CURRENT, profile_path);
185 return res != S_OK ?
"" : unicode_cast<std::string>(std::wstring{profile_path});
197 return os << pinf.
name <<
" [" << pinf.
label <<
"] - " << pinf.
path;
200std::vector<path_info>
game_paths(
const std::set<GAME_PATH_TYPES>& paths)
207 std::vector<path_info> res;
209 if(paths.count(
GAME_BIN_DIR) > 0 && !have_path(res, game_bin_dir)) {
210 res.push_back({{
N_(
"filesystem_path_game^Game executables"),
GETTEXT_DOMAIN },
"", game_bin_dir});
214 res.push_back({{
N_(
"filesystem_path_game^Game data"),
GETTEXT_DOMAIN },
"", game_data_dir});
218 res.push_back({{
N_(
"filesystem_path_game^User data"),
GETTEXT_DOMAIN },
"", game_user_data_dir});
222 res.push_back({{
N_(
"filesystem_path_game^Editor maps"),
GETTEXT_DOMAIN },
"", game_editor_map_dir});
228std::vector<path_info>
system_paths(
const std::set<SYSTEM_PATH_TYPES>& paths)
232 std::vector<path_info> res;
235 res.push_back({{
N_(
"filesystem_path_system^Home"),
GETTEXT_DOMAIN },
"", home_dir});
239 enumerate_storage_devices(res);
244 res.push_back({{
N_(
"filesystem_path_system^Root"),
GETTEXT_DOMAIN },
"",
"/"});
256 bookmark_cfg[
"label"] =
label;
257 bookmark_cfg[
"path"] = path;
259 commit_bookmarks_config(
cfg);
269 if(index < prev_size) {
273 commit_bookmarks_config(
cfg);
278 const config&
cfg = get_bookmarks_config();
279 std::vector<bookmark_info> res;
283 res.push_back({ bookmark_cfg[
"label"], bookmark_cfg[
"path"] });
A config object defines a single node in a WML file, with access to child nodes.
config & add_child(std::string_view key)
child_itors child_range(std::string_view key)
void remove_child(std::string_view key, std::size_t index)
std::size_t child_count(std::string_view key) const
bool has_child(std::string_view key) const
Determine whether a config has a child or not.
optional_const_config dir_bookmarks()
void set_dir_bookmarks(const config &cfg)
Declarations for File-IO.
std::string label
What to show in the filter's drop-down list.
Standard logging facilities (interface).
std::vector< bookmark_info > user_bookmarks()
unsigned add_user_bookmark(const std::string &label, const std::string &path)
@ GAME_EDITOR_MAP_DIR
Editor map dir.
@ GAME_USER_DATA_DIR
User data dir.
@ GAME_CORE_DATA_DIR
Game data dir.
@ GAME_BIN_DIR
Game executable dir.
void remove_user_bookmark(unsigned index)
std::vector< path_info > system_paths(const std::set< SYSTEM_PATH_TYPES > &paths)
Returns a list of system-defined paths.
@ SYSTEM_USER_PROFILE
Path to the user's profile dir (e.g.
@ SYSTEM_ALL_DRIVES
Paths for each storage media found (Windows), /media and/or /mnt (X11, if non-empty).
@ SYSTEM_ROOTFS
Path to the root of the filesystem hierarchy (ignored on Windows).
std::string user_profile_dir()
Returns the path to the user profile dir (e.g.
std::vector< path_info > game_paths(const std::set< GAME_PATH_TYPES > &paths)
Returns a list of game-related paths.
std::ostream & operator<<(std::ostream &os, const path_info &pinf)
std::string get_legacy_editor_dir()
std::string get_user_data_dir()
std::string get_exe_dir()
std::string normalize_path(const std::string &path, bool normalize_separators=false, bool resolve_dot_entries=false)
Returns the absolute path of a file.
std::string get_unknown_exception_type()
Utility function for finding the type of thing caught with catch(...).
static lg::log_domain log_desktop("desktop")
Desktop paths, storage media and bookmark functions.
std::string path
Real path.
std::string display_name() const
Formats this path for UI display.
std::string label
System-defined label, if the path is a drive or mount point.
t_string name
Path name or drive letter/mount point path; may be a translatable string if it's a game resources pat...
static map_location::direction n