Use boost instead of fstat.

This commit is contained in:
Maeyanie
2025-09-09 07:55:49 -04:00
parent 91df961287
commit 0896a9e686

View File

@@ -1,7 +1,6 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include <cstring> #include <cstring>
#include <sys/stat.h>
#include <draco/compression/decode.h> #include <draco/compression/decode.h>
#include <draco/io/mesh_io.h> #include <draco/io/mesh_io.h>
@@ -22,18 +21,15 @@ namespace Slic3r {
bool load_drc(const char *path, TriangleMesh *meshptr) bool load_drc(const char *path, TriangleMesh *meshptr)
{ {
struct stat st; size_t size = boost::filesystem::file_size(path);
if (stat(path, &st)) {
return false;
}
FILE *fp = fopen(path, "rb"); FILE *fp = boost::nowide::fopen(path, "rb");
if (fp == nullptr) { if (fp == nullptr) {
return false; return false;
} }
char *data = new char[st.st_size]; char *data = new char[size];
if (fread(data, 1, st.st_size, fp) != st.st_size) { if (fread(data, 1, size, fp) != size) {
fclose(fp); fclose(fp);
delete[] data; delete[] data;
return false; return false;
@@ -41,7 +37,7 @@ bool load_drc(const char *path, TriangleMesh *meshptr)
fclose(fp); fclose(fp);
DecoderBuffer buffer; DecoderBuffer buffer;
buffer.Init(data, st.st_size); buffer.Init(data, size);
auto geotype = Decoder::GetEncodedGeometryType(&buffer); auto geotype = Decoder::GetEncodedGeometryType(&buffer);
if ((!geotype.ok()) || geotype.value() != TRIANGULAR_MESH) { if ((!geotype.ok()) || geotype.value() != TRIANGULAR_MESH) {