FileUtil_Common.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0 OR MIT
  5. *
  6. */
  7. #include "EditorDefs.h"
  8. #include "FileUtil_Common.h"
  9. namespace Common
  10. {
  11. bool Exists(const QString& strPath, bool boDirectory, IFileUtil::FileDesc* pDesc)
  12. {
  13. auto pIPak = GetIEditor()->GetSystem()->GetIPak();
  14. bool boIsDirectory(false);
  15. AZ::IO::ArchiveFileIterator nFindHandle = pIPak->FindFirst(strPath.toUtf8().data());
  16. // If it found nothing, no matter if it is a file or directory, it was not found.
  17. if (!nFindHandle)
  18. {
  19. return false;
  20. }
  21. pIPak->FindClose(nFindHandle);
  22. if ((nFindHandle.m_fileDesc.nAttrib & AZ::IO::FileDesc::Attribute::Subdirectory) == AZ::IO::FileDesc::Attribute::Subdirectory)
  23. {
  24. boIsDirectory = true;
  25. }
  26. else if (pDesc)
  27. {
  28. pDesc->filename = strPath;
  29. pDesc->attrib = static_cast<unsigned int>(nFindHandle.m_fileDesc.nAttrib);
  30. pDesc->size = nFindHandle.m_fileDesc.nSize;
  31. pDesc->time_access = nFindHandle.m_fileDesc.tAccess;
  32. pDesc->time_create = nFindHandle.m_fileDesc.tCreate;
  33. pDesc->time_write = nFindHandle.m_fileDesc.tWrite;
  34. }
  35. // If we are seeking directories...
  36. if (boDirectory)
  37. {
  38. // The return value will tell us if the found element is a directory.
  39. return boIsDirectory;
  40. }
  41. else
  42. {
  43. // If we are not seeking directories...
  44. // We return true if the found element is not a directory.
  45. return !boIsDirectory;
  46. }
  47. }
  48. bool PathExists(const QString& strPath)
  49. {
  50. return Exists(strPath, true);
  51. }
  52. }