coastline 0.0.4
Loading...
Searching...
No Matches
paths.h
Go to the documentation of this file.
1#pragma once
2
3#include <expected>
4#include <filesystem>
5#include <functional>
6#include <optional>
7#include <span>
8#include <string>
9#include <string_view>
10#include <vector>
11
12namespace coastline {
13
19 auto native = path;
20 const auto text = native.make_preferred().u8string();
21 return {text.begin(), text.end()};
22}
23
33
36
45 const std::filesystem::path &appImage = {});
46
56std::expected<GamePaths, std::string>
58 const std::filesystem::path &executable,
59 const std::filesystem::path &workingDirectory = {});
60
70 const std::filesystem::path &root,
71 const std::filesystem::path &home);
72
82 const std::filesystem::path &root,
83 const std::filesystem::path &home);
84
87
97 const std::string &application);
98
108
116
126
133bool CreateGamePaths(const GamePaths &paths);
134
146MigratePortablePaths(const GamePaths &source, const GamePaths &destination, bool copyOnly = false);
147
157 const std::filesystem::path &directory,
158 bool copyOnly = false);
159
171 const std::filesystem::path &executable,
172 const std::filesystem::path &directory,
173 bool copyOnly = false);
174
182std::optional<std::string> ResetGamePaths(const GamePaths &paths, bool factoryReset = false);
183
192 return data / "assets" / "default";
193}
194
196inline constexpr std::string_view DEFAULT_PACK = "default";
197
207 std::string_view pack,
208 const std::filesystem::path &fallback = {});
209
228 const std::filesystem::path &cache,
229 std::string_view pack,
230 const std::filesystem::path &fallback = {},
231 std::string_view region = {});
232
233} // namespace coastline
T make_preferred(T... args)
Definition assetimport.h:11
std::optional< std::string > MakePortablePaths(const GamePaths &source, const std::filesystem::path &directory, bool copyOnly=false)
Export platform data as a portable installation, without copying the executable.
std::optional< std::string > ResetGamePaths(const GamePaths &paths, bool factoryReset=false)
Clear imported assets and asset caches, or all application data for a factory reset.
std::optional< std::filesystem::path > PackAssets(const std::filesystem::path &data, const std::filesystem::path &cache, std::string_view pack, const std::filesystem::path &fallback={}, std::string_view region={})
The directory the game reads its assets from with a pack selected.
std::optional< std::filesystem::path > FindAssetData(const std::filesystem::path &user, std::span< const std::filesystem::path > system)
Find usable assets in system roots first, then in the writable user data root.
bool PortablePathsEnabled()
std::optional< std::string > MakePortableDistribution(const GamePaths &source, const std::filesystem::path &executable, const std::filesystem::path &directory, bool copyOnly=false)
Export installed program files and platform data into a complete portable distribution.
std::function< std::optional< std::string >(const char *name)> EnvironmentReader
Reads an environment variable, or nothing when it is unset or empty.
Definition paths.h:86
constexpr std::string_view DEFAULT_PACK
The name of the asset pack of the import, the directory assets/default.
Definition paths.h:196
std::optional< GamePaths > ResolveGamePaths(const std::string &application)
Resolve the directories with the conventions of the running operating system: the XDG Base Directory ...
std::filesystem::path PortableRoot(const std::filesystem::path &executable, const std::filesystem::path &appImage={})
Locate portable files beside an application bundle, AppImage, or ordinary executable.
std::filesystem::path StorePortablePath(const std::filesystem::path &path, const std::filesystem::path &root, const std::filesystem::path &home)
Store an input path relative to the portable directory, using '~' for external home paths.
std::filesystem::path DefaultAssets(const std::filesystem::path &data)
The directory the import writes the game data to, the default pack.
Definition paths.h:191
std::optional< GamePaths > ResolveXdgPaths(const EnvironmentReader &environment, const std::string &application)
Resolve the directories with the XDG Base Directory variables and their defaults under the home direc...
std::string Utf8FromPath(const std::filesystem::path &path)
Definition paths.h:18
std::filesystem::path RestorePortablePath(const std::filesystem::path &path, const std::filesystem::path &root, const std::filesystem::path &home)
Rebuild a stored portable input path at its current executable or home location.
std::expected< GamePaths, std::string > ResolvePortablePaths(const GamePaths &fallback, const std::filesystem::path &executable, const std::filesystem::path &workingDirectory={})
Prefer adjacent configuration and assets independently when portable lookup is enabled.
std::optional< std::string > MigratePortablePaths(const GamePaths &source, const GamePaths &destination, bool copyOnly=false)
Move portable assets, settings, saves, screenshots, and state to platform directories.
std::filesystem::path PackDirectory(const std::filesystem::path &data, std::string_view pack, const std::filesystem::path &fallback={})
The directory of a pack under assets of the data directory, named after the pack.
bool CreateGamePaths(const GamePaths &paths)
Create every directory of paths that does not exist.
std::vector< std::filesystem::path > SystemDataDirectories(const std::filesystem::path &executable)
List system data roots, including the relocated installation and platform defaults.
The directories the game reads and writes, each ending in the application directory.
Definition paths.h:25
bool portableConfig
Definition paths.h:30
bool portableData
Definition paths.h:31
std::filesystem::path state
Definition paths.h:28
std::filesystem::path config
Definition paths.h:26
std::filesystem::path data
Definition paths.h:27
std::filesystem::path cache
Definition paths.h:29