2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-03-07 05:23:02 +00:00

chore: use namespace for FileUtils

This commit is contained in:
Jan Laupetin
2026-03-05 20:27:47 +01:00
parent 304ebd56a7
commit d469af2328
15 changed files with 103 additions and 96 deletions

View File

@@ -225,50 +225,50 @@ bool LinkerArgs::ParseArgs(const int argc, const char** argv, bool& shouldContin
// --asset-search-path
if (m_argument_parser.IsOptionSpecified(OPTION_ASSET_SEARCH_PATH))
{
if (!FileUtils::ParsePathsString(m_argument_parser.GetValueForOption(OPTION_ASSET_SEARCH_PATH), m_asset_search_paths))
if (!utils::ParsePathsString(m_argument_parser.GetValueForOption(OPTION_ASSET_SEARCH_PATH), m_asset_search_paths))
return false;
}
else
{
if (!FileUtils::ParsePathsString(DEFAULT_ASSET_SEARCH_PATH, m_asset_search_paths))
if (!utils::ParsePathsString(DEFAULT_ASSET_SEARCH_PATH, m_asset_search_paths))
return false;
}
// --add-assets-search-path
for (const auto& specifiedValue : m_argument_parser.GetParametersForOption(OPTION_ADD_ASSET_SEARCH_PATH))
{
if (!FileUtils::ParsePathsString(specifiedValue, m_asset_search_paths))
if (!utils::ParsePathsString(specifiedValue, m_asset_search_paths))
return false;
}
// --gdt-search-path
if (m_argument_parser.IsOptionSpecified(OPTION_GDT_SEARCH_PATH))
{
if (!FileUtils::ParsePathsString(m_argument_parser.GetValueForOption(OPTION_GDT_SEARCH_PATH), m_gdt_search_paths))
if (!utils::ParsePathsString(m_argument_parser.GetValueForOption(OPTION_GDT_SEARCH_PATH), m_gdt_search_paths))
return false;
}
else
{
if (!FileUtils::ParsePathsString(DEFAULT_GDT_SEARCH_PATH, m_gdt_search_paths))
if (!utils::ParsePathsString(DEFAULT_GDT_SEARCH_PATH, m_gdt_search_paths))
return false;
}
// --source-search-path
if (m_argument_parser.IsOptionSpecified(OPTION_SOURCE_SEARCH_PATH))
{
if (!FileUtils::ParsePathsString(m_argument_parser.GetValueForOption(OPTION_SOURCE_SEARCH_PATH), m_source_search_paths))
if (!utils::ParsePathsString(m_argument_parser.GetValueForOption(OPTION_SOURCE_SEARCH_PATH), m_source_search_paths))
return false;
}
else
{
if (!FileUtils::ParsePathsString(DEFAULT_SOURCE_SEARCH_PATH, m_source_search_paths))
if (!utils::ParsePathsString(DEFAULT_SOURCE_SEARCH_PATH, m_source_search_paths))
return false;
}
// --add-source-search-path
for (const auto& specifiedValue : m_argument_parser.GetParametersForOption(OPTION_ADD_SOURCE_SEARCH_PATH))
{
if (!FileUtils::ParsePathsString(specifiedValue, m_source_search_paths))
if (!utils::ParsePathsString(specifiedValue, m_source_search_paths))
return false;
}

View File

@@ -6,12 +6,12 @@
namespace ipak_consts
{
static constexpr uint32_t IPAK_MAGIC = FileUtils::MakeMagic32('K', 'A', 'P', 'I');
static constexpr uint32_t IPAK_MAGIC = utils::MakeMagic32('K', 'A', 'P', 'I');
static constexpr uint32_t IPAK_VERSION = 0x50000;
static constexpr uint32_t IPAK_INDEX_SECTION = 1;
static constexpr uint32_t IPAK_DATA_SECTION = 2;
static constexpr uint32_t IPAK_BRANDING_SECTION = FileUtils::MakeMagic32('M', 'E', 'T', 'A');
static constexpr uint32_t IPAK_BRANDING_SECTION = utils::MakeMagic32('M', 'E', 'T', 'A');
static constexpr size_t IPAK_CHUNK_SIZE = 0x8000;
static constexpr size_t IPAK_CHUNK_COUNT_PER_READ = 0x8;

View File

@@ -41,8 +41,8 @@ namespace d3d11
namespace
{
constexpr auto TAG_RDEF = FileUtils::MakeMagic32('R', 'D', 'E', 'F');
constexpr auto TAG_SHDR = FileUtils::MakeMagic32('S', 'H', 'D', 'R');
constexpr auto TAG_RDEF = utils::MakeMagic32('R', 'D', 'E', 'F');
constexpr auto TAG_SHDR = utils::MakeMagic32('S', 'H', 'D', 'R');
constexpr auto CHUNK_TABLE_OFFSET = 28u;

View File

@@ -222,7 +222,7 @@ namespace d3d9
const char* constantTableComment;
size_t constantTableCommentSize;
if (!FindComment(shaderByteCode, shaderByteCodeSize, FileUtils::MakeMagic32('C', 'T', 'A', 'B'), constantTableComment, constantTableCommentSize))
if (!FindComment(shaderByteCode, shaderByteCodeSize, utils::MakeMagic32('C', 'T', 'A', 'B'), constantTableComment, constantTableCommentSize))
return false;
if (constantTableCommentSize < sizeof(ConstantTable))

View File

@@ -12,7 +12,7 @@
namespace
{
constexpr auto FLAC_MAGIC = FileUtils::MakeMagic32('f', 'L', 'a', 'C');
constexpr auto FLAC_MAGIC = utils::MakeMagic32('f', 'L', 'a', 'C');
enum class MetaDataBlockType : unsigned
{

View File

@@ -1,12 +1,13 @@
#pragma once
#include "Utils/FileUtils.h"
#include <cstdint>
constexpr uint32_t WAV_WAVE_ID = FileUtils::MakeMagic32('W', 'A', 'V', 'E');
constexpr uint32_t WAV_CHUNK_ID_RIFF = FileUtils::MakeMagic32('R', 'I', 'F', 'F');
constexpr uint32_t WAV_CHUNK_ID_FMT = FileUtils::MakeMagic32('f', 'm', 't', ' ');
constexpr uint32_t WAV_CHUNK_ID_DATA = FileUtils::MakeMagic32('d', 'a', 't', 'a');
constexpr uint32_t WAV_WAVE_ID = utils::MakeMagic32('W', 'A', 'V', 'E');
constexpr uint32_t WAV_CHUNK_ID_RIFF = utils::MakeMagic32('R', 'I', 'F', 'F');
constexpr uint32_t WAV_CHUNK_ID_FMT = utils::MakeMagic32('f', 'm', 't', ' ');
constexpr uint32_t WAV_CHUNK_ID_DATA = utils::MakeMagic32('d', 'a', 't', 'a');
struct WavChunkHeader
{

View File

@@ -7,12 +7,12 @@
namespace gltf
{
constexpr uint32_t GLTF_MAGIC = FileUtils::MakeMagic32('g', 'l', 'T', 'F');
constexpr uint32_t GLTF_MAGIC = utils::MakeMagic32('g', 'l', 'T', 'F');
constexpr uint32_t GLTF_VERSION = 2u;
constexpr auto GLTF_VERSION_STRING = "2.0";
constexpr uint32_t CHUNK_MAGIC_JSON = FileUtils::MakeMagic32('J', 'S', 'O', 'N');
constexpr uint32_t CHUNK_MAGIC_BIN = FileUtils::MakeMagic32('B', 'I', 'N', '\x00');
constexpr uint32_t CHUNK_MAGIC_JSON = utils::MakeMagic32('J', 'S', 'O', 'N');
constexpr uint32_t CHUNK_MAGIC_BIN = utils::MakeMagic32('B', 'I', 'N', '\x00');
constexpr auto GLTF_LENGTH_OFFSET = 8u;
constexpr auto GLTF_JSON_CHUNK_LENGTH_OFFSET = 12u;

View File

@@ -41,15 +41,15 @@ namespace oat
D3DFMT_V16U16 = 64,
D3DFMT_A2W10V10U10 = 67,
D3DFMT_UYVY = FileUtils::MakeMagic32('U', 'Y', 'V', 'Y'),
D3DFMT_R8G8_B8G8 = FileUtils::MakeMagic32('R', 'G', 'B', 'G'),
D3DFMT_YUY2 = FileUtils::MakeMagic32('Y', 'U', 'Y', '2'),
D3DFMT_G8R8_G8B8 = FileUtils::MakeMagic32('G', 'R', 'G', 'B'),
D3DFMT_DXT1 = FileUtils::MakeMagic32('D', 'X', 'T', '1'),
D3DFMT_DXT2 = FileUtils::MakeMagic32('D', 'X', 'T', '2'),
D3DFMT_DXT3 = FileUtils::MakeMagic32('D', 'X', 'T', '3'),
D3DFMT_DXT4 = FileUtils::MakeMagic32('D', 'X', 'T', '4'),
D3DFMT_DXT5 = FileUtils::MakeMagic32('D', 'X', 'T', '5'),
D3DFMT_UYVY = utils::MakeMagic32('U', 'Y', 'V', 'Y'),
D3DFMT_R8G8_B8G8 = utils::MakeMagic32('R', 'G', 'B', 'G'),
D3DFMT_YUY2 = utils::MakeMagic32('Y', 'U', 'Y', '2'),
D3DFMT_G8R8_G8B8 = utils::MakeMagic32('G', 'R', 'G', 'B'),
D3DFMT_DXT1 = utils::MakeMagic32('D', 'X', 'T', '1'),
D3DFMT_DXT2 = utils::MakeMagic32('D', 'X', 'T', '2'),
D3DFMT_DXT3 = utils::MakeMagic32('D', 'X', 'T', '3'),
D3DFMT_DXT4 = utils::MakeMagic32('D', 'X', 'T', '4'),
D3DFMT_DXT5 = utils::MakeMagic32('D', 'X', 'T', '5'),
D3DFMT_D16_LOCKABLE = 70,
D3DFMT_D32 = 71,
@@ -78,7 +78,7 @@ namespace oat
D3DFMT_Q16W16V16U16 = 110,
D3DFMT_MULTI2_ARGB8 = FileUtils::MakeMagic32('M', 'E', 'T', '1'),
D3DFMT_MULTI2_ARGB8 = utils::MakeMagic32('M', 'E', 'T', '1'),
// Floating point surface formats

View File

@@ -1,7 +1,6 @@
#include "DdsLoader.h"
#include "Image/DdsTypes.h"
#include "Utils/ClassUtils.h"
#include "Utils/FileUtils.h"
#include "Utils/Logging/Log.h"
@@ -15,7 +14,7 @@ namespace
{
class DdsLoaderInternal
{
static constexpr auto DDS_MAGIC = FileUtils::MakeMagic32('D', 'D', 'S', ' ');
static constexpr auto DDS_MAGIC = utils::MakeMagic32('D', 'D', 'S', ' ');
public:
explicit DdsLoaderInternal(std::istream& stream)
@@ -105,29 +104,29 @@ namespace
{
switch (pf.dwFourCC)
{
case FileUtils::MakeMagic32('D', 'X', 'T', '1'):
case utils::MakeMagic32('D', 'X', 'T', '1'):
m_format = &ImageFormat::FORMAT_BC1;
return true;
case FileUtils::MakeMagic32('D', 'X', 'T', '3'):
case utils::MakeMagic32('D', 'X', 'T', '3'):
m_format = &ImageFormat::FORMAT_BC2;
return true;
case FileUtils::MakeMagic32('D', 'X', 'T', '5'):
case utils::MakeMagic32('D', 'X', 'T', '5'):
m_format = &ImageFormat::FORMAT_BC3;
return true;
case FileUtils::MakeMagic32('A', 'T', 'I', '1'):
case FileUtils::MakeMagic32('B', 'C', '4', 'U'):
case utils::MakeMagic32('A', 'T', 'I', '1'):
case utils::MakeMagic32('B', 'C', '4', 'U'):
m_format = &ImageFormat::FORMAT_BC4;
return true;
case FileUtils::MakeMagic32('A', 'T', 'I', '2'):
case FileUtils::MakeMagic32('B', 'C', '5', 'U'):
case utils::MakeMagic32('A', 'T', 'I', '2'):
case utils::MakeMagic32('B', 'C', '5', 'U'):
m_format = &ImageFormat::FORMAT_BC5;
return true;
case FileUtils::MakeMagic32('D', 'X', '1', '0'):
case utils::MakeMagic32('D', 'X', '1', '0'):
return ReadDxt10Header();
default:

View File

@@ -25,7 +25,7 @@ public:
class SoundBank final : public ObjContainerReferenceable
{
static constexpr uint32_t MAGIC = FileUtils::MakeMagic32('2', 'U', 'X', '#');
static constexpr uint32_t MAGIC = utils::MakeMagic32('2', 'U', 'X', '#');
static constexpr uint32_t VERSION = 14u;
std::string m_file_name;

View File

@@ -32,7 +32,7 @@ class SoundBankWriterImpl : public SoundBankWriter
{
static constexpr char BRANDING[] = "Created with OAT - OpenAssetTools";
static constexpr int64_t DATA_OFFSET = 0x800;
static constexpr uint32_t MAGIC = FileUtils::MakeMagic32('2', 'U', 'X', '#');
static constexpr uint32_t MAGIC = utils::MakeMagic32('2', 'U', 'X', '#');
static constexpr uint32_t VERSION = 14u;
inline static const std::string PAD_DATA = std::string(16, '\x00');

View File

@@ -23,7 +23,7 @@ void BinOutput::AlignToFour(const char value) const
const auto offset = m_stream.tellp();
if (offset % 4 > 0)
{
const uint32_t alignmentValue = FileUtils::MakeMagic32(value, value, value, value);
const uint32_t alignmentValue = utils::MakeMagic32(value, value, value, value);
Write(&alignmentValue, 4u - (offset % 4u));
}
}

View File

@@ -330,7 +330,7 @@ bool UnlinkerArgs::ParseArgs(const int argc, const char** argv, bool& shouldCont
// --search-path
if (m_argument_parser.IsOptionSpecified(OPTION_SEARCH_PATH))
{
if (!FileUtils::ParsePathsString(m_argument_parser.GetValueForOption(OPTION_SEARCH_PATH), m_user_search_paths))
if (!utils::ParsePathsString(m_argument_parser.GetValueForOption(OPTION_SEARCH_PATH), m_user_search_paths))
{
return false;
}

View File

@@ -2,62 +2,67 @@
#include <sstream>
bool FileUtils::ParsePathsString(const std::string& pathsString, std::set<std::string>& output)
namespace fs = std::filesystem;
namespace utils
{
std::ostringstream currentPath;
auto pathStart = true;
auto quotationPos = 0; // 0 = before quotations, 1 = in quotations, 2 = after quotations
for (auto character : pathsString)
bool ParsePathsString(const std::string& pathsString, std::set<std::string>& output)
{
switch (character)
std::ostringstream currentPath;
auto pathStart = true;
auto quotationPos = 0; // 0 = before quotations, 1 = in quotations, 2 = after quotations
for (const auto character : pathsString)
{
case '"':
if (quotationPos == 0 && pathStart)
switch (character)
{
quotationPos = 1;
}
else if (quotationPos == 1)
{
quotationPos = 2;
pathStart = false;
}
else
{
return false;
}
break;
case ';':
if (quotationPos != 1)
{
auto path = currentPath.str();
if (!path.empty())
case '"':
if (quotationPos == 0 && pathStart)
{
output.insert(path);
currentPath = std::ostringstream();
quotationPos = 1;
}
else if (quotationPos == 1)
{
quotationPos = 2;
pathStart = false;
}
else
{
return false;
}
break;
pathStart = true;
quotationPos = 0;
}
else
{
case ';':
if (quotationPos != 1)
{
auto path = currentPath.str();
if (!path.empty())
{
output.insert(path);
currentPath = std::ostringstream();
}
pathStart = true;
quotationPos = 0;
}
else
{
currentPath << character;
}
break;
default:
currentPath << character;
pathStart = false;
break;
}
break;
default:
currentPath << character;
pathStart = false;
break;
}
}
if (currentPath.tellp() > 0)
{
output.insert(currentPath.str());
}
if (currentPath.tellp() > 0)
{
output.insert(currentPath.str());
}
return true;
}
return true;
}
} // namespace utils

View File

@@ -1,12 +1,14 @@
#pragma once
#include <cstdint>
#include <filesystem>
#include <fstream>
#include <set>
#include <sstream>
#include <string>
class FileUtils
namespace utils
{
public:
static constexpr uint32_t MakeMagic32(const char ch0, const char ch1, const char ch2, const char ch3)
{
return static_cast<uint32_t>(ch0) | static_cast<uint32_t>(ch1) << 8 | static_cast<uint32_t>(ch2) << 16 | static_cast<uint32_t>(ch3) << 24;
@@ -18,5 +20,5 @@ public:
* \param output A set for strings to save the output to.
* \return \c true if the user input was valid and could be processed successfully, otherwise \c false.
*/
static bool ParsePathsString(const std::string& pathsString, std::set<std::string>& output);
};
bool ParsePathsString(const std::string& pathsString, std::set<std::string>& output);
} // namespace utils