|
@@ -1,70 +1,80 @@
|
|
|
$#include "FileSystem.h"
|
|
$#include "FileSystem.h"
|
|
|
|
|
|
|
|
-/// Return files.
|
|
|
|
|
static const unsigned SCAN_FILES;
|
|
static const unsigned SCAN_FILES;
|
|
|
-/// Return directories.
|
|
|
|
|
static const unsigned SCAN_DIRS;
|
|
static const unsigned SCAN_DIRS;
|
|
|
-/// Return also hidden files.
|
|
|
|
|
static const unsigned SCAN_HIDDEN;
|
|
static const unsigned SCAN_HIDDEN;
|
|
|
|
|
|
|
|
-/// Subsystem for file and directory operations and access control.
|
|
|
|
|
class FileSystem : public Object
|
|
class FileSystem : public Object
|
|
|
{
|
|
{
|
|
|
-public:
|
|
|
|
|
- /// Set the current working directory.
|
|
|
|
|
bool SetCurrentDir(const String& pathName);
|
|
bool SetCurrentDir(const String& pathName);
|
|
|
- /// Create a directory.
|
|
|
|
|
|
|
+ bool SetCurrentDir(const char* pathName);
|
|
|
|
|
+
|
|
|
bool CreateDir(const String& pathName);
|
|
bool CreateDir(const String& pathName);
|
|
|
- /// Run a program using the command interpreter, block until it exits and return the exit code. Will fail if any allowed paths are defined.
|
|
|
|
|
|
|
+ bool CreateDir(const char* pathName);
|
|
|
|
|
+
|
|
|
int SystemCommand(const String& commandLine);
|
|
int SystemCommand(const String& commandLine);
|
|
|
- /// Open a file in an external program, with mode such as "edit" optionally specified. Will fail if any allowed paths are defined.
|
|
|
|
|
|
|
+ int SystemCommand(const char* commandLine);
|
|
|
|
|
+
|
|
|
|
|
+ int SystemRun(const String& fileName, const Vector<String>& arguments);
|
|
|
|
|
+ int SystemRun(const char* fileName, const Vector<String>& arguments);
|
|
|
|
|
+
|
|
|
bool SystemOpen(const String& fileName, const String& mode = String::EMPTY);
|
|
bool SystemOpen(const String& fileName, const String& mode = String::EMPTY);
|
|
|
- /// Copy a file. Return true if successful.
|
|
|
|
|
|
|
+ bool SystemOpen(const char* fileName, const char* mode = 0);
|
|
|
|
|
+
|
|
|
bool Copy(const String& srcFileName, const String& destFileName);
|
|
bool Copy(const String& srcFileName, const String& destFileName);
|
|
|
- /// Rename a file. Return true if successful.
|
|
|
|
|
|
|
+ bool Copy(const char* srcFileName, const char* destFileName);
|
|
|
|
|
+
|
|
|
bool Rename(const String& srcFileName, const String& destFileName);
|
|
bool Rename(const String& srcFileName, const String& destFileName);
|
|
|
- /// Delete a file. Return true if successful.
|
|
|
|
|
|
|
+ bool Rename(const char* srcFileName, const char* destFileName);
|
|
|
|
|
+
|
|
|
bool Delete(const String& fileName);
|
|
bool Delete(const String& fileName);
|
|
|
- /// Register a path as allowed to access. If no paths are registered, all are allowed.
|
|
|
|
|
|
|
+ bool Delete(const char* fileName);
|
|
|
|
|
+
|
|
|
void RegisterPath(const String& pathName);
|
|
void RegisterPath(const String& pathName);
|
|
|
|
|
+ void RegisterPath(const char* pathName);
|
|
|
|
|
|
|
|
- /// Return the absolute current working directory.
|
|
|
|
|
String GetCurrentDir() const;
|
|
String GetCurrentDir() const;
|
|
|
- /// Return whether paths have been registered.
|
|
|
|
|
- bool HasRegisteredPaths() const { return allowedPaths_.Size() > 0; }
|
|
|
|
|
- /// Check if a path is allowed to be accessed. If no paths are registered, all are allowed.
|
|
|
|
|
|
|
+ bool HasRegisteredPaths() const;
|
|
|
|
|
+
|
|
|
bool CheckAccess(const String& pathName) const;
|
|
bool CheckAccess(const String& pathName) const;
|
|
|
- /// Returns the file's last modified time as seconds since 1.1.1970, or 0 if can not be accessed.
|
|
|
|
|
|
|
+ bool CheckAccess(const char* pathName) const;
|
|
|
|
|
+
|
|
|
unsigned GetLastModifiedTime(const String& fileName) const;
|
|
unsigned GetLastModifiedTime(const String& fileName) const;
|
|
|
- /// Check if a file exists.
|
|
|
|
|
|
|
+ unsigned GetLastModifiedTime(const char* fileName) const;
|
|
|
|
|
+
|
|
|
bool FileExists(const String& fileName) const;
|
|
bool FileExists(const String& fileName) const;
|
|
|
- /// Check if a directory exists.
|
|
|
|
|
|
|
+ bool FileExists(const char* fileName) const;
|
|
|
|
|
+
|
|
|
bool DirExists(const String& pathName) const;
|
|
bool DirExists(const String& pathName) const;
|
|
|
- /// Return the program's directory.
|
|
|
|
|
|
|
+ bool DirExists(const char* pathName) const;
|
|
|
|
|
+
|
|
|
|
|
+ // void ScanDir(Vector<String>& result, const String& pathName, const String& filter, unsigned flags, bool recursive) const;
|
|
|
|
|
+ tolua_outside Vector<String> FileSystemScanDir @ ScanDir(const String& pathName, const String& filter, unsigned flags, bool recursive) const;
|
|
|
|
|
+ tolua_outside Vector<String> FileSystemScanDir @ ScanDir(const char* pathName, const char* filter, unsigned flags, bool recursive) const;
|
|
|
|
|
+
|
|
|
String GetProgramDir() const;
|
|
String GetProgramDir() const;
|
|
|
- /// Return the user documents directory.
|
|
|
|
|
String GetUserDocumentsDir() const;
|
|
String GetUserDocumentsDir() const;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-/// Split a full path to path, filename and extension. The extension will be converted to lowercase.
|
|
|
|
|
-void SplitPath(const String& fullPath, String& pathName, String& fileName, String& extension);
|
|
|
|
|
-/// Return the path from a full path.
|
|
|
|
|
|
|
+// void SplitPath(const String& fullPath, String& pathName, String& fileName, String& extension);
|
|
|
String GetPath(const String& fullPath);
|
|
String GetPath(const String& fullPath);
|
|
|
-/// Return the filename from a full path.
|
|
|
|
|
String GetFileName(const String& fullPath);
|
|
String GetFileName(const String& fullPath);
|
|
|
-/// Return the extension from a full path, converted to lowercase.
|
|
|
|
|
String GetExtension(const String& fullPath);
|
|
String GetExtension(const String& fullPath);
|
|
|
-/// Return the filename and extension from a full path. The extension will be converted to lowercase.
|
|
|
|
|
String GetFileNameAndExtension(const String& fullPath);
|
|
String GetFileNameAndExtension(const String& fullPath);
|
|
|
-/// Replace the extension of a file name with another.
|
|
|
|
|
String ReplaceExtension(const String& fullPath, const String& newExtension);
|
|
String ReplaceExtension(const String& fullPath, const String& newExtension);
|
|
|
-/// Add a slash at the end of the path if missing and convert to internal format (use slashes.)
|
|
|
|
|
String AddTrailingSlash(const String& pathName);
|
|
String AddTrailingSlash(const String& pathName);
|
|
|
-/// Remove the slash from the end of a path if exists and convert to internal format (use slashes.)
|
|
|
|
|
String RemoveTrailingSlash(const String& pathName);
|
|
String RemoveTrailingSlash(const String& pathName);
|
|
|
-/// Return the parent path, or the path itself if not available.
|
|
|
|
|
String GetParentPath(const String& pathName);
|
|
String GetParentPath(const String& pathName);
|
|
|
-/// Convert a path to internal format (use slashes.)
|
|
|
|
|
String GetInternalPath(const String& pathName);
|
|
String GetInternalPath(const String& pathName);
|
|
|
-/// Convert a path to the format required by the operating system.
|
|
|
|
|
String GetNativePath(const String& pathName);
|
|
String GetNativePath(const String& pathName);
|
|
|
|
|
+
|
|
|
|
|
+${
|
|
|
|
|
+
|
|
|
|
|
+static Vector<String> FileSystemScanDir(const FileSystem* fileSystem, const String& pathName, const String& filter, unsigned flags, bool recursive)
|
|
|
|
|
+{
|
|
|
|
|
+ Vector<String> result;
|
|
|
|
|
+ fileSystem->ScanDir(result, pathName, filter, flags, recursive);
|
|
|
|
|
+ return result;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+$}
|