Move ArchiveType into it's own file
This commit is contained in:
@@ -13,7 +13,6 @@ namespace OpenVulkano
|
||||
namespace
|
||||
{
|
||||
constexpr int TYPE_MAP[] = { ARCHIVE_FORMAT_TAR, ARCHIVE_FORMAT_CPIO, ARCHIVE_FORMAT_ISO9660, ARCHIVE_FORMAT_ZIP, ARCHIVE_FORMAT_XAR, ARCHIVE_FORMAT_7ZIP, ARCHIVE_FORMAT_WARC, ARCHIVE_FORMAT_SHAR };
|
||||
constexpr std::string_view TYPE_NAMES[] = { ".tar", ".cpio", ".iso", ".zip", ".xar", ".7z", ".warc", ".shar" };
|
||||
|
||||
constexpr int COMP_MAP[] = { ARCHIVE_FILTER_COMPRESS, ARCHIVE_FILTER_NONE, ARCHIVE_FILTER_GZIP, ARCHIVE_FILTER_BZIP2, ARCHIVE_FILTER_XZ, ARCHIVE_FILTER_LZ4, ARCHIVE_FILTER_ZSTD };
|
||||
constexpr std::string_view COMP_NAMES[] = { ".Z", "", ".gz", ".bz2", ".xz", ".lz", ".zst" };
|
||||
@@ -23,7 +22,7 @@ namespace OpenVulkano
|
||||
|
||||
std::string ArchiveConfiguration::GetFileExtension() const
|
||||
{
|
||||
const std::string_view& tName = TYPE_NAMES[static_cast<int>(type)];
|
||||
const std::string_view tName = type.GetExtension();
|
||||
if (type == ArchiveType::TAR)
|
||||
{
|
||||
const std::string_view& cName = COMP_NAMES[static_cast<int>(compression)];
|
||||
@@ -39,20 +38,12 @@ namespace OpenVulkano
|
||||
{
|
||||
std::string_view fName = fileName;
|
||||
ArchiveConfiguration ac;
|
||||
int tId = 0;
|
||||
for(const std::string_view& tName : TYPE_NAMES)
|
||||
if (auto type = ArchiveType::FromExtension(fName))
|
||||
{
|
||||
if (tId > 0)
|
||||
{
|
||||
if (Utils::EndsWith(fName, tName))
|
||||
{
|
||||
ac.type = static_cast<ArchiveType>(tId);
|
||||
return ac;
|
||||
}
|
||||
}
|
||||
tId++;
|
||||
ac.type = *type;
|
||||
return ac;
|
||||
}
|
||||
tId = 0;
|
||||
int tId = 0;
|
||||
for(const std::string_view& tsName : TAR_SORTS)
|
||||
{
|
||||
if (Utils::EndsWith(fName, tsName))
|
||||
|
||||
@@ -6,12 +6,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ArchiveType.hpp"
|
||||
#include <string>
|
||||
|
||||
namespace OpenVulkano
|
||||
{
|
||||
enum class ArchiveType { TAR = 0, CPIO, ISO, ZIP, XAR, SEVEN_ZIP, WARC, SHAR };
|
||||
|
||||
enum class CompressionType { AUTO = 0, NONE, GZIP, BZIP2, XZ, LZ4, ZSTD };
|
||||
|
||||
struct ArchiveConfiguration final
|
||||
|
||||
57
openVulkanoCpp/IO/Archive/ArchiveType.hpp
Normal file
57
openVulkanoCpp/IO/Archive/ArchiveType.hpp
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Base/Utils.hpp"
|
||||
#include <string_view>
|
||||
#include <optional>
|
||||
|
||||
namespace OpenVulkano
|
||||
{
|
||||
class ArchiveType final
|
||||
{
|
||||
static inline constexpr std::string_view TYPE_NAMES[] = { ".tar", ".cpio", ".iso", ".zip", ".xar", ".7z", ".warc", ".shar" };
|
||||
|
||||
public:
|
||||
enum Type { TAR = 0, CPIO, ISO, ZIP, XAR, SEVEN_ZIP, WARC, SHAR };
|
||||
|
||||
constexpr ArchiveType(Type type) : m_type(type) {}
|
||||
|
||||
[[nodiscard]] constexpr bool AllowsUnknownFileSize() const { return m_type == ZIP; }
|
||||
|
||||
[[nodiscard]] constexpr bool AllowsMixedCompressionLevels() const { return m_type == ZIP; }
|
||||
|
||||
[[nodiscard]] constexpr std::string_view GetExtension() const { return TYPE_NAMES[m_type]; }
|
||||
|
||||
[[nodiscard]] constexpr bool operator==(Type rhs) const { return m_type == rhs; }
|
||||
[[nodiscard]] constexpr bool operator==(ArchiveType rhs) const { return m_type == rhs.m_type; }
|
||||
[[nodiscard]] constexpr bool operator!=(Type rhs) const { return m_type != rhs; }
|
||||
[[nodiscard]] constexpr bool operator!=(ArchiveType rhs) const { return m_type != rhs.m_type; }
|
||||
|
||||
[[nodiscard]] constexpr explicit operator int() const { return m_type; }
|
||||
|
||||
[[nodiscard]] static constexpr std::optional<ArchiveType> FromExtension(std::string_view fName)
|
||||
{
|
||||
int tId = 0;
|
||||
for(const std::string_view& tName : TYPE_NAMES)
|
||||
{
|
||||
if (tId > 0)
|
||||
{
|
||||
if (Utils::EndsWith(fName, tName))
|
||||
{
|
||||
return static_cast<Type>(tId);
|
||||
}
|
||||
}
|
||||
tId++;
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
private:
|
||||
Type m_type;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user