MCPcopy Create free account
hub / github.com/deathkiller/jazz2-native / Initialize

Method Initialize

Sources/Jazz2/PreferencesCache.cpp:155–589  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153 }
154
155 void PreferencesCache::Initialize(AppConfiguration& config)
156 {
157 bool resetConfig = false;
158
159#if defined(DEATH_TARGET_EMSCRIPTEN)
160 auto configDir = "/Persistent"_s;
161 fs::MountAsPersistent(configDir);
162 _configPath = "/Persistent/Jazz2.config"_s;
163
164 for (int32_t i = 0; i < config.argc(); i++) {
165 auto arg = config.argv(i);
166 if (arg == "/reset-config"_s) {
167 resetConfig = true;
168 }
169 }
170#else
171 _configPath = "Jazz2.config"_s;
172 bool overrideConfigPath = false;
173
174# if !defined(DEATH_TARGET_ANDROID) && !defined(DEATH_TARGET_IOS) && !defined(DEATH_TARGET_SWITCH)
175 for (std::int32_t i = 0; i < config.argc(); i++) {
176 auto arg = config.argv(i);
177 if (arg == "/config"_s) {
178 if (i + 1 < config.argc()) {
179 _configPath = config.argv(i + 1);
180 overrideConfigPath = true;
181 i++;
182 }
183 } else if (arg == "/reset-config"_s) {
184 resetConfig = true;
185 }
186 }
187# endif
188
189 // If config path is not overriden and portable config doesn't exist, use common path for current user
190 if (!overrideConfigPath && !fs::IsReadableFile(_configPath)) {
191# if defined(DEATH_TARGET_SWITCH)
192 // Save config file next to `Source` directory
193 auto& resolver = ContentResolver::Get();
194 _configPath = fs::CombinePath(fs::GetDirectoryName(resolver.GetSourcePath()), "Jazz2.config"_s);
195# elif defined(DEATH_TARGET_UNIX) && defined(NCINE_PACKAGED_CONTENT_PATH)
196 _configPath = fs::CombinePath(fs::GetSavePath(NCINE_LINUX_PACKAGE), "Jazz2.config"_s);
197# else
198 _configPath = fs::CombinePath(fs::GetSavePath("Jazz² Resurrection"_s), "Jazz2.config"_s);
199# endif
200
201# if defined(DEATH_TARGET_ANDROID)
202 // Save config file to external path if possible
203 auto& resolver = ContentResolver::Get();
204 auto externalConfigPath = fs::CombinePath(fs::GetDirectoryName(resolver.GetSourcePath()), "Jazz2.config"_s);
205 if (!fs::IsReadableFile(_configPath) || fs::IsReadableFile(externalConfigPath)) {
206 _configPath = externalConfigPath;
207 }
208# elif defined(DEATH_TARGET_WINDOWS_RT)
209 // Save config file next to `Source` directory (e.g., on external drive) if possible
210 auto& resolver = ContentResolver::Get();
211 auto localConfigPath = fs::CombinePath(fs::GetDirectoryName(resolver.GetSourcePath()), "Jazz2.config"_s);
212 if (_configPath != localConfigPath) {

Callers

nothing calls this directly

Calls 15

GetEnvironmentVariableFunction · 0.85
argcMethod · 0.80
argvMethod · 0.80
GetSourcePathMethod · 0.80
AttachTraceTargetMethod · 0.80
ReadVariableUint32Method · 0.80
IsScreenRoundMethod · 0.80
StringClass · 0.50
IsValidMethod · 0.45
DisposeMethod · 0.45
hasPrefixMethod · 0.45

Tested by

no test coverage detected