From 0e93373824c9dcb3d7f086adf91a10c849fb8c3e Mon Sep 17 00:00:00 2001 From: Robert MacGregor Date: Mon, 20 Dec 2021 19:26:32 -0500 Subject: [PATCH] * BugFix: When querying against root with Torque::FS::DumpDirectories, correctly return directories with their path. * Adjustment: Add commenting to some of the new programming. * Adjustment: Tweak fileCreatedTime and fileModifiedTime functions to use the VFS. --- Engine/source/console/fileSystemFunctions.cpp | 44 +++++++++---------- Engine/source/core/util/timeClass.cpp | 25 +++++++++++ Engine/source/core/util/timeClass.h | 6 ++- Engine/source/core/volume.cpp | 12 ++++- Engine/source/platform/platformVolume.cpp | 7 +-- .../source/windowManager/sdl/sdlWindowMgr.cpp | 14 ++++-- .../source/windowManager/sdl/sdlWindowMgr.h | 3 ++ 7 files changed, 77 insertions(+), 34 deletions(-) diff --git a/Engine/source/console/fileSystemFunctions.cpp b/Engine/source/console/fileSystemFunctions.cpp index 11a286e22..c9a0f5ae2 100644 --- a/Engine/source/console/fileSystemFunctions.cpp +++ b/Engine/source/console/fileSystemFunctions.cpp @@ -532,20 +532,20 @@ DefineEngineFunction( fileModifiedTime, String, ( const char* fileName ),, "@return Formatted string (OS specific) containing modified time, \"9/3/2010 12:33:47 PM\" for example\n" "@ingroup FileSystem") { - Con::expandScriptFilename(sgScriptFilenameBuffer, sizeof(sgScriptFilenameBuffer), fileName); + Torque::FS::FileNodeRef node = Torque::FS::GetFileNode(fileName); - FileTime ft = {0}; - Platform::getFileTimes( sgScriptFilenameBuffer, NULL, &ft ); + if (node) + { + Platform::LocalTime lt = node->getModifiedTime().toLocalTime(); - Platform::LocalTime lt = {0}; - Platform::fileToLocalTime( ft, < ); - - String fileStr = Platform::localTimeToString( lt ); - - char *buffer = Con::getReturnBuffer( fileStr.size() ); - dStrcpy( buffer, fileStr, fileStr.size() ); - - return buffer; + String fileStr = Platform::localTimeToString(lt); + + char *buffer = Con::getReturnBuffer(fileStr.size()); + dStrcpy(buffer, fileStr, fileStr.size()); + + return buffer; + } + return ""; } DefineEngineFunction( fileCreatedTime, String, ( const char* fileName ),, @@ -555,20 +555,20 @@ DefineEngineFunction( fileCreatedTime, String, ( const char* fileName ),, "@return Formatted string (OS specific) containing created time, \"9/3/2010 12:33:47 PM\" for example\n" "@ingroup FileSystem") { - Con::expandScriptFilename( sgScriptFilenameBuffer, sizeof(sgScriptFilenameBuffer), fileName ); + Torque::FS::FileNodeRef node = Torque::FS::GetFileNode(fileName); - FileTime ft = {0}; - Platform::getFileTimes( sgScriptFilenameBuffer, &ft, NULL ); + if (node) + { + Platform::LocalTime lt = node->getCreatedTime().toLocalTime(); - Platform::LocalTime lt = {0}; - Platform::fileToLocalTime( ft, < ); + String fileStr = Platform::localTimeToString(lt); - String fileStr = Platform::localTimeToString( lt ); + char *buffer = Con::getReturnBuffer(fileStr.size()); + dStrcpy(buffer, fileStr, fileStr.size()); - char *buffer = Con::getReturnBuffer( fileStr.size() ); - dStrcpy( buffer, fileStr, fileStr.size() ); - - return buffer; + return buffer; + } + return ""; } DefineEngineFunction(compareFileTimes, S32, (const char* fileA, const char* fileB), ("", ""), diff --git a/Engine/source/core/util/timeClass.cpp b/Engine/source/core/util/timeClass.cpp index 98c60e882..b30c36d66 100644 --- a/Engine/source/core/util/timeClass.cpp +++ b/Engine/source/core/util/timeClass.cpp @@ -195,4 +195,29 @@ void Time::get(S32 *pyear, S32 *pmonth, S32 *pday, S32 *phour, S32 *pminute, S32 *pmicrosecond = time % OneSecond; } +Platform::LocalTime Time::toLocalTime() +{ + Platform::LocalTime result; + result.isdst = false; + + S32 year; + S32 month; + S32 day; + S32 hour; + S32 minute; + S32 second; + S32 microsecond; + + get(&year, &month, &day, &hour, &minute, &second, µsecond); + result.year = year - 1900; + result.month = month - 1; + result.yearday = day; + result.hour = hour; + result.min = minute; + result.sec = second; + result.monthday = day % 32; + result.weekday = day % 7; + return result; +} + } // Namespace diff --git a/Engine/source/core/util/timeClass.h b/Engine/source/core/util/timeClass.h index af9fe09fa..cfee70a86 100644 --- a/Engine/source/core/util/timeClass.h +++ b/Engine/source/core/util/timeClass.h @@ -26,7 +26,9 @@ #ifndef _TORQUE_TYPES_H_ #include "platform/types.h" #endif - +#ifndef _PLATFORM_H_ +#include "platform/platform.h" +#endif #if defined(TORQUE_COMPILER_VISUALC) #define TORQUE_CONSTANT_S64(a) (a##I64) @@ -105,6 +107,8 @@ public: S64 getMicroseconds() const; S64 getInternalRepresentation() const; + Platform::LocalTime toLocalTime(); + private: class Tester { diff --git a/Engine/source/core/volume.cpp b/Engine/source/core/volume.cpp index 5e58ad452..f4338c692 100644 --- a/Engine/source/core/volume.cpp +++ b/Engine/source/core/volume.cpp @@ -600,17 +600,24 @@ bool MountSystem::_dumpDirectories(DirectoryRef directory, Vector basePath.getDirectoryCount()) + if (iteration > basePathDirectoryCount) { newDirectoryPath.setPath(newDirectoryPath.getPath() + "/"); } @@ -622,6 +629,7 @@ bool MountSystem::_dumpDirectories(DirectoryRef directory, Vectorinsert(directoryPathString, true)); if (currentDepth <= depth) { diff --git a/Engine/source/platform/platformVolume.cpp b/Engine/source/platform/platformVolume.cpp index c14347496..c7778b363 100644 --- a/Engine/source/platform/platformVolume.cpp +++ b/Engine/source/platform/platformVolume.cpp @@ -50,12 +50,7 @@ bool MountDefaults() return false; #ifdef TORQUE_SECURE_VFS - // Set working directory to where the executable is - StringTableEntry executablePath = Platform::getExecutablePath(); - SetCwd(executablePath); - - // FIXME: Should we use the asset path here as well? - mounted = Mount("/", createNativeFS(executablePath)); + mounted = Mount("/", createNativeFS(path)); if (!mounted) { return false; diff --git a/Engine/source/windowManager/sdl/sdlWindowMgr.cpp b/Engine/source/windowManager/sdl/sdlWindowMgr.cpp index f86e09a09..68def351a 100644 --- a/Engine/source/windowManager/sdl/sdlWindowMgr.cpp +++ b/Engine/source/windowManager/sdl/sdlWindowMgr.cpp @@ -52,8 +52,7 @@ PlatformWindowManagerSDL::DragAndDropFSInfo::DragAndDropFSInfo(String rootName, PlatformWindowManagerSDL::DragAndDropFSInfo::~DragAndDropFSInfo() { -// FIXME: Cleanup - we can't simply do this unmount due to the way the hash mapping works -// Torque::FS::Unmount(mDragAndDropFS); + } #endif @@ -88,6 +87,15 @@ PlatformWindowManagerSDL::PlatformWindowManagerSDL() PlatformWindowManagerSDL::~PlatformWindowManagerSDL() { + // Unmount all drag and drop FS mounts + for (auto iteration = mActiveDragAndDropFSByPath.begin(); iteration != mActiveDragAndDropFSByPath.end(); ++iteration) + { + auto&& mapping = *iteration; + Torque::FS::Unmount(mapping.value.mDragAndDropFS); + } + mActiveDragAndDropByRoot.clear(); + mActiveDragAndDropFSByPath.clear(); + // Kill all our windows first. while(mWindowListHead) // The destructors update the list, so this works just fine. @@ -473,7 +481,7 @@ void PlatformWindowManagerSDL::_process() while (search != mActiveDragAndDropByRoot.end()) { char buffer[32]; - dSprintf(buffer, 32, "%u", rootCounter); + dSprintf(buffer, sizeof(buffer), "%u", rootCounter); chosenRootName = directoryName + buffer; search = mActiveDragAndDropByRoot.find(chosenRootName); diff --git a/Engine/source/windowManager/sdl/sdlWindowMgr.h b/Engine/source/windowManager/sdl/sdlWindowMgr.h index c5456e50d..fc2ae4969 100644 --- a/Engine/source/windowManager/sdl/sdlWindowMgr.h +++ b/Engine/source/windowManager/sdl/sdlWindowMgr.h @@ -111,7 +111,10 @@ protected: KeyboardInputState mInputState; #ifdef TORQUE_SECURE_VFS + /// Used to check if a root is already used when generating root names. HashMap mActiveDragAndDropByRoot; + + /// Used to keep track of what mounts are handling a given path. HashMap mActiveDragAndDropFSByPath; #endif