# Windows Development Setup Scripts

This directory contains PowerShell scripts for setting up a complete Windows development environment. Each script handles a specific aspect of the setup process.

## Quick Start

### Option 1: GUI Launcher (Recommended)
1. Double-click `launch.bat` to start the graphical interface
2. Use the GUI to run individual scripts or all scripts in sequence
3. Each script can be run individually with detailed descriptions
4. **Theme Support**: Click the "Theme" button to cycle between Auto, Light, and Dark themes
5. **Settings**: Your preferences are automatically saved to `%USERPROFILE%\.spikingneurons\.core\.settings\windows-setup-tool.yaml`

### Option 2: Remote Download & Run (One-liner)
Download and run the setup directly from GitHub without cloning the repository:
```powershell
# One-liner: Download and execute the windows-setup scripts
$content = gh api repos/SpikingNeurons/.devcontainer/contents/core/.windows-setup/gist.ps1 --jq '.content' | Out-String
$decoded = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($content.Trim()))
Invoke-Expression $decoded
```
**Requirements**: GitHub CLI (`gh`) must be installed and authenticated

### Option 3: Manual Script Execution
Run scripts individually in PowerShell as Administrator:
```powershell
# Navigate to the script directory
Set-Location "C:\Github\anana\.devcontainer\core\.windows_script"

# Run individual scripts
.\01_Install-Winget.ps1
.\02_Install-DevTools.ps1
.\09_Install-VSCodeExtensions.ps1
# ... and so on
```

## Script Overview

### 01_Install-Winget.ps1
**Purpose**: Install/Update Windows Package Manager (winget)
- Checks if winget is installed
- Attempts to upgrade winget if present
- Installs winget via Microsoft Store or GitHub if not found
- Essential for all subsequent package installations

### 02_Install-DevTools.ps1
**Purpose**: Install/Update Development Tools
- Installs UniGetUI (Windows Package Manager GUI)
- Installs Microsoft WingetCreate (Package creation tool)
- Installs Python 3.13 and upgrades pip
- Installs Git version control system

### 03_Enable-WindowsFeatures.ps1
**Purpose**: Enable Windows Features
- Enables Telnet Client
- Enables Virtual Machine Platform
- Enables Windows Subsystem for Linux (WSL)
- Enables Hyper-V components
- Enables IIS Web Server components

### 04_Setup-WSL.ps1
**Purpose**: WSL Setup
- Installs and configures WSL with Ubuntu-24.04
- Enables required Windows features if missing
- Starts required services
- Guides through initial Linux user setup
- Handles distribution management

### 05_Set-EnvVars.ps1
**Purpose**: Set Environment Variables
- Sets persistent environment variables for the current user
- Sets `GIT_LFS_SKIP_SMUDGE=1` to improve Git LFS performance
- Can be extended for additional environment variables

### 06_Configure-Windows.ps1
**Purpose**: Configure Windows Settings
- Enables Developer Mode for development features
- Sets system and Edge browser to dark theme
- Configures file explorer (show extensions, hidden files)
- Pins common folders to Quick Access
- Sets up Git global configuration
- Optimizes Windows for development

### 07_Create-CoreCommand.ps1
**Purpose**: Create Global Core Command
- Creates a global 'core' command accessible from anywhere in Windows
- Detects core.yaml in the current directory
- Automatically calls .devcontainer\core\cli\core-cli.py
- Adds C:\tools to system PATH for global access

### 08_Launch-UbundleFiles.ps1
**Purpose**: UniGetUI Bundle Launcher with File Association
- Provides a modern GUI interface for managing .ubundle files
- Auto-discovers bundle files in the .winget-bundles directory
- Shows bundle information (package count, size, modification date)
- Supports individual and batch launching of bundles with UniGetUI
- Features dark/light theme support and settings persistence
- Includes bundle validation and error handling
- **File Association Setup**: Creates Windows file associations for .ubundle files
- **Administrator Handling**: Automatically requests elevation for registry modifications
- **Force Association**: Option to recreate associations and clear cache

### 09_Install-VSCodeExtensions.ps1
**Purpose**: Install VS Code Extensions
- Installs VS Code extensions from the vscode-extensions.yaml configuration file
- Uses the 'code' CLI command for extension management
- Automatically checks if VS Code is installed before proceeding
- Reads extensions organized by category from the YAML configuration
- Skips commented entries and already installed extensions
- Provides detailed installation progress and summary
- Handles installation errors gracefully with helpful error messages
- Supports both individual and batch extension installation

## Key Features

### Theme Support
- **Auto Theme**: Automatically detects and follows your Windows system theme (light/dark)
- **Light Theme**: Clean, bright interface optimized for daytime use
- **Dark Theme**: Easy-on-the-eyes dark interface for low-light environments
- **Theme Toggle**: Click the "Theme" button to cycle between Auto → Light → Dark → Auto
- **Settings Persistence**: Theme preference is saved to `%USERPROFILE%\.spikingneurons\.core\.settings\windows-setup-tool.yaml`

### GUI Application
- Clean, modern interface with script descriptions
- Individual "Run Script" and "View Script" buttons
- "Run All Scripts" option for sequential execution
- Admin status indicator
- Error handling and user feedback
- Responsive design that adapts to your chosen theme

### Settings Management
Settings are automatically saved to: `%USERPROFILE%\.spikingneurons\.core\.settings\windows-setup-tool.yaml`

The settings file includes:
- Theme preference (Auto, Light, or Dark)
- Last usage timestamp
- Application version info

### UBundle Package Management
Script 08 introduces advanced package management through .ubundle files:

**What are UBundle Files?**
- JSON-formatted package lists that define collections of software to install
- Created and managed by UniGetUI for batch software installation
- Located in the `.winget-bundles` directory

**Available Bundle Collections:**
- `mandatory.ubundle` - Essential development tools and utilities
- `programming.ubundle` - Programming languages, IDEs, and development tools
- `productivity.ubundle` - Productivity applications and office tools
- `nvidia.ubundle` - NVIDIA-specific drivers and tools
- `nuc.ubundle` - Intel NUC optimized packages

**Bundle Launcher Features:**
- **Visual Interface**: Modern GUI showing all available bundles with details
- **Bundle Information**: Package count, file size, last modification date
- **Batch Operations**: Launch multiple bundles simultaneously
- **Validation**: Checks bundle integrity and warns about invalid files
- **Settings**: Configurable UniGetUI path and persistent preferences
- **Theme Support**: Consistent theming with the main setup interface
- **File Association**: Integrated setup for .ubundle file associations with Windows registry
- **Administrator Support**: Automatic privilege elevation for system modifications
- **Force Mode**: Option to recreate associations and clear Windows cache

## Files in This Directory

- **Individual Scripts**: `01_*.ps1` through `09_*.ps1` - Individual setup scripts
- **GUI Launcher**: `run.ps1` - PowerShell GUI application for script management
- **Batch Launcher**: `launch.bat` - Easy double-click launcher for the GUI
- **Bundle Launcher**: `08_Launch-UbundleFiles.ps1` - GUI for managing .ubundle files
- **Bundle Files**: `.winget-bundles\*.ubundle` - Software package bundles for UniGetUI
- **Configuration Files**: `.configs\vscode-extensions.yaml` - VS Code extensions configuration
- **Documentation**: `README.md` - This file

## Prerequisites

- Windows 10/11 with PowerShell 5.1 or later
- Administrator privileges (scripts will prompt for elevation if needed)
- Internet connection for downloading packages and repositories

## Recommended Execution Order

1. **01_Install-Winget.ps1** - Required for package management
2. **02_Install-DevTools.ps1** - Install essential development tools
3. **03_Enable-WindowsFeatures.ps1** - Enable Windows features (may require restart)
4. **04_Setup-WSL.ps1** - Set up Linux subsystem
5. **05_Set-EnvVars.ps1** - Configure environment variables
6. **06_Configure-Windows.ps1** - Optimize Windows settings
7. **07_Create-CoreCommand.ps1** - Create global core command (optional)
8. **08_Launch-UbundleFiles.ps1** - Launch bundle manager for software packages (optional)
9. **09_Install-VSCodeExtensions.ps1** - Install VS Code extensions (optional)

## Important Notes

### Administrator Privileges
- Most scripts require administrator privileges
- The GUI will automatically prompt for elevation when needed
- You can run the entire launcher as administrator for seamless execution

### Restart Requirements
- Some Windows features may require a system restart
- WSL installation typically requires a restart
- The scripts will inform you when a restart is needed

### Error Handling
- Each script includes comprehensive error handling
- Failed operations are logged with helpful error messages
- Scripts can be re-run safely (they check for existing installations)

### Customization
- Script paths and repository URLs can be modified in individual scripts
- The GUI can be customized by editing `run.ps1`
- Additional scripts can be added by following the existing naming convention

## Troubleshooting

### Common Issues

1. **PowerShell Execution Policy**
   ```powershell
   Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
   ```

2. **Administrator Rights**
   - Right-click PowerShell and select "Run as Administrator"
   - Or use the GUI which handles elevation automatically

3. **Network Issues**
   - Ensure internet connection for package downloads
   - Check firewall settings if downloads fail

4. **Path Issues**
   - Restart terminal after tool installations to refresh PATH
   - Some tools may require a full system restart

5. **UBundle Launcher Issues**
   ```powershell
   # If UniGetUI is not found, update the path in Settings
   # Default path: C:\Users\[username]\AppData\Local\Programs\UniGetUI\UniGetUI.exe
   
   # If bundles don't launch, check that .ubundle file association is set
   # Use Script 08 Settings dialog to set up file associations
   
   # If no bundles are found, ensure .winget-bundles directory exists
   # with .ubundle files in the script directory
   
   # If file associations fail, ensure running as Administrator
   # Script 08 will automatically prompt for elevation when needed
   ```

6. **VS Code Extensions Issues**
   ```powershell
   # If VS Code CLI is not found, ensure VS Code is installed
   winget install Microsoft.VisualStudioCode
   
   # If extensions fail to install, check network connectivity
   # You can also install them manually through VS Code's Extensions panel
   
   # To verify extensions are installed correctly
   code --list-extensions
   
   # To update the extensions configuration, edit:
   # .configs\vscode-extensions.yaml
   ```

### Support
- Check individual script output for detailed error messages
- Review the original README.md for additional context
- Scripts include verbose logging for troubleshooting

## License and Attribution

These scripts are based on the setup procedures documented in the SpikingNeurons/Core project README.md file. They are designed to automate the manual setup process described in that documentation.

---

**Last Updated**: August 2025
**Version**: 1.0
**Compatibility**: Windows 10/11, PowerShell 5.1+
