Skip to content

Improved safety checks, thread safety, logging, and documentation#2

Open
dpo007 wants to merge 18 commits intoInviseLabs:masterfrom
dpo007:dpo007_Changes
Open

Improved safety checks, thread safety, logging, and documentation#2
dpo007 wants to merge 18 commits intoInviseLabs:masterfrom
dpo007:dpo007_Changes

Conversation

@dpo007
Copy link

@dpo007 dpo007 commented Dec 13, 2025

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

  • Adds Safe Mode detection and prompts for confirmation when running outside Safe Mode.
  • Improves pre-checks and error messaging around profile rename operations.

Thread safety & reliability

  • Improves thread safety by using Interlocked for shared counters.
  • Cleans up privilege handling and handle lifetime management to reduce execution risk.
  • Strengthens validation of optional log/output paths to prevent invalid targets.

Logging & diagnostics

  • Improves consistency and detail in error logging, especially for registry access failures.
  • Centralizes checks for whether logging is enabled to avoid duplicated logic.

Code clarity & maintainability

  • Adds XML documentation and inline comments throughout the codebase.
  • Refactors method names and control flow for readability and consistency.
  • Removes redundant logic and standardizes exit handling.

Documentation

  • Expands and clarifies the README with improved usage guidance and internal behavior notes.

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.

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.
@dpo007
Copy link
Author

dpo007 commented Dec 13, 2025

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

1 participant