From ca0e39cd0ce7ca1ca76994d35832e48749dfad74 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sat, 31 Mar 2018 15:20:00 +0300 Subject: [PATCH] Added ability to load any IWAD without extension Previously, only .wad files can specified without file extension for -iwad command line option For example, -iwad square1 will load square1.pk3 as IWAD --- src/d_iwad.cpp | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/src/d_iwad.cpp b/src/d_iwad.cpp index 29c3ea98b..5aa5f35b8 100644 --- a/src/d_iwad.cpp +++ b/src/d_iwad.cpp @@ -519,28 +519,39 @@ int FIWadManager::IdentifyVersion (TArray &wadfiles, const char *iwad, if (iwadparm) { - // Check if the given IWAD has an absolute path, in which case the search path will be ignored. - custwad = iwadparm; - FixPathSeperator(custwad); - DefaultExtension(custwad, ".wad"); - bool isAbsolute = (custwad[0] == '/'); + const char* const extensions[] = { ".wad", ".pk3", ".iwad", ".ipk3", ".ipk7" }; + + for (auto ext : extensions) + { + // Check if the given IWAD has an absolute path, in which case the search path will be ignored. + custwad = iwadparm; + FixPathSeperator(custwad); + DefaultExtension(custwad, ext); + bool isAbsolute = (custwad[0] == '/'); #ifdef WINDOWS - isAbsolute |= (custwad.Len() >= 2 && custwad[1] == ':'); + isAbsolute |= (custwad.Len() >= 2 && custwad[1] == ':'); #endif - if (isAbsolute) - { - if (FileExists(custwad)) mFoundWads.Push({ custwad, "", -1 }); - } - else - { - for (auto &dir : mSearchPaths) + if (isAbsolute) { - FStringf fullpath("%s/%s", dir.GetChars(), custwad.GetChars()); - if (FileExists(fullpath)) + if (FileExists(custwad)) mFoundWads.Push({ custwad, "", -1 }); + } + else + { + for (auto &dir : mSearchPaths) { - mFoundWads.Push({ fullpath, "", -1 }); + FStringf fullpath("%s/%s", dir.GetChars(), custwad.GetChars()); + if (FileExists(fullpath)) + { + mFoundWads.Push({ fullpath, "", -1 }); + } } } + + if (mFoundWads.Size() != numFoundWads) + { + // Found IWAD with guessed extension + break; + } } } // -iwad not found or not specified. Revert back to standard behavior.