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