Browse Source

Simplified getPathFromConfigOrDefault

George King 6 months ago
parent
commit
f802c5f717
1 changed files with 3 additions and 5 deletions
  1. 3 5
      lib/VCMIDirs.cpp

+ 3 - 5
lib/VCMIDirs.cpp

@@ -145,16 +145,14 @@ std::wstring VCMIDirsWIN32::utf8ToWstring(const std::string& str) const
 
 bfs::path VCMIDirsWIN32::getPathFromConfigOrDefault(const std::string& key, const std::function<bfs::path()>& fallbackFunc) const
 {
-
 	if (!dirsConfig || !dirsConfig->isStruct())
 		return fallbackFunc();
 
-	const auto& structMap = dirsConfig->Struct();
-	auto it = structMap.find(key);
-	if (it == structMap.end() || !it->second.isString())
+	const JsonNode& node = (*dirsConfig)[key];
+	if (!node.isString())
 		return fallbackFunc();
 
-	std::wstring raw = utf8ToWstring(it->second.String());
+	std::wstring raw = utf8ToWstring(node.String());
 	wchar_t expanded[MAX_PATH];
 	if (ExpandEnvironmentStringsW(raw.c_str(), expanded, MAX_PATH))
 		return bfs::path(expanded);