From 28e5cc536aa28a5b5ccad032da524d5a99d6cce3 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Thu, 29 Aug 2013 21:16:11 -0500 Subject: [PATCH] Add some awareness of short file names - Added I_GetLongPathName(). It wraps the Win32 API's GetLongPathName(). DArgs::CollectFiles() now calls this for every argument it processes, so any arguments passed using short file names will be converted to long file names. This is mainly of interest so that savegames will never record the short file name, which can change based on what else is in the directory. --- src/m_argv.cpp | 9 +++++++++ src/win32/i_system.cpp | 28 ++++++++++++++++++++++++++++ src/win32/i_system.h | 3 +++ 3 files changed, 40 insertions(+) diff --git a/src/m_argv.cpp b/src/m_argv.cpp index 54d9ffda46..816a2d54c0 100644 --- a/src/m_argv.cpp +++ b/src/m_argv.cpp @@ -35,6 +35,7 @@ #include #include "m_argv.h" #include "cmdlib.h" +#include "i_system.h" IMPLEMENT_CLASS (DArgs) @@ -391,6 +392,14 @@ void DArgs::CollectFiles(const char *param, const char *extension) } } + // Optional: Replace short path names with long path names +#ifdef _WIN32 + for (i = 0; i < work.Size(); ++i) + { + work[i] = I_GetLongPathName(work[i]); + } +#endif + // Step 3: Add work back to Argv, as long as it's non-empty. if (work.Size() > 0) { diff --git a/src/win32/i_system.cpp b/src/win32/i_system.cpp index b5843ec7a5..a82cb65f9c 100644 --- a/src/win32/i_system.cpp +++ b/src/win32/i_system.cpp @@ -1569,3 +1569,31 @@ unsigned int I_MakeRNGSeed() CryptReleaseContext(prov, 0); return seed; } + +//========================================================================== +// +// I_GetLongPathName +// +// Returns the long version of the path, or the original if there isn't +// anything worth changing. +// +//========================================================================== + +FString I_GetLongPathName(FString shortpath) +{ + DWORD buffsize = GetLongPathName(shortpath.GetChars(), NULL, 0); + if (buffsize == 0) + { // nothing to change (it doesn't exist, maybe?) + return shortpath; + } + TCHAR *buff = new TCHAR[buffsize]; + DWORD buffsize2 = GetLongPathName(shortpath.GetChars(), buff, buffsize); + if (buffsize2 >= buffsize) + { // Failure! Just return the short path + delete[] buff; + return shortpath; + } + FString longpath(buff, buffsize2); + delete[] buff; + return longpath; +} diff --git a/src/win32/i_system.h b/src/win32/i_system.h index 6bafdc01c3..9fbf2db5cb 100644 --- a/src/win32/i_system.h +++ b/src/win32/i_system.h @@ -155,6 +155,9 @@ typedef _W64 long WLONG_PTR; typedef long WLONG_PTR; #endif +// Wrapper for GetLongPathName +FString I_GetLongPathName(FString shortpath); + // Directory searching routines // Mirror WIN32_FIND_DATAA in