BurntToast.psm1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
$WinMajorVersion = (Get-CimInstance -ClassName Win32_OperatingSystem -Property Version).Version.Split('.')[0]

if ($WinMajorVersion -ge 10)
{
    $PublicBasic  = @( Get-ChildItem -Path $PSScriptRoot\Public\Basic\*.ps1 -ErrorAction SilentlyContinue )
    $PublicAdvanced  = @( Get-ChildItem -Path $PSScriptRoot\Public\Advanced\*.ps1 -ErrorAction SilentlyContinue )
    $Private = @( Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -ErrorAction SilentlyContinue )
    $Library = @( Get-ChildItem -Path $PSScriptRoot\lib\*.dll -Recurse -ErrorAction SilentlyContinue )
    
    $Script:Config = Get-Content -Path $PSScriptRoot\config.json -ErrorAction SilentlyContinue | ConvertFrom-Json
    $Script:DefaultImage = "$PSScriptRoot$($Script:Config.AppLogo)"
    
    Foreach($Import in @($PublicBasic + $PublicAdvanced + $Private))
    {
        Try
        {
            . $Import.FullName
        }
        Catch
        {
            Write-Error -Message "Failed to import function $($Import.FullName): $_"
        }
    }
    
    Foreach($Type in $Library)
    {
        Try
        {
            Add-Type -Path $Type.FullName
        }
        Catch
        {
            Write-Error -Message "Failed to load library $($Type.FullName): $_"
        }
    }
    
    $ModuleMembers = $PublicBasic.BaseName
    
    if ($Script:Config.FunctionLevel -eq 'Advanced')
    {
        $ModuleMembers = $ModuleMembers + $PublicAdvanced.BaseName
    }
    
    Export-ModuleMember -Function $ModuleMembers
}
else
{
    throw 'This version of BurntToast will only work on Windows 10. If you would like to use BurntToast on Windows 8, please use version 0.4'
}