Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor codebase for clarity, portability, and consistency improvements. #256

Merged
merged 7 commits into from
Nov 13, 2024

Conversation

stevewgr
Copy link
Member

Description

This pull request introduces a series of codebase improvements to enhance clarity, portability, and maintainability. Key changes include namespace renaming, function refactoring, unused code removal, and consistency adjustments.

Details

  • Namespace Renaming: Renamed the N3 namespace to n3std to emphasize its role as a utility namespace for standardizing the codebase, akin to the std namespace.

  • Function Refactoring: Refactored and relocated GetProgPath and LogFileWrite to N3Utils.h. This centralization reduces code duplication and ensures compatibility across all platforms.

  • Redundant Code Removal: Removed unused and redundant code from the Launcher, which included a custom button control that was never used. Additionally, removed an unused Windows-based ShellTree implementation to streamline the codebase.

  • Improved Dialog Functionality: Replaced the custom DlgBrowsePath dialog with CFolderPickerDialog. The previous implementation had limitations with deeply nested folders and lacked path copy-paste functionality. Using CFolderPickerDialog offers a modern, user-friendly folder selection approach, leveraging Windows Explorer’s capabilities.

  • Memory Allocation Warning Fix: Fixed warnings associated with large stack buffers by replacing char buff[size] with std::vector<char>. This change enables dynamic memory allocation for large buffers, specifically in multi-file selection dialogs, using a 512 KB buffer to support long file paths.

  • Consistent Header Includes: Standardized header includes to improve portability and consistency. This involved addressing inconsistent casing and correcting system headers to use angle brackets (<>) instead of quotes (""). Future enhancements may involve integrating tools like clang-tidy or include-what-you-use (iwyu) for further consistency.

Benefits

These updates enhance the overall quality of the codebase by improving portability, reducing redundancy, ensuring compatibility, and simplifying functionality. They lay the groundwork for a more standardized, maintainable, and user-friendly application.

This change highlights that the namespace contains utility functions
intended to standardize the codebase, similar to the `std` namespace.
Centralized these functions to reduce code duplication across the
project. The refactored implementation ensures compatibility across all
platforms.
Seems like they copied this code from somewhere to use it as a custom
button control for the Launcher but it was never used. Hence there is no
reason to maintain this anymore.
The previous DlgBrowsePath dialog stored recent paths by updating
registry values but was difficult to use for deeply nested folders and
lacked copy-paste support for paths.

Switching to CFolderPickerDialog leverages Windows Explorer’s modern
file dialog, simplifying path selection. This update provides a more
user-friendly and modern approach, available in VS12 / MFC11 and later.
Replaced `char buff[size]` with `std::vector<char>`, enabling dynamic
memory allocation for large buffers used in multi-file selection dialogs
via `dlg.m_ofn.lpstrFile`.

A 512 KB buffer size is used, which should accommodate even very long
file paths.
Standardized header includes to address inconsistencies in case usage
(some were lower-case, others upper-case), which impacts portability
across platforms.

Also corrected cases where system headers were included with quotes ("")
instead of angle brackets (<>).

Long-term, this issue could be further addressed by integrating tools
like clang-tidy or include-what-you-use (iwyu).
@stevewgr stevewgr requested a review from a team November 12, 2024 03:29
@stevewgr stevewgr self-assigned this Nov 12, 2024
@stevewgr
Copy link
Member Author

Build passing: https://github.com/ko4life-net/ko/actions/runs/11790164397/job/32840149101

Also worth mentioning that build time almost reduced by 2 minutes 🤯 🎉 🚀

@SeniourMarquies
Copy link

You're an antworker.

UTengine
UTengine approved these changes Nov 12, 2024
UTengine

This comment was marked as duplicate.

UTengine

This comment was marked as duplicate.

UTengine

This comment was marked as duplicate.

Copy link
Contributor

@UTengine UTengine left a comment

Choose a reason for hiding this comment

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

Fine

@stevewgr stevewgr requested review from srmeier, ForcePower, xGuTeK and a team November 12, 2024 22:38
@stevewgr
Copy link
Member Author

Build passing: https://github.com/ko4life-net/ko/actions/runs/11807325401

Merging.

@stevewgr stevewgr merged commit 7a6a7d6 into master Nov 13, 2024
3 checks passed
@stevewgr stevewgr deleted the refactor-duplications branch November 13, 2024 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants