-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConfig-Manager.ps1
More file actions
119 lines (99 loc) · 3.5 KB
/
Config-Manager.ps1
File metadata and controls
119 lines (99 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# Config-Manager.ps1
# Manages configuration loading, saving, and defaults for FolderToLLM
$script:ConfigFileName = "folderToLLM.config.json"
function Get-ConfigFilePath {
# Returns the path to the global config file (in script directory)
return Join-Path $PSScriptRoot $script:ConfigFileName
}
function Get-DefaultConfig {
# Returns a hashtable with default configuration values
return @{
lastUsed = $null
useGitignore = $true
excludeFolders = @("node_modules", ".git", "dist", "build", ".svelte-kit", "__pycache__", ".venv", "venv")
excludeExtensions = @(".env", ".log", ".tmp", ".cache")
includeFolders = @()
includeExtensions = @()
maxFileSize = 1048576 # 1MB
minFileSize = -1
outputPrefix = "LLM_Output"
}
}
function Get-SavedConfig {
# Loads configuration from file, returns default if file doesn't exist
$configPath = Get-ConfigFilePath
if (Test-Path $configPath) {
try {
$jsonContent = Get-Content -Path $configPath -Raw -Encoding UTF8
$config = $jsonContent | ConvertFrom-Json -AsHashtable
Write-Host "Configuration loaded from: $configPath" -ForegroundColor Green
return $config
}
catch {
Write-Warning "Failed to load config file. Using defaults. Error: $($_.Exception.Message)"
return Get-DefaultConfig
}
}
else {
Write-Host "No config file found. Using defaults." -ForegroundColor Yellow
return Get-DefaultConfig
}
}
function Save-Config {
# Saves configuration to file
param(
[Parameter(Mandatory=$true)]
[hashtable]$Config
)
$configPath = Get-ConfigFilePath
# Update lastUsed timestamp
$Config.lastUsed = (Get-Date).ToString("yyyy-MM-ddTHH:mm:ss")
try {
$jsonContent = $Config | ConvertTo-Json -Depth 10
$jsonContent | Out-File -FilePath $configPath -Encoding UTF8 -Force
Write-Host "Configuration saved to: $configPath" -ForegroundColor Green
return $true
}
catch {
Write-Error "Failed to save config file. Error: $($_.Exception.Message)"
return $false
}
}
function Merge-ConfigWithDefaults {
# Ensures all required keys exist in config by merging with defaults
param(
[hashtable]$Config
)
$defaults = Get-DefaultConfig
foreach ($key in $defaults.Keys) {
if (-not $Config.ContainsKey($key)) {
$Config[$key] = $defaults[$key]
}
}
return $Config
}
function Format-FileSize {
# Converts bytes to human-readable format
param([long]$Bytes)
if ($Bytes -lt 0) { return "No limit" }
if ($Bytes -lt 1KB) { return "$Bytes B" }
if ($Bytes -lt 1MB) { return "{0:N1} KB" -f ($Bytes / 1KB) }
if ($Bytes -lt 1GB) { return "{0:N1} MB" -f ($Bytes / 1MB) }
return "{0:N1} GB" -f ($Bytes / 1GB)
}
function Parse-FileSize {
# Converts human-readable size string to bytes
param([string]$SizeString)
$SizeString = $SizeString.Trim().ToUpper()
if ($SizeString -match '^(\d+(?:\.\d+)?)\s*(B|KB|MB|GB)?$') {
$value = [double]$Matches[1]
$unit = if ($Matches[2]) { $Matches[2] } else { "B" }
switch ($unit) {
"B" { return [long]$value }
"KB" { return [long]($value * 1KB) }
"MB" { return [long]($value * 1MB) }
"GB" { return [long]($value * 1GB) }
}
}
return -1 # Invalid input
}