Browse Source

Fix warnings in MpqWriter

pull/6878/head
obligaron 2 years ago committed by Anders Jenbo
parent
commit
780015bfd4
  1. 10
      Source/mpq/mpq_writer.cpp
  2. 4
      Source/mpq/mpq_writer.hpp

10
Source/mpq/mpq_writer.cpp

@ -97,11 +97,13 @@ MpqWriter::MpqWriter(const char *path)
const char *mode = "wb";
if (exists) {
mode = "r+b";
if (!GetFileSize(path, &size_)) {
std::uintmax_t fileSize;
if (!GetFileSize(path, &fileSize)) {
error = R"(GetFileSize failed: "{}")";
LogError(error, path, std::strerror(errno));
goto on_error;
}
size_ = static_cast<uint32_t>(fileSize);
LogVerbose("GetFileSize(\"{}\") = {}", path, size_);
}
if (!stream_.Open(path, mode)) {
@ -360,7 +362,7 @@ MpqBlockEntry *MpqWriter::AddFile(std::string_view filename, MpqBlockEntry *bloc
return block;
}
bool MpqWriter::WriteFileContents(const std::byte *fileData, size_t fileSize, MpqBlockEntry *block)
bool MpqWriter::WriteFileContents(const std::byte *fileData, uint32_t fileSize, MpqBlockEntry *block)
{
const uint32_t numSectors = (fileSize + (BlockSize - 1)) / BlockSize;
const uint32_t offsetTableByteSize = sizeof(uint32_t) * (numSectors + 1);
@ -442,7 +444,7 @@ bool MpqWriter::WriteHeader()
memset(&fhdr, 0, sizeof(fhdr));
fhdr.signature = MpqFileHeader::DiabloSignature;
fhdr.headerSize = MpqFileHeader::DiabloSize;
fhdr.fileSize = static_cast<uint32_t>(size_);
fhdr.fileSize = size_;
fhdr.version = 0;
fhdr.blockSizeFactor = BlockSizeFactor;
fhdr.hashEntriesOffset = MpqHashEntryOffset;
@ -501,7 +503,7 @@ bool MpqWriter::WriteFile(std::string_view filename, const std::byte *data, size
RemoveHashEntry(filename);
blockEntry = AddFile(filename, nullptr, 0);
if (!WriteFileContents(data, size, blockEntry)) {
if (!WriteFileContents(data, static_cast<uint32_t>(size), blockEntry)) {
RemoveHashEntry(filename);
return false;
}

4
Source/mpq/mpq_writer.hpp

@ -38,7 +38,7 @@ private:
bool ReadMPQHeader(MpqFileHeader *hdr);
MpqBlockEntry *AddFile(std::string_view filename, MpqBlockEntry *block, uint32_t blockIndex);
bool WriteFileContents(const std::byte *fileData, size_t fileSize, MpqBlockEntry *block);
bool WriteFileContents(const std::byte *fileData, uint32_t fileSize, MpqBlockEntry *block);
// Returns an unused entry in the block entry table.
MpqBlockEntry *NewBlock(uint32_t *blockIndex = nullptr);
@ -57,7 +57,7 @@ private:
LoggedFStream stream_;
std::string name_;
std::uintmax_t size_ {};
uint32_t size_ {};
std::unique_ptr<MpqHashEntry[]> hashTable_;
std::unique_ptr<MpqBlockEntry[]> blockTable_;

Loading…
Cancel
Save