The Battle for Wesnoth  1.19.5+dev
paths.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2024
3  by Iris Morelle <shadowm2006@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  * @file
18  * Desktop paths, storage media and bookmark functions.
19  */
20 
21 #pragma once
22 
23 #include "tstring.hpp"
24 
25 #include <iosfwd>
26 #include <set>
27 #include <vector>
28 
29 namespace desktop
30 {
31 
32 /**
33  * Returns the path to the user profile dir (e.g. /home/username).
34  *
35  * An empty string is returned if the path cannot be determined somehow.
36  */
37 std::string user_profile_dir();
38 
39 struct path_info
40 {
41  /** Path name or drive letter/mount point path; may be a translatable string if it's a game resources path. */
43  /** System-defined label, if the path is a drive or mount point. */
44  std::string label;
45  /** Real path. */
46  std::string path;
47 
48  /**
49  * Formats this path for UI display.
50  */
51  std::string display_name() const;
52 };
53 
54 std::ostream& operator<<(std::ostream& os, const path_info& pinf);
55 
57 {
58  GAME_BIN_DIR = 0, /**< Game executable dir. */
59  GAME_CORE_DATA_DIR = 1, /**< Game data dir. */
60  GAME_USER_DATA_DIR = 3, /**< User data dir. */
61  GAME_EDITOR_MAP_DIR = 4, /**< Editor map dir */
62 };
63 
65 {
66  SYSTEM_ALL_DRIVES = 0, /**< Paths for each storage media found (Windows), /media and/or /mnt (X11, if non-empty). */
67  SYSTEM_USER_PROFILE = 1, /**< Path to the user's profile dir (e.g. /home/username or X:\\Users\\Username). */
68  SYSTEM_ROOTFS = 2 /**< Path to the root of the filesystem hierarchy (ignored on Windows). */
69 };
70 
71 /**
72  * Returns a list of game-related paths.
73  *
74  * These paths are guaranteed to be their canonical forms (with links and dot
75  * entries resolved) and using the platform's preferred path delimiter.
76  */
77 std::vector<path_info> game_paths(std::set<GAME_PATH_TYPES> paths);
78 
79 /**
80  * Returns a list of system-defined paths.
81  *
82  * This includes removable media on platforms where we can reasonably
83  * accurately enumerate those (FIXME: only Windows right now), the path to the
84  * user's profile directory (/home/username, X:\\Users\\Username, etc.), and
85  * the system drive root.
86  *
87  * These paths are guaranteed to be their canonical forms (with links and dot
88  * entries resolved) and using the platform's preferred path delimiter.
89  */
90 std::vector<path_info> system_paths(std::set<SYSTEM_PATH_TYPES> paths);
91 
93 {
94  /** User defined label. */
95  std::string label;
96  /** Real path. */
97  std::string path;
98 };
99 
100 unsigned add_user_bookmark(const std::string& label, const std::string& path);
101 
102 void remove_user_bookmark(unsigned index);
103 
104 std::vector<bookmark_info> user_bookmarks();
105 
106 } // namespace desktop
std::string label
What to show in the filter's drop-down list.
Definition: manager.cpp:200
std::vector< bookmark_info > user_bookmarks()
Definition: paths.cpp:276
unsigned add_user_bookmark(const std::string &label, const std::string &path)
Definition: paths.cpp:251
GAME_PATH_TYPES
Definition: paths.hpp:57
@ GAME_EDITOR_MAP_DIR
Editor map dir.
Definition: paths.hpp:61
@ GAME_USER_DATA_DIR
User data dir.
Definition: paths.hpp:60
@ GAME_CORE_DATA_DIR
Game data dir.
Definition: paths.hpp:59
@ GAME_BIN_DIR
Game executable dir.
Definition: paths.hpp:58
void remove_user_bookmark(unsigned index)
Definition: paths.cpp:264
std::vector< path_info > system_paths(std::set< SYSTEM_PATH_TYPES > paths)
Returns a list of system-defined paths.
Definition: paths.cpp:228
SYSTEM_PATH_TYPES
Definition: paths.hpp:65
@ SYSTEM_USER_PROFILE
Path to the user's profile dir (e.g.
Definition: paths.hpp:67
@ SYSTEM_ALL_DRIVES
Paths for each storage media found (Windows), /media and/or /mnt (X11, if non-empty).
Definition: paths.hpp:66
@ SYSTEM_ROOTFS
Path to the root of the filesystem hierarchy (ignored on Windows).
Definition: paths.hpp:68
std::string user_profile_dir()
Returns the path to the user profile dir (e.g.
Definition: paths.cpp:166
std::vector< path_info > game_paths(std::set< GAME_PATH_TYPES > paths)
Returns a list of game-related paths.
Definition: paths.cpp:200
std::ostream & operator<<(std::ostream &os, const path_info &pinf)
Definition: paths.cpp:195
std::string path
Definition: filesystem.cpp:90
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.
Definition: unicode.cpp:70
std::string path
Real path.
Definition: paths.hpp:97
std::string label
User defined label.
Definition: paths.hpp:95
std::string path
Real path.
Definition: paths.hpp:46
std::string display_name() const
Formats this path for UI display.
Definition: paths.cpp:190
std::string label
System-defined label, if the path is a drive or mount point.
Definition: paths.hpp:44
t_string name
Path name or drive letter/mount point path; may be a translatable string if it's a game resources pat...
Definition: paths.hpp:42