feat: files app - render modified dates in Properties dialog

This commit is contained in:
2026-07-21 14:44:44 +02:00
parent de7edaf623
commit e9d8c66ff5
5 changed files with 81 additions and 16 deletions
@@ -30,6 +30,9 @@ bool filemanager_ensure_entry_capacity(FileManagerState* fm, int needed) {
uint64_t* sizes = (uint64_t*)montauk::realloc(fm->entry_sizes, (uint64_t)new_cap * sizeof(uint64_t));
if (!sizes) return false;
fm->entry_sizes = sizes;
int64_t* mtimes = (int64_t*)montauk::realloc(fm->entry_mtimes, (uint64_t)new_cap * sizeof(int64_t));
if (!mtimes) return false;
fm->entry_mtimes = mtimes;
bool* isdir = (bool*)montauk::realloc(fm->is_dir, (uint64_t)new_cap * sizeof(bool));
if (!isdir) return false;
fm->is_dir = isdir;
@@ -81,6 +84,7 @@ void filemanager_free_arrays(FileManagerState* fm) {
montauk::mfree(fm->entry_names); fm->entry_names = nullptr;
montauk::mfree(fm->entry_types); fm->entry_types = nullptr;
montauk::mfree(fm->entry_sizes); fm->entry_sizes = nullptr;
montauk::mfree(fm->entry_mtimes); fm->entry_mtimes = nullptr;
montauk::mfree(fm->is_dir); fm->is_dir = nullptr;
montauk::mfree(fm->drive_indices); fm->drive_indices = nullptr;
montauk::mfree(fm->drive_kinds); fm->drive_kinds = nullptr;
@@ -125,6 +129,7 @@ static void filemanager_add_root_entry(FileManagerState* fm,
montauk::strncpy(fm->entry_names[idx], name, 63);
fm->entry_types[idx] = type;
fm->entry_sizes[idx] = 0;
fm->entry_mtimes[idx] = 0;
fm->is_dir[idx] = true;
fm->drive_indices[idx] = drive_index;
fm->drive_kinds[idx] = 0;
@@ -143,6 +148,7 @@ static int filemanager_add_virtual_entry(FileManagerState* fm,
montauk::strncpy(fm->entry_names[idx], name, 63);
fm->entry_types[idx] = FM_ENTRY_VIRTUAL_APP;
fm->entry_sizes[idx] = 0;
fm->entry_mtimes[idx] = 0;
fm->is_dir[idx] = false;
fm->drive_indices[idx] = -1;
filemanager_reset_virtual_entry(&fm->virtual_entries[idx]);
@@ -322,21 +328,22 @@ void filemanager_read_dir(FileManagerState* fm) {
fm->entry_types[i] = detect_file_type(fm->entry_names[i], fm->is_dir[i]);
// Get file size (64-bit: no truncation for files >= 2 GiB)
// Fetch size + modified time in one stat call (works for files and
// directories). Filesystems without stat support leave both 0.
fm->entry_sizes[i] = 0;
if (!fm->is_dir[i]) {
char fullpath[512];
montauk::strcpy(fullpath, fm->current_path);
int plen = montauk::slen(fullpath);
if (plen > 0 && fullpath[plen - 1] != '/') {
str_append(fullpath, "/", 512);
}
str_append(fullpath, fm->entry_names[i], 512);
int fd = montauk::open(fullpath);
if (fd >= 0) {
fm->entry_sizes[i] = montauk::getsize(fd);
montauk::close(fd);
}
fm->entry_mtimes[i] = 0;
char fullpath[512];
montauk::strcpy(fullpath, fm->current_path);
int plen = montauk::slen(fullpath);
if (plen > 0 && fullpath[plen - 1] != '/') {
str_append(fullpath, "/", 512);
}
str_append(fullpath, fm->entry_names[i], 512);
montauk::abi::FileStat stt;
if (montauk::stat(fullpath, &stt) == 0) {
if (!fm->is_dir[i]) fm->entry_sizes[i] = stt.size;
fm->entry_mtimes[i] = stt.mtime;
}
}
@@ -349,6 +356,7 @@ void filemanager_read_dir(FileManagerState* fm) {
char tmp_name[128];
int tmp_type = fm->entry_types[i];
uint64_t tmp_size = fm->entry_sizes[i];
int64_t tmp_mtime = fm->entry_mtimes[i];
bool tmp_isdir = fm->is_dir[i];
montauk::strcpy(tmp_name, fm->entry_names[i]);
@@ -367,12 +375,14 @@ void filemanager_read_dir(FileManagerState* fm) {
montauk::strcpy(fm->entry_names[j + 1], fm->entry_names[j]);
fm->entry_types[j + 1] = fm->entry_types[j];
fm->entry_sizes[j + 1] = fm->entry_sizes[j];
fm->entry_mtimes[j + 1] = fm->entry_mtimes[j];
fm->is_dir[j + 1] = fm->is_dir[j];
j--;
}
montauk::strcpy(fm->entry_names[j + 1], tmp_name);
fm->entry_types[j + 1] = tmp_type;
fm->entry_sizes[j + 1] = tmp_size;
fm->entry_mtimes[j + 1] = tmp_mtime;
fm->is_dir[j + 1] = tmp_isdir;
}