extends table


var FILES_EXCLUDE_NAMES      = ['.', '..']
var FILES_HEADERS_TEXT       = ['Имя файла',                  'Размер',                     'Дата'                       ]
var FILES_COLUMN_WIDTHS      = [ 400,                          150,                          250                         ]
var FILES_HEADERS_ALIGNMENT  = [ HORIZONTAL_ALIGNMENT_CENTER,  HORIZONTAL_ALIGNMENT_CENTER,  HORIZONTAL_ALIGNMENT_CENTER ]
var FILES_ROWS_ALIGNMENT     = [ HORIZONTAL_ALIGNMENT_LEFT,    HORIZONTAL_ALIGNMENT_RIGHT,   HORIZONTAL_ALIGNMENT_CENTER ]


func fill_files_table(tbl: table, folder: String, rows_types: Array):
    var dir: = DirAccess.open(folder)
    if dir == null:
        return
    var files: = []
    var exclude_names: = ['.', '..']
    dir.list_dir_begin() # TODO: GODOT4 fill missing arguments https://github.com/godotengine/godot/pull/40547
    while true:
        var file: = dir.get_next()
        if file == '':
            break
        if file in exclude_names:
            continue
        var file_name = folder + '/' + file
        var fd = FileAccess.open(file_name, FileAccess.READ)
        if not fd:
            continue
        var glob_path = ProjectSettings.globalize_path(file_name)
        var sz = fd.get_length()
        var ut = fd.get_modified_time(file_name)
        fd.close()
        var mt = Time.get_datetime_dict_from_unix_time(ut)
        var file_row = [file, '%d' % sz, '%d-%02d-%02d %02d:%02d' % [mt.year, mt.month, mt.day, mt.hour, mt.minute]]
        tbl.add_row(rows_types)
        var i_row: int = tbl.get_rows_count() - 1
        tbl.set_row_text(i_row, file_row)
        tbl.set_node_meta(0, i_row, 'file_path', glob_path)
    dir.list_dir_end()
