Archived
1
Fork 0
This repository has been archived on 2025-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
libxiv/src/exhparser.cpp

48 lines
1.3 KiB
C++
Raw Normal View History

2022-03-16 00:02:07 -04:00
#include "exhparser.h"
#include "utility.h"
#include <cstdio>
#include <stdexcept>
#include <vector>
#include <algorithm>
2022-04-10 18:08:07 -04:00
#include <string>
2022-03-16 00:02:07 -04:00
EXH readEXH(const std::string_view path) {
EXH exh;
FILE* file = fopen(path.data(), "rb");
if(file == nullptr) {
throw std::runtime_error("Failed to open exh file " + std::string(path));
}
fread(&exh.header, sizeof(ExhHeader), 1, file);
endianSwap(&exh.header.dataOffset);
endianSwap(&exh.header.columnCount);
endianSwap(&exh.header.pageCount);
endianSwap(&exh.header.languageCount);
endianSwap(&exh.header.rowCount);
exh.columnDefinitions.resize(exh.header.columnCount);
fread(exh.columnDefinitions.data(), sizeof(ExcelColumnDefinition) * exh.header.columnCount, 1, file);
exh.pages.resize(exh.header.pageCount);
fread(exh.pages.data(), sizeof(ExcelDataPagination) * exh.header.pageCount, 1, file);
exh.language.resize(exh.header.languageCount);
fread(exh.language.data(), sizeof(Language) * exh.header.languageCount, 1, file);
for(auto& columnDef : exh.columnDefinitions) {
endianSwap(&columnDef.offset);
endianSwap(&columnDef.type);
}
for(auto& page : exh.pages) {
endianSwap(&page.rowCount);
endianSwap(&page.startId);
}
return exh;
}