function Load_main {
    param ($root)

    # Arraydefinition
    ## 0=Name,1=Größe,2=checked,3=$false->Name $true->Größe
    $Script:sortmain=@("up","up",$false, $false)

    # XAML Fenster

    [XML]$Form = @"
    <?xaml encoding="utf-8"?>
    <Window 
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
                xmlns:winForms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
                Name="Window" Title="Cleaner - Hauptfenster" Height="551" Width="1003.333" Icon="{Binding Icon}" ResizeMode="NoResize">
        <Window.Resources>
            <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="#0082c6"/>
            <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color="#022335"/>
        </Window.Resources>
        <Grid Background="#00344E">
            <TreeView TabIndex="2" Name="treeview" BorderThickness="0" HorizontalAlignment="Left" Height="374" Margin="10,57,0,0" VerticalAlignment="Top" Width="218" Background="#013C5A" Foreground="White">
                <TreeView.Resources>
                    <Style TargetType="{x:Type TreeViewItem}">
                        <Setter Property="HeaderTemplate">
                            <Setter.Value>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <Image Name="treeimage" Source="$root\Source\Folder.png" HorizontalAlignment="Left" Width="18" Margin="2" />
                                        <TextBlock VerticalAlignment="Center" Text="{Binding}" FontSize="14" Foreground="White"/>
                                    </StackPanel>
                                </DataTemplate>
                            </Setter.Value>
                        </Setter>
                        <Style.Triggers>
                            <Trigger Property="TreeViewItem.IsMouseOver" Value="True">
                                <Setter Property="Background" Value="#0082c6"></Setter>
                                <Setter Property="Foreground" Value="#022335"></Setter>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </TreeView.Resources>
            </TreeView>
            <Image Name="Laufwerk" HorizontalAlignment="Left" Height="104" Margin="-18,428,0,-10" VerticalAlignment="Top" Width="110" Source="Binding" RenderTransformOrigin="0.409,0.857"/>
            <Label Content="H-Laufwerk Auslastung:" HorizontalAlignment="Left" Margin="68,446,0,0" VerticalAlignment="Top" Height="36" Width="186" FontSize="16" Foreground="White"/>
            <TextBox Name="tblaufwerkauslastung" BorderThickness="0" HorizontalAlignment="Left" Height="22" Margin="68,478,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="190" Background="#013C5A" Foreground="White" IsReadOnly="True" FontSize="14" IsTabStop="False"/>
            <ListView TabIndex="3" Name="browser" BorderThickness="0" HorizontalAlignment="Left" Height="374" Margin="233,57,0,0" VerticalAlignment="Top" Width="550" Background="#013C5A" Foreground="White">
                <ListView.View>
                    <GridView>
                        <GridView.ColumnHeaderContainerStyle>
                            <Style TargetType="{x:Type GridViewColumnHeader}">
                                <Setter Property="Background" Value="#013C5A"/>
                                <Setter Property="Foreground" Value="White"/>
                                <Setter Property="BorderThickness" Value="0"/>
                            </Style>
                        </GridView.ColumnHeaderContainerStyle>
                        <GridViewColumn Width="30">
                            <GridViewColumn.Header>
                                <GridViewColumnHeader Name="btncheckbox" Margin="0,-1,0,-1"/>
                            </GridViewColumn.Header>
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <Image Name="CheckedImage" Source="{Binding SourceChecked}" Height="18"/>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Width="230">
                            <GridViewColumn.Header>
                                <GridViewColumnHeader Name="btnsortname" Content="Name" Margin="0,-1,0,-1"/>
                            </GridViewColumn.Header>
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <Image Name="Image_GridViewColumnName" Source="{Binding Source}" Height="20"/>
                                        <Label Name="Label_GridViewColumnName" Content="{Binding name}" Foreground="White"/>
                                    </StackPanel>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn DisplayMemberBinding="{Binding size}" Width="70">
                            <GridViewColumn.Header>
                                <GridViewColumnHeader Name="btnsortsize" Content="Größe" Margin="0,-1,0,-1"/>
                            </GridViewColumn.Header>
                        </GridViewColumn>
                        <GridViewColumn Width="210">
                            <GridViewColumn.Header>
                                <GridViewColumnHeader Name="empty" Content="" Margin="0,-1,0,-1"/>
                            </GridViewColumn.Header>
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <Label Name="Empty_Label" Content=""/>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                    </GridView>
                </ListView.View>
                <ListView.Resources>
                    <Style TargetType="ListViewItem">
                        <Style.Resources>
                            <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="red"/>
                        </Style.Resources>
                        <Style.Triggers>
                            <Trigger Property="ListViewItem.IsMouseOver" Value="True">
                                <Setter Property="Background" Value="#0082c6"></Setter>
                                <Setter Property="Foreground" Value="#022335"></Setter>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </ListView.Resources>
            </ListView>
            <Label Content="Selektierte Auswahl" HorizontalAlignment="Left" Margin="788,348,0,0" VerticalAlignment="Top" Height="83" Width="200" Background="#013C5A" Foreground="White" FontSize="16" FontWeight="Bold" HorizontalContentAlignment="Center"/>
            <Label Content="Dateitypen" HorizontalAlignment="Left" Margin="788,57,0,0" VerticalAlignment="Top" Height="286" Width="200" Background="#013C5A" Foreground="White" FontSize="16" FontWeight="Bold" HorizontalContentAlignment="Center"/>
            <Label Content="Gewählte Filter:" HorizontalAlignment="Left" Margin="799,129,0,0" VerticalAlignment="Top" Width="177" Height="27" Foreground="White" FontWeight="Medium"/>
            <Button TabIndex="4" Name="btnchoosefilter" Content="Auswählen" BorderThickness="0" HorizontalAlignment="Left" Margin="799,88,0,0" VerticalAlignment="Top" Width="177" Height="36" FontSize="13" Background="#00b8d4" Foreground="White" FontWeight="Medium">
                <Button.Resources>
                    <Style TargetType="Border">
                        <Setter Property="CornerRadius" Value="2"/>
                    </Style>
                </Button.Resources>
            </Button>
            <Button TabIndex="5" Name="btnfiltersw" FontSize="13" BorderThickness="0" HorizontalAlignment="Left" Margin="799,300,0,0" VerticalAlignment="Top" Width="50" Height="30" Background="Transparent" Foreground="White" FontWeight="Medium">
                <Image Name="imgswitch" Source="{Binding}"/>
                <Button.Resources>
                    <Style TargetType="Border">
                        <Setter Property="CornerRadius" Value="8"/>
                    </Style>
                </Button.Resources>
            </Button>
            <Button TabIndex="0" Name="btnScanner" Content="Zum Scannen" BorderThickness="0" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="218" Height="42" FontSize="16" FontWeight="Bold" Background="#00b8d4" Foreground="White">
                <Button.Resources>
                    <Style TargetType="Border">
                        <Setter Property="CornerRadius" Value="2"/>
                    </Style>
                </Button.Resources>
            </Button>
            <Button TabIndex="7" Name="btndel" Content="Löschen" BorderThickness="0" HorizontalAlignment="Left" Margin="857,436,0,0" VerticalAlignment="Top" Width="131" Height="77" FontSize="20" FontWeight="Bold" Background="#FFC5C5C5" Foreground="#FF7A7A7A" IsEnabled="False">
                <Button.Resources>
                    <Style TargetType="Border">
                        <Setter Property="CornerRadius" Value="2"/>
                    </Style>
                </Button.Resources>
            </Button>
            <TextBox Name="elemente" BorderThickness="0" HorizontalAlignment="Left" Height="22" Margin="794,377,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="186" Background="#013C5A" Foreground="White" IsReadOnly="True" FontSize="14" TextAlignment="Center" IsTabStop="False"/>
            <TextBox Name="size" BorderThickness="0" HorizontalAlignment="Left" Height="22" Margin="794,404,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="186" Background="#013C5A" Foreground="White" IsReadOnly="True" FontSize="14" TextAlignment="Center" IsTabStop="False"/>
            <ProgressBar Name="pbbar" HorizontalAlignment="Left" Height="4" Margin="68,502,0,0" VerticalAlignment="Top" Width="190" Background="#008000" Foreground="#ff6400" IsTabStop="False"/>
            <Label Content="Dieses Tool hilft Ihnen beim Bereinigen Ihres H-Laufwerks. Rechts können Sie auswählen, &#xD;&#xA;welche Art von Dateien aus dem ausgewählten Ordner angezeigt werden sollen." HorizontalAlignment="Left" Margin="233,5,0,0" VerticalAlignment="Top" Width="755" Height="52" FontSize="15" Foreground="White"/>
            <Label Content="Unterordner mit &#xD;&#xA;einbeziehen" HorizontalAlignment="Left" Margin="857,291,0,0" VerticalAlignment="Top" Width="177" Height="63" Foreground="White" FontWeight="Medium" FontSize="13"/>
            <Label Name="choosen1" Content="" HorizontalAlignment="Left" Margin="799,156,0,0" VerticalAlignment="Top" Width="177" Height="23" FontSize="12" Foreground="White"/>
            <Label Name="choosen2" Content="" HorizontalAlignment="Left" Margin="799,179,0,0" VerticalAlignment="Top" Width="177" Height="23" FontSize="12" Foreground="White"/>
            <Label Name="choosen3" Content="" HorizontalAlignment="Left" Margin="799,202,0,0" VerticalAlignment="Top" Width="177" Height="23" FontSize="12" Foreground="White"/>
            <Label Name="choosen4" Content="" HorizontalAlignment="Left" Margin="799,225,0,0" VerticalAlignment="Top" Width="177" Height="23" FontSize="12" Foreground="White"/>
            <Button TabIndex="1" Name="btninfo" HorizontalAlignment="Left" Margin="955,15,0,0" VerticalAlignment="Top" Width="30" Height="30" Background="Transparent" ToolTip="Information" BorderThickness="0">
                <Image Name="imginfo" Source="{Binding}"/>
                <Button.Resources>
                    <Style TargetType="Border">
                        <Setter Property="CornerRadius" Value="5"/>
                    </Style>
                </Button.Resources>
            </Button>
            <Button TabIndex="6" Name="btnmove" Content="Verschieben" BorderThickness="0" HorizontalAlignment="Left" Margin="718,436,0,0" VerticalAlignment="Top" Width="131" Height="77" FontSize="20" FontWeight="Bold" Background="#FFC5C5C5" Foreground="#FF7A7A7A" IsEnabled="False">
                <Button.Resources>
                    <Style TargetType="{x:Type Border}">
                        <Setter Property="CornerRadius" Value="2"/>
                    </Style>
                </Button.Resources>
            </Button>
            <wfi:WindowsFormsHost Name="pbLoading" Height="95" Margin="453,202,456,0" Width="95" Visibility="Hidden" VerticalAlignment="Top" Background="#013C5A">
                <winForms:PictureBox x:Name="pb"></winForms:PictureBox>
            </wfi:WindowsFormsHost>
        </Grid>
    </Window>
"@

    # Lädt das Fenster
    $window=[Windows.Markup.XamlReader]::Load((New-Object System.Xml.XmlNodeReader $Form))

    # Objekt - Variablen Verknüpfung
    $pb = $window.findName("pb")
    $Laufwerk = $window.findName("Laufwerk")
    $Script:mainimgswitch = $window.findName("imgswitch")
    $imginfo = $window.findName("imginfo")
    $Script:mainelements = $window.findName("elemente")
    $Script:mainsize = $window.findName("size")
    $Script:bar = $window.findName("pbbar")
    $Script:last = $window.findName("tblaufwerkauslastung")
    $Script:maintree = $window.findName("treeview")
    $Script:mainbrowser = $window.findName("browser")
    $Script:mainscanner = $window.findName("btnScanner")
    $Script:mainfilter = $window.findName("btnchoosefilter")
    $Script:maininfo = $window.findName("btninfo")
    $Script:mainloading = $window.findName("pbLoading")
    $Script:mainswitch = $window.findName("btnfiltersw")
    $Script:maindel = $window.findName("btndel")
    $Script:mainmove = $window.findName("btnmove")
    $Script:mainsortname = $window.findName("btnsortname")
    $Script:mainsortsize = $window.findName("btnsortsize")
    $Script:maincheckall = $window.findName("btncheckbox")
    $Script:mainchoosen1 = $window.findName("choosen1")
    $Script:mainchoosen2 = $window.findName("choosen2")
    $Script:mainchoosen3 = $window.findName("choosen3")
    $Script:mainchoosen4 = $window.findName("choosen4")

    # Verknüpft feste Elemente
    $window.Title = $Script:Version
    $window.icon="$root/Source/Logo.png"
    $Laufwerk.Source = "$root/Source/HDD1.png"
    $mainimgswitch.Source = "$root/Source/swfalse.png"
    $imginfo.Source = "$root/Source/info.png"
    $mainelements.Text = " 0 Elemente"
    $mainsize.Text = " 0 MB"

    ### GIF Sanduhr
    $file = (get-item "$root/Source/mainhourglas.gif")
    $img = [System.Drawing.Image]::Fromfile($file);
    $pb.Image = $img

    return $window
}

function Set_Defaults_Main {
    param ($array)
    if (!$array[5]) {
        $Script:bar.Value=$array[4]
        $Script:last.Text=$array[0]
    }else{
        $Script:last.Text="OFFLINE"
    }
}

function Get_TreeView {
    $maintree.Items.Clear()
    $RootItem = New-Object System.Windows.Controls.TreeViewItem
    $RootItem.Header = $Script:folderdb[0][0]
    $RootItem.Tag = 0
    for ($i = 5; $i -lt $Script:folderdb[0].count; $i++) {
        if ($Script:folderdb[0][$i].contains("f")) {
            $item=$Script:folderdb[0][$i].Substring(1)
            Get_TreeViewExpand $RootItem $item
        } 
        [System.Windows.Forms.Application]::DoEvents()
    }
    $maintree.Items.Add($RootItem)
}

function Get_TreeViewExpand {
    param ($parentItem, $Folder)
    $int = [int]$Folder
    if (!$Script:folderdb[$int][4]) {
        $subItem = New-Object System.Windows.Controls.TreeViewItem
        $subItem.Header = $Script:folderdb[$int][0]
        $subItem.Tag = $int
        [void]$parentItem.Items.Add($subItem)
        for ($i = 5; $i -lt $Script:folderdb[$int].count; $i++) {
            if ($Script:folderdb[$int][$i] -match "f") {
                $item=$Script:folderdb[$int][$i].Substring(1)
                Get_TreeViewExpand $subItem $item
            }
            [System.Windows.Forms.Application]::DoEvents()
        }
    }
}

function Browser_Path {
    param ($path)
    $data = @()
    $c=$false
    Log "Tree $path" -clear
    for ($t = 0; $t -lt 3; $t++) {
        if ($Script:filtercheck[$t]) {
            $c=$true
        }
        [System.Windows.Forms.Application]::DoEvents()
    }
    if ($c) {
        Filter_data $path
    }else {
        for ($i = 5; $i -lt $Script:folderdb[$path].count; $i++) {
            if ($Script:folderdb[$path][$i] -match "f") {
                $string=$Script:folderdb[$path][$i].Substring(1)
                $int = [int]$string
                if (!$Script:folderdb[$int][4]) {
                    if ($Script:folderdb[$int][3]) {
                        $cp = "$Script:ScriptRoot\Source\checked.png"
                    }else {
                        $cp = "$Script:ScriptRoot\Source\unchecked.png"
                    }
                    $Length = calc_Size $Script:folderdb[$int][1]
                    $data += New-Object PSObject -prop @{Source="$Script:ScriptRoot\Source\Folder.png";Name=$Script:folderdb[$int][0];Size="$Length";Tag=$Script:folderdb[$path][$i];SourceChecked="$cp"}
                }
            }else {
                if (!$Script:filedb[$Script:folderdb[$path][$i]][4]) {
                    if ($Script:filedb[$Script:folderdb[$path][$i]][3]) {
                        $cp = "$Script:ScriptRoot\Source\checked.png"
                    }else {
                        $cp = "$Script:ScriptRoot\Source\unchecked.png"
                    }
                    $Length = calc_Size $Script:filedb[$Script:folderdb[$path][$i]][1]
                    $icon = $Script:icontypes[$Script:filedb[$Script:folderdb[$path][$i]][5]]
                    $data += New-Object PSObject -prop @{Source="$Script:ScriptRoot\icons\$icon.ico";Name=$Script:filedb[$Script:folderdb[$path][$i]][0];Size="$Length";Tag=$Script:folderdb[$path][$i];SourceChecked="$cp"}
                }
            }
            [System.Windows.Forms.Application]::DoEvents()
            $logcontent = "Main: Browser " + $Script:folderdb[$path][$i]
            Log $logcontent -clear
        }
        $item = [System.Windows.Data.ListCollectionView]$data
        $mainbrowser.Remove
        $mainbrowser.ItemsSource = $item
    }
}

function Check_Browser {
    param ($tag)
    $data = @()
    for ($i = 0; $i -lt $mainbrowser.Items.Count; $i++) {
        if (($mainbrowser.Items.Tag[$i] -eq $tag) -or ($mainbrowser.Items.Count -eq 1)) {
            $item=$mainbrowser.Items[$i]
            if ($tag -match "f") {
                $string=$tag.Substring(1)
                $int = [int]$string
                if ($Script:folderdb[$int][3]) {
                    $Script:folderdb[$int][3]=$false
                    count_element $false $Script:folderdb[$int][1]
                    $data += New-Object PSObject -prop @{Source=$item.Source;Name=$item.Name;Size=$item.Size;Tag=$item.Tag;SourceChecked="$Script:ScriptRoot\Source\unchecked.png"}
                }else {
                    $Script:folderdb[$int][3]=$true
                    count_element $true $Script:folderdb[$int][1]
                    $data += New-Object PSObject -prop @{Source=$item.Source;Name=$item.Name;Size=$item.Size;Tag=$item.Tag;SourceChecked="$Script:ScriptRoot\Source\checked.png"}
                }
            }else {
                if ($Script:filedb[$tag][3]) {
                    $Script:filedb[$tag][3]=$false
                    count_element $false $Script:filedb[$tag][1]
                    $data += New-Object PSObject -prop @{Source=$item.Source;Name=$item.Name;Size=$item.Size;Tag=$item.Tag;SourceChecked="$Script:ScriptRoot\Source\unchecked.png"}
                }else {
                    $Script:filedb[$tag][3]=$true
                    count_element $true $Script:filedb[$tag][1]
                    $data += New-Object PSObject -prop @{Source=$item.Source;Name=$item.Name;Size=$item.Size;Tag=$item.Tag;SourceChecked="$Script:ScriptRoot\Source\checked.png"}
                }
            }
        }else {
            $data += $mainbrowser.Items[$i]
        }
        [System.Windows.Forms.Application]::DoEvents()
    }
    $item = [System.Windows.Data.ListCollectionView]$data
    $mainbrowser.Remove
    $mainbrowser.ItemsSource = $item
}

function main_sortname{
    param([switch]$change)
    $data= @()
    if ($change) {
        if ($sortmain[0] -eq "up") {
            $sortmain[0]="down"
        }else {
            $sortmain[0]="up"
        }
    }
    for ($i = 0; $i -lt $mainbrowser.Items.count; $i++) {
        $item = $mainbrowser.Items[$i]
        $data += New-Object PSObject -prop @{Name=$item.Name;Source=$item.Source;Size=$item.Size;Checked=$item.Checked;Tag=$item.Tag;SourceChecked=$Item.SourceChecked}
        [System.Windows.Forms.Application]::DoEvents()
    }
    if ($sortmain[0] -eq "up") {
        $data = $data | Sort-Object -Property Name
    }else {
        $data = $data | Sort-Object -Property Name -Descending
    }
    $sortmain[3]=$false
    $ItemList = [System.Windows.Data.ListCollectionView]$data
    $mainbrowser.ItemsSource = $ItemList
}

function main_sortsize {
    param([switch]$change)
    if ($change) {
        if ($sortmain[1] -eq "up") {
            $sortmain[1]="down"
        }else {
            $sortmain[1]="up"
        }
    }
    $data=@()
    $array=@()
    for ($i = 0; $i -lt $mainbrowser.Items.Count; $i++) {
        $item = $mainbrowser.Items[$i]
        if ($item.Size.EndsWith("GB")) {
            $stringtrim = $item.Size.TrimEnd(" GB")
        }else {
            $stringtrim = $item.Size.TrimEnd(" MB")
        }
        $int = [int]$stringtrim
        $array += New-Object PSObject -prop @{Tag=$item.Tag;Size=$int}
        [System.Windows.Forms.Application]::DoEvents()
    }
    if ($sortmain[1] -eq "up") {
        $array = $array | Sort-Object -Property Size 
    }else {
        $array = $array | Sort-Object -Property Size -Descending
    }
    for ($i = 0; $i -lt $array.Count; $i++) {
        for ($e = 0; $e -lt $mainbrowser.items.Count; $e++) {
            if ($array.Tag[$i] -eq $mainbrowser.Items.Tag[$e]) {
                $item=$mainbrowser.Items[$e]
                $data += New-Object PSObject -prop @{Name=$item.Name;Source=$item.Source;Size=$item.Size;Checked=$item.Checked;Tag=$item.Tag;SourceChecked=$Item.SourceChecked}
                $e=$mainbrowser.items.Count               
            }
            [System.Windows.Forms.Application]::DoEvents()
        }
        [System.Windows.Forms.Application]::DoEvents()
    }
    $sortmain[3]=$true
    $ItemList = [System.Windows.Data.ListCollectionView]$data
    $mainbrowser.Remove
    $mainbrowser.ItemsSource = $ItemList
}

function main_checkall {
    $data = @()
    $check = 0
    if ($sortmain[2]) {
        $sortmain[2]=$false
        for ($i = 0; $i -lt $mainbrowser.Items.Count; $i++) {
            $item = $mainbrowser.Items[$i]
            $tag=$item.Tag
            if ($tag -match "f") {
                $string=$tag.Substring(1)
                $int = [int]$string
                if ($folderdb[$int][3]) {
                    $folderdb[$int][3]=$false
                    count_element $false $Script:folderdb[$int][1]
                    $data += New-Object PSObject -prop @{Name=$item.Name;Source=$item.Source;Size=$item.Size;Checked=$false;Tag=$item.Tag;SourceChecked="$Script:ScriptRoot\Source\unchecked.png"}
                    $check++
                }else {
                    $data += $item
                }
            }else {
                if ($filedb[$tag][3]) {
                    $filedb[$tag][3]=$false
                    count_element $false $Script:filedb[$tag][1]
                    $data += New-Object PSObject -prop @{Name=$item.Name;Source=$item.Source;Size=$item.Size;Checked=$false;Tag=$item.Tag;SourceChecked="$Script:ScriptRoot\Source\unchecked.png"}
                    $check++
                }else {
                    $data += $item
                }
            }
            [System.Windows.Forms.Application]::DoEvents()
        }
    }else {
        $sortmain[2]=$true
        for ($i = 0; $i -lt $mainbrowser.Items.Count; $i++) {
            $item = $mainbrowser.Items[$i]
            $tag=$item.Tag
            if ($tag -match "f") {
                $string=$tag.Substring(1)
                $int = [int]$string
                if (!$folderdb[$int][3]) {
                    $folderdb[$int][3]=$true
                    count_element $true $Script:folderdb[$int][1]
                    $data += New-Object PSObject -prop @{Name=$item.Name;Source=$item.Source;Size=$item.Size;Checked=$true;Tag=$item.Tag;SourceChecked="$Script:ScriptRoot\Source\checked.png"}
                    $check++
                }else {
                    $data += $item
                }
            }else {
                if (!$filedb[$tag][3]) {
                    $filedb[$tag][3]=$true
                    count_element $true $Script:filedb[$tag][1]
                    $data += New-Object PSObject -prop @{Name=$item.Name;Source=$item.Source;Size=$item.Size;Checked=$true;Tag=$item.Tag;SourceChecked="$Script:ScriptRoot\Source\checked.png"}
                    $check++
                }else {
                    $data += $item
                }
            }
            [System.Windows.Forms.Application]::DoEvents()
        }
    }
    if ($check -eq 0) {
        main_checkall
    }else{
        $ItemList = [System.Windows.Data.ListCollectionView]$data
        $mainbrowser.ItemsSource = $ItemList
    }
}

function main_loading {
    param ($stat)
    if($stat){
        $Script:mainloading.Visibility = "Visible"
        $Script:maininfo.Visibility = "Hidden"
    }else {
        $Script:mainloading.Visibility = "Hidden"
        $Script:maininfo.Visibility = "Visible"
    }
}

Function Select-FolderDialog{
    param([string]$Description="Zielverzeichnis wählen",[string]$RootFolder="Desktop")
    [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |Out-Null     
    $objForm = New-Object System.Windows.Forms.FolderBrowserDialog
    $objForm.Rootfolder = $RootFolder
    $objForm.Description = $Description
    $Show = $objForm.ShowDialog()
    If ($Show -eq "OK"){
        Return $objForm.SelectedPath
    }else{
        Return $false
    }
}

Log "### Main geladen ###" -clear