PSWriteOffice.Libraries.ps1

# PSWriteOffice.Libraries.ps1
# Auto-generated by PowerForge. Do not edit.

$LibrariesByFolder = @{
    'Core' = @(
        'Lib\Core\PSWriteOffice.dll'
        'Lib\Core\AngleSharp.Css.dll'
        'Lib\Core\AngleSharp.dll'
        'Lib\Core\BouncyCastle.Cryptography.dll'
        'Lib\Core\DocumentFormat.OpenXml.dll'
        'Lib\Core\DocumentFormat.OpenXml.Framework.dll'
        'Lib\Core\OfficeIMO.AsciiDoc.dll'
        'Lib\Core\OfficeIMO.AsciiDoc.Markdown.dll'
        'Lib\Core\OfficeIMO.CSV.dll'
        'Lib\Core\OfficeIMO.Drawing.dll'
        'Lib\Core\OfficeIMO.Email.dll'
        'Lib\Core\OfficeIMO.Epub.dll'
        'Lib\Core\OfficeIMO.Excel.dll'
        'Lib\Core\OfficeIMO.Excel.GoogleSheets.dll'
        'Lib\Core\OfficeIMO.Excel.Html.dll'
        'Lib\Core\OfficeIMO.Excel.OpenDocument.dll'
        'Lib\Core\OfficeIMO.Excel.Pdf.dll'
        'Lib\Core\OfficeIMO.GoogleWorkspace.dll'
        'Lib\Core\OfficeIMO.GoogleWorkspace.Drive.dll'
        'Lib\Core\OfficeIMO.Html.dll'
        'Lib\Core\OfficeIMO.Html.Pdf.dll'
        'Lib\Core\OfficeIMO.Latex.dll'
        'Lib\Core\OfficeIMO.Latex.Markdown.dll'
        'Lib\Core\OfficeIMO.Markdown.dll'
        'Lib\Core\OfficeIMO.Markdown.Html.dll'
        'Lib\Core\OfficeIMO.Markdown.Pdf.dll'
        'Lib\Core\OfficeIMO.OneNote.dll'
        'Lib\Core\OfficeIMO.OneNote.Markdown.dll'
        'Lib\Core\OfficeIMO.OpenDocument.dll'
        'Lib\Core\OfficeIMO.Pdf.dll'
        'Lib\Core\OfficeIMO.PowerPoint.dll'
        'Lib\Core\OfficeIMO.PowerPoint.Html.dll'
        'Lib\Core\OfficeIMO.PowerPoint.OpenDocument.dll'
        'Lib\Core\OfficeIMO.PowerPoint.Pdf.dll'
        'Lib\Core\OfficeIMO.Reader.All.dll'
        'Lib\Core\OfficeIMO.Reader.AsciiDoc.dll'
        'Lib\Core\OfficeIMO.Reader.Core.dll'
        'Lib\Core\OfficeIMO.Reader.Csv.dll'
        'Lib\Core\OfficeIMO.Reader.Email.dll'
        'Lib\Core\OfficeIMO.Reader.Epub.dll'
        'Lib\Core\OfficeIMO.Reader.Excel.dll'
        'Lib\Core\OfficeIMO.Reader.Html.dll'
        'Lib\Core\OfficeIMO.Reader.Image.dll'
        'Lib\Core\OfficeIMO.Reader.Json.dll'
        'Lib\Core\OfficeIMO.Reader.Latex.dll'
        'Lib\Core\OfficeIMO.Reader.Markdown.dll'
        'Lib\Core\OfficeIMO.Reader.Notebook.dll'
        'Lib\Core\OfficeIMO.Reader.Ocr.Process.dll'
        'Lib\Core\OfficeIMO.Reader.Ocr.Tesseract.dll'
        'Lib\Core\OfficeIMO.Reader.OneNote.dll'
        'Lib\Core\OfficeIMO.Reader.OpenDocument.dll'
        'Lib\Core\OfficeIMO.Reader.Pdf.dll'
        'Lib\Core\OfficeIMO.Reader.PowerPoint.dll'
        'Lib\Core\OfficeIMO.Reader.Rtf.dll'
        'Lib\Core\OfficeIMO.Reader.Subtitles.dll'
        'Lib\Core\OfficeIMO.Reader.Visio.dll'
        'Lib\Core\OfficeIMO.Reader.Word.dll'
        'Lib\Core\OfficeIMO.Reader.Xml.dll'
        'Lib\Core\OfficeIMO.Reader.Yaml.dll'
        'Lib\Core\OfficeIMO.Reader.Zip.dll'
        'Lib\Core\OfficeIMO.Rtf.dll'
        'Lib\Core\OfficeIMO.Rtf.Markdown.dll'
        'Lib\Core\OfficeIMO.Rtf.Pdf.dll'
        'Lib\Core\OfficeIMO.Security.dll'
        'Lib\Core\OfficeIMO.Visio.dll'
        'Lib\Core\OfficeIMO.Word.dll'
        'Lib\Core\OfficeIMO.Word.GoogleDocs.dll'
        'Lib\Core\OfficeIMO.Word.Html.dll'
        'Lib\Core\OfficeIMO.Word.Markdown.dll'
        'Lib\Core\OfficeIMO.Word.OpenDocument.dll'
        'Lib\Core\OfficeIMO.Word.Pdf.dll'
        'Lib\Core\OfficeIMO.Word.Rtf.dll'
        'Lib\Core\OfficeIMO.Zip.dll'
        'Lib\Core\System.IO.Packaging.dll'
        'Lib\Core\YamlDotNet.dll'
    )
    'Default' = @(
        'Lib\Default\PSWriteOffice.dll'
        'Lib\Default\AngleSharp.Css.dll'
        'Lib\Default\AngleSharp.dll'
        'Lib\Default\BouncyCastle.Cryptography.dll'
        'Lib\Default\DocumentFormat.OpenXml.dll'
        'Lib\Default\DocumentFormat.OpenXml.Framework.dll'
        'Lib\Default\Microsoft.Bcl.AsyncInterfaces.dll'
        'Lib\Default\OfficeIMO.AsciiDoc.dll'
        'Lib\Default\OfficeIMO.AsciiDoc.Markdown.dll'
        'Lib\Default\OfficeIMO.CSV.dll'
        'Lib\Default\OfficeIMO.Drawing.dll'
        'Lib\Default\OfficeIMO.Email.dll'
        'Lib\Default\OfficeIMO.Epub.dll'
        'Lib\Default\OfficeIMO.Excel.dll'
        'Lib\Default\OfficeIMO.Excel.GoogleSheets.dll'
        'Lib\Default\OfficeIMO.Excel.Html.dll'
        'Lib\Default\OfficeIMO.Excel.OpenDocument.dll'
        'Lib\Default\OfficeIMO.Excel.Pdf.dll'
        'Lib\Default\OfficeIMO.GoogleWorkspace.dll'
        'Lib\Default\OfficeIMO.GoogleWorkspace.Drive.dll'
        'Lib\Default\OfficeIMO.Html.dll'
        'Lib\Default\OfficeIMO.Html.Pdf.dll'
        'Lib\Default\OfficeIMO.Latex.dll'
        'Lib\Default\OfficeIMO.Latex.Markdown.dll'
        'Lib\Default\OfficeIMO.Markdown.dll'
        'Lib\Default\OfficeIMO.Markdown.Html.dll'
        'Lib\Default\OfficeIMO.Markdown.Pdf.dll'
        'Lib\Default\OfficeIMO.OneNote.dll'
        'Lib\Default\OfficeIMO.OneNote.Markdown.dll'
        'Lib\Default\OfficeIMO.OpenDocument.dll'
        'Lib\Default\OfficeIMO.Pdf.dll'
        'Lib\Default\OfficeIMO.PowerPoint.dll'
        'Lib\Default\OfficeIMO.PowerPoint.Html.dll'
        'Lib\Default\OfficeIMO.PowerPoint.OpenDocument.dll'
        'Lib\Default\OfficeIMO.PowerPoint.Pdf.dll'
        'Lib\Default\OfficeIMO.Reader.All.dll'
        'Lib\Default\OfficeIMO.Reader.AsciiDoc.dll'
        'Lib\Default\OfficeIMO.Reader.Core.dll'
        'Lib\Default\OfficeIMO.Reader.Csv.dll'
        'Lib\Default\OfficeIMO.Reader.Email.dll'
        'Lib\Default\OfficeIMO.Reader.Epub.dll'
        'Lib\Default\OfficeIMO.Reader.Excel.dll'
        'Lib\Default\OfficeIMO.Reader.Html.dll'
        'Lib\Default\OfficeIMO.Reader.Image.dll'
        'Lib\Default\OfficeIMO.Reader.Json.dll'
        'Lib\Default\OfficeIMO.Reader.Latex.dll'
        'Lib\Default\OfficeIMO.Reader.Markdown.dll'
        'Lib\Default\OfficeIMO.Reader.Notebook.dll'
        'Lib\Default\OfficeIMO.Reader.Ocr.Process.dll'
        'Lib\Default\OfficeIMO.Reader.Ocr.Tesseract.dll'
        'Lib\Default\OfficeIMO.Reader.OneNote.dll'
        'Lib\Default\OfficeIMO.Reader.OpenDocument.dll'
        'Lib\Default\OfficeIMO.Reader.Pdf.dll'
        'Lib\Default\OfficeIMO.Reader.PowerPoint.dll'
        'Lib\Default\OfficeIMO.Reader.Rtf.dll'
        'Lib\Default\OfficeIMO.Reader.Subtitles.dll'
        'Lib\Default\OfficeIMO.Reader.Visio.dll'
        'Lib\Default\OfficeIMO.Reader.Word.dll'
        'Lib\Default\OfficeIMO.Reader.Xml.dll'
        'Lib\Default\OfficeIMO.Reader.Yaml.dll'
        'Lib\Default\OfficeIMO.Reader.Zip.dll'
        'Lib\Default\OfficeIMO.Rtf.dll'
        'Lib\Default\OfficeIMO.Rtf.Markdown.dll'
        'Lib\Default\OfficeIMO.Rtf.Pdf.dll'
        'Lib\Default\OfficeIMO.Security.dll'
        'Lib\Default\OfficeIMO.Visio.dll'
        'Lib\Default\OfficeIMO.Word.dll'
        'Lib\Default\OfficeIMO.Word.GoogleDocs.dll'
        'Lib\Default\OfficeIMO.Word.Html.dll'
        'Lib\Default\OfficeIMO.Word.Markdown.dll'
        'Lib\Default\OfficeIMO.Word.OpenDocument.dll'
        'Lib\Default\OfficeIMO.Word.Pdf.dll'
        'Lib\Default\OfficeIMO.Word.Rtf.dll'
        'Lib\Default\OfficeIMO.Zip.dll'
        'Lib\Default\System.Buffers.dll'
        'Lib\Default\System.IO.Packaging.dll'
        'Lib\Default\System.IO.Pipelines.dll'
        'Lib\Default\System.Memory.dll'
        'Lib\Default\System.Numerics.Vectors.dll'
        'Lib\Default\System.Runtime.CompilerServices.Unsafe.dll'
        'Lib\Default\System.Text.Encoding.CodePages.dll'
        'Lib\Default\System.Text.Encodings.Web.dll'
        'Lib\Default\System.Text.Json.dll'
        'Lib\Default\System.Threading.Tasks.Extensions.dll'
        'Lib\Default\YamlDotNet.dll'
    )
}


$AssemblyFolders = Get-ChildItem -Path $PSScriptRoot\Lib -Directory -ErrorAction SilentlyContinue

$Default = $false
$Core = $false
$Standard = $false
foreach ($A in $AssemblyFolders.Name) {
    if ($A -eq 'Default') {
        $Default = $true
    } elseif ($A -eq 'Core') {
        $Core = $true
    } elseif ($A -eq 'Standard') {
        $Standard = $true
    }
}
if ($Standard -and $Core -and $Default) {
    $FrameworkNet = 'Default'
    $Framework = 'Standard'
} elseif ($Standard -and $Core) {
    $Framework = 'Standard'
    $FrameworkNet = 'Standard'
} elseif ($Core -and $Default) {
    $Framework = 'Core'
    $FrameworkNet = 'Default'
} elseif ($Standard -and $Default) {
    $Framework = 'Standard'
    $FrameworkNet = 'Default'
} elseif ($Standard) {
    $Framework = 'Standard'
    $FrameworkNet = 'Standard'
} elseif ($Core) {
    $Framework = 'Core'
    $FrameworkNet = ''
} elseif ($Default) {
    $Framework = ''
    $FrameworkNet = 'Default'
} else {
    #Write-Error -Message 'No assemblies found'
}

if ($PSEdition -eq 'Core') {
    $LibFolder = $Framework
} else {
    $LibFolder = $FrameworkNet
}

$LibrariesToLoad = $LibrariesByFolder[$LibFolder]
if ($null -eq $LibrariesToLoad) { $LibrariesToLoad = @() }
foreach ($L in $LibrariesToLoad) {
    try {
        $LibraryPathParts = @($PSScriptRoot) + @($L -split '[\\/]' | Where-Object { -not [string]::IsNullOrWhiteSpace($_) })
        $LibraryPath = [IO.Path]::Combine([string[]] $LibraryPathParts)
        try {
            $null = [System.Reflection.AssemblyName]::GetAssemblyName($LibraryPath)
        } catch [System.BadImageFormatException] {
            Write-Verbose -Message "Skipping non-managed library '$L'."
            continue
        }

        Add-Type -Path $LibraryPath -ErrorAction Stop
    } catch {
        if ($_.Exception.Message -like '*Assembly with same name is already loaded*') {
            Write-Warning -Message "Assembly with same name is already loaded. Ignoring '$L'."
        } else {
            throw $_
        }
    }
}