diff --git a/source/common/utility/cmdlib.cpp b/source/common/utility/cmdlib.cpp index c0fc1dcb0..dcae2ec8d 100644 --- a/source/common/utility/cmdlib.cpp +++ b/source/common/utility/cmdlib.cpp @@ -47,6 +47,7 @@ #endif #endif #include "cmdlib.h" +#include "compat.h" #include #include @@ -757,3 +758,17 @@ bool IsAbsPath(const char *name) #endif /* _WIN32 */ return 0; } + +//========================================================================== +// +// +// +//========================================================================== + +void NormalizeFileName(FString &str) +{ + auto strp = str.LockBuffer(); + Bcorrectfilename(strp, false); + str.UnlockBuffer(); +} + diff --git a/source/common/utility/cmdlib.h b/source/common/utility/cmdlib.h index 045037651..cda5b8a74 100644 --- a/source/common/utility/cmdlib.h +++ b/source/common/utility/cmdlib.h @@ -27,6 +27,7 @@ bool DirEntryExists (const char *pathname, bool *isdir = nullptr); extern FString progdir; void DefaultExtension (FString &path, const char *extension); +void NormalizeFileName(FString &str); FString ExtractFilePath (const char *path); FString ExtractFileBase (const char *path, bool keep_extension=false); diff --git a/source/duke3d/src/game.cpp b/source/duke3d/src/game.cpp index ca79bfbc1..759310fda 100644 --- a/source/duke3d/src/game.cpp +++ b/source/duke3d/src/game.cpp @@ -5656,38 +5656,30 @@ static void G_Startup(void) if (userConfig.CommandMap.IsNotEmpty()) { + FString startupMap; if (VOLUMEONE) { initprintf("The -map option is available in the registered version only!\n"); - boardfilename[0] = 0; } else { - char *dot, *slash; + startupMap = userConfig.CommandMap; + if (startupMap.IndexOfAny("/\\") < 0) startupMap.Insert(0, "/"); + DefaultExtension(startupMap, ".map"); + startupMap.Substitute("\\", "/"); + NormalizeFileName(startupMap); - boardfilename[0] = '/'; - boardfilename[1] = 0; - Bstrcat(boardfilename, userConfig.CommandMap); - - dot = Bstrrchr(boardfilename,'.'); - slash = Bstrrchr(boardfilename,'/'); - if (!slash) slash = Bstrrchr(boardfilename,'\\'); - - if ((!slash && !dot) || (slash && dot < slash)) - Bstrcat(boardfilename,".map"); - - Bcorrectfilename(boardfilename,0); - - if (fileSystem.FileExists(boardfilename)) + if (fileSystem.FileExists(startupMap)) { - initprintf("Using level: \"%s\".\n",boardfilename); + initprintf("Using level: \"%s\".\n",startupMap.GetChars()); } else { - initprintf("Level \"%s\" not found.\n",boardfilename); + initprintf("Level \"%s\" not found.\n",startupMap.GetChars()); boardfilename[0] = 0; } } + strncpy(boardfilename, startupMap, BMAX_PATH); } for (i=0; i