*: "Support" MSVC

For Windows builds of EuropaTools. For now I'm using MSVC since clang completely barfs.
This commit is contained in:
Lily Tsuru 2025-01-17 20:25:34 -05:00
parent 6faa960753
commit f5d03cfdeb
6 changed files with 38 additions and 5 deletions

View file

@ -13,5 +13,6 @@
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
include(CompilerFlags-GNU) include(CompilerFlags-GNU)
else() else()
message(FATAL_ERROR "Unsupported (for now?) compiler ${CMAKE_CXX_COMPILER_ID}") message(WARNING "Unsupported (for now?) compiler ${CMAKE_CXX_COMPILER_ID}. Configuration will continue,"
"however this configuration may break at any time.")
endif() endif()

View file

@ -25,6 +25,11 @@ namespace europa::structs {
Ver5 = 0x5 Ver5 = 0x5
}; };
#ifdef _MSC_VER
#pragma pack(push, 1)
#endif
struct [[gnu::packed]] PakHeader_Common { struct [[gnu::packed]] PakHeader_Common {
char magic[16]; // "Europa Packfile\0" char magic[16]; // "Europa Packfile\0"
@ -99,6 +104,7 @@ namespace europa::structs {
u32 reservedPad {}; u32 reservedPad {};
}; };
struct [[gnu::packed]] PakHeader_V4 : public PakHeader_Impl<PakHeader_V4, PakVersion::Ver4> { struct [[gnu::packed]] PakHeader_V4 : public PakHeader_Impl<PakHeader_V4, PakVersion::Ver4> {
using PakHeader_Impl<PakHeader_V4, PakVersion::Ver4>::PakHeader_Impl; using PakHeader_Impl<PakHeader_V4, PakVersion::Ver4>::PakHeader_Impl;
@ -162,6 +168,11 @@ namespace europa::structs {
u8 pad2; u8 pad2;
}; };
#ifdef _MSC_VER
#pragma pack(pop)
#endif
using PakHeaderVariant = std::variant< using PakHeaderVariant = std::variant<
structs::PakHeader_V3, structs::PakHeader_V3,
structs::PakHeader_V4, structs::PakHeader_V4,

View file

@ -15,6 +15,10 @@
namespace europa::structs { namespace europa::structs {
#ifdef _MSC_VER
#pragma pack(push, 1)
#endif
struct [[gnu::packed]] YatfHeader { struct [[gnu::packed]] YatfHeader {
enum class TextureFormat : u8 { enum class TextureFormat : u8 {
// V1 formats. // V1 formats.
@ -52,6 +56,10 @@ namespace europa::structs {
} }
}; };
#ifdef _MSC_VER
#pragma pack(pop)
#endif
} // namespace europa::structs } // namespace europa::structs
#endif // EUROPA_STRUCTS_YATF_H #endif // EUROPA_STRUCTS_YATF_H

View file

@ -86,14 +86,14 @@ namespace europa::io::pak {
// Update the offset to where we currently are, since we will be writing the file there // Update the offset to where we currently are, since we will be writing the file there
file.VisitTocEntry([&](auto& tocEntry) { file.VisitTocEntry([&](auto& tocEntry) {
tocEntry.offset = os.tellp(); tocEntry.offset = static_cast<std::uint32_t>(os.tellp());
}); });
// For sector alignment. // For sector alignment.
if constexpr(THeader::VERSION == structs::PakVersion::Ver5) { if constexpr(THeader::VERSION == structs::PakVersion::Ver5) {
if(sectorAlignment == SectorAlignment::Align) { if(sectorAlignment == SectorAlignment::Align) {
auto& toc = file.GetTOCEntry<structs::PakHeader_V5::TocEntry_SectorAligned>(); auto& toc = file.GetTOCEntry<structs::PakHeader_V5::TocEntry_SectorAligned>();
toc.startLBA = (os.tellp() / util::kCDSectorSize); toc.startLBA = static_cast<std::uint32_t>((os.tellp() / util::kCDSectorSize));
} }
} }
@ -132,7 +132,7 @@ namespace europa::io::pak {
filename }); filename });
} }
pakHeader.tocOffset = os.tellp(); pakHeader.tocOffset = static_cast<std::uint32_t>(os.tellp());
sink.OnEvent({ WriterProgressReportSink::PakEvent::EventCode::WritingToc }); sink.OnEvent({ WriterProgressReportSink::PakEvent::EventCode::WritingToc });
@ -156,7 +156,7 @@ namespace europa::io::pak {
sink.OnEvent({ WriterProgressReportSink::PakEvent::EventCode::FillInHeader }); sink.OnEvent({ WriterProgressReportSink::PakEvent::EventCode::FillInHeader });
// Fill out the rest of the header. // Fill out the rest of the header.
pakHeader.fileCount = sortedFiles.size(); pakHeader.fileCount = static_cast<std::uint32_t>(sortedFiles.size());
pakHeader.tocSize = static_cast<std::uint32_t>(os.tellp()) - (pakHeader.tocOffset - 1); pakHeader.tocSize = static_cast<std::uint32_t>(os.tellp()) - (pakHeader.tocOffset - 1);
// Timestamp. // Timestamp.

View file

@ -246,10 +246,15 @@ namespace eupak {
// Setup other stuff like modtime // Setup other stuff like modtime
file.VisitTocEntry([&](auto& tocEntry) { file.VisitTocEntry([&](auto& tocEntry) {
#ifdef _WIN32
auto seconds = std::chrono::time_point_cast<std::chrono::seconds>(lastModified);
tocEntry.creationUnixTime = static_cast<std::uint32_t>(seconds.time_since_epoch().count());
#else
// Kinda stupid but works // Kinda stupid but works
auto sys = std::chrono::file_clock::to_sys(lastModified); auto sys = std::chrono::file_clock::to_sys(lastModified);
auto seconds = std::chrono::time_point_cast<std::chrono::seconds>(sys); auto seconds = std::chrono::time_point_cast<std::chrono::seconds>(sys);
tocEntry.creationUnixTime = static_cast<std::uint32_t>(seconds.time_since_epoch().count()); tocEntry.creationUnixTime = static_cast<std::uint32_t>(seconds.time_since_epoch().count());
#endif
}); });
files.emplace_back(std::make_pair(relativePathName, std::move(file))); files.emplace_back(std::make_pair(relativePathName, std::move(file)));

View file

@ -48,7 +48,15 @@ namespace eupak {
char buf[1024]{}; char buf[1024]{};
tm tmObject{}; tm tmObject{};
#ifdef _MSC_VER
// All I will choose to say is: Why didn't Microsoft
// just implement _r versions. This is nearly exactly
// the same as those! ... This is why I hate cross-platform
// software development sometimes
localtime_s(&tmObject, &time);
#else
localtime_r(&time, &tmObject); localtime_r(&time, &tmObject);
#endif
auto count = std::strftime(&buf[0], sizeof(buf), format.data(), &tmObject); auto count = std::strftime(&buf[0], sizeof(buf), format.data(), &tmObject);