The Battle for Wesnoth  1.19.0-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_PREFS_DIR = 2, /**< User preferences dir. */
61  GAME_USER_DATA_DIR = 3, /**< User data dir. */
62  GAME_EDITOR_MAP_DIR = 4, /**< Editor map dir */
63 };
64 
66 {
67  SYSTEM_ALL_DRIVES = 0, /**< Paths for each storage media found (Windows), /media and/or /mnt (X11, if non-empty). */
68  SYSTEM_USER_PROFILE = 1, /**< Path to the user's profile dir (e.g. /home/username or X:\\Users\\Username). */
69  SYSTEM_ROOTFS = 2 /**< Path to the root of the filesystem hierarchy (ignored on Windows). */
70 };
71 
72 /**
73  * Returns a list of game-related paths.
74  *
75  * These paths are guaranteed to be their canonical forms (with links and dot
76  * entries resolved) and using the platform's preferred path delimiter.
77  */
78 std::vector<path_info> game_paths(std::set<GAME_PATH_TYPES> paths);
79 
80 /**
81  * Returns a list of system-defined paths.
82  *
83  * This includes removable media on platforms where we can reasonably
84  * accurately enumerate those (FIXME: only Windows right now), the path to the
85  * user's profile directory (/home/username, X:\\Users\\Username, etc.), and
86  * the system drive root.
87  *
88  * These paths are guaranteed to be their canonical forms (with links and dot
89  * entries resolved) and using the platform's preferred path delimiter.
90  */
91 std::vector<path_info> system_paths(std::set<SYSTEM_PATH_TYPES> paths);
92 
94 {
95  /** User defined label. */
96  std::string label;
97  /** Real path. */
98  std::string path;
99 };
100 
101 unsigned add_user_bookmark(const std::string& label, const std::string& path);
102 
103 void remove_user_bookmark(unsigned index);
104 
105 std::vector<bookmark_info> user_bookmarks();
106 
107 } // namespace desktop
std::string label
What to show in the filter's drop-down list.
Definition: manager.cpp:209
std::vector< bookmark_info > user_bookmarks()
Definition: paths.cpp:279
unsigned add_user_bookmark(const std::string &label, const std::string &path)
Definition: paths.cpp:254
GAME_PATH_TYPES
Definition: paths.hpp:57
@ GAME_EDITOR_MAP_DIR
Editor map dir.
Definition: paths.hpp:62
@ GAME_USER_DATA_DIR
User data dir.
Definition: paths.hpp:61
@ GAME_CORE_DATA_DIR
Game data dir.
Definition: paths.hpp:59
@ GAME_USER_PREFS_DIR
User preferences dir.
Definition: paths.hpp:60
@ GAME_BIN_DIR
Game executable dir.
Definition: paths.hpp:58
void remove_user_bookmark(unsigned index)
Definition: paths.cpp:267
std::vector< path_info > system_paths(std::set< SYSTEM_PATH_TYPES > paths)
Returns a list of system-defined paths.
Definition: paths.cpp:231
SYSTEM_PATH_TYPES
Definition: paths.hpp:66
@ SYSTEM_USER_PROFILE
Path to the user's profile dir (e.g.
Definition: paths.hpp:68
@ SYSTEM_ALL_DRIVES
Paths for each storage media found (Windows), /media and/or /mnt (X11, if non-empty).
Definition: paths.hpp:67
@ SYSTEM_ROOTFS
Path to the root of the filesystem hierarchy (ignored on Windows).
Definition: paths.hpp:69
std::string user_profile_dir()
Returns the path to the user profile dir (e.g.
Definition: paths.cpp:164
std::vector< path_info > game_paths(std::set< GAME_PATH_TYPES > paths)
Returns a list of game-related paths.
Definition: paths.cpp:198
std::ostream & operator<<(std::ostream &os, const path_info &pinf)
Definition: paths.cpp:193
std::string path
Definition: filesystem.cpp:83
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:98
std::string label
User defined label.
Definition: paths.hpp:96
std::string path
Real path.
Definition: paths.hpp:46
std::string display_name() const
Formats this path for UI display.
Definition: paths.cpp:188
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