| 327 | } |
| 328 | |
| 329 | void InitFileSystem(TArray<GrpEntry>& groups) |
| 330 | { |
| 331 | TArray<int> dependencies; |
| 332 | std::vector<std::string> Files; |
| 333 | |
| 334 | // First comes the engine's own stuff. |
| 335 | const char* baseres = BaseFileSearch(ENGINERES_FILE, nullptr, true, GameConfig); |
| 336 | D_AddFile(Files, baseres, true, -1, GameConfig); |
| 337 | |
| 338 | bool insertdirectoriesafter = Args->CheckParm("-insertdirafter"); |
| 339 | |
| 340 | int i = groups.Size()-1; |
| 341 | FString fn; |
| 342 | for (auto &grp : groups) |
| 343 | { |
| 344 | // Add all dependencies, plus the directory of the base dependency. |
| 345 | // Directories of addon content are not added if they differ from the main directory. |
| 346 | // Also, the directory is inserted after the base dependency, allowing the addons to override directory content. |
| 347 | // This can be overridden via command line switch if needed. |
| 348 | if (!grp.FileInfo.loaddirectory && grp.FileName.IsNotEmpty()) |
| 349 | { |
| 350 | D_AddFile(Files, grp.FileName.GetChars(), true, -1, GameConfig); |
| 351 | fn = ExtractFilePath(grp.FileName.GetChars()); |
| 352 | if (fn.Len() > 0 && fn.Back() != '/') fn += '/'; |
| 353 | } |
| 354 | |
| 355 | for (auto& fname : grp.FileInfo.loadfiles) |
| 356 | { |
| 357 | FString newname = fn + fname; |
| 358 | D_AddFile(Files, newname.GetChars(), true, -1, GameConfig); |
| 359 | } |
| 360 | bool insert = (!insertdirectoriesafter && &grp == &groups[0]) || (insertdirectoriesafter && &grp == &groups.Last()); |
| 361 | |
| 362 | // Add the game's main directory in the proper spot. |
| 363 | if (insert) |
| 364 | { |
| 365 | // Build's original 'file system' loads all GRPs before the first external directory. |
| 366 | // Do this only if explicitly requested because this severely limits the usability of GRP files. |
| 367 | if (insertdirectoriesafter && userConfig.AddFilesPre) for (auto& file : *userConfig.AddFilesPre) |
| 368 | { |
| 369 | D_AddFile(Files, file.GetChars(), true, -1, GameConfig); |
| 370 | } |
| 371 | |
| 372 | D_AddFile(Files, fn.GetChars(), true, -1, GameConfig); |
| 373 | } |
| 374 | i--; |
| 375 | } |
| 376 | fileSystem.SetIwadNum(1); |
| 377 | fileSystem.SetMaxIwadNum((int)Files.size() - 1); |
| 378 | |
| 379 | if (!Args->CheckParm("-noautoload")) |
| 380 | { |
| 381 | D_AddConfigFiles(Files, "Global.Autoload", "*.grp", GameConfig); |
| 382 | |
| 383 | size_t len; |
| 384 | size_t lastpos = 0; |
| 385 | |
| 386 | while (lastpos < LumpFilter.Len() && (len = strcspn(LumpFilter.GetChars() + lastpos, ".")) > 0) |
no test coverage detected