Centralize method for creating temporary directories
This commit is contained in:
parent
f4198ff39d
commit
f99b180f98
2 changed files with 8 additions and 7 deletions
|
@ -53,4 +53,10 @@ class Context {
|
|||
-Wait `
|
||||
-NoNewWindow;
|
||||
}
|
||||
|
||||
[string] GetTempDirectory() {
|
||||
$tempDir = Join-Path $([System.IO.Path]::GetTempPath()) $([System.IO.Path]::GetRandomFileName());
|
||||
$null = New-Item -ItemType Directory $tempDir;
|
||||
return $tempDir;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,16 +4,11 @@ $null = New-Module {
|
|||
$softwareName = "PuTTY";
|
||||
$configFile = "$($softwareName).reg";
|
||||
|
||||
function New-TempDirectory() {
|
||||
$tempDir = Join-Path $([System.IO.Path]::GetTempPath()) $([System.IO.Path]::GetRandomFileName());
|
||||
$null = New-Item -ItemType Directory $tempDir;
|
||||
return $tempDir;
|
||||
}
|
||||
|
||||
function Invoke-BackupPuTTY([Context] $context) {
|
||||
$tempDir = New-TempDirectory;
|
||||
$tempDir = $context.GetTempDirectory();
|
||||
$fileName = Join-Path "$tempDir" $configFile;
|
||||
& reg export "HKCU\Software\SimonTatham" "$fileName" /y;
|
||||
$context.Backup($tempDir, $context.SoftwareArchive($softwareName), @());
|
||||
Remove-Item -Recurse $tempDir;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue