16 #define GETTEXT_DOMAIN "wesnoth-lib" 28 #if !defined(_WIN32) && !defined(__APPLE__) 29 #include <boost/filesystem.hpp> 36 #include <sys/types.h> 44 #define WIN32_LEAN_AND_MEAN 52 #define ERR_DU LOG_STREAM(err, log_desktop) 53 #define LOG_DU LOG_STREAM(info, log_desktop) 54 #define DBG_DU LOG_STREAM(debug, log_desktop) 62 void enumerate_storage_devices(std::vector<path_info>& res)
66 const DWORD drive_table = GetLogicalDrives();
68 for(
unsigned n = 0;
n < 26; ++
n) {
69 if((drive_table >>
n) & 1) {
70 std::string u8drive =
"A:";
73 LOG_DU <<
"enumerate_win32_drives(): " << u8drive <<
" is reported to be present";
75 wchar_t drive[] = L
"A:\\";
78 const DWORD label_bufsize = MAX_PATH + 1;
79 wchar_t label[label_bufsize] { 0 };
81 if(GetVolumeInformation(drive,
label, label_bufsize,
nullptr,
nullptr,
nullptr,
nullptr, 0) == 0) {
83 const DWORD
err = GetLastError();
84 LOG_DU <<
"enumerate_win32_drives(): GetVolumeInformation() failed (" << err <<
")";
90 res.push_back({u8drive,
unicode_cast<std::string>(std::wstring{
label}), u8drive +
'\\'});
94 #elif defined(__APPLE__) 98 res.push_back({{
N_(
"filesystem_path_system^Volumes"),
GETTEXT_DOMAIN },
"",
"/Volumes"});
102 namespace bsys = boost::system;
103 namespace bfs = boost::filesystem;
109 static const std::vector<std::string> candidates {
"/media",
"/mnt" };
111 for(
const auto& mnt : candidates) {
115 DBG_DU <<
"enumerate_mount_parents(): " << mnt <<
" appears to be a non-empty dir";
116 res.push_back({mnt,
"", mnt});
129 bool have_path(
const std::vector<path_info>& pathset,
const std::string&
path)
131 for(
const auto& pinfo : pathset) {
132 if(pinfo.path == path) {
140 inline std::string pretty_path(
const std::string& path)
145 inline config get_bookmarks_config()
148 return cfg ? cfg :
config{};
151 inline void commit_bookmarks_config(
config& cfg)
165 const passwd*
const pwd = getpwuid(geteuid());
167 if(!pwd || !pwd->pw_dir || !*pwd->pw_dir) {
175 wchar_t profile_path[MAX_PATH];
176 HRESULT res = SHGetFolderPath(
nullptr, CSIDL_PROFILE,
nullptr, SHGFP_TYPE_CURRENT, profile_path);
177 return res != S_OK ?
"" :
unicode_cast<std::string>(std::wstring{profile_path});
189 return os << pinf.
name <<
" [" << pinf.
label <<
"] - " << pinf.
path;
199 std::vector<path_info> res;
201 if(path_types &
GAME_BIN_DIR && !have_path(res, game_bin_dir)) {
202 res.push_back({{
N_(
"filesystem_path_game^Game executables"),
GETTEXT_DOMAIN },
"", game_bin_dir});
206 res.push_back({{
N_(
"filesystem_path_game^Game data"),
GETTEXT_DOMAIN },
"", game_data_dir});
210 res.push_back({{
N_(
"filesystem_path_game^User data"),
GETTEXT_DOMAIN },
"", game_user_data_dir});
214 res.push_back({{
N_(
"filesystem_path_game^User preferences"),
GETTEXT_DOMAIN },
"", game_user_pref_dir});
224 std::vector<path_info> res;
227 res.push_back({{
N_(
"filesystem_path_system^Home"),
GETTEXT_DOMAIN },
"", home_dir});
231 enumerate_storage_devices(res);
236 res.push_back({{
N_(
"filesystem_path_system^Root"),
GETTEXT_DOMAIN },
"",
"/"});
245 config cfg = get_bookmarks_config();
248 bookmark_cfg[
"label"] =
label;
249 bookmark_cfg[
"path"] =
path;
251 commit_bookmarks_config(cfg);
258 config cfg = get_bookmarks_config();
259 const unsigned prev_size = cfg.
child_count(
"bookmark");
261 if(index < prev_size) {
265 commit_bookmarks_config(cfg);
270 const config& cfg = get_bookmarks_config();
271 std::vector<bookmark_info> res;
275 res.push_back({ bookmark_cfg[
"label"], bookmark_cfg[
"path"] });
void remove_user_bookmark(unsigned index)
Paths for each storage media found (Windows), /media and/or /mnt (X11, if non-empty).
bool has_child(config_key_type key) const
Determine whether a config has a child or not.
unsigned child_count(config_key_type key) const
ucs4_convert_impl::enableif< TD, typename TS::value_type >::type unicode_cast(const TS &source)
child_itors child_range(config_key_type key)
std::vector< bookmark_info > user_bookmarks()
Path to the root of the filesystem hierarchy (ignored on Windows).
std::string get_unknown_exception_type()
Utility function for finding the type of thing caught with catch(...).
std::string normalize_path(const std::string &fpath, bool normalize_separators, bool resolve_dot_entries)
Returns the absolute path of a file.
std::vector< path_info > game_paths(unsigned path_types)
Returns a list of game-related paths.
std::string label
What to show in the filter's drop-down list.
static lg::log_domain log_desktop("desktop")
std::string get_user_data_dir()
std::vector< path_info > system_paths(unsigned path_types)
Returns a list of system-defined paths.
t_string name
Path name or drive letter/mount point path; may be a translatable string if it's a game resources pat...
std::string display_name() const
Formats this path for UI display.
bool is_directory(const std::string &fname)
Returns true if the given file is a directory.
Desktop paths, storage media and bookmark functions.
std::string label
System-defined label, if the path is a drive or mount point.
void set_child(const std::string &key, const config &val)
std::string get_exe_dir()
std::string path
Real path.
Path to the user's profile dir (e.g.
unsigned add_user_bookmark(const std::string &label, const std::string &path)
Declarations for File-IO.
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
const config & get_child(const std::string &key)
config & add_child(config_key_type key)
std::string user_profile_dir()
Returns the path to the user profile dir (e.g.
std::string get_user_config_dir()
Standard logging facilities (interface).
std::ostream & operator<<(std::ostream &os, const path_info &pinf)
A config object defines a single node in a WML file, with access to child nodes.
static map_location::DIRECTION n
void remove_child(config_key_type key, unsigned index)