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
10
namespace
monopoly::udutils
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(),
21
globalSearchPaths
.end(),
22
path
) ==
globalSearchPaths
.end())
23
{
24
globalSearchPaths
.push_back(
path
);
25
}
26
}
27
}
28
29
bool
generateINIFile
()
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
};
54
auto
resolved
=
data::ResourcePaths::create
(
roots
);
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.
64
addPath
(
modulePath
);
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
77
const
data::ResourcePaths
*
resourcePaths
()
noexcept
78
{
79
return
globalResourcePaths
? &*
globalResourcePaths
:
nullptr
;
80
}
81
}
index
unsigned index
Definition
ModernIBarSkin.cpp:25
roots
std::array< data::DataTag, 3 > roots
Definition
ModernMenuSkin.cpp:31
path
std::string path
Definition
StartupResources.cpp:24
UDUtils.hpp
monopoly::data::ResourcePaths
Definition
ResourcePaths.hpp:16
monopoly::data::ResourcePaths::create
static std::expected< ResourcePaths, DataError > create(std::span< const std::filesystem::path > roots)
Definition
ResourcePaths.cpp:160
monopoly::udutils
Definition
UDUtils.cpp:11
monopoly::udutils::resourcePaths
const data::ResourcePaths * resourcePaths() noexcept
Definition
UDUtils.cpp:77
monopoly::udutils::searchPaths
const std::vector< std::filesystem::path > & searchPaths()
Definition
UDUtils.cpp:71
monopoly::udutils::generateINIFile
bool generateINIFile()
Definition
UDUtils.cpp:29
UDUtils.cpp
Generated by
1.9.8