-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtfe_02_game_data_detection.patch
More file actions
137 lines (134 loc) · 5.1 KB
/
tfe_02_game_data_detection.patch
File metadata and controls
137 lines (134 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 919dd4c5..eb855704 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -14,7 +14,7 @@ project(TheForceEngine
DESCRIPTION "Modern 'Jedi Engine' replacement supporting Dark Forces, mods, and in the future Outlaws."
)
-set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
diff --git a/TheForceEngine/TFE_Settings/settings.cpp b/TheForceEngine/TFE_Settings/settings.cpp
index fa495dd0..e7ef42aa 100644
--- a/TheForceEngine/TFE_Settings/settings.cpp
+++ b/TheForceEngine/TFE_Settings/settings.cpp
@@ -10,6 +10,8 @@
#include <TFE_A11y/accessibility.h>
#include <assert.h>
#include <algorithm>
+#include <filesystem>
+#include <array>
#include <vector>
#ifdef _WIN32
@@ -157,96 +159,21 @@ namespace TFE_Settings
{
for (u32 gameId = 0; gameId < Game_Count; gameId++)
{
- const size_t sourcePathLen = strlen(s_gameSettings.header[gameId].sourcePath);
- bool pathValid = sourcePathLen && validatePath(s_gameSettings.header[gameId].sourcePath, c_validationFile[gameId]);
-
- // First check locally, and then check the registry.
- if (!pathValid && gameId == Game_Dark_Forces) // Only Dark Forces for now.
- {
- // First try the local path.
- char localPath[TFE_MAX_PATH];
- TFE_Paths::appendPath(PATH_PROGRAM, "DARK.GOB", localPath);
-
- FileStream file;
- if (file.open(localPath, Stream::MODE_READ))
- {
- if (file.getSize() > 1)
- {
- strcpy(s_gameSettings.header[gameId].sourcePath, TFE_Paths::getPath(PATH_PROGRAM));
- FileUtil::fixupPath(s_gameSettings.header[gameId].sourcePath);
- pathValid = true;
- }
- file.close();
- }
-
- // Then try local/Games/Dark Forces/
- if (!pathValid)
- {
- char gamePath[TFE_MAX_PATH];
- sprintf(gamePath, "%sGames/Dark Forces/", TFE_Paths::getPath(PATH_PROGRAM));
- FileUtil::fixupPath(gamePath);
-
- sprintf(localPath, "%sDARK.GOB", gamePath);
- if (file.open(localPath, Stream::MODE_READ))
- {
- if (file.getSize() > 1)
- {
- strcpy(s_gameSettings.header[gameId].sourcePath, gamePath);
- pathValid = true;
- }
- file.close();
- }
- }
- }
-
-#ifdef _WIN32
- // Next try looking through the registry.
- if (!pathValid)
- {
- // Remaster - search here first so that new assets are readily available.
- pathValid = WindowsRegistry::getSteamPathFromRegistry(c_steamRemasterProductId[gameId], c_steamRemasterLocalPath[gameId], c_steamRemasterLocalSubPath[gameId], c_validationFile[gameId], s_gameSettings.header[gameId].sourcePath);
- // Remaster on GOG.
- if (!pathValid)
- {
- pathValid = WindowsRegistry::getGogPathFromRegistry(c_gogRemasterProductId[gameId], c_validationFile[gameId], s_gameSettings.header[gameId].sourcePath);
- }
-
- // Then try the vanilla version on Steam.
- if (!pathValid)
- {
- pathValid = WindowsRegistry::getSteamPathFromRegistry(c_steamProductId[gameId], c_steamLocalPath[gameId], c_steamLocalSubPath[gameId], c_validationFile[gameId], s_gameSettings.header[gameId].sourcePath);
- }
- // And the vanilla version on GOG.
- if (!pathValid)
- {
- pathValid = WindowsRegistry::getGogPathFromRegistry(c_gogProductId[gameId], c_validationFile[gameId], s_gameSettings.header[gameId].sourcePath);
- }
- }
-#endif
-#ifdef __linux__
- if (!pathValid)
- {
- pathValid = LinuxSteam::getSteamPath(c_steamRemasterProductId[gameId], c_steamRemasterLocalPath[gameId],
- c_validationFile[gameId], s_gameSettings.header[gameId].sourcePath);
-
- if (!pathValid)
- {
- pathValid = LinuxSteam::getSteamPath(c_steamProductId[gameId], c_steamLocalSubPath[gameId],
- c_validationFile[gameId], s_gameSettings.header[gameId].sourcePath);
- }
- }
-#endif
- // If the registry approach fails, just try looking in the various hardcoded paths.
- if (!pathValid)
+ std::array<std::string, 4> locations = {
+ std::getenv("XDG_DATA_HOME"),
+ ".steam/steam/steamapps/common/Dark Forces/Game",
+ ".var/app/com.valvesoftware.Steam/.local/share/Steam/steamapps/common/Dark Forces/Game",
+ "snap/steam/common/.local/share/Steam/steamapps/common/Dark Forces/Game"
+ };
+ for (const auto& loc : locations)
{
- // Try various possible locations.
- const char* const * locations = c_gameLocations[gameId];
- for (u32 i = 0; i < c_hardcodedPathCount[gameId]; i++)
- {
- if (FileUtil::directoryExits(locations[i]))
- {
- strcpy(s_gameSettings.header[gameId].sourcePath, locations[i]);
- pathValid = true;
+ std::filesystem::path checkPath = std::filesystem::path(std::getenv("HOME"));
+ checkPath /= loc;
+ if (! std::filesystem::exists(checkPath)) { continue; }
+ for (auto const& dir_entry : std::filesystem::directory_iterator{checkPath}) {
+ if (strcasecmp(const_cast<char*>(dir_entry.path().filename().c_str()), "dark.gob") == 0) {
+ TFE_System::logWrite(LOG_MSG, "Main", const_cast<char*>(checkPath.c_str()));
+ strcpy(s_gameSettings.header[gameId].sourcePath, const_cast<char*>((std::string(checkPath) + "/").c_str()));
break;
}
}