IntelliSearch.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
51
52
53
54
55
#requires -version 4
#requires -RunAsAdministrator
#requires -Modules powershell-yaml

function ModuleRoot { $MyInvocation.ScriptName | Split-Path -Parent }

# Removes the Zone Identifier from the files.
# This is to help with importing the .dll files, .ps1 files and other executables
Get-Item -Path ".\*" -Stream Zone.Identifier -ErrorAction:SilentlyContinue | Remove-Item -ErrorAction:SilentlyContinue

$Public  = @( Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -ErrorAction SilentlyContinue )
$Private = @( Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -ErrorAction SilentlyContinue )

foreach($import in @($Public + $Private))
{
    try
    {   
        Write-Verbose "Importing cmdlet $($import.fullname)"
        . $import.fullname
    }
    catch
    {
        Write-Error -Message "Failed to import function $($import.fullname): $_"
    }
}

Write-Verbose "Exporting cmdlets"
Export-ModuleMember -Function $Public.BaseName

#region Load config file
$IS_SettingsPath = Join-Path $Env:ProgramData "\IntelliSearch\.IntelliShell\settings.config"
if ( -not (Test-Path $IS_SettingsPath))
{
    $IS_SettingsFile = New-Item -Path $IS_SettingsPath -ItemType File -Force
    $IS_SettingsFile.Directory.Attributes = $IS_SettingsFile.Directory.Attributes -bor [io.fileattributes]::Hidden
}

$IS_Settings = ConvertFrom-Yaml -Yaml (Get-Content $IS_SettingsPath -Raw)

if ($IS_Settings -eq $null)
{
    $IS_Settings = New-Object -TypeName System.Collections.Hashtable
}

$IS_Settings.InstanceStore = if ($IS_Settings.InstanceStore) {$IS_Settings.InstanceStore} else {(Join-Path $env:ProgramData "\IntelliSearch")}
$IS_Settings.ComponentStore = if ($IS_Settings.ComponentStore) {$IS_Settings.ComponentStore} else {(Join-Path $env:ProgramFiles "\IntelliSearch")}
$IS_Settings.InstanceCreationPluginStore = if ($IS_Settings.InstanceCreationPluginStore) {$IS_Settings.InstanceCreationPluginStore} else {@((Join-Path (ModuleRoot) "\InstanceCreationPlugins"))}

Write-Verbose "Loaded settings file with following key-values:"
foreach ($Key in $IS_Settings.GetEnumerator())
{
    Write-Verbose ("${Key}: $($IS_Settings.$Key)")
}
Export-ModuleMember -Variable "IS_Settings"
#endregion Load config file