ArchiveTOC.inl 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 "ArchiveTOCView.h"
  10. namespace Archive
  11. {
  12. inline ArchiveTableOfContents::ArchiveTableOfContents() = default;
  13. // Archive Table of Contents file path wrapper
  14. inline ArchiveTableOfContents::Path::Path(AZ::IO::Path filePath)
  15. : m_posixPath{ AZStd::move(filePath.Native()), AZ::IO::PosixPathSeparator }
  16. {
  17. // Convert the path to use Posix path separators
  18. m_posixPath.MakePreferred();
  19. }
  20. inline ArchiveTableOfContents::Path::Path(AZ::IO::PathView filePath)
  21. : m_posixPath{ filePath.Native(), AZ::IO::PosixPathSeparator }
  22. {
  23. // Convert the path to use Posix path separators
  24. m_posixPath.MakePreferred();
  25. }
  26. inline auto ArchiveTableOfContents::Path::operator=(AZ::IO::Path filePath) -> Path&
  27. {
  28. m_posixPath = AZ::IO::Path(AZStd::move(filePath.Native()), AZ::IO::PosixPathSeparator).MakePreferred();
  29. return *this;
  30. }
  31. inline auto ArchiveTableOfContents::Path::operator=(AZ::IO::PathView filePath) -> Path&
  32. {
  33. m_posixPath = AZ::IO::Path(filePath.Native(), AZ::IO::PosixPathSeparator).MakePreferred();
  34. return *this;
  35. }
  36. inline ArchiveTableOfContents::Path::operator AZ::IO::Path&() &
  37. {
  38. return m_posixPath;
  39. }
  40. inline ArchiveTableOfContents::Path::operator const AZ::IO::Path&() const&
  41. {
  42. return m_posixPath;
  43. }
  44. inline ArchiveTableOfContents::Path::operator AZ::IO::Path&&() &&
  45. {
  46. return AZStd::move(m_posixPath);
  47. }
  48. inline ArchiveTableOfContents::Path::operator const AZ::IO::Path&&() const&&
  49. {
  50. return AZStd::move(m_posixPath);
  51. }
  52. inline bool ArchiveTableOfContents::Path::empty() const
  53. {
  54. return m_posixPath.empty();
  55. }
  56. inline void ArchiveTableOfContents::Path::clear()
  57. {
  58. m_posixPath.clear();
  59. }
  60. inline const typename AZ::IO::Path::string_type& ArchiveTableOfContents::Path::Native() const& noexcept
  61. {
  62. return m_posixPath.Native();
  63. }
  64. inline const typename AZ::IO::Path::string_type&& ArchiveTableOfContents::Path::Native() const&& noexcept
  65. {
  66. return AZStd::move(m_posixPath.Native());
  67. }
  68. inline typename AZ::IO::Path::string_type& ArchiveTableOfContents::Path::Native() & noexcept
  69. {
  70. return m_posixPath.Native();
  71. }
  72. inline typename AZ::IO::Path::string_type&& ArchiveTableOfContents::Path::Native() && noexcept
  73. {
  74. return AZStd::move(m_posixPath.Native());
  75. }
  76. inline const typename AZ::IO::Path::value_type* ArchiveTableOfContents::Path::c_str() const noexcept
  77. {
  78. return m_posixPath.c_str();
  79. }
  80. inline auto ArchiveTableOfContents::CreateFromTocView(
  81. const ArchiveTableOfContentsView& tocView) -> CreateFromTocViewOutcome
  82. {
  83. ArchiveTableOfContents tableOfContents;
  84. tableOfContents.m_fileMetadataTable = { tocView.m_fileMetadataTable.begin(), tocView.m_fileMetadataTable.end() };
  85. tableOfContents.m_blockOffsetTable = { tocView.m_blockOffsetTable.begin(), tocView.m_blockOffsetTable.end() };
  86. size_t fileCount = tocView.m_filePathIndexTable.size();
  87. // Populate the file path table using the file path index offset entries from the raw TOC view
  88. tableOfContents.m_filePaths.reserve(fileCount);
  89. for (const auto& filePathIndexEntry : tocView.m_filePathIndexTable)
  90. {
  91. // add an empty path entry and populate it with the file path
  92. auto& filePath = tableOfContents.m_filePaths.emplace_back();
  93. AZ::IO::PathView pathView{ AZStd::string_view(
  94. tocView.m_filePathBlob.data() + filePathIndexEntry.m_offset,
  95. filePathIndexEntry.m_size) };
  96. filePath = pathView.LexicallyNormal();
  97. }
  98. return tableOfContents;
  99. }
  100. } // namespace Archive