Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a user-configurable option to display file sizes in human-readable format (KB/MB/GB) instead of raw byte counts, addressing issue #616 which requested smart file size display. The feature adds a checkbox in the Settings dialog that allows users to toggle between traditional byte display and the new smart size format.
Changes:
- Added a new setting
ShowSmartSizeswith UI checkbox, registry persistence, and integration in the settings page - Implemented
ConvertFileSizeToSmartString()function to format file sizes with appropriate units (B, KB, MB, GB, TB, PB, EB) - Modified
SetItemText()in PanelListNotify.cpp to use the smart size formatting when the setting is enabled
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| SettingsPageRes.h | Adds constant IDX_SETTINGS_SHOW_SMART_SIZES for the new checkbox control |
| SettingsPage2.rc | Adds UI checkbox for smart sizes and adjusts vertical spacing for existing controls |
| SettingsPage.cpp | Integrates the new setting in the settings page initialization, application, and change tracking |
| RegistryUtils.h | Adds ShowSmartSizes boolean field to CFmSettings structure |
| RegistryUtils.cpp | Implements registry save/load operations for the ShowSmartSizes setting |
| PanelListNotify.cpp | Conditionally applies smart size formatting based on user preference when displaying file sizes |
| FormatUtils.h | Declares the new ConvertFileSizeToSmartString() function |
| FormatUtils.cpp | Implements the smart size formatting logic with unit conversion |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| void ConvertFileSizeToSmartString(UInt64 value, wchar_t *s) | ||
| { | ||
| const wchar_t *units[] = { L"B", L"KB", L"MB", L"GB", L"TB", L"PB", L"EB" }; | ||
| int unitIndex = 0; | ||
| double size = (double)value; | ||
|
|
||
| while (size >= 1024.0 && unitIndex < 6) | ||
| { | ||
| size /= 1024.0; | ||
| unitIndex++; | ||
| } | ||
|
|
||
| if (unitIndex == 0) | ||
| { | ||
| ConvertUInt64ToString(value, s); | ||
| wcscat(s, L" B"); | ||
| } | ||
| else | ||
| { | ||
| wchar_t temp[64]; | ||
| swprintf_s(temp, L"%.2f %s", size, units[unitIndex]); | ||
| wcscpy(s, temp); | ||
| } |
There was a problem hiding this comment.
Potential buffer overflow: The ConvertFileSizeToSmartString function uses wcscat and wcscpy without checking the buffer size. The function signature doesn't accept a buffer size parameter, but it's called with a buffer that has a maximum size of item.cchTextMax. For very large numbers, ConvertUInt64ToString could produce a long string, and wcscat(s, L" B") could overflow the buffer. Similarly, swprintf_s writes to a 64-byte temp buffer, but wcscpy copies it to s without verifying s has sufficient space. Consider adding a buffer size parameter to ConvertFileSizeToSmartString and using safer string functions like wcscat_s or ensuring the buffer is large enough.
| CONTROL "Show real file icons", IDX_SETTINGS_SHOW_REAL_FILE_ICONS, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, m, 36, xc, 10 | ||
| CONTROL "Full row select", IDX_SETTINGS_FULL_ROW, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, m, 50, xc, 10 | ||
| CONTROL "Show grid lines", IDX_SETTINGS_SHOW_GRID, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, m, 64, xc, 10 | ||
| CONTROL "&Single-click to open an item", IDX_SETTINGS_SINGLE_CLICK, MY_CHECKBOX, m, 78, xc, 10 | ||
| CONTROL "&Alternative selection mode", IDX_SETTINGS_ALTERNATIVE_SELECTION, MY_CHECKBOX, m, 92, xc, 10 | ||
|
|
||
| CONTROL "Show system &menu", IDX_SETTINGS_SHOW_SYSTEM_MENU, MY_CHECKBOX, m, 100, xc, 10 | ||
| CONTROL "Use &large memory pages", IDX_SETTINGS_LARGE_PAGES, MY_CHECKBOX, m, 122, xc, 10 | ||
| CONTROL "Show system menu", IDX_SETTINGS_SHOW_SYSTEM_MENU, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, m, 106, xc, 10 |
There was a problem hiding this comment.
Inconsistent control definition style. These checkboxes use the explicit "Button", BS_AUTOCHECKBOX | WS_TABSTOP style instead of the MY_CHECKBOX macro that's used in the rest of the file (lines 5, 10-11, 14, 17-21). For consistency with the existing codebase style, use MY_CHECKBOX instead.
| ReadOption(key, kCopyHistory, CopyHistory); | ||
| ReadOption(key, kFolderHistory, FolderHistory); | ||
| ReadOption(key, kLowercaseHashes, LowercaseHashes); | ||
| ReadOption(key, kShowSmartSizes, ShowSmartSizes); |
There was a problem hiding this comment.
Missing initialization for ShowSmartSizes field. All other boolean fields in CFmSettings::Load() are initialized to false (lines 164-177), but ShowSmartSizes is not initialized. Add "ShowSmartSizes = false;" after line 174 to ensure consistent initialization and default behavior.
| CONTROL "Show &grid lines", IDX_SETTINGS_SHOW_GRID, MY_CHECKBOX, m, 50, xc, 10 | ||
| CONTROL "&Single-click to open an item", IDX_SETTINGS_SINGLE_CLICK, MY_CHECKBOX, m, 64, xc, 10 | ||
| CONTROL "&Alternative selection mode", IDX_SETTINGS_ALTERNATIVE_SELECTION, MY_CHECKBOX, m, 78, xc, 10 | ||
| CONTROL "Show file size in KB/MB/GB", IDX_SETTINGS_SHOW_SMART_SIZES, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, m, 22, xc, 10 |
There was a problem hiding this comment.
Inconsistent control definition style. The new checkbox uses the explicit "Button", BS_AUTOCHECKBOX | WS_TABSTOP style, while the first checkbox (line 5) and several others (lines 10-11, 14, 17-21) use the MY_CHECKBOX macro. For consistency with the existing codebase style, use MY_CHECKBOX instead of the explicit "Button" definition.
| CONTROL "Show real file icons", IDX_SETTINGS_SHOW_REAL_FILE_ICONS, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, m, 36, xc, 10 | ||
| CONTROL "Full row select", IDX_SETTINGS_FULL_ROW, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, m, 50, xc, 10 | ||
| CONTROL "Show grid lines", IDX_SETTINGS_SHOW_GRID, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, m, 64, xc, 10 |
There was a problem hiding this comment.
Keyboard shortcuts removed unintentionally. The ampersands (&) that define keyboard shortcuts have been removed from these checkbox labels when changing them to the explicit "Button" style. The original code had "&Full row select" but this change makes it "Full row select" without the keyboard shortcut. Restore the ampersands in the label text to preserve keyboard navigation accessibility.
| CONTROL "Show file size in KB/MB/GB", IDX_SETTINGS_SHOW_SMART_SIZES, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, m, 22, xc, 10 | ||
| CONTROL "Show real file icons", IDX_SETTINGS_SHOW_REAL_FILE_ICONS, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, m, 36, xc, 10 | ||
| CONTROL "Full row select", IDX_SETTINGS_FULL_ROW, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, m, 50, xc, 10 | ||
| CONTROL "Show grid lines", IDX_SETTINGS_SHOW_GRID, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, m, 64, xc, 10 |
There was a problem hiding this comment.
Keyboard shortcut removed unintentionally. The ampersand (&) that defines the keyboard shortcut has been removed from this checkbox label when changing it to the explicit "Button" style. The original code had "Show &grid lines" but this change makes it "Show grid lines" without the keyboard shortcut. Restore the ampersand in the label text to preserve keyboard navigation accessibility.
| CONTROL "Show grid lines", IDX_SETTINGS_SHOW_GRID, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, m, 64, xc, 10 | |
| CONTROL "Show &grid lines", IDX_SETTINGS_SHOW_GRID, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, m, 64, xc, 10 |
|
|
||
| CONTROL "Show system &menu", IDX_SETTINGS_SHOW_SYSTEM_MENU, MY_CHECKBOX, m, 100, xc, 10 | ||
| CONTROL "Use &large memory pages", IDX_SETTINGS_LARGE_PAGES, MY_CHECKBOX, m, 122, xc, 10 | ||
| CONTROL "Show system menu", IDX_SETTINGS_SHOW_SYSTEM_MENU, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, m, 106, xc, 10 |
There was a problem hiding this comment.
Keyboard shortcut removed unintentionally. The ampersand (&) that defines the keyboard shortcut has been removed from this checkbox label when changing it to the explicit "Button" style. The original code had "Show system &menu" but this change makes it "Show system menu" without the keyboard shortcut. Restore the ampersand in the label text to preserve keyboard navigation accessibility.
| CONTROL "Show system menu", IDX_SETTINGS_SHOW_SYSTEM_MENU, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, m, 106, xc, 10 | |
| CONTROL "Show system &menu", IDX_SETTINGS_SHOW_SYSTEM_MENU, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, m, 106, xc, 10 |
| #include "../../PropID.h" | ||
|
|
||
| #include "App.h" | ||
| #include "App.h" |
There was a problem hiding this comment.
Duplicate include statement for "App.h". The file is included on both line 16 and line 17. Remove one of these duplicate includes.
| #include "App.h" |
| CFmSettings st; | ||
| st.Load(); | ||
| if (st.ShowSmartSizes) | ||
| ConvertFileSizeToSmartString(v, text); | ||
| else | ||
| ConvertSizeToString(v, text); |
There was a problem hiding this comment.
Performance issue: Settings are loaded on every call to SetItemText, which is called for each list view item display. This function is invoked frequently (potentially for every visible item in the file list), causing repeated registry reads. Consider caching the ShowSmartSizes setting in the CPanel class and reloading it only when settings change, similar to how other panel settings like _showDots and _showRealFileIcons are handled.
|
Please follow the code style specified in CONTRIBUTING.md, especially wrt. variable names and modification markers. |
Okay, I'll submit it again after I wake up from my afternoon nap. |
I have rewritten and optimized the relevant code following the guidelines in CONTRIBUTING.md. |
|
I have closed this PR because you should recreate a new PR with the following requirements. You can use AI/LLM to help you coding only before pushing to the public. Before pushing your commits to public, ensure you implementation and commit have no AI/LLM smell. Also, never assign Copilot for reviewing because we should keep the pull request history cleaner. Kenji Mouri |
增加一个开关用于显示

解决 #616