Examples.ps1

# =====================================================================================
# BookmarkBackupTool Module - Usage Examples
# =====================================================================================
# This script demonstrates various ways to use the BookmarkBackupTool module
# You can copy and modify these examples for your own use

# Import the module (if not already loaded)
Import-Module BookmarkBackupTool

Write-Host "`n=== BookmarkBackupTool Usage Examples ===`n" -ForegroundColor Cyan

# =====================================================================================
# Example 1: Simple GUI Launch
# =====================================================================================
Write-Host "Example 1: Launch GUI (uncomment to run)" -ForegroundColor Yellow
# Show-BookmarkGUI

# =====================================================================================
# Example 2: Basic Export
# =====================================================================================
Write-Host "`nExample 2: Export bookmarks to Desktop" -ForegroundColor Yellow
$backupPath = Join-Path ([Environment]::GetFolderPath('Desktop')) "BookmarkBackups"

# Uncomment to run:
# Export-Bookmarks -Path $backupPath -Chrome -Edge -Verbose

# =====================================================================================
# Example 3: Export with Auto-Detected Path
# =====================================================================================
Write-Host "`nExample 3: Export using auto-detected network path" -ForegroundColor Yellow

# Uncomment to run:
# $autoPath = Get-HomeSharePath
# Write-Host "Auto-detected path: $autoPath" -ForegroundColor Cyan
# Export-Bookmarks -Path $autoPath -Chrome -Edge -Firefox

# =====================================================================================
# Example 4: Export All Browser Profiles
# =====================================================================================
Write-Host "`nExample 4: Export all profiles from all browsers" -ForegroundColor Yellow

# Uncomment to run:
# $date = Get-Date -Format "yyyy-MM-dd"
# $fullBackupPath = "D:\Backups\Complete_$date"
# Export-Bookmarks -Path $fullBackupPath -Chrome -Edge -Firefox -AllProfiles -Verbose

# =====================================================================================
# Example 5: Preview Export (WhatIf)
# =====================================================================================
Write-Host "`nExample 5: Preview export without actually doing it" -ForegroundColor Yellow

# Uncomment to run:
# Export-Bookmarks -Path "C:\Test" -Chrome -WhatIf

# =====================================================================================
# Example 6: Import Bookmarks
# =====================================================================================
Write-Host "`nExample 6: Import Chrome bookmarks with confirmation" -ForegroundColor Yellow

# Uncomment to run:
# $sourcePath = Join-Path ([Environment]::GetFolderPath('Desktop')) "BookmarkBackups"
# Import-Bookmarks -Path $sourcePath -Chrome

# =====================================================================================
# Example 7: Force Import (Skip Browser Check)
# =====================================================================================
Write-Host "`nExample 7: Force import even if browser is running" -ForegroundColor Yellow

# Uncomment to run (NOT RECOMMENDED):
# Import-Bookmarks -Path "D:\Backups" -Chrome -Force

# =====================================================================================
# Example 8: Check Browser Status
# =====================================================================================
Write-Host "`nExample 8: Check which browsers are installed and running" -ForegroundColor Yellow

# Uncomment to run:
# $browsers = @('Chrome', 'Edge', 'Firefox')
# foreach ($browser in $browsers) {
# $installed = Test-BrowserInstalled -BrowserName $browser
# $running = Test-BrowserRunning -BrowserName $browser
#
# Write-Host "$browser - Installed: $installed, Running: $running" -ForegroundColor Cyan
# }

# =====================================================================================
# Example 9: Get Browser Profiles
# =====================================================================================
Write-Host "`nExample 9: List all browser profiles" -ForegroundColor Yellow

# Uncomment to run:
# Write-Host "`nChrome Profiles:" -ForegroundColor Cyan
# Get-BrowserProfiles -BrowserName Chrome | Format-Table Name, FullName, LastWriteTime
#
# Write-Host "Edge Profiles:" -ForegroundColor Cyan
# Get-BrowserProfiles -BrowserName Edge | Format-Table Name, FullName, LastWriteTime
#
# Write-Host "Firefox Profiles:" -ForegroundColor Cyan
# Get-BrowserProfiles -BrowserName Firefox | Format-Table Name, FullName, LastWriteTime

# =====================================================================================
# Example 10: Create Scheduled Daily Backup
# =====================================================================================
Write-Host "`nExample 10: Create scheduled task for daily backups at 6 PM" -ForegroundColor Yellow

# Uncomment to run:
# New-BookmarkScheduledTask -Frequency Daily -Time "18:00"

# =====================================================================================
# Example 11: Create Weekly Backup Schedule
# =====================================================================================
Write-Host "`nExample 11: Create weekly backup every Sunday at 9 AM" -ForegroundColor Yellow

# Uncomment to run:
# New-BookmarkScheduledTask -Frequency Weekly -Time "09:00"

# =====================================================================================
# Example 12: Remove Scheduled Task
# =====================================================================================
Write-Host "`nExample 12: Remove scheduled backup task" -ForegroundColor Yellow

# Uncomment to run:
# Remove-BookmarkScheduledTask

# =====================================================================================
# Example 13: Configuration Management
# =====================================================================================
Write-Host "`nExample 13: View and modify configuration" -ForegroundColor Yellow

# Uncomment to run:
# $config = Get-BookmarkConfiguration
# Write-Host "Current Configuration:" -ForegroundColor Cyan
# $config | Format-List
#
# # Modify configuration
# $config.DefaultBrowsers = @('Chrome', 'Edge')
# $config.LoggingEnabled = $true
# Set-BookmarkConfiguration -Configuration $config

# =====================================================================================
# Example 14: Backup Before Import
# =====================================================================================
Write-Host "`nExample 14: Create manual backup before importing" -ForegroundColor Yellow

# Uncomment to run:
# $backupLocation = "D:\SafetyBackups\$(Get-Date -Format 'yyyy-MM-dd_HHmmss')"
# New-Item -ItemType Directory -Path $backupLocation -Force | Out-Null
#
# Backup-ExistingBookmarks -BrowserName Chrome -BackupPath $backupLocation
# Backup-ExistingBookmarks -BrowserName Edge -BackupPath $backupLocation
#
# # Now safe to import
# Import-Bookmarks -Path "D:\OldBackups" -Chrome -Edge

# =====================================================================================
# Example 15: Complete Workflow - Daily Sync
# =====================================================================================
Write-Host "`nExample 15: Complete daily sync workflow" -ForegroundColor Yellow

# Uncomment to run:
# function Sync-BookmarksDaily {
# [CmdletBinding()]
# param(
# [string]$SyncPath = (Get-HomeSharePath)
# )
#
# Write-Host "Starting daily bookmark sync..." -ForegroundColor Cyan
# Write-Host "Sync location: $SyncPath" -ForegroundColor Yellow
#
# # Export current bookmarks
# Write-Host "`nExporting bookmarks..." -ForegroundColor Yellow
# $exportResults = Export-Bookmarks -Path $SyncPath -Chrome -Edge -Firefox
#
# # Display summary
# $successCount = ($exportResults | Where-Object {$_.Status -eq 'Success'}).Count
# Write-Host "Export completed: $successCount successful operations" -ForegroundColor Green
#
# Write-Host "`nDaily sync completed!" -ForegroundColor Green
# }
#
# # Run the sync
# Sync-BookmarksDaily

# =====================================================================================
# Example 16: Browser Migration
# =====================================================================================
Write-Host "`nExample 16: Migrate from Chrome to Edge" -ForegroundColor Yellow

# Uncomment to run:
# function Move-ChromeToEdge {
# [CmdletBinding()]
# param(
# [string]$TempPath = "$env:TEMP\BrowserMigration"
# )
#
# Write-Host "Migrating bookmarks from Chrome to Edge..." -ForegroundColor Cyan
#
# # Create temp directory
# New-Item -ItemType Directory -Path $TempPath -Force | Out-Null
#
# # Step 1: Export from Chrome
# Write-Host "`n[1/3] Exporting from Chrome..." -ForegroundColor Yellow
# Export-Bookmarks -Path $TempPath -Chrome
#
# # Step 2: Backup Edge bookmarks
# Write-Host "`n[2/3] Creating safety backup of Edge..." -ForegroundColor Yellow
# $backupPath = "$TempPath\EdgeBackup"
# New-Item -ItemType Directory -Path $backupPath -Force | Out-Null
# Backup-ExistingBookmarks -BrowserName Edge -BackupPath $backupPath
#
# # Step 3: Import to Edge
# Write-Host "`n[3/3] Importing to Edge..." -ForegroundColor Yellow
# Import-Bookmarks -Path $TempPath -Edge
#
# Write-Host "`nMigration complete!" -ForegroundColor Green
# Write-Host "Please restart Edge to see your bookmarks." -ForegroundColor Yellow
# }
#
# # Run the migration
# Move-ChromeToEdge

# =====================================================================================
# Example 17: System Prerequisites Check
# =====================================================================================
Write-Host "`nExample 17: Validate system prerequisites" -ForegroundColor Yellow

# Uncomment to run:
# Write-Host "Checking system prerequisites..." -ForegroundColor Yellow
# $prereqsPassed = Test-BookmarkPrerequisites -TargetPath "D:\Backups"
#
# if ($prereqsPassed) {
# Write-Host "All prerequisites met!" -ForegroundColor Green
# } else {
# Write-Host "Prerequisites check failed. See errors above." -ForegroundColor Red
# }

# =====================================================================================
# Example 18: Using Aliases
# =====================================================================================
Write-Host "`nExample 18: Using command aliases" -ForegroundColor Yellow

# Uncomment to run:
# # These are equivalent to Export-Bookmarks
# Backup-Bookmarks -Path "D:\Backups" -Chrome
# Export-BrowserBookmarks -Path "D:\Backups" -Chrome
#
# # These are equivalent to Import-Bookmarks
# Restore-Bookmarks -Path "D:\Backups" -Chrome
# Import-BrowserBookmarks -Path "D:\Backups" -Chrome

# =====================================================================================
# Example 19: Verbose Logging
# =====================================================================================
Write-Host "`nExample 19: Run operations with verbose logging" -ForegroundColor Yellow

# Uncomment to run:
# Export-Bookmarks -Path "D:\Backups" -Chrome -Verbose
#
# # View log file
# $logPath = "$env:USERPROFILE\.bookmarktool\logs\BookmarkTool_$(Get-Date -Format 'yyyy-MM-dd').log"
# if (Test-Path $logPath) {
# Write-Host "`nRecent log entries:" -ForegroundColor Cyan
# Get-Content $logPath -Tail 20
# }

# =====================================================================================
# Example 20: Error Handling
# =====================================================================================
Write-Host "`nExample 20: Proper error handling" -ForegroundColor Yellow

# Uncomment to run:
# try {
# $results = Export-Bookmarks -Path "D:\Backups" -Chrome -Edge -Firefox -ErrorAction Stop
#
# # Check results
# $failed = $results | Where-Object {$_.Status -eq 'Failed'}
# if ($failed.Count -gt 0) {
# Write-Warning "Some operations failed:"
# $failed | Format-Table Browser, Action, Reason
# }
#
# $successful = $results | Where-Object {$_.Status -eq 'Success'}
# Write-Host "`nSuccessful operations: $($successful.Count)" -ForegroundColor Green
# }
# catch {
# Write-Error "Operation failed: $($_.Exception.Message)"
# Write-Host "Check logs for details: $env:USERPROFILE\.bookmarktool\logs\" -ForegroundColor Yellow
# }

# =====================================================================================
# Help Resources
# =====================================================================================
Write-Host "`n=== For More Information ===" -ForegroundColor Cyan
Write-Host "Get-Help Export-Bookmarks -Full" -ForegroundColor White
Write-Host "Get-Help Import-Bookmarks -Examples" -ForegroundColor White
Write-Host "Get-Command -Module BookmarkBackupTool" -ForegroundColor White
Write-Host "Show-BookmarkGUI`n" -ForegroundColor White