Stable Build
This commit is contained in:
@@ -32,6 +32,9 @@ include(cmake/CPM.cmake)
|
||||
CPMAddPackage(NAME mcolor
|
||||
URL https://git.redacted.cc/maxine/mcolor/archive/Release-1.zip)
|
||||
|
||||
CPMAddPackage(NAME Endianness
|
||||
URL https://git.redacted.cc/josh/Endianness/archive/Release-1.zip)
|
||||
|
||||
|
||||
target_compile_definitions(ReArchive PUBLIC ARCHIVE_PROJECT_VERSION=${ArchiveProjectVersion})
|
||||
target_compile_definitions(ReArchive PUBLIC ARCHIVE_FORMAT_VERSION=${ArchiveFormatVersion})
|
||||
@@ -39,13 +42,16 @@ target_compile_definitions(ReArchive PUBLIC ARCHIVE_FORMAT_VERSION=${ArchiveForm
|
||||
|
||||
set_target_properties(ReArchive PROPERTIES LINKER_LANGUAGE CXX)
|
||||
target_include_directories(ReArchive PUBLIC ${PROJECT_SOURCE_DIR}/include)
|
||||
target_include_directories(ReArchive PRIVATE ${Endianness_SOURCE_DIR}/include)
|
||||
target_link_libraries(ReArchive PRIVATE Endianness)
|
||||
|
||||
add_executable(rsarchive main.cpp)
|
||||
|
||||
target_compile_definitions(rsarchive PRIVATE ARCHIVE_APP_VERSION=${ArchiveAppVersion})
|
||||
|
||||
target_include_directories(rsarchive PUBLIC ${mcolor_SOURCE_DIR}/include)
|
||||
target_link_libraries(rsarchive PUBLIC ReArchive mcolor)
|
||||
target_link_libraries(rsarchive PUBLIC ReArchive)
|
||||
target_include_directories(rsarchive PRIVATE ${mcolor_SOURCE_DIR}/include)
|
||||
target_link_libraries(rsarchive PRIVATE mcolor)
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the build type" FORCE)
|
||||
|
@@ -1,139 +0,0 @@
|
||||
|
||||
#pragma once
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <bit>
|
||||
#include <concepts>
|
||||
#include <ranges>
|
||||
|
||||
namespace IntegerLiterals
|
||||
{
|
||||
using u8 = uint8_t; using ub = u8;
|
||||
using u16 = uint16_t; using us = u16;
|
||||
using u32 = uint32_t; //using ul = u32;
|
||||
using u64 = uint64_t; using ud = u64;
|
||||
|
||||
using s8 = int8_t; using sb = s8;
|
||||
using s16 = int16_t; using ss = s16;
|
||||
using s32 = int32_t; using sl = s32;
|
||||
using s64 = int64_t; using sd = s64;
|
||||
|
||||
constexpr inline u8 operator ""_u8(unsigned long long int value) { return value;}
|
||||
constexpr inline ub operator ""_ub(unsigned long long int value) { return value;}
|
||||
constexpr inline u16 operator ""_u16(unsigned long long int value) { return value;}
|
||||
constexpr inline us operator ""_us(unsigned long long int value) { return value;}
|
||||
constexpr inline u32 operator ""_u32(unsigned long long int value) { return value;}
|
||||
constexpr inline u32 operator ""_ul(unsigned long long int value) { return value;}
|
||||
constexpr inline u64 operator ""_u64(unsigned long long int value) { return value;}
|
||||
constexpr inline u64 operator ""_ud(unsigned long long int value) { return value;}
|
||||
|
||||
constexpr inline s8 operator ""_s8(long double value) { return value;}
|
||||
constexpr inline s8 operator ""_sb(long double value) { return value;}
|
||||
constexpr inline s16 operator ""_s16(long double value) { return value;}
|
||||
constexpr inline s16 operator ""_ss(long double value) { return value;}
|
||||
constexpr inline s32 operator ""_s32(long double value) { return value;}
|
||||
constexpr inline s32 operator ""_sl(long double value) { return value;}
|
||||
constexpr inline s64 operator ""_s64(long double value) { return value;}
|
||||
constexpr inline s64 operator ""_sd(long double value) { return value;}
|
||||
}
|
||||
|
||||
using namespace IntegerLiterals;
|
||||
|
||||
/// https://commandcenter.blogspot.com/2012/04/byte-order-fallacy.html
|
||||
|
||||
|
||||
/// Platform-independent functions for swapping the byte order of common data types.
|
||||
namespace Endianness
|
||||
{
|
||||
|
||||
|
||||
// TODO: It seems these can't have their implementation put into
|
||||
// a separate .cpp file else the compiler throws undefined reference
|
||||
// is it because they're constexpr?
|
||||
constexpr bool IsBigEndian() { return (std::endian::native == std::endian::big); }
|
||||
|
||||
constexpr bool IsLittleEndian() { return (std::endian::native == std::endian::little); }
|
||||
|
||||
template <typename T>
|
||||
T ReverseByteOrder(T val)
|
||||
{
|
||||
T retVal;
|
||||
char* pVal = (char*)&val;
|
||||
char* pRetVal = (char*)&retVal;
|
||||
int size = sizeof(T);
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
pRetVal[size - 1 - i] = pVal[i];
|
||||
}
|
||||
return retVal;
|
||||
|
||||
//return byteswap(val);
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
T ReverseByteOrderIfLittleEndian(T val)
|
||||
{
|
||||
if (IsLittleEndian())
|
||||
return ReverseByteOrder(val);
|
||||
else return val;
|
||||
|
||||
}
|
||||
|
||||
/// Returns the given values converted into network byte order.
|
||||
/// Generally on x86, numbers are stored in 'little-endian' order.
|
||||
/// Network order is 'big-endian'. Supposing a big-endian host machine,
|
||||
/// no conversion will take place and the original value will be returned.
|
||||
|
||||
|
||||
|
||||
u16 HostToNetworkOrder(u16 host);
|
||||
u32 HostToNetworkOrder(u32 host);
|
||||
u64 HostToNetworkOrder(u64 host);
|
||||
s16 HostToNetworkOrder(s16 host);
|
||||
s32 HostToNetworkOrder(s32 host);
|
||||
s64 HostToNetworkOrder(s64 host);
|
||||
float HostToNetworkOrder(float host);
|
||||
double HostToNetworkOrder(double host);
|
||||
|
||||
template <typename T> T HostToNetworkOrder(T host) { return HostToNetworkOrder(host);}
|
||||
|
||||
template<> inline u16 HostToNetworkOrder<u16>(u16 host) { return HostToNetworkOrder(host);}
|
||||
template<> inline u32 HostToNetworkOrder<u32>(u32 host) { return HostToNetworkOrder(host);}
|
||||
template<> inline u64 HostToNetworkOrder<u64>(u64 host) { return HostToNetworkOrder(host);}
|
||||
template<> inline s16 HostToNetworkOrder<s16>(s16 host) { return HostToNetworkOrder(host);}
|
||||
template<> inline s32 HostToNetworkOrder<s32>(s32 host) { return HostToNetworkOrder(host);}
|
||||
template<> inline s64 HostToNetworkOrder<s64>(s64 host) { return HostToNetworkOrder(host);}
|
||||
template<> inline float HostToNetworkOrder<float>(float host) { return HostToNetworkOrder(host);}
|
||||
template<> inline double HostToNetworkOrder<double>(double host) { return HostToNetworkOrder(host);}
|
||||
|
||||
/// Returns the given values converted into host-byte order.
|
||||
/// On x86, this will usually be 'little-endian'
|
||||
/// On ARM (and other RISC architectures), it is often big-endian.
|
||||
/// Supposing a big-endian host machine, no conversion will take place and the original value will be returned.
|
||||
u16 NetworkToHostOrder(u16 network);
|
||||
u32 NetworkToHostOrder(u32 network);
|
||||
u64 NetworkToHostOrder(u64 network);
|
||||
s16 NetworkToHostOrder(s16 network);
|
||||
s32 NetworkToHostOrder(s32 network);
|
||||
s64 NetworkToHostOrder(s64 network);
|
||||
float NetworkToHostOrder(float network);
|
||||
double NetworkToHostOrder(double network);
|
||||
|
||||
|
||||
template <typename T> T NetworkToHostOrder(T network) { return NetworkToHostOrder(network);}
|
||||
|
||||
template<> inline u16 NetworkToHostOrder<u16>(u16 network) { return NetworkToHostOrder(network);}
|
||||
template<> inline u32 NetworkToHostOrder<u32>(u32 network) { return NetworkToHostOrder(network);}
|
||||
template<> inline u64 NetworkToHostOrder<u64>(u64 network) { return NetworkToHostOrder(network);}
|
||||
template<> inline s16 NetworkToHostOrder<s16>(s16 network) { return NetworkToHostOrder(network);}
|
||||
template<> inline s32 NetworkToHostOrder<s32>(s32 network) { return NetworkToHostOrder(network);}
|
||||
template<> inline s64 NetworkToHostOrder<s64>(s64 network) { return NetworkToHostOrder(network);}
|
||||
template<> inline float NetworkToHostOrder<float>(float network) { return NetworkToHostOrder(network);}
|
||||
template<> inline double NetworkToHostOrder<double>(double network) { return NetworkToHostOrder(network);}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@@ -3,7 +3,7 @@
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <ReArchive/Endianness.h>
|
||||
#include <Endianness.hpp>
|
||||
|
||||
|
||||
namespace ReArchive {
|
||||
|
@@ -1,59 +0,0 @@
|
||||
#ifdef WIN32
|
||||
#pragma comment(lib, "Ws2_32.lib")
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <winsock.h>
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
#include <socket.h>
|
||||
#endif
|
||||
|
||||
#include <ReArchive/Endianness.h>
|
||||
|
||||
namespace Endianness
|
||||
{
|
||||
|
||||
// TODO: Manually swap bytes so we can depend less on clunky include directives.
|
||||
u16 HostToNetworkOrder(u16 host) { return htons(host); }
|
||||
u16 NetworkToHostOrder(u16 network) { return ntohs(network); }
|
||||
s16 HostToNetworkOrder(s16 host) { return htons( host); }
|
||||
s16 NetworkToHostOrder(s16 network) { return ntohs(network);}
|
||||
u32 HostToNetworkOrder(u32 host) { return htonl(host); }
|
||||
u32 NetworkToHostOrder(u32 network) { return ntohl(network); }
|
||||
s32 HostToNetworkOrder(s32 host) { return htonl(host);}
|
||||
s32 NetworkToHostOrder(s32 network) { return ntohl(network);}
|
||||
u64 HostToNetworkOrder(u64 host) { return ReverseByteOrderIfLittleEndian(host); }
|
||||
u64 NetworkToHostOrder(u64 network) { return ReverseByteOrderIfLittleEndian(network); }
|
||||
s64 HostToNetworkOrder(s64 host) { return ReverseByteOrderIfLittleEndian(host); }
|
||||
s64 NetworkToHostOrder(s64 network) { return ReverseByteOrderIfLittleEndian(network); }
|
||||
|
||||
|
||||
float HostToNetworkOrder(float host) {
|
||||
if (IsLittleEndian())
|
||||
return ReverseByteOrder(host);
|
||||
else
|
||||
return host;
|
||||
}
|
||||
|
||||
float NetworkToHostOrder(float network) {
|
||||
if (IsLittleEndian())
|
||||
return ReverseByteOrder(network);
|
||||
else
|
||||
return network;
|
||||
}
|
||||
|
||||
double HostToNetworkOrder(double host) {
|
||||
if (IsLittleEndian())
|
||||
return ReverseByteOrder(host);
|
||||
else
|
||||
return host;
|
||||
}
|
||||
|
||||
double NetworkToHostOrder(double network) {
|
||||
if (IsLittleEndian())
|
||||
return ReverseByteOrder(network);
|
||||
else
|
||||
return network;
|
||||
}
|
||||
}
|
@@ -5,7 +5,7 @@
|
||||
#include <ReArchive/types/FileTable.h>
|
||||
#include <ReArchive/types/FileEntry.h>
|
||||
#include <cassert>
|
||||
#include <ReArchive/Endianness.h>
|
||||
#include <Endianness.hpp>
|
||||
|
||||
using ReArchive::Header;
|
||||
using ReArchive::FileTable;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include <ReArchive/types/FileEntry.h>
|
||||
#include <cstring>
|
||||
#include <ReArchive/Endianness.h>
|
||||
#include <Endianness.hpp>
|
||||
|
||||
|
||||
using namespace ReArchive;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include <ReArchive/types/FileTable.h>
|
||||
#include <cstring>
|
||||
#include <ReArchive/Endianness.h>
|
||||
#include <Endianness.hpp>
|
||||
|
||||
using namespace ReArchive;
|
||||
|
||||
|
Reference in New Issue
Block a user