FileSystem.pkg 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. $#include "FileSystem.h"
  2. /// Return files.
  3. static const unsigned SCAN_FILES;
  4. /// Return directories.
  5. static const unsigned SCAN_DIRS;
  6. /// Return also hidden files.
  7. static const unsigned SCAN_HIDDEN;
  8. /// Subsystem for file and directory operations and access control.
  9. class FileSystem : public Object
  10. {
  11. public:
  12. /// Set the current working directory.
  13. bool SetCurrentDir(const String& pathName);
  14. /// Create a directory.
  15. bool CreateDir(const String& pathName);
  16. /// Run a program using the command interpreter, block until it exits and return the exit code. Will fail if any allowed paths are defined.
  17. int SystemCommand(const String& commandLine);
  18. /// Open a file in an external program, with mode such as "edit" optionally specified. Will fail if any allowed paths are defined.
  19. bool SystemOpen(const String& fileName, const String& mode = String::EMPTY);
  20. /// Copy a file. Return true if successful.
  21. bool Copy(const String& srcFileName, const String& destFileName);
  22. /// Rename a file. Return true if successful.
  23. bool Rename(const String& srcFileName, const String& destFileName);
  24. /// Delete a file. Return true if successful.
  25. bool Delete(const String& fileName);
  26. /// Register a path as allowed to access. If no paths are registered, all are allowed.
  27. void RegisterPath(const String& pathName);
  28. /// Return the absolute current working directory.
  29. String GetCurrentDir() const;
  30. /// Return whether paths have been registered.
  31. bool HasRegisteredPaths() const { return allowedPaths_.Size() > 0; }
  32. /// Check if a path is allowed to be accessed. If no paths are registered, all are allowed.
  33. bool CheckAccess(const String& pathName) const;
  34. /// Returns the file's last modified time as seconds since 1.1.1970, or 0 if can not be accessed.
  35. unsigned GetLastModifiedTime(const String& fileName) const;
  36. /// Check if a file exists.
  37. bool FileExists(const String& fileName) const;
  38. /// Check if a directory exists.
  39. bool DirExists(const String& pathName) const;
  40. /// Return the program's directory.
  41. String GetProgramDir() const;
  42. /// Return the user documents directory.
  43. String GetUserDocumentsDir() const;
  44. };
  45. /// Split a full path to path, filename and extension. The extension will be converted to lowercase.
  46. void SplitPath(const String& fullPath, String& pathName, String& fileName, String& extension);
  47. /// Return the path from a full path.
  48. String GetPath(const String& fullPath);
  49. /// Return the filename from a full path.
  50. String GetFileName(const String& fullPath);
  51. /// Return the extension from a full path, converted to lowercase.
  52. String GetExtension(const String& fullPath);
  53. /// Return the filename and extension from a full path. The extension will be converted to lowercase.
  54. String GetFileNameAndExtension(const String& fullPath);
  55. /// Replace the extension of a file name with another.
  56. String ReplaceExtension(const String& fullPath, const String& newExtension);
  57. /// Add a slash at the end of the path if missing and convert to internal format (use slashes.)
  58. String AddTrailingSlash(const String& pathName);
  59. /// Remove the slash from the end of a path if exists and convert to internal format (use slashes.)
  60. String RemoveTrailingSlash(const String& pathName);
  61. /// Return the parent path, or the path itself if not available.
  62. String GetParentPath(const String& pathName);
  63. /// Convert a path to internal format (use slashes.)
  64. String GetInternalPath(const String& pathName);
  65. /// Convert a path to the format required by the operating system.
  66. String GetNativePath(const String& pathName);