* Feature: Initial secure VFS implementation with asset import capability.

This commit is contained in:
Robert MacGregor 2021-12-17 21:16:42 -05:00
parent d9bedbe31c
commit 277cdf67b0
12 changed files with 220 additions and 10 deletions

View file

@ -22,6 +22,8 @@
#include "windowManager/sdl/sdlWindowMgr.h"
#include "platformSDL/sdlInputManager.h"
#include "platform/platformVolume.h"
#include "core/util/path.h"
#include "gfx/gfxDevice.h"
#include "core/util/journal/process.h"
#include "core/strings/unicode.h"
@ -35,6 +37,26 @@ void sdl_CloseSplashWindow(void* hinst);
#ifdef TORQUE_SDL
#ifdef TORQUE_SECURE_VFS
PlatformWindowManagerSDL::DragAndDropFSInfo::DragAndDropFSInfo()
{
}
PlatformWindowManagerSDL::DragAndDropFSInfo::DragAndDropFSInfo(String rootName, Torque::FS::FileSystemRef fileSystem) : mRootName(rootName), mDragAndDropFS(fileSystem)
{
if (!Torque::FS::Mount(rootName, fileSystem))
{
Con::errorf("Could not mount drag and drop FS!");
}
}
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
PlatformWindowManager * CreatePlatformWindowManager()
{
return new PlatformWindowManagerSDL();
@ -427,7 +449,61 @@ void PlatformWindowManagerSDL::_process()
if (!Platform::isDirectory(fileName) && !Platform::isFile(fileName))
break;
#ifdef TORQUE_SECURE_VFS
// Determine what the directory is so we can mount it
Torque::Path targetDirectory = Torque::Path(fileName);
// If we're dropping a file, strip off file information - otherwise if a directory mount it directly
if (Platform::isFile(fileName))
{
targetDirectory.setExtension("");
targetDirectory.setFileName("");
}
const String directoryName = targetDirectory.getDirectory(targetDirectory.getDirectoryCount() - 1);
auto dropFSMount = mActiveDragAndDropFSByPath.find(targetDirectory);
if (dropFSMount == mActiveDragAndDropFSByPath.end())
{
Torque::FS::FileSystemRef newMount = Platform::FS::createNativeFS(targetDirectory.getFullPath());
// Search for an unused root in case we have duplicate names
U32 rootCounter = 1;
String chosenRootName = directoryName;
auto search = mActiveDragAndDropByRoot.find(chosenRootName);
while (search != mActiveDragAndDropByRoot.end())
{
char buffer[32];
dSprintf(buffer, 32, "%u", rootCounter);
chosenRootName = directoryName + buffer;
search = mActiveDragAndDropByRoot.find(chosenRootName);
}
mActiveDragAndDropFSByPath[targetDirectory] = DragAndDropFSInfo(directoryName, newMount);
mActiveDragAndDropFSByPath[chosenRootName] = mActiveDragAndDropFSByPath[targetDirectory];
}
DragAndDropFSInfo& filesystemInformation = mActiveDragAndDropFSByPath[targetDirectory];
// Load source file information
Torque::Path sourceFile = fileName;
// Build a reference to the file in VFS
Torque::Path targetFile;
targetFile.setRoot(filesystemInformation.mRootName);
targetFile.setPath("/");
// Only copy file & extension information if we're dropping a file
if (Platform::isFile(fileName))
{
targetFile.setFileName(sourceFile.getFileName());
targetFile.setExtension(sourceFile.getExtension());
}
Con::executef("onDropFile", StringTable->insert(targetFile.getFullPath()));
#else
Con::executef("onDropFile", StringTable->insert(fileName));
#endif
SDL_free(fileName); // Free dropped_filedir memory
break;

View file

@ -27,6 +27,7 @@
#include "gfx/gfxStructs.h"
#include "windowManager/sdl/sdlWindow.h"
#include "core/util/tVector.h"
#include "core/volume.h"
struct SDL_Window;
class FileDialog; // TODO SDL REMOVE
@ -57,6 +58,18 @@ public:
RAW_INPUT = 2 /// < We only want raw input.
};
#ifdef TORQUE_SECURE_VFS
struct DragAndDropFSInfo
{
String mRootName;
Torque::FS::FileSystemRef mDragAndDropFS;
DragAndDropFSInfo();
DragAndDropFSInfo(String rootName, Torque::FS::FileSystemRef fileSystem);
~DragAndDropFSInfo();
};
#endif
protected:
friend class PlatformWindowSDL;
friend class FileDialog; // TODO SDL REMOVE
@ -97,6 +110,11 @@ protected:
/// After it is handled, it will return to state NONE.
KeyboardInputState mInputState;
#ifdef TORQUE_SECURE_VFS
HashMap<String, DragAndDropFSInfo> mActiveDragAndDropByRoot;
HashMap<Torque::Path, DragAndDropFSInfo> mActiveDragAndDropFSByPath;
#endif
public:
PlatformWindowManagerSDL();
~PlatformWindowManagerSDL();