|
| 1 | + |
| 2 | + |
| 3 | +function CreateFolderIfNotExist { |
| 4 | + param ([string]$Folder) |
| 5 | + if( Test-Path $Folder -PathType Leaf){ |
| 6 | + Write-Error "The destanation path ${Folder} is file." |
| 7 | + } |
| 8 | + |
| 9 | + if ( ! (Test-Path $Folder -PathType Container )) { |
| 10 | + New-Item -Path $Folder -ItemType 'Directory' |
| 11 | + } |
| 12 | +} |
| 13 | + |
| 14 | + |
| 15 | +function Test-Empty { |
| 16 | + param ( |
| 17 | + [Parameter(Position = 0)] |
| 18 | + [string]$string |
| 19 | + ) |
| 20 | + return [string]::IsNullOrWhitespace($string) |
| 21 | +} |
| 22 | + |
| 23 | +function Get-ProfileDataFile { |
| 24 | + param ( |
| 25 | + [string]$file, |
| 26 | + [string]$moduleName = $null |
| 27 | + ) |
| 28 | + return Join-Path (Get-ProfileDir $moduleName) $file |
| 29 | + |
| 30 | +} |
| 31 | +function Get-ProfileDir { |
| 32 | + param ( |
| 33 | + [string]$moduleName = $null |
| 34 | + ) |
| 35 | + |
| 36 | + $profileDir = $ENV:AppData |
| 37 | + |
| 38 | + if( Test-Empty $moduleName ){ |
| 39 | + |
| 40 | + if ( $script:MyInvocation.MyCommand.Name.EndsWith('.psm1') ){ |
| 41 | + $moduleName = $script:MyInvocation.MyCommand.Name |
| 42 | + } |
| 43 | + |
| 44 | + if ( $script:MyInvocation.MyCommand.Name.EndsWith('.ps1') ){ |
| 45 | + $modulePath = Split-Path -Path $script:MyInvocation.MyCommand.Path |
| 46 | + $moduleName = Split-Path -Path $modulePath -Leaf |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + if( Test-Empty $moduleName ){ |
| 51 | + throw "Unable to read module name." |
| 52 | + } |
| 53 | + |
| 54 | + $scriptProfile = Combine-Path $profileDir '.ps1' 'ScriptData' $moduleName |
| 55 | + if ( ! (Test-Path $scriptProfile -PathType Container )) { |
| 56 | + New-Item -Path $scriptProfile -ItemType 'Directory' |
| 57 | + } |
| 58 | + return $scriptProfile |
| 59 | +} |
| 60 | + |
| 61 | + |
| 62 | +function Combine-Path { |
| 63 | + param ( |
| 64 | + [string]$baseDir, |
| 65 | + [string]$path |
| 66 | + ) |
| 67 | + $allArgs = $PsBoundParameters.Values + $args |
| 68 | + |
| 69 | + [IO.Path]::Combine([string[]]$allArgs) |
| 70 | +} |
| 71 | + |
| 72 | +$_sharedLoaded = $true |
| 73 | + |
0 commit comments