From dfc252666ebcc6e7100c4aa5d8f77160a0f16535 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 10 Mar 2024 08:46:49 +0100 Subject: [PATCH] Base: Implement FileInfo::size() --- src/Base/FileInfo.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Base/FileInfo.cpp b/src/Base/FileInfo.cpp index ee70cb4f9a..526300f671 100644 --- a/src/Base/FileInfo.cpp +++ b/src/Base/FileInfo.cpp @@ -451,9 +451,26 @@ bool FileInfo::isDir() const unsigned int FileInfo::size() const { - // not implemented - assert(0); - return 0; + unsigned int bytes {}; + if (exists()) { + +#if defined(FC_OS_WIN32) + std::wstring wstr = toStdWString(); + struct _stat st; + if (_wstat(wstr.c_str(), &st) == 0) { + bytes = st.st_size; + } + +#elif defined(FC_OS_LINUX) || defined(FC_OS_CYGWIN) || defined(FC_OS_MACOSX) || defined(FC_OS_BSD) + struct stat st + { + }; + if (stat(FileName.c_str(), &st) == 0) { + bytes = st.st_size; + } +#endif + } + return bytes; } TimeInfo FileInfo::lastModified() const