Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/intern/BLI_filelist.c
| Show First 20 Lines • Show All 255 Lines • ▼ Show 20 Lines | unsigned int BLI_filelist_dir_contents(const char *dirname, struct direntry **r_filelist) | ||||
| return dir_ctx.nrfiles; | return dir_ctx.nrfiles; | ||||
| } | } | ||||
| /** | /** | ||||
| * Convert given entry's size into human-readable strings. | * Convert given entry's size into human-readable strings. | ||||
| */ | */ | ||||
| void BLI_filelist_entry_size_to_string(const struct stat *st, | void BLI_filelist_entry_size_to_string(const struct stat *st, | ||||
| const uint64_t sz, | const uint64_t sz, | ||||
| const bool compact, | /* Used to change MB -> M, etc. - is that really useful? */ | ||||
| const bool UNUSED(compact), | |||||
| char r_size[FILELIST_DIRENTRY_SIZE_LEN]) | char r_size[FILELIST_DIRENTRY_SIZE_LEN]) | ||||
| { | { | ||||
| double size; | |||||
| const char *fmt; | |||||
| const char *units[] = {"KiB", "MiB", "GiB", "TiB", NULL}; | |||||
| const char *units_compact[] = {"K", "M", "G", "T", NULL}; | |||||
| const char *unit = "B"; | |||||
| /* | /* | ||||
| * Seems st_size is signed 32-bit value in *nix and Windows. This | * Seems st_size is signed 32-bit value in *nix and Windows. This | ||||
| * will buy us some time until files get bigger than 4GB or until | * will buy us some time until files get bigger than 4GB or until | ||||
| * everyone starts using __USE_FILE_OFFSET64 or equivalent. | * everyone starts using __USE_FILE_OFFSET64 or equivalent. | ||||
| */ | */ | ||||
| size = (double)(st ? st->st_size : sz); | double size = (double)(st ? st->st_size : sz); | ||||
| BLI_str_format_byte_unit(r_size, size, true); | |||||
| if (size > 1024.0) { | |||||
| const char **u; | |||||
| for (u = compact ? units_compact : units, size /= 1024.0; size > 1024.0 && *(u + 1); | |||||
| u++, size /= 1024.0) { | |||||
| /* pass */ | |||||
| } | |||||
| fmt = size > 100.0 ? "%.0f %s" : (size > 10.0 ? "%.1f %s" : "%.2f %s"); | |||||
| unit = *u; | |||||
| } | |||||
| else { | |||||
| fmt = "%.0f %s"; | |||||
| } | |||||
| BLI_snprintf(r_size, sizeof(*r_size) * FILELIST_DIRENTRY_SIZE_LEN, fmt, size, unit); | |||||
| } | } | ||||
| /** | /** | ||||
| * Convert given entry's modes into human-readable strings. | * Convert given entry's modes into human-readable strings. | ||||
| */ | */ | ||||
| void BLI_filelist_entry_mode_to_string(const struct stat *st, | void BLI_filelist_entry_mode_to_string(const struct stat *st, | ||||
| const bool UNUSED(compact), | const bool UNUSED(compact), | ||||
| char r_mode1[FILELIST_DIRENTRY_MODE_LEN], | char r_mode1[FILELIST_DIRENTRY_MODE_LEN], | ||||
| ▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | #else | ||||
| else { | else { | ||||
| BLI_snprintf(r_owner, sizeof(*r_owner) * FILELIST_DIRENTRY_OWNER_LEN, "%u", st->st_uid); | BLI_snprintf(r_owner, sizeof(*r_owner) * FILELIST_DIRENTRY_OWNER_LEN, "%u", st->st_uid); | ||||
| } | } | ||||
| #endif | #endif | ||||
| } | } | ||||
| /** | /** | ||||
| * Convert given entry's time into human-readable strings. | * Convert given entry's time into human-readable strings. | ||||
| * | |||||
| * \param r_is_today: optional, returns true if the date matches today's. | |||||
| * \param r_is_yesterday: optional, returns true if the date matches yesterday's. | |||||
| */ | */ | ||||
| void BLI_filelist_entry_datetime_to_string(const struct stat *st, | void BLI_filelist_entry_datetime_to_string(const struct stat *st, | ||||
| const int64_t ts, | const int64_t ts, | ||||
| const bool compact, | const bool compact, | ||||
| char r_time[FILELIST_DIRENTRY_TIME_LEN], | char r_time[FILELIST_DIRENTRY_TIME_LEN], | ||||
| char r_date[FILELIST_DIRENTRY_DATE_LEN]) | char r_date[FILELIST_DIRENTRY_DATE_LEN], | ||||
| bool *r_is_today, | |||||
| bool *r_is_yesterday) | |||||
| { | { | ||||
| time_t ts_mtime = ts; | int today_year = 0; | ||||
| int today_yday = 0; | |||||
| int yesterday_year = 0; | |||||
| int yesterday_yday = 0; | |||||
| if (r_is_today || r_is_yesterday) { | |||||
| /* Localtime() has only one buffer so need to get data out before called again. */ | |||||
| const time_t ts_now = time(NULL); | |||||
| struct tm *today = localtime(&ts_now); | |||||
| today_year = today->tm_year; | |||||
| today_yday = today->tm_yday; | |||||
| /* Handle a yesterday that spans a year */ | |||||
| today->tm_mday--; | |||||
| mktime(today); | |||||
| yesterday_year = today->tm_year; | |||||
| yesterday_yday = today->tm_yday; | |||||
| if (r_is_today) { | |||||
| *r_is_today = false; | |||||
| } | |||||
| if (r_is_yesterday) { | |||||
| *r_is_yesterday = false; | |||||
| } | |||||
| } | |||||
| const time_t ts_mtime = ts; | |||||
| const struct tm *tm = localtime(st ? &st->st_mtime : &ts_mtime); | const struct tm *tm = localtime(st ? &st->st_mtime : &ts_mtime); | ||||
| const time_t zero = 0; | const time_t zero = 0; | ||||
| /* Prevent impossible dates in windows. */ | /* Prevent impossible dates in windows. */ | ||||
| if (tm == NULL) { | if (tm == NULL) { | ||||
| tm = localtime(&zero); | tm = localtime(&zero); | ||||
| } | } | ||||
| if (r_time) { | if (r_time) { | ||||
| strftime(r_time, sizeof(*r_time) * FILELIST_DIRENTRY_TIME_LEN, "%H:%M", tm); | strftime(r_time, sizeof(*r_time) * FILELIST_DIRENTRY_TIME_LEN, "%H:%M", tm); | ||||
| } | } | ||||
| if (r_date) { | if (r_date) { | ||||
| strftime(r_date, | strftime(r_date, | ||||
| sizeof(*r_date) * FILELIST_DIRENTRY_DATE_LEN, | sizeof(*r_date) * FILELIST_DIRENTRY_DATE_LEN, | ||||
| compact ? "%d/%m/%y" : "%d-%b-%y", | compact ? "%d/%m/%y" : "%d %b %Y", | ||||
| tm); | tm); | ||||
| } | } | ||||
mont29: You also need to tag the strings for i18n message extraction tool (`N_()` macro). Same with… | |||||
| if (r_is_today && (tm->tm_year == today_year) && (tm->tm_yday == today_yday)) { | |||||
| *r_is_today = true; | |||||
| } | |||||
Done Inline ActionsThose needs to be translated mont29: Those needs to be translated | |||||
| else if (r_is_yesterday && (tm->tm_year == yesterday_year) && (tm->tm_yday == yesterday_yday)) { | |||||
| *r_is_yesterday = true; | |||||
| } | |||||
| } | } | ||||
| /** | /** | ||||
| * Deep-duplicate of a single direntry. | * Deep-duplicate of a single direntry. | ||||
| */ | */ | ||||
| void BLI_filelist_entry_duplicate(struct direntry *dst, const struct direntry *src) | void BLI_filelist_entry_duplicate(struct direntry *dst, const struct direntry *src) | ||||
| { | { | ||||
| *dst = *src; | *dst = *src; | ||||
| ▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines | |||||
You also need to tag the strings for i18n message extraction tool (N_() macro). Same with other strings of course.