<commit_before>﻿param
(
	[Parameter(Mandatory=$true)]
	[Hashtable] $settings
)

Set-StrictMode -version Latest

$latestBuild = 'https://github.com/downloads/EastPoint/PerfTap/PerfTap-0.1.zip'

function Test-IsAdmin   
{  
	$identity = [Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent();
    If (-NOT $identity.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
    {  
		throw 'You are not currently running this installation under an Administrator account.  Installation aborted!'
	}
}

function Merge-Parameters()
{
	param
	(
		[Parameter(Mandatory=$true)]
		[Hashtable] $Hash
	)
	
	$defaults = 
	@{
		Key = '';
		Port = 8125;
		SampleInterval = '00:00:05';
		DefinitionPaths = @('CounterDefinitions\system.counters');
		CounterNames = @()
	}
	
	$allowedKeys = ($defaults | Select -ExpandProperty Keys) + @('Server')
	$Hash | Select -ExpandProperty Keys | 
	% {
		if (-not $allowedKeys -contains $_)
		{
			$msg = "Parameter $_ not expected"
			Write-Error -Message $msg -Category InvalidArgument
			throw $msg
		}
		$defaults.$_ = $Hash.$_ 
	}
	
	$defaults
}

function Extract-Zip()
{
    Write-Host "Downloading Latest Package from $latestBuild"
	$path = "${Env:Temp}\perftap.zip"
    (New-Object Net.WebClient).DownloadFile($latestBuild, $path)
	$shellApplication = New-Object -com Shell.Application
	$zipItems = $shellApplication.NameSpace($path).Items()
	$extracted = "${Env:ProgramFiles}\PerfTap"
	if (!(test-path $extracted)) { [Void](New-Item $extracted -type directory) }
	$shellApplication.NameSpace($extracted).CopyHere($zipItems, 0x14)
	Remove-Item $path
}

function Run-ServiceInstaller()
{
	Set-Alias installutil $Env:windir\Microsoft.NET\Framework\v4.0.30319\installutil.exe
	$servicePath = "${Env:ProgramFiles}\PerfTap\PerfTap.WindowsServiceHost.exe"
	if ((Get-Service PerfTap -ErrorAction SilentlyContinue) -eq $null)
	{
		installutil /u """$servicePath"""
	}
	
	installutil """$servicePath"""
}

function Modify-ConfigFile()<commit_msg>fixed minor bug in install script -- should be uninstalling service when it *does* exist<commit_after>﻿param
(
	[Parameter(Mandatory=$true)]
	[Hashtable] $settings
)

Set-StrictMode -version Latest

$latestBuild = 'https://github.com/downloads/EastPoint/PerfTap/PerfTap-0.1.zip'

function Test-IsAdmin   
{  
	$identity = [Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent();
    If (-NOT $identity.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
    {  
		throw 'You are not currently running this installation under an Administrator account.  Installation aborted!'
	}
}

function Merge-Parameters()
{
	param
	(
		[Parameter(Mandatory=$true)]
		[Hashtable] $Hash
	)
	
	$defaults = 
	@{
		Key = '';
		Port = 8125;
		SampleInterval = '00:00:05';
		DefinitionPaths = @('CounterDefinitions\system.counters');
		CounterNames = @()
	}
	
	$allowedKeys = ($defaults | Select -ExpandProperty Keys) + @('Server')
	$Hash | Select -ExpandProperty Keys | 
	% {
		if (-not $allowedKeys -contains $_)
		{
			$msg = "Parameter $_ not expected"
			Write-Error -Message $msg -Category InvalidArgument
			throw $msg
		}
		$defaults.$_ = $Hash.$_ 
	}
	
	$defaults
}

function Extract-Zip()
{
    Write-Host "Downloading Latest Package from $latestBuild"
	$path = "${Env:Temp}\perftap.zip"
    (New-Object Net.WebClient).DownloadFile($latestBuild, $path)
	$shellApplication = New-Object -com Shell.Application
	$zipItems = $shellApplication.NameSpace($path).Items()
	$extracted = "${Env:ProgramFiles}\PerfTap"
	if (!(test-path $extracted)) { [Void](New-Item $extracted -type directory) }
	$shellApplication.NameSpace($extracted).CopyHere($zipItems, 0x14)
	Remove-Item $path
}

function Run-ServiceInstaller()
{
	Set-Alias installutil $Env:windir\Microsoft.NET\Framework\v4.0.30319\installutil.exe
	$servicePath = "${Env:ProgramFiles}\PerfTap\PerfTap.WindowsServiceHost.exe"
	if ((Get-Service PerfTap -ErrorAction SilentlyContinue) -ne $null)
	{
		installutil /u """$servicePath"""
	}
	
	installutil """$servicePath"""
}

function Modify-ConfigFile()
{'fraction_non_alphanumeric': 0.1465917419985341, 'fraction_numerical': 0.010750061079892499, 'mean_word_length': 4.678224687933426, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2311334', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1352, 'n_words': 266}