Commit 939d7e6e authored by Rob Swindell's avatar Rob Swindell 💬
Browse files

Add options to sort directories by file size (ascending or descending)

Size is indexed, so might as well sort by it. This does have an issue with files >= 4GB in length however, so I'm looking at that next.
parent 8fe69227
Pipeline #2911 failed with stage
in 9 minutes and 36 seconds
......@@ -305,6 +305,22 @@ static int file_compare_date_d(const void* v1, const void* v2)
return f2->hdr.when_imported.time - f1->hdr.when_imported.time;
}
static int file_compare_size_a(const void* v1, const void* v2)
{
file_t* f1 = (file_t*)v1;
file_t* f2 = (file_t*)v2;
return f1->idx.size - f2->idx.size;
}
static int file_compare_size_d(const void* v1, const void* v2)
{
file_t* f1 = (file_t*)v1;
file_t* f2 = (file_t*)v2;
return f2->idx.size - f1->idx.size;
}
void sortfiles(file_t* filelist, size_t count, enum file_sort order)
{
switch(order) {
......@@ -326,6 +342,12 @@ void sortfiles(file_t* filelist, size_t count, enum file_sort order)
case FILE_SORT_DATE_D:
qsort(filelist, count, sizeof(*filelist), file_compare_date_d);
break;
case FILE_SORT_SIZE_A:
qsort(filelist, count, sizeof(*filelist), file_compare_size_a);
break;
case FILE_SORT_SIZE_D:
qsort(filelist, count, sizeof(*filelist), file_compare_size_d);
break;
}
}
......
......@@ -1911,6 +1911,10 @@ JSObject* js_CreateFileBaseClass(JSContext* cx, JSObject* parent, scfg_t* cfg)
, JSPROP_PERMANENT|JSPROP_ENUMERATE|JSPROP_READONLY);
JS_DefineProperty(cx, sort, "DATE_D", INT_TO_JSVAL(FILE_SORT_DATE_D), NULL, NULL
, JSPROP_PERMANENT|JSPROP_ENUMERATE|JSPROP_READONLY);
JS_DefineProperty(cx, sort, "SIZE_A", INT_TO_JSVAL(FILE_SORT_SIZE_A), NULL, NULL
, JSPROP_PERMANENT|JSPROP_ENUMERATE|JSPROP_READONLY);
JS_DefineProperty(cx, sort, "SIZE_D", INT_TO_JSVAL(FILE_SORT_SIZE_D), NULL, NULL
, JSPROP_PERMANENT|JSPROP_ENUMERATE|JSPROP_READONLY);
#ifdef BUILD_JSDOCS
js_DescribeSyncObject(cx, sort, "Sort order numeric constants", 0);
js_CreateArrayOfStrings(cx, sort, "_property_desc_list", filebase_sort_prop_desc, JSPROP_READONLY);
......
......@@ -296,6 +296,8 @@ enum file_sort { /* Values for dir[x].sort */
,FILE_SORT_NAME_DC = 5 /* Sort by filename, descending (case-sensitive) */
,FILE_SORT_DATE_A = 2 /* Sort by upload date, ascending */
,FILE_SORT_DATE_D = 3 /* Sort by upload date, descending */
,FILE_SORT_SIZE_A = 6 /* Sort by file size, ascending */
,FILE_SORT_SIZE_D = 7 /* Sort by file size, descending */
,FILE_SORT_NATURAL = FILE_SORT_DATE_A
};
......
......@@ -31,6 +31,8 @@ char* file_sort_desc[] = {
"Date Descending",
"Name Ascending (case-sensitive)",
"Name Descending (case-sensitive)",
"Size Ascending",
"Size Descending",
NULL
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment