mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-13 15:44:36 +00:00
* Adjustment: Change several filesystem functions to use the VFS.
* Feature: Initial implementation of a VFS dump directories function.
This commit is contained in:
parent
948bc43d85
commit
cbe7ee13d6
5 changed files with 130 additions and 42 deletions
|
|
@ -368,15 +368,11 @@ DefineEngineFunction(getFileCRC, S32, ( const char* fileName ),,
|
||||||
|
|
||||||
"@ingroup FileSystem")
|
"@ingroup FileSystem")
|
||||||
{
|
{
|
||||||
String cleanfilename(Torque::Path::CleanSeparators(fileName));
|
Torque::FS::FileNodeRef fileRef = Torque::FS::GetFileNode( fileName );
|
||||||
Con::expandScriptFilename(sgScriptFilenameBuffer, sizeof(sgScriptFilenameBuffer), cleanfilename.c_str());
|
|
||||||
|
|
||||||
Torque::Path givenPath(Torque::Path::CompressPath(sgScriptFilenameBuffer));
|
|
||||||
Torque::FS::FileNodeRef fileRef = Torque::FS::GetFileNode( givenPath );
|
|
||||||
|
|
||||||
if ( fileRef == NULL )
|
if ( fileRef == NULL )
|
||||||
{
|
{
|
||||||
Con::errorf("getFileCRC() - could not access file: [%s]", givenPath.getFullPath().c_str() );
|
Con::errorf("getFileCRC() - could not access file: [%s]", fileName );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -391,11 +387,7 @@ DefineEngineFunction(isFile, bool, ( const char* fileName ),,
|
||||||
|
|
||||||
"@ingroup FileSystem")
|
"@ingroup FileSystem")
|
||||||
{
|
{
|
||||||
String cleanfilename(Torque::Path::CleanSeparators(fileName));
|
return Torque::FS::IsFile(fileName);
|
||||||
Con::expandScriptFilename(sgScriptFilenameBuffer, sizeof(sgScriptFilenameBuffer), cleanfilename.c_str());
|
|
||||||
|
|
||||||
Torque::Path givenPath(Torque::Path::CompressPath(sgScriptFilenameBuffer));
|
|
||||||
return Torque::FS::IsFile(givenPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DefineEngineFunction(isScriptFile, bool, (const char* fileName), ,
|
DefineEngineFunction(isScriptFile, bool, (const char* fileName), ,
|
||||||
|
|
@ -406,11 +398,7 @@ DefineEngineFunction(isScriptFile, bool, (const char* fileName), ,
|
||||||
|
|
||||||
"@ingroup FileSystem")
|
"@ingroup FileSystem")
|
||||||
{
|
{
|
||||||
String cleanfilename(Torque::Path::CleanSeparators(fileName));
|
return Torque::FS::IsScriptFile(fileName);
|
||||||
Con::expandScriptFilename(sgScriptFilenameBuffer, sizeof(sgScriptFilenameBuffer), cleanfilename.c_str());
|
|
||||||
|
|
||||||
Torque::Path givenPath(Torque::Path::CompressPath(sgScriptFilenameBuffer));
|
|
||||||
return Torque::FS::IsScriptFile(givenPath.getFullPath());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DefineEngineFunction( IsDirectory, bool, ( const char* directory ),,
|
DefineEngineFunction( IsDirectory, bool, ( const char* directory ),,
|
||||||
|
|
@ -423,11 +411,7 @@ DefineEngineFunction( IsDirectory, bool, ( const char* directory ),,
|
||||||
|
|
||||||
"@ingroup FileSystem")
|
"@ingroup FileSystem")
|
||||||
{
|
{
|
||||||
String dir(Torque::Path::CleanSeparators(directory));
|
return Torque::FS::IsDirectory( directory );
|
||||||
Con::expandScriptFilename(sgScriptFilenameBuffer, sizeof(sgScriptFilenameBuffer), dir.c_str());
|
|
||||||
|
|
||||||
Torque::Path givenPath(Torque::Path::CompressPath(sgScriptFilenameBuffer));
|
|
||||||
return Torque::FS::IsDirectory( givenPath );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DefineEngineFunction(isWriteableFileName, bool, ( const char* fileName ),,
|
DefineEngineFunction(isWriteableFileName, bool, ( const char* fileName ),,
|
||||||
|
|
@ -438,14 +422,7 @@ DefineEngineFunction(isWriteableFileName, bool, ( const char* fileName ),,
|
||||||
|
|
||||||
"@ingroup FileSystem")
|
"@ingroup FileSystem")
|
||||||
{
|
{
|
||||||
String filename(Torque::Path::CleanSeparators(fileName));
|
return !Torque::FS::IsReadOnly(fileName);
|
||||||
Con::expandScriptFilename(sgScriptFilenameBuffer, sizeof(sgScriptFilenameBuffer), filename.c_str());
|
|
||||||
|
|
||||||
Torque::Path givenPath(Torque::Path::CompressPath(sgScriptFilenameBuffer));
|
|
||||||
Torque::FS::FileSystemRef fs = Torque::FS::GetFileSystem(givenPath);
|
|
||||||
Torque::Path path = fs->mapTo(givenPath);
|
|
||||||
|
|
||||||
return !Torque::FS::IsReadOnly(path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DefineEngineFunction(startFileChangeNotifications, void, (),,
|
DefineEngineFunction(startFileChangeNotifications, void, (),,
|
||||||
|
|
@ -840,7 +817,11 @@ DefineEngineFunction( getCurrentDirectory, String, (),,
|
||||||
"@see getWorkingDirectory()"
|
"@see getWorkingDirectory()"
|
||||||
"@ingroup FileSystem")
|
"@ingroup FileSystem")
|
||||||
{
|
{
|
||||||
|
#ifdef TORQUE_SECURE_VFS
|
||||||
|
return Torque::FS::GetCwd();
|
||||||
|
#else
|
||||||
return Platform::getCurrentDirectory();
|
return Platform::getCurrentDirectory();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
@ -853,8 +834,11 @@ DefineEngineFunction( setCurrentDirectory, bool, ( const char* path ),,
|
||||||
"@note Only present in a Tools build of Torque.\n"
|
"@note Only present in a Tools build of Torque.\n"
|
||||||
"@ingroup FileSystem")
|
"@ingroup FileSystem")
|
||||||
{
|
{
|
||||||
|
#ifdef TORQUE_SECURE_VFS
|
||||||
|
return Torque::FS::SetCwd(path);
|
||||||
|
#else
|
||||||
return Platform::setCurrentDirectory( StringTable->insert( path ) );
|
return Platform::setCurrentDirectory( StringTable->insert( path ) );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -129,4 +129,4 @@ namespace Torque
|
||||||
} // Namespace
|
} // Namespace
|
||||||
} // Namespace
|
} // Namespace
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -75,4 +75,4 @@ private:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -255,6 +255,64 @@ File::~File() {}
|
||||||
Directory::Directory() {}
|
Directory::Directory() {}
|
||||||
Directory::~Directory() {}
|
Directory::~Directory() {}
|
||||||
|
|
||||||
|
bool Directory::dump(Vector<Path>& out)
|
||||||
|
{
|
||||||
|
const Path sourcePath = getName();
|
||||||
|
|
||||||
|
FileNode::Attributes currentAttributes;
|
||||||
|
while (read(¤tAttributes))
|
||||||
|
{
|
||||||
|
Path currentPath = sourcePath;
|
||||||
|
currentPath.appendPath(currentPath.getFileName());
|
||||||
|
currentPath.setFileName(currentAttributes.name);
|
||||||
|
|
||||||
|
out.push_back(currentPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Directory::dumpFiles(Vector<Path>& out)
|
||||||
|
{
|
||||||
|
const Path sourcePath = getName();
|
||||||
|
|
||||||
|
FileNode::Attributes currentAttributes;
|
||||||
|
while (read(¤tAttributes))
|
||||||
|
{
|
||||||
|
Path currentPath = sourcePath;
|
||||||
|
currentPath.appendPath(currentPath.getFileName());
|
||||||
|
currentPath.setFileName(currentAttributes.name);
|
||||||
|
|
||||||
|
if (IsFile(currentPath))
|
||||||
|
{
|
||||||
|
out.push_back(currentPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Directory::dumpDirectories(Vector<Path>& out)
|
||||||
|
{
|
||||||
|
const Path sourcePath = getName();
|
||||||
|
|
||||||
|
FileNode::Attributes currentAttributes;
|
||||||
|
while (read(¤tAttributes))
|
||||||
|
{
|
||||||
|
Path currentPath = sourcePath;
|
||||||
|
currentPath.appendPath(currentPath.getFileName());
|
||||||
|
currentPath.setFileName(currentAttributes.name);
|
||||||
|
|
||||||
|
const bool result = IsDirectory(currentPath);
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
out.push_back(currentPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
FileNode::FileNode()
|
FileNode::FileNode()
|
||||||
: mChecksum(0)
|
: mChecksum(0)
|
||||||
|
|
@ -534,6 +592,39 @@ bool MountSystem::copyFile(const Path& source, const Path& destination, bool noO
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MountSystem::_dumpDirectories(DirectoryRef directory, Vector<StringTableEntry>& directories, S32 depth, bool noBasePath, S32 currentDepth, const Path& basePath)
|
||||||
|
{
|
||||||
|
Vector<Torque::Path> directoryPaths;
|
||||||
|
if (!directory->dumpDirectories(directoryPaths))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (U32 iteration = 0; iteration < directoryPaths.size(); ++iteration)
|
||||||
|
{
|
||||||
|
directories.push_back(StringTable->insert(directoryPaths[iteration].getFullPath().c_str(), true));
|
||||||
|
|
||||||
|
if (currentDepth <= depth)
|
||||||
|
{
|
||||||
|
DirectoryRef nextDirectory = OpenDirectory(directoryPaths[iteration]);
|
||||||
|
_dumpDirectories(nextDirectory, directories, depth, noBasePath, currentDepth + 1, basePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MountSystem::dumpDirectories(const Path& path, Vector<StringTableEntry>& directories, S32 depth, bool noBasePath)
|
||||||
|
{
|
||||||
|
if (!isDirectory(path))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
DirectoryRef sourceDirectory = openDirectory(path);
|
||||||
|
return _dumpDirectories(sourceDirectory, directories, depth, noBasePath, 0, path);
|
||||||
|
}
|
||||||
|
|
||||||
FileRef MountSystem::createFile(const Path& path)
|
FileRef MountSystem::createFile(const Path& path)
|
||||||
{
|
{
|
||||||
Path np = _normalize(path);
|
Path np = _normalize(path);
|
||||||
|
|
@ -830,22 +921,19 @@ bool MountSystem::isDirectory(const Path& path, FileSystemRef fsRef)
|
||||||
{
|
{
|
||||||
FileNode::Attributes attr;
|
FileNode::Attributes attr;
|
||||||
|
|
||||||
|
bool result = false;
|
||||||
if (fsRef.isNull())
|
if (fsRef.isNull())
|
||||||
{
|
{
|
||||||
if (getFileAttributes(path,&attr))
|
if (getFileAttributes(path, &attr))
|
||||||
return attr.flags & FileNode::Directory;
|
result = (attr.flags & FileNode::Directory) != 0;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FileNodeRef fnRef = fsRef->resolve(path);
|
FileNodeRef fnRef = fsRef->resolve(path);
|
||||||
if (fnRef.isNull())
|
if (!fnRef.isNull() && fnRef->getAttributes(&attr))
|
||||||
return false;
|
result = (attr.flags & FileNode::Directory) != 0;
|
||||||
|
|
||||||
if (fnRef->getAttributes(&attr))
|
|
||||||
return attr.flags & FileNode::Directory;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MountSystem::isReadOnly(const Path& path)
|
bool MountSystem::isReadOnly(const Path& path)
|
||||||
|
|
@ -948,6 +1036,11 @@ bool CopyFile(const Path& source, const Path& destination, bool noOverwrite)
|
||||||
return sgMountSystem.copyFile(source, destination, noOverwrite);
|
return sgMountSystem.copyFile(source, destination, noOverwrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DumpDirectories(const Path& path, Vector<StringTableEntry>& directories, S32 depth, bool noBasePath)
|
||||||
|
{
|
||||||
|
return sgMountSystem.dumpDirectories(path, directories, depth, noBasePath);
|
||||||
|
}
|
||||||
|
|
||||||
DirectoryRef CreateDirectory(const Path &path)
|
DirectoryRef CreateDirectory(const Path &path)
|
||||||
{
|
{
|
||||||
return sgMountSystem.createDirectory(path);
|
return sgMountSystem.createDirectory(path);
|
||||||
|
|
|
||||||
|
|
@ -203,7 +203,11 @@ public:
|
||||||
// Functions
|
// Functions
|
||||||
virtual bool open() = 0;
|
virtual bool open() = 0;
|
||||||
virtual bool close() = 0;
|
virtual bool close() = 0;
|
||||||
virtual bool read(Attributes*) = 0;
|
virtual bool read(Attributes*) = 0;
|
||||||
|
|
||||||
|
bool dump(Vector<Path>& out);
|
||||||
|
bool dumpFiles(Vector<Path>& out);
|
||||||
|
bool dumpDirectories(Vector<Path>& out);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef WeakRefPtr<Directory> DirectoryPtr;
|
typedef WeakRefPtr<Directory> DirectoryPtr;
|
||||||
|
|
@ -338,6 +342,8 @@ public:
|
||||||
|
|
||||||
FileRef createFile(const Path& path);
|
FileRef createFile(const Path& path);
|
||||||
bool copyFile(const Path& source, const Path& destination, bool noOverwrite);
|
bool copyFile(const Path& source, const Path& destination, bool noOverwrite);
|
||||||
|
bool dumpDirectories(const Path& path, Vector<StringTableEntry>& directories, S32 depth, bool noBasePath);
|
||||||
|
|
||||||
DirectoryRef createDirectory(const Path& path, FileSystemRef fs = NULL);
|
DirectoryRef createDirectory(const Path& path, FileSystemRef fs = NULL);
|
||||||
virtual bool createPath(const Path& path);
|
virtual bool createPath(const Path& path);
|
||||||
|
|
||||||
|
|
@ -377,6 +383,8 @@ public:
|
||||||
void startFileChangeNotifications();
|
void startFileChangeNotifications();
|
||||||
void stopFileChangeNotifications();
|
void stopFileChangeNotifications();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool _dumpDirectories(DirectoryRef directory, Vector<StringTableEntry>& directories, S32 depth, bool noBasePath, S32 currentDepth, const Path& basePath);
|
||||||
protected:
|
protected:
|
||||||
virtual void _log(const String& msg);
|
virtual void _log(const String& msg);
|
||||||
|
|
||||||
|
|
@ -544,6 +552,9 @@ FileRef CreateFile(const Path &file);
|
||||||
/// Copy a file from one location to another.
|
/// Copy a file from one location to another.
|
||||||
bool CopyFile(const Path& source, const Path& destination, bool noOverride);
|
bool CopyFile(const Path& source, const Path& destination, bool noOverride);
|
||||||
|
|
||||||
|
/// Retrieve list of directories in the specified directory.
|
||||||
|
bool DumpDirectories(const Path& path, Vector<StringTableEntry>& directories, S32 depth, bool noBasePath);
|
||||||
|
|
||||||
/// Create a directory.
|
/// Create a directory.
|
||||||
/// The directory object is returned in a closed state.
|
/// The directory object is returned in a closed state.
|
||||||
///@ingroup VolumeSystem
|
///@ingroup VolumeSystem
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue