Skip to content

Commit

Permalink
Merge pull request #116 from mniederw/trunk
Browse files Browse the repository at this point in the history
Merge trunk to main - Unittests are successful - V7.66
  • Loading branch information
mniederw authored Aug 25, 2024
2 parents 00cb6cd + eabd258 commit 3a62697
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/PowershellModuleTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
# Windows : C:\Windows\system32\curl.exe # 2024-02: V8.4
echo "github.event.schedule=${{github.event.schedule}} ";
echo "List ps gallery repositories: "; Get-PSRepository;
echo "List installed ps modules "; Get-Module -ListAvailable | Sort-Object ModuleType, Name, Version | Select-Object ModuleType, Name, Version;
echo "List installed ps modules "; Get-Module -ListAvailable | Sort-Object ModuleType, Name, Version | Select-Object ModuleType, Name, Version | Format-Table -AutoSize;
- name: Test all
shell: pwsh
Expand Down
3 changes: 2 additions & 1 deletion MnCommonPsToolLib/MnCommonPsToolLib.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
}
#HelpInfoURI = '';

ModuleVersion = '7.65';
ModuleVersion = '7.66';

<#
Releasenotes
Expand All @@ -43,6 +43,7 @@
Major version will reflect breaking changes, minor identifies extensions and third number identifies urgent bugfixes.
Breaking changes are usually removed deprecated functions or changed behaviours.
2024-08-18 V7.66 Fix FsEntryGetAbsolutePath, FsEntryListAsFileSystemInfo, DriveFreeSpace. Deprecate SvnExe. Extend OsWindowsRegRunDisable.
2024-08-13 V7.65 Added ProcessStartByArray, ProcessStartByCmdLine. OsWindowsPackageListInstalled, OsWindowsPackageUninstall, OsWindowsRegRunDisable. Extend Doc. Improve ToolInstallNuPckMgrAndCommonPsGalMo, TaskIsDisabled, OsWindowsPackageUninstall.
2024-08-10 V7.64 Extend Doc.
2024-08-08 V7.63 Extend Install options. Use portable username and computername. Improve linux portability.
Expand Down
27 changes: 16 additions & 11 deletions MnCommonPsToolLib/MnCommonPsToolLib.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -685,12 +685,12 @@ function StreamToStringIndented ( [Int32] $nrOfChars = 2 ){ String
function StreamToDataRowsString ( [String[]] $propertyNames = @() ){ # no header, only rows.
$propertyNames = @()+$propertyNames;
if( (@()+$propertyNames).Count -eq 0 ){ $propertyNames = @("*"); }
$input | Format-Table -Wrap -Force -autosize -HideTableHeaders $propertyNames | StreamToStringDelEmptyLeadAndTrLines; }
$input | Format-Table -Wrap -Force -AutoSize -HideTableHeaders $propertyNames | StreamToStringDelEmptyLeadAndTrLines; }
function StreamToTableString ( [String[]] $propertyNames = @() ){
# Note: For a simple string array as example @("one","two")|StreamToTableString it results with 4 lines "Length","------"," 3"," 3".
$propertyNames = @()+$propertyNames;
if( $propertyNames.Count -eq 0 ){ $propertyNames = @("*"); }
$input | Format-Table -Wrap -Force -autosize $propertyNames | StreamToStringDelEmptyLeadAndTrLines; }
$input | Format-Table -Wrap -Force -AutoSize $propertyNames | StreamToStringDelEmptyLeadAndTrLines; }
function StreamFromCsvStrings ( [Char] $delimiter = ',' ){ $input | ConvertFrom-Csv -Delimiter $delimiter; }
function StreamToCsvFile ( [String] $file, [Boolean] $overwrite = $false, [String] $encoding = "UTF8BOM" ){
# If overwrite is false then nothing done if target already exists.
Expand Down Expand Up @@ -813,7 +813,7 @@ function ProcessListRunningsFormatted (){ return [Object[]] (@()+( Proce
StreamToTableString )); }
function ProcessListRunningsAsStringArray (){ return [String[]] (@()+(StringSplitIntoLines (@()+(ProcessListRunnings |
Where-Object{$null -ne $_} |
Format-Table -auto -HideTableHeaders " ",ProcessName,ProductVersion,Company |
Format-Table -AutoSize -HideTableHeaders " ",ProcessName,ProductVersion,Company |
StreamToStringDelEmptyLeadAndTrLines)))); }
function ProcessIsRunning ( [String] $processName ){ return [Boolean] ($null -ne (Get-Process -ErrorAction SilentlyContinue ($processName.Replace(".exe","")))); }
function ProcessCloseMainWindow ( [String] $processName ){ # enter name without exe extension.
Expand Down Expand Up @@ -1081,14 +1081,20 @@ function FsEntryEsc ( [String] $fsentry ){ # Escaping
AssertNotEmpty $fsentry "file-system-entry";
return [String] [Management.Automation.WildcardPattern]::Escape($fsentry); }
function FsEntryUnifyDirSep ( [String] $fsEntry ){ return [String] ($fsEntry -replace "[\\/]",(DirSep)); }
function FsEntryGetAbsolutePath ( [String] $fsEntry ){ # works without IO, so no check to file system; does not remove a trailing dir-separator. Return empty for empty input.
function FsEntryGetAbsolutePath ( [String] $fsEntry ){ # Works without IO, so no check to file system; does not remove a trailing dir-separator. Return empty for empty input.
# Convert dir-separators slashes or backslashes to correct os dependent dir separators.
# On windows for entries as "C:" it returns "C:\".
# Note: We cannot use (Resolve-Path -LiteralPath $fsEntry) because it will throw if path not exists,
# see http://stackoverflow.com/questions/3038337/powershell-resolve-path-that-might-not-exist
if( $fsEntry -eq "" ){ return [String] ""; }
if( (OsIsWindows) -and $fsEntry.StartsWith("//") ){ $fsEntry = $fsEntry.Replace("/","\"); }
if( (OsIsWindows) ){
if( $fsEntry.StartsWith("//") ){ $fsEntry = $fsEntry.Replace("/","\"); }
if( $fsEntry.Length -eq 2 -and $fsEntry[1] -eq ':' -and [char]::IsLetter($fsEntry[0]) ){ $fsEntry += '\'; }
}
try{
# Note: GetUnresolvedProviderPathFromPSPath("./") does not return a trailing dir sep.
# Note: On Windows for entries as "C:" GetUnresolvedProviderPathFromPSPath
# would unexpectedly return undocumented current dir of that drive. Similar effects for or GetFullPath.
return [String] ($ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($fsEntry)+
$(switch( $fsEntry -eq "./" -or $fsEntry.Replace("\","/").EndsWith("/./") ){($true){(DirSep)}($false){""}}));
}catch [System.Management.Automation.DriveNotFoundException] {
Expand Down Expand Up @@ -1200,10 +1206,11 @@ function FsEntryListAsFileSystemInfo ( [String] $fsEntryPattern, [Boole
# In non-recursive mode they are handled as they are not present, so files are also matched ("*\myfile\").
# In recursive mode they wrongly match only files and not directories ("*\myfile\") and
# so parent dir parts (".\*\dir\" or "d1\dir\") would not be found for unknown reasons.
# Very strange is that (CD "D:\tmp"; CD "C:"; Get-Item "D:";) does not list D:\ but it lists the current directory of that drive.
# On Windows very strange is that (CD "C:\Windows"; CD "C:"; Get-Item "C:";) does not list "C:\" but it lists unexpectedly
# the current directory of that drive. The (Get-Item "C:\*") works as expected correctly.
# So we interpret a trailing backslash as it would not be present with the exception that
# If pattern contains a trailing backslash then pattern "\*\" will be replaced by ("\.\").
# If pattern is a drive as "C:" then a trailing backslash is added to avoid the unexpected listing of current dir of that drive.
# If pattern is a drive as "C:" or "C:\" then it is converted to "C:\*" to avoid the unexpected listing of current dir of that drive.
AssertNotEmpty $fsEntryPattern "pattern";
[String] $pa = $fsEntryPattern;
[Boolean] $trailingBackslashMode = (FsEntryHasTrailingDirSep $pa);
Expand All @@ -1216,7 +1223,7 @@ function FsEntryListAsFileSystemInfo ( [String] $fsEntryPattern, [Boole
# enable that ".\*\dir\" can also find dir as top dir
$pa = $pa.Replace("\*\","\.\").Replace("/*/","/./"); # Otherwise Get-ChildItem would find dirs.
}
if( $pa.Length -eq 2 -and $pa.EndsWith(":") -and $pa -match "[a-z]" ){ $pa += $(DirSep); }
if( $pa -match "^[a-z]\:[\/\\]?$" ){ $pa = "$($pa[0]):$(DirSep)*"; }
if( $inclTopDir -and $includeDirs -and -not ($pa -eq "*" -or $pa.EndsWith("$(DirSep)*")) ){
$result += @()+((Get-Item -Force -ErrorAction SilentlyContinue -Path $pa) |
Where-Object{$null -ne $_} | Where-Object{ $_.PSIsContainer });
Expand Down Expand Up @@ -1464,9 +1471,7 @@ function FsEntryGetSize ( [String] $fsEntry ){ # Must exis
Where-Object{$null -ne $_} | Measure-Object -Property length -sum;
if( $null -eq $size ){ return [Int64] 0; }
return [Int64] $size.sum; }
function DriveFreeSpace ( [String] $drive ){
FsEntryAssertHasTrailingDirSep $drive;
return [Int64] (Get-PSDrive $drive | Select-Object -ExpandProperty Free); }
function DriveFreeSpace ( [String] $driveLetter ){ return [Int64] (Get-PSDrive $drive | Select-Object -ExpandProperty Free); } # Example: "C"
function DirSep (){ return [Char] [IO.Path]::DirectorySeparatorChar; }
function DirExists ( [String] $dir ){
FsEntryAssertHasTrailingDirSep $dir;
Expand Down
Loading

0 comments on commit 3a62697

Please sign in to comment.