The Battle for Wesnoth  1.17.0-dev
paths.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2021
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 <vector>
27 
28 namespace desktop
29 {
30 
31 /**
32  * Returns the path to the user profile dir (e.g. /home/username).
33  *
34  * An empty string is returned if the path cannot be determined somehow.
35  */
36 std::string user_profile_dir();
37 
38 struct path_info
39 {
40  /** Path name or drive letter/mount point path; may be a translatable string if it's a game resources path. */
42  /** System-defined label, if the path is a drive or mount point. */
43  std::string label;
44  /** Real path. */
45  std::string path;
46 
47  /**
48  * Formats this path for UI display.
49  */
50  std::string display_name() const;
51 };
52 
53 std::ostream& operator<<(std::ostream& os, const path_info& pinf);
54 
56 {
57  GAME_BIN_DIR = 0x1, /**< Game executable dir. */
58  GAME_CORE_DATA_DIR = 0x2, /**< Game data dir. */
59  GAME_USER_PREFS_DIR = 0x4, /**< User preferences dir. */
60  GAME_USER_DATA_DIR = 0x8, /**< User data dir. */
61 };
62 
64 {
65  SYSTEM_ALL_DRIVES = 0x1, /**< Paths for each storage media found (Windows), /media and/or /mnt (X11, if non-empty). */
66  SYSTEM_USER_PROFILE = 0x2, /**< Path to the user's profile dir (e.g. /home/username or X:\\Users\\Username). */
67  SYSTEM_ROOTFS = 0x4 /**< Path to the root of the filesystem hierarchy (ignored on Windows). */
68 };
69 
70 /**
71  * Returns a list of game-related paths.
72  *
73  * These paths are guaranteed to be their canonical forms (with links and dot
74  * entries resolved) and using the platform's preferred path delimiter.
75  */
76 std::vector<path_info> game_paths(unsigned path_types = GAME_CORE_DATA_DIR | GAME_USER_DATA_DIR);
77 
78 /**
79  * Returns a list of system-defined paths.
80  *
81  * This includes removable media on platforms where we can reasonably
82  * accurately enumerate those (FIXME: only Windows right now), the path to the
83  * user's profile directory (/home/username, X:\\Users\\Username, etc.), and
84  * the system drive root.
85  *
86  * These paths are guaranteed to be their canonical forms (with links and dot
87  * entries resolved) and using the platform's preferred path delimiter.
88  */
89 std::vector<path_info> system_paths(unsigned path_types = SYSTEM_ALL_DRIVES | SYSTEM_USER_PROFILE | SYSTEM_ROOTFS);
90 
92 {
93  /** User defined label. */
94  std::string label;
95  /** Real path. */
96  std::string path;
97 };
98 
99 unsigned add_user_bookmark(const std::string& label, const std::string& path);
100 
101 void remove_user_bookmark(unsigned index);
102 
103 std::vector<bookmark_info> user_bookmarks();
104 
105 } // namespace desktop
void remove_user_bookmark(unsigned index)
Definition: paths.cpp:255
Paths for each storage media found (Windows), /media and/or /mnt (X11, if non-empty).
Definition: paths.hpp:65
std::vector< bookmark_info > user_bookmarks()
Definition: paths.cpp:267
Path to the root of the filesystem hierarchy (ignored on Windows).
Definition: paths.hpp:67
std::string label
User defined label.
Definition: paths.hpp:94
std::vector< path_info > game_paths(unsigned path_types)
Returns a list of game-related paths.
Definition: paths.cpp:191
std::vector< path_info > system_paths(unsigned path_types)
Returns a list of system-defined paths.
Definition: paths.cpp:219
t_string name
Path name or drive letter/mount point path; may be a translatable string if it&#39;s a game resources pat...
Definition: paths.hpp:41
std::string display_name() const
Formats this path for UI display.
Definition: paths.cpp:181
SYSTEM_PATH_TYPES
Definition: paths.hpp:63
std::string label
System-defined label, if the path is a drive or mount point.
Definition: paths.hpp:43
User preferences dir.
Definition: paths.hpp:59
std::string path
Real path.
Definition: paths.hpp:45
Path to the user&#39;s profile dir (e.g.
Definition: paths.hpp:66
Game executable dir.
Definition: paths.hpp:57
unsigned add_user_bookmark(const std::string &label, const std::string &path)
Definition: paths.cpp:242
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:72
std::string user_profile_dir()
Returns the path to the user profile dir (e.g.
Definition: paths.cpp:157
std::string path
Real path.
Definition: paths.hpp:96
Game data dir.
Definition: paths.hpp:58
std::ostream & operator<<(std::ostream &os, const path_info &pinf)
Definition: paths.cpp:186
GAME_PATH_TYPES
Definition: paths.hpp:55
User data dir.
Definition: paths.hpp:60