Skip to content

Commit 0df140d

Browse files
committed
Últimos ajustes; build clean
1 parent fd07273 commit 0df140d

File tree

5 files changed

+35
-56
lines changed

5 files changed

+35
-56
lines changed

Functions/Compress-FolderToTarGz.ps1

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,23 @@ function Compress-FolderToTarGz {
1414
Compress-FolderToTarGz -TargetDir C:\Projetos\App -Exclude @('.git','node_modules')
1515
#>
1616
[CmdletBinding(SupportsShouldProcess)]
17-
param(
18-
[string]$TargetDir = '.',
19-
[string[]]$Exclude
20-
)
17+
param([string]$TargetDir='.',[string[]]$Exclude)
2118

2219
$resolved = Resolve-Path $TargetDir
2320
$baseName = Split-Path $resolved -Leaf
2421
$parent = Split-Path $resolved -Parent
25-
$timestamp= Get-Date -Format 'yyyy-MM-dd_HH-mm-ss'
26-
$tarName = \"${baseName}_${timestamp}.tar\"
27-
$gzName = \"$tarName.gz\"
28-
$tarFull = Join-Path $parent $tarName
29-
$gzFull = Join-Path $parent $gzName
30-
31-
if ($PSCmdlet.ShouldProcess($TargetDir,\"Compress to $gzFull\")) {
32-
$excludeArgs = @()
33-
foreach ($ex in $Exclude) { $excludeArgs += \"--exclude=$ex\" }
22+
$stamp = Get-Date -Format 'yyyy-MM-dd_HH-mm-ss'
23+
$tarFull = Join-Path $parent ("${baseName}_${stamp}.tar")
24+
$gzFull = "$tarFull.gz"
3425

26+
if ($PSCmdlet.ShouldProcess($TargetDir, "Compress to $gzFull")) {
3527
Push-Location $parent
36-
& tar @excludeArgs -cf $tarFull $baseName
37-
if ($LASTEXITCODE) { throw 'tar falhou.' }
38-
39-
# gzip -9 se disponível, senão usa tar -czf direto
28+
$excludeArgs = $Exclude | ForEach-Object { "--exclude=$_" }
29+
tar @excludeArgs -cf $tarFull $baseName
4030
if (Get-Command gzip -ErrorAction SilentlyContinue) {
41-
& gzip -9 $tarFull
31+
gzip -9 $tarFull
4232
} else {
43-
& tar -czf $gzFull -C $parent $baseName
33+
tar -czf $gzFull -C $parent $baseName
4434
Remove-Item $tarFull -Force
4535
}
4636
Pop-Location

Functions/Export-EnvBackup.ps1

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,19 @@ function Export-EnvBackup {
2121

2222
if ($PSCmdlet.ShouldProcess('Environment', "Export to $OutDir")) {
2323
New-Item -ItemType Directory -Path $OutDir -Force | Out-Null
24-
25-
reg.exe export "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "$OutDir\SystemEnvironment.reg" /y
26-
reg.exe export "HKCU\Environment" "$OutDir\UserEnvironment.reg" /y
27-
reg.exe export "HKEY_USERS\.DEFAULT\Environment" "$OutDir\DefaultUserEnvironment.reg" /y
24+
reg export "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "$OutDir\SystemEnvironment.reg" /y
25+
reg export "HKCU\Environment" "$OutDir\UserEnvironment.reg" /y
26+
reg export "HKEY_USERS\.DEFAULT\Environment" "$OutDir\DefaultUserEnvironment.reg" /y
2827

2928
$jsonOpts = @{Depth = 3; Compress = $false}
30-
3129
Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' |
32-
Select-Object -ExcludeProperty PS* |
33-
ConvertTo-Json @jsonOpts | Set-Content -Encoding UTF8 "$OutDir\SystemEnvironment.json"
34-
30+
Select-Object -ExcludeProperty PS* | ConvertTo-Json @jsonOpts |
31+
Set-Content "$OutDir\SystemEnvironment.json" -Encoding utf8
3532
Get-ItemProperty -Path 'HKCU:\Environment' |
36-
Select-Object -ExcludeProperty PS* |
37-
ConvertTo-Json @jsonOpts | Set-Content -Encoding UTF8 "$OutDir\UserEnvironment.json"
38-
33+
Select-Object -ExcludeProperty PS* | ConvertTo-Json @jsonOpts |
34+
Set-Content "$OutDir\UserEnvironment.json" -Encoding utf8
3935
Get-ItemProperty -Path 'Registry::HKEY_USERS\.DEFAULT\Environment' -ErrorAction SilentlyContinue |
40-
Select-Object -ExcludeProperty PS* |
41-
ConvertTo-Json @jsonOpts | Set-Content -Encoding UTF8 "$OutDir\DefaultUserEnvironment.json"
42-
43-
Write-Output $OutDir
36+
Select-Object -ExcludeProperty PS* | ConvertTo-Json @jsonOpts |
37+
Set-Content "$OutDir\DefaultUserEnvironment.json" -Encoding utf8
4438
}
4539
}

Functions/Export-RegistrySelection.ps1

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,28 @@ function Export-RegistrySelection {
2727
[ValidateSet('HKEY_LOCAL_MACHINE','HKEY_CURRENT_USER','HKEY_CLASSES_ROOT','HKEY_USERS','HKEY_CURRENT_CONFIG')]
2828
[string[]]$TargetRoots = @('HKEY_LOCAL_MACHINE','HKEY_CURRENT_USER'),
2929
[string[]]$Filters = @('Open with','Edit with'),
30-
[ValidateSet('Key','Value','Data')]
31-
[string]$MatchFields = 'Data',
30+
[ValidateSet('Key','Value','Data')][string]$MatchFields = 'Data',
3231
[string]$OutputDir = (Join-Path $PWD 'RegistryExport'),
3332
[string]$Prefix,
3433
[string]$Suffix
3534
)
3635

37-
if (!(Test-Path $OutputDir)) { New-Item -ItemType Directory -Path $OutputDir -Force | Out-Null }
38-
36+
New-Item -Path $OutputDir -ItemType Directory -Force | Out-Null
3937
$timestamp = Get-Date -Format 'yyyyMMdd-HHmmss'
40-
$fileBase = '{0}{1}{2}_{3}.reg' -f `
41-
($Prefix ?? ''), ($Prefix? '_':''), ($Suffix? ($Suffix+'_'):'') , $timestamp
42-
$filePath = Join-Path $OutputDir $fileBase
38+
$parts = @()
39+
if ($Prefix) { $parts += $Prefix }
40+
if ($Suffix) { $parts += $Suffix }
41+
$parts += $timestamp
42+
$filePath = Join-Path $OutputDir (($parts -join '_') + '.reg')
4343

4444
foreach ($root in $TargetRoots) {
45-
# usa reg query com /s pra percorrer
46-
$lines = & reg.exe query $root /s 2>$null
45+
$lines = reg query $root /s 2>$null
4746
foreach ($line in $lines) {
48-
$match = switch ($MatchFields) {
49-
'Key' { ($Filters | Where-Object { $line -like \"*$_*\" }).Count -gt 0 }
50-
default { ($Filters | Where-Object { $line -like \"*$_*\" }).Count -gt 0 }
51-
}
52-
if ($match) {
53-
$line | Out-File -Append -FilePath $filePath -Encoding Unicode
47+
$isMatch = switch ($MatchFields) {
48+
'Key' { $Filters | Where-Object { $line -like "*$_*" } }
49+
default { $Filters | Where-Object { $line -like "*$_*" } }
5450
}
51+
if ($isMatch) { $line | Out-File -Append $filePath -Encoding Unicode }
5552
}
5653
}
5754
Write-Output $filePath

NicolasAigner.SystemToolkit.psd1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
GUID = '8b2042b8-550d-46b7-b4b8-7b34154bae01'
55
Author = 'Nícolas Aigner'
66
CompanyName = 'Nícolas Aigner'
7-
Copyright = '(c) 2025 Nícolas Aigner'
87
Description = 'Ferramentas PowerShell para backup/merge de variáveis de ambiente, exportação de registro e compactação tar.gz.'
98
PowerShellVersion = '5.1'
109
CompatiblePSEditions = @('Desktop','Core')
1110
FunctionsToExport = @('Export-EnvBackup','Merge-EnvFromBackup','Export-RegistrySelection','Compress-FolderToTarGz')
1211
CmdletsToExport = @()
1312
AliasesToExport = @()
14-
PrivateData = @{}
1513
}

NicolasAigner.SystemToolkit.psm1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Auto‑loader: importa todas as funções do subdiretório Functions
2-
Get-ChildItem -Path (Join-Path $PSScriptRoot 'Functions') -Filter '*.ps1' |
3-
ForEach-Object {
4-
. $_.FullName
5-
Export-ModuleMember -Function $_.BaseName
6-
}
2+
$funcPath = Join-Path $PSScriptRoot 'Functions'
3+
foreach ($file in Get-ChildItem -Path $funcPath -Filter '*.ps1') {
4+
. $file.FullName
5+
}
6+
Export-ModuleMember -Function (Get-ChildItem -Path $funcPath -Filter '*.ps1').BaseName

0 commit comments

Comments
 (0)