Skip to content

✨ feat: 更好的大小显示#822

Closed
kalicyh wants to merge 1 commit intoM2Team:mainfrom
kalicyh:main
Closed

✨ feat: 更好的大小显示#822
kalicyh wants to merge 1 commit intoM2Team:mainfrom
kalicyh:main

Conversation

@kalicyh
Copy link

@kalicyh kalicyh commented Feb 5, 2026

增加一个开关用于显示
解决 #616
f140e1b1c89a0d8c6f778eaa0c77368e

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ShowSmartSizes with 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.

Comment on lines 19 to 41
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);
}
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines 7 to 13
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
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
ReadOption(key, kCopyHistory, CopyHistory);
ReadOption(key, kFolderHistory, FolderHistory);
ReadOption(key, kLowercaseHashes, LowercaseHashes);
ReadOption(key, kShowSmartSizes, ShowSmartSizes);
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
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
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines 7 to 9
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
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
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
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.

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
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
#include "../../PropID.h"

#include "App.h"
#include "App.h"
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate include statement for "App.h". The file is included on both line 16 and line 17. Remove one of these duplicate includes.

Suggested change
#include "App.h"

Copilot uses AI. Check for mistakes.
Comment on lines 519 to 524
CFmSettings st;
st.Load();
if (st.ShowSmartSizes)
ConvertFileSizeToSmartString(v, text);
else
ConvertSizeToString(v, text);
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@dinhngtu
Copy link
Member

dinhngtu commented Feb 5, 2026

Please follow the code style specified in CONTRIBUTING.md, especially wrt. variable names and modification markers.

@kalicyh
Copy link
Author

kalicyh commented Feb 5, 2026

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.

@kalicyh
Copy link
Author

kalicyh commented Feb 6, 2026

Please follow the code style specified in CONTRIBUTING.md, especially wrt. variable names and modification markers.

I have rewritten and optimized the relevant code following the guidelines in CONTRIBUTING.md.

@MouriNaruto
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants