This document describes the architecture and design of the Tron PowerShell port.
Tron PowerShell is a complete rewrite of the original Tron batch script in native PowerShell. The architecture is designed to be modular, maintainable, and extensible while preserving the core functionality of the original Tron.
- Modularity - Separate concerns into distinct modules
- Maintainability - Clear code structure and documentation
- Safety - DryRun mode and comprehensive error handling
- Extensibility - Easy to add new stages and features
- Compatibility - Maintains compatibility with existing Tron resources
tron_PowerShell/
├── Tron.ps1 # Main entry point
├── Debug-Tron.ps1 # Sandbox testing script
├── build_release.ps1 # Build script for releases
├── Modules/ # PowerShell modules
│ ├── Tron.Core.psm1 # Core functions
│ └── Tron.Stages.psm1 # Stage implementations
├── Config/ # Configuration
│ └── defaults.json # Default configuration
└── Resources/ # External tools and scripts
├── stage_0_prep/
├── stage_1_tempclean/
├── stage_2_de-bloat/
├── stage_3_disinfect/
├── stage_4_repair/
├── stage_5_patch/
├── stage_6_optimize/
├── stage_7_wrap-up/
└── stage_8_custom_scripts/
The main script handles:
- Parameter Parsing - Command-line switches (
-DryRun,-Verbose, etc.) - Module Loading - Imports Core and Stages modules
- Configuration - Loads and applies configuration settings
- Prerequisite Checks - OS version, admin rights, PowerShell version
- Stage Orchestration - Calls each stage function in sequence
- Error Handling - Top-level try/catch and logging
Flow:
1. Parse parameters
2. Import modules
3. Load configuration
4. Check prerequisites
5. Execute stages (0-8)
6. Handle errors and exit
Provides foundational functions used across all stages.
Centralized state management:
$Global:TronState = @{
Config = $null # Configuration object
LogFile = $null # Log file path
IsAdmin = $false # Admin privilege status
Mode = "Standard" # Execution mode
}Modes:
Standard- Full execution with admin rightsLimited- Non-admin execution (skips privileged tasks)DryRun- Simulation mode (no actual changes)
| Function | Purpose |
|---|---|
Write-TronLog |
Unified logging to console and file |
Get-TronConfig |
Loads configuration from JSON |
Test-IsAdmin |
Checks for administrator privileges |
Initialize-TronLogging |
Sets up logging infrastructure |
Implements the logic for each Tron stage.
Each stage is implemented as a separate function:
function Invoke-Stage0 { } # Prep
function Invoke-Stage1 { } # TempClean
function Invoke-Stage2 { } # De-bloat
function Invoke-Stage3 { } # Disinfect
function Invoke-Stage4 { } # Repair
function Invoke-Stage5 { } # Patch
function Invoke-Stage6 { } # Optimize
function Invoke-Stage7 { } # Wrap-up
function Invoke-Stage8 { } # Custom ScriptsEach stage follows a consistent pattern:
function Invoke-StageX {
Write-TronLog "Stage X: Name begin..."
# Get resource paths
$ResourcesPath = "$PSScriptRoot\..\Resources\"
$StagePath = "$ResourcesPath\stage_X_name\"
# Execute sub-tasks
if (-not $Global:TronState.Config.DryRun) {
# Actual work here
}
Write-TronLog "Stage X: Name complete."
}JSON-based configuration for flexibility:
{
"DryRun": false,
"Verbose": false,
"Autorun": false,
"SkipDebloat": false,
"SkipUpdate": false,
"PreserveMetroApps": false,
"SkipCookieCleanup": false,
"SkipMbam": false,
"LogFile": "C:\\Logs\\tron\\tron.log",
"RawLogsPath": "C:\\Logs\\tron_raw_logs"
}Configuration Priority:
- Command-line parameters (highest)
- Configuration file values
- Built-in defaults (lowest)
External tools are organized by stage in the Resources/ directory.
Resource Types:
- Executables - Third-party tools (e.g.,
rkill.exe,ccleaner.exe) - Scripts - Batch and PowerShell scripts
- Data Files - Lists, configurations, and databases
- Libraries - DLLs and dependencies
Compatibility: The resource directory structure mirrors the original Tron batch version for easy tool updates.
graph TD
A[Start Tron.ps1] --> B[Parse Parameters]
B --> C[Import Modules]
C --> D[Load Configuration]
D --> E[Check Prerequisites]
E --> F{Admin Rights?}
F -->|Yes| G[Standard Mode]
F -->|No| H[Limited Mode]
G --> I[Execute Stages 0-8]
H --> I
I --> J[Stage 0: Prep]
J --> K[Stage 1: TempClean]
K --> L[Stage 2: De-bloat]
L --> M[Stage 3: Disinfect]
M --> N[Stage 4: Repair]
N --> O[Stage 5: Patch]
O --> P[Stage 6: Optimize]
P --> Q[Stage 7: Wrap-up]
Q --> R[Stage 8: Custom Scripts]
R --> S[Exit Success]
When -DryRun is specified:
- All stages execute
$Global:TronState.Config.DryRunis set totrue- Each stage checks this flag before performing destructive operations
- Actions are logged but not executed
When running without admin rights:
- Privileged operations are skipped:
- DISM and SFC checks
- System restore point creation
- Metro app removal
- Registry modifications requiring HKLM access
- User-level cleanup continues:
- Temp file removal
- Browser cache cleanup
- User registry modifications
| Level | Purpose | Color |
|---|---|---|
INFO |
General information | White |
WARN |
Warnings and skipped tasks | Yellow |
ERROR |
Errors and failures | Red |
DEBUG |
Verbose debugging info | Gray |
Logs are written to:
- Console - Real-time colored output
- Log File - Persistent file log (specified in config)
- Transcript - Complete PowerShell session capture
[YYYY-MM-DD HH:MM:SS] [LEVEL] Message
Example:
[2025-11-27 14:32:15] [INFO] Tron PowerShell Edition v1.0.0 Initialized
[2025-11-27 14:32:16] [WARN] Tron is NOT running as Administrator.
[2025-11-27 14:32:16] [INFO] Stage 0: Prep begin...
- Top-Level Handler - Main
try/catchinTron.ps1 - Stage-Level Handlers - Each stage handles its own errors
- Graceful Degradation - Failed operations are logged and skipped
- Clean Shutdown - Ensures logs are written before exit
$ErrorActionPreference = "Stop" # Catch all errorsIndividual commands use -ErrorAction SilentlyContinue when failures are acceptable.
Allows safe testing without affecting the real system.
How it works:
- Creates
Sandbox/directory in project root - Populates with mock files and directories
- Redirects Tron to operate within sandbox
- Executes stages in isolation
Use case: Testing file cleanup logic, stage implementations, and new features.
- Plugin System - Allow third-party stage extensions
- Event System - Pre/post stage hooks for custom logic
- Parallel Execution - Run independent tasks concurrently
- Remote Execution - Run Tron on remote machines
- GUI Option - Windows Forms or WPF interface
- Configuration Profiles - Named profiles for different use cases
- Rollback System - Ability to undo changes
- Separate each stage into its own module file
- Create utility modules for common patterns
- Implement dependency injection for better testing
- Add unit tests for core functions
| Aspect | Batch Version | PowerShell Version |
|---|---|---|
| Language | Batch script | PowerShell |
| Structure | Monolithic | Modular |
| Error Handling | Basic | Comprehensive |
| Testing | Manual | Sandbox + DryRun |
| Configuration | Hardcoded | JSON-based |
| Logging | Basic text | Structured levels |
| Extensibility | Limited | High |
| Maintainability | Difficult | Easy |
When adding new features:
- Follow the Module Pattern - Use existing modules or create new ones
- Respect State Management - Use
$Global:TronStatefor shared state - Implement DryRun - Always check
Config.DryRunbefore destructive operations - Add Logging - Use
Write-TronLogfor all significant actions - Handle Errors - Use try/catch and appropriate
ErrorActionsettings - Document - Update this document for architectural changes
Questions about the architecture? Open an issue: https://github.com/thookham/tron_PowerShell/issues