FileUtil_impl.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include "Include/IFileUtil.h"
  10. #ifdef DeleteFile
  11. #undef DeleteFile
  12. #endif
  13. #ifdef CreateDirectory
  14. #undef CreateDirectory
  15. #endif
  16. #ifdef RemoveDirectory
  17. #undef RemoveDirectory
  18. #endif
  19. #ifdef CopyFile
  20. #undef CopyFile
  21. #endif
  22. AZ_PUSH_DISABLE_DLL_EXPORT_BASECLASS_WARNING
  23. class SANDBOX_API CFileUtil_impl
  24. : public IFileUtil
  25. {
  26. AZ_POP_DISABLE_DLL_EXPORT_BASECLASS_WARNING
  27. public:
  28. bool ScanDirectory(const QString& path, const QString& fileSpec, FileArray& files, bool recursive = true, bool addDirAlso = false, ScanDirectoryUpdateCallBack updateCB = nullptr, bool bSkipPaks = false) override;
  29. void ShowInExplorer(const QString& path) override;
  30. bool ExtractFile(QString& file, bool bMsgBoxAskForExtraction = true, const char* pDestinationFilename = nullptr) override;
  31. void EditTextureFile(const char* txtureFile, bool bUseGameFolder) override;
  32. //! Reformat filter string for (MFC) CFileDialog style file filtering
  33. void FormatFilterString(QString& filter) override;
  34. bool SelectSaveFile(const QString& fileFilter, const QString& defaulExtension, const QString& startFolder, QString& fileName) override;
  35. //! Attempt to make a file writable
  36. bool OverwriteFile(const QString& filename) override;
  37. //! Checks out the file from source control API. Blocks until completed
  38. bool CheckoutFile(const char* filename, QWidget* parentWindow = nullptr) override;
  39. //! Discard changes to a file from source control API. Blocks until completed
  40. bool RevertFile(const char* filename, QWidget* parentWindow = nullptr) override;
  41. //! Renames (moves) a file through the source control API. Blocks until completed
  42. bool RenameFile(const char* sourceFile, const char* targetFile, QWidget* parentWindow = nullptr) override;
  43. //! Deletes a file using source control API. Blocks until completed.
  44. bool DeleteFromSourceControl(const char* filename, QWidget* parentWindow = nullptr) override;
  45. //! Attempts to get the latest version of a file from source control. Blocks until completed
  46. bool GetLatestFromSourceControl(const char* filename, QWidget* parentWindow = nullptr) override;
  47. //! Gather information about a file using the source control API. Blocks until completed
  48. bool GetFileInfoFromSourceControl(const char* filename, AzToolsFramework::SourceControlFileInfo& fileInfo, QWidget* parentWindow = nullptr) override;
  49. //! Creates this directory.
  50. void CreateDirectory(const char* dir) override;
  51. //! Makes a backup file.
  52. void BackupFile(const char* filename) override;
  53. //! Makes a backup file, marked with a datestamp, e.g. myfile.20071014.093320.xml
  54. //! If bUseBackupSubDirectory is true, moves backup file into a relative subdirectory "backups"
  55. void BackupFileDated(const char* filename, bool bUseBackupSubDirectory = false) override;
  56. // ! Added deltree as a copy from the function found in Crypak.
  57. bool Deltree(const char* szFolder, bool bRecurse) override;
  58. // Checks if a file or directory exist.
  59. // We are using 3 functions here in order to make the names more instructive for the programmers.
  60. // Those functions only work for OS files and directories.
  61. bool Exists(const QString& strPath, bool boDirectory, FileDesc* pDesc = nullptr) override;
  62. bool FileExists(const QString& strFilePath, FileDesc* pDesc = nullptr) override;
  63. bool PathExists(const QString& strPath) override;
  64. bool GetDiskFileSize(const char* pFilePath, uint64& rOutSize) override;
  65. // This function should be used only with physical files.
  66. bool IsFileExclusivelyAccessable(const QString& strFilePath) override;
  67. // Creates the entire path, if needed.
  68. bool CreatePath(const QString& strPath) override;
  69. // Attempts to delete a file (if read only it will set its attributes to normal first).
  70. bool DeleteFile(const QString& strPath) override;
  71. // Attempts to remove a directory (if read only it will set its attributes to normal first).
  72. bool RemoveDirectory(const QString& strPath) override;
  73. // Copies all the elements from the source directory to the target directory.
  74. // It doesn't copy the source folder to the target folder, only it's contents.
  75. // THIS FUNCTION IS NOT DESIGNED FOR MULTI-THREADED USAGE
  76. ECopyTreeResult CopyTree(const QString& strSourceDirectory, const QString& strTargetDirectory, bool boRecurse = true, bool boConfirmOverwrite = false) override;
  77. //////////////////////////////////////////////////////////////////////////
  78. // @param LPPROGRESS_ROUTINE pfnProgress - called by the system to notify of file copy progress
  79. // @param LPBOOL pbCancel - when the contents of this BOOL are set to true, the system cancels the copy operation
  80. ECopyTreeResult CopyFile(const QString& strSourceFile, const QString& strTargetFile, bool boConfirmOverwrite = false, ProgressRoutine pfnProgress = nullptr, bool* pbCancel = nullptr) override;
  81. // As we don't have a FileUtil interface here, we have to duplicate some code :-( in order to keep
  82. // function calls clean.
  83. // Moves all the elements from the source directory to the target directory.
  84. // It doesn't move the source folder to the target folder, only it's contents.
  85. // THIS FUNCTION IS NOT DESIGNED FOR MULTI-THREADED USAGE
  86. ECopyTreeResult MoveTree(const QString& strSourceDirectory, const QString& strTargetDirectory, bool boRecurse = true, bool boConfirmOverwrite = false) override;
  87. // Get file attributes include source control attributes if available
  88. uint32 GetAttributes(const char* filename, bool bUseSourceControl = true) override;
  89. // Returns true if the files have the same content, false otherwise
  90. bool CompareFiles(const QString& strFilePath1, const QString& strFilePath2) override;
  91. // Extract path from full specified file path.
  92. QString GetPath(const QString& path) override;
  93. };