From c38336b3a197de505761fb52390678c262b506df Mon Sep 17 00:00:00 2001 From: Nishi Date: Sat, 14 Sep 2024 16:25:08 +0000 Subject: [PATCH] show size git-svn-id: file:///raid/svn-personal/tewi/trunk@28 8739d7e6-ffea-ec47-b151-bdff447c6205 --- Server/server.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Server/server.c b/Server/server.c index 0ce6d38..b885aab 100644 --- a/Server/server.c +++ b/Server/server.c @@ -482,9 +482,30 @@ void tw_server_pass(int sock, bool ssl, int port, SOCKADDR addr) { addstring(&str, " \n"); addstring(&str, " \n"); addstring(&str, " Filename\n"); + addstring(&str, " MIME\n"); + addstring(&str, " Size\n"); addstring(&str, " \n"); if(items != NULL) { for(i = 0; items[i] != NULL; i++) { + char* fpth = cm_strcat3(path, "/", items[i]); + struct stat s; + char size[512]; + size[0] = 0; + stat(fpth, &s); + if(s.st_size < 1024ULL){ + sprintf(size, "%d", s.st_size); + }else if(s.st_size < 1024ULL * 1024){ + sprintf(size, "%.1f K", (double)s.st_size / 1024); + }else if(s.st_size < 1024ULL * 1024 * 1024){ + sprintf(size, "%.1f M", (double)s.st_size / 1024 / 1024); + }else if(s.st_size < 1024ULL * 1024 * 1024 * 1024){ + sprintf(size, "%.1f G", (double)s.st_size / 1024 / 1024 / 1024); + }else if(s.st_size < 1024ULL * 1024 * 1024 * 1024 * 1024){ + sprintf(size, "%.1f T", (double)s.st_size / 1024 / 1024 / 1024 / 1024); + } + + free(fpth); + char* ext = NULL; int j; for(j = strlen(items[i]) - 1; j >= 0; j--) { @@ -495,11 +516,14 @@ void tw_server_pass(int sock, bool ssl, int port, SOCKADDR addr) { break; } } + char* showmime = ""; char* mime = tw_get_mime(ext, vhost_entry); if(strcmp(items[i], "../") == 0) { mime = "misc/parent"; } else if(items[i][strlen(items[i]) - 1] == '/') { mime = "misc/dir"; + }else{ + showmime = mime; } char* icon = tw_get_icon(mime, vhost_entry); if(ext != NULL) free(ext); @@ -521,6 +545,8 @@ void tw_server_pass(int sock, bool ssl, int port, SOCKADDR addr) { addstring(&str, "\n"); addstring(&str, " \"icon\"\n", icon); addstring(&str, " %h\n", items[i], itm); + addstring(&str, " %h\n", showmime); + addstring(&str, " %s\n", size); addstring(&str, "\n"); free(itm); } -- 2.43.0