@@ -1038,6 +1038,7 @@ GlobalData::GlobalData()
10381038
10391039 // Set user data directory based on registry settings instead of INI parameters. This allows us to
10401040 // localize the leaf name.
1041+ #if defined(_MSC_VER) && _MSC_VER < 1300
10411042 char temp[_MAX_PATH + 1 ];
10421043 if (::SHGetSpecialFolderPath (nullptr , temp, CSIDL_PERSONAL , true ))
10431044 {
@@ -1062,6 +1063,37 @@ GlobalData::GlobalData()
10621063 CreateDirectory (myDocumentsDirectory.str (), nullptr );
10631064 m_userDataDir = myDocumentsDirectory;
10641065 }
1066+ #else
1067+ // TheSuperHackers @bugfix Mauller 20/03/2026 Fix the handling of folder redirection
1068+ // OneDrive and Group Policy folder redirection is better supported by SHGetKnownFolderPath()
1069+ PWSTR pszPath = nullptr ;
1070+ HRESULT hr = SHGetKnownFolderPath (FOLDERID_Documents, KF_FLAG_DEFAULT , nullptr , &pszPath);
1071+ if (SUCCEEDED (hr) && pszPath)
1072+ {
1073+ AsciiString myDocumentsDirectory;
1074+ myDocumentsDirectory.translate (UnicodeString (pszPath));
1075+
1076+ if (myDocumentsDirectory.getCharAt (myDocumentsDirectory.getLength () -1 ) != ' \\ ' )
1077+ myDocumentsDirectory.concat ( ' \\ ' );
1078+
1079+ AsciiString leafName;
1080+
1081+ if ( !GetStringFromRegistry ( " " , " UserDataLeafName" , leafName ) )
1082+ {
1083+ // Use something, anything
1084+ // [MH] had to remove this, otherwise mapcache build step won't run... DEBUG_CRASH( ( "Could not find registry key UserDataLeafName; defaulting to \"Command and Conquer Generals Zero Hour Data\" " ) );
1085+ leafName = " Command and Conquer Generals Zero Hour Data" ;
1086+ }
1087+
1088+ myDocumentsDirectory.concat ( leafName );
1089+ if (myDocumentsDirectory.getCharAt ( myDocumentsDirectory.getLength () - 1 ) != ' \\ ' )
1090+ myDocumentsDirectory.concat ( ' \\ ' );
1091+
1092+ CreateDirectory (myDocumentsDirectory.str (), nullptr );
1093+ m_userDataDir = myDocumentsDirectory;
1094+ }
1095+ CoTaskMemFree (pszPath);
1096+ #endif
10651097
10661098 // -allAdvice feature
10671099 // m_allAdvice = FALSE;
0 commit comments