MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / resolveLocoInstallPath

Function resolveLocoInstallPath

src/OpenLoco/src/Environment.cpp:75–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73 }
74
75 static fs::path resolveLocoInstallPath()
76 {
77 autoCreateDirectory(Platform::getUserDirectory());
78 auto& cfg = Config::get();
79
80 // Validate any existing configured install path first
81 auto path = fs::u8path(cfg.locoInstallPath);
82 if (!path.empty())
83 {
84 if (validateLocoInstallPath(path))
85 {
86 return path;
87 }
88 Logging::error("Configured Locomotion game folder is missing Data/g1.DAT.");
89 }
90
91 // Try to detect the Locomotion install path
92 path = autoDetectLocoInstallPath();
93 if (!path.empty())
94 {
95 cfg.locoInstallPath = path.make_preferred().u8string();
96 Config::write();
97 return path;
98 }
99
100 Logging::error("Unable to automatically find the Locomotion game folder.\n"
101 "Please provide the location manually.");
102 Ui::showMessageBox("OpenLoco", "Unable to automatically detect the Locomotion game folder.\n"
103 "Please locate the Locomotion game folder manually.");
104
105 // Let user manually specify the Locomotion install folder, and verify files are present
106 //
107 // FIXME: Instead of passing the hwnd we should have a function to bring the window to the front after
108 // this call.
109 path = Platform::promptDirectory("Locate original Locomotion game files", Ui::hwnd());
110 if (validateLocoInstallPath(path))
111 {
112 cfg.locoInstallPath = path.make_preferred().u8string();
113 Config::write();
114 return path;
115 }
116
117 // Files could not be located -- bail with a helpful error message
118 Logging::error("The selected folder does not contain Data/g1.DAT");
119 Ui::showMessageBox("OpenLoco", "The selected folder does not contain Data/g1.DAT, suggesting it is not a Locomotion\n"
120 "install folder. Please verify the folder contains the original Locomotion game files,\n"
121 "then restart OpenLoco to try again.");
122
123 std::exit(-1);
124 }
125
126#ifndef _WIN32
127 /**

Callers 1

resolvePathsFunction · 0.85

Calls 11

autoCreateDirectoryFunction · 0.85
validateLocoInstallPathFunction · 0.85
errorFunction · 0.85
writeFunction · 0.85
showMessageBoxFunction · 0.85
hwndFunction · 0.85
getFunction · 0.70
getUserDirectoryFunction · 0.50
promptDirectoryFunction · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected