Skip to content

Commit 9ba8a3f

Browse files
committed
[FIX] : size and date was not retrieved for file pata name with non utf8 chars (#202)
[ADD] : add a new method in IFileSystem interface for retrieve file size and date (#202)
1 parent 796617a commit 9ba8a3f

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

FileSystemBoost.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,26 @@ class FileSystemBoost : public IGFD::IFileSystem {
171171
bool IsDirectory(const std::string& vFilePathName) override {
172172
return fs::is_directory(vFilePathName);
173173
}
174+
void GetFileDateAndSize(const std::string& vFilePathName, const IGFD::FileType& vFileType, std::string& voDate, size_t& voSize) override {
175+
namespace fs = boost::filesystem;
176+
fs::path fpath(vFilePathName);
177+
// date
178+
size_t len{};
179+
std::time_t cftime = fs::last_write_time(fpath);
180+
static char timebuf[100];
181+
if (std::strftime(timebuf, sizeof(timebuf), DateTimeFormat, std::localtime(&cftime))) {
182+
voDate.assign(timebuf);
183+
}
184+
// size
185+
if (!vFileType.isDir()) {
186+
try {
187+
voSize = static_cast<size_t>(fs::file_size(fpath));
188+
}
189+
catch (const fs::filesystem_error&) {
190+
voSize = 0; // fallback en cas d'erreur
191+
}
192+
}
193+
}
174194
};
175195

176196
#define FILE_SYSTEM_OVERRIDE FileSystemBoost

samples/unicode/chinese_Ä║.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent egestas ut dui id feugiat.
2+
Maecenas blandit, nisl et porta tincidunt, erat risus ultricies lectus, et tincidunt dolor risus quis enim.
3+
Maecenas urna leo, cursus id dolor quis, molestie pulvinar diam. Vivamus scelerisque nibh sit amet lacus ornare rutrum eget non ligula.
4+
Vestibulum tempor libero ipsum. Proin velit mauris, faucibus eu bibendum eu, fringilla id nulla.
5+
Vivamus id lectus orci. Nam vitae sagittis ipsum.

src/gui/DemoDialog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,8 @@ void DemoDialog::display(const ImVec4& vDisplayRect) {
729729
fileSize.second.c_str(), //
730730
(vFileInfosPtr->fileNameLevels[0] + ".bin").c_str(), //
731731
statInfosSize.first.c_str(), //
732-
statInfosSize.second.c_str()); //
733-
vFileInfosPtr->tooltipColumn = 2; // size column
732+
statInfosSize.second.c_str());
733+
vFileInfosPtr->tooltipColumn = 2; // size column
734734
vFileInfosPtr->fileSize += (size_t)statInfos.st_size;
735735
} else {
736736
// no bin, so escaped.

0 commit comments

Comments
 (0)