Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
UDUtils.cpp
Go to the documentation of this file.
1#include "UDUtils.hpp"
2
3#include <SDL3/SDL.h>
4
5#include <algorithm>
6#include <array>
7#include <iostream>
8#include <optional>
9
11{
12 namespace
13 {
14 std::vector<std::filesystem::path> globalSearchPaths;
15 std::optional<data::ResourcePaths> globalResourcePaths;
16
17 void addPath(const std::filesystem::path& path)
18 {
19 if (std::find(
20 globalSearchPaths.begin(),
22 path) == globalSearchPaths.end())
23 {
24 globalSearchPaths.push_back(path);
25 }
26 }
27 }
28
30 {
31 globalSearchPaths.clear();
32 globalResourcePaths.reset();
33
34 const char* basePath = SDL_GetBasePath();
35
36 if (basePath == nullptr)
37 {
38 return false;
39 }
40
41 // Une installation de donnees explicite remplace la racine executable.
42 // Aucun cwd ou chemin CD/machine implicite ne fournit des banques.
43 const char* overrideRoot = SDL_getenv("MONOPOLY_DATA_ROOT");
44 const std::string_view rootText{
45 overrideRoot != nullptr ? overrideRoot : basePath };
46 std::u8string utf8Root;
47 utf8Root.reserve(rootText.size());
48 for (const unsigned char byte : rootText)
49 {
50 utf8Root.push_back(static_cast<char8_t>(byte));
51 }
52 const std::filesystem::path modulePath{ utf8Root };
53 const std::array roots{ modulePath };
55 if (!resolved)
56 {
57 std::cerr << "Resource root configuration failed: "
58 << resolved.error().detail << '\n';
59 return false;
60 }
61 globalResourcePaths = std::move(*resolved);
62
63 // Correspondance avec UDUTILS_GenerateINIFile() original.
65 addPath(modulePath / "Dat_Mon");
66 addPath(modulePath / "AVI");
67
68 return true;
69 }
70
71 const std::vector<std::filesystem::path>& searchPaths()
72 {
73 return globalSearchPaths;
74 }
75
76
81}
unsigned index
std::array< data::DataTag, 3 > roots
std::string path
static std::expected< ResourcePaths, DataError > create(std::span< const std::filesystem::path > roots)
const data::ResourcePaths * resourcePaths() noexcept
Definition UDUtils.cpp:77
const std::vector< std::filesystem::path > & searchPaths()
Definition UDUtils.cpp:71
bool generateINIFile()
Definition UDUtils.cpp:29