Improved safety checks, thread safety, logging, and documentation#2
Open
dpo007 wants to merge 18 commits intoInviseLabs:masterfrom
Open
Improved safety checks, thread safety, logging, and documentation#2dpo007 wants to merge 18 commits intoInviseLabs:masterfrom
dpo007 wants to merge 18 commits intoInviseLabs:masterfrom
Conversation
Removed unused usings, improved struct marshalling, standardized variable declarations, and refactored method visibility and formatting. Fixed XML formatting in App.config and improved error logging. Minor bug fixes and code consistency updates throughout.
Reformat P/Invoke signatures and method calls across NativeMethods.cs and Privileges.cs for improved clarity. Expand conditional logic in Program.cs to multi-line blocks for better readability and explicit error handling. In RegistryUtils.cs, simplify exception handling and add comments for intent. No functional changes; all updates focus on code style and maintainability.
Refactored several catch blocks in Program.cs from single-line to expanded, multi-line format. This improves code readability and maintainability by clearly separating error logging, console output, and error counting. No changes were made to the underlying logic.
Enhanced the validation logic for the error path (errPath) argument. Now checks for non-whitespace, minimum length, absence of invalid path characters, and existence of the directory. This prevents invalid or non-existent paths from being accepted.
Added CloseHandle P/Invoke and refactored privilege enabling to ensure proper handle cleanup and error checking. Replaced direct counter increments with Interlocked.Increment for thread safety. Enhanced error handling throughout registry operations.
Changed LogError to internal for cross-class access. Now log detailed exceptions to file and console when registry subkey access fails, enhancing error reporting and diagnostics.
Refactored the codebase to include detailed XML documentation comments and explanatory inline comments across all major files. Documented P/Invoke declarations, privilege management, registry operations, and main program logic. Improved error handling comments and clarified Windows API workarounds (e.g., privilege requirements, 8.3 path handling, URL-encoded key names). These changes enhance code readability and make the codebase more maintainable for future development.
Standardized all exit codes to use 0 for success and 1 for errors, removing use of -1. Updated ExitConsole to default to 0 and revised user messages to reflect the new convention. Simplified calls to ExitConsole where appropriate.
Rewrote and reformatted README.md for clearer usage instructions. Added README.md to the Visual Studio solution as a Solution Item for easier access.
Refactored Main method to eliminate unnecessary return statements immediately following ExitConsole() calls, as these were unreachable due to application termination. This improves code clarity and removes dead code.
Renamed the Start() method to PerformProfileRename() and updated its invocation in the main program flow. This improves code readability by making the method's purpose explicit.
- Update syntax help message for clarity and accuracy. - Add pre-check to test profile directory renaming before registry changes. - Enhance error handling and logging for directory rename failures. - Make registry subkey access error messages more consistent and concise.
Move logErrs check into LogError method to eliminate redundant conditional checks before logging errors. This simplifies error handling code and ensures consistent logging behavior.
Refactored Program class fields from public to private and updated naming to follow C# conventions. Reformatted try/catch and if statements for readability, improved summary output formatting, and enhanced error logging structure. Made minor formatting fixes, including Console.WriteLine usage and .csproj indentation.
Added NativeMethods.User32 for Safe Mode detection via user32.dll. Program now warns and prompts user if not running in Safe Mode, exiting unless 'Y' is pressed. Improved error handling for detection failures and clarified path examples in help text.
Added a comprehensive "How RenProfile Works" section detailing internal logic and workflow. Clarified and reformatted usage instructions, argument descriptions, and exit codes. Enhanced troubleshooting guidance and provided explicit reversal instructions. Added a "Technical Details" section covering requirements and performance. Fixed minor typos and improved overall clarity and formatting.
Author
|
Happy to make adjustments. :) |
Corrected file path examples in help text and comments by replacing double backslashes with single backslashes, ensuring accurate and standard Windows path notation throughout the codebase.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR focuses on making RenProfile safer to run, easier to understand, and more robust internally. The changes emphasize clearer documentation, stronger validation and logging, improved thread safety, and general code cleanup to make future maintenance easier.
Highlights
Safety & UX
Thread safety & reliability
Interlockedfor shared counters.Logging & diagnostics
Code clarity & maintainability
Documentation
Notes
Most changes are non-breaking and focused on correctness, safety, and maintainability, with functional changes limited to improved validation, thread safety, and execution safeguards.