init
This commit is contained in:
254
GUIS/scanner/scanner.ps1
Normal file
254
GUIS/scanner/scanner.ps1
Normal file
@@ -0,0 +1,254 @@
|
||||
|
||||
#0=ScanAktiv;
|
||||
$Script:switch=@($false,$false)
|
||||
function Load_scanner {
|
||||
param ($root)
|
||||
|
||||
# Lädt das Fenster
|
||||
[xml]$Form = Get-Content "$PSScriptRoot\scanner.xaml" -Encoding utf8
|
||||
$NR=(New-Object System.Xml.XmlNodeReader $Form)
|
||||
$window=[Windows.Markup.XamlReader]::Load($NR)
|
||||
|
||||
# Objekt - Variablen Verknüpfung
|
||||
$pb=$window.findName("pb")
|
||||
$Logo=$window.findName("Logo")
|
||||
$Laufwerk=$window.findName("Laufwerk")
|
||||
$Script:bar = $window.FindName("pbbar")
|
||||
$Script:offline = $window.findName("Offline")
|
||||
$Script:gesamt = $window.FindName("tbgesamt")
|
||||
$Script:belegt = $window.FindName("tbbelegt")
|
||||
$Script:scantxt = $window.findName("Scantxt")
|
||||
$Script:pbloading = $window.findName("pbLoading")
|
||||
$Script:scannerscan = $window.findName("btnscan")
|
||||
$Script:scanlb = $window.findName("lbanalyse1")
|
||||
$Script:POOP_AIDS_COPY = $window.findName("lbanalyse2")
|
||||
|
||||
# Verknüpft feste Elemente
|
||||
$window.Title = $Script:Version
|
||||
$window.icon="$root/Source/Logo.png"
|
||||
$Logo.Source="$root/Source/Logowhite.png"
|
||||
$Laufwerk.Source="$root/Source/HDD1.png"
|
||||
|
||||
### GIF Sanduhr
|
||||
$file = (get-item "$root/Source/hourglas.gif")
|
||||
$img = [System.Drawing.Image]::Fromfile($file);
|
||||
$pb.Image = $img
|
||||
|
||||
return $window
|
||||
}
|
||||
|
||||
function Scan_Label_Swtich {
|
||||
param(
|
||||
[switch]$scan
|
||||
)
|
||||
if (!$scan) {
|
||||
$Script:scanlb.Visibility="Visible"
|
||||
$Script:POOP_AIDS_COPY.Visibility="Hidden"
|
||||
}else{
|
||||
$Script:scanlb.Visibility="Hidden"
|
||||
$Script:POOP_AIDS_COPY.Visibility="Visible"
|
||||
}
|
||||
}
|
||||
|
||||
function Set_Defaults_Scanner {
|
||||
param ($array)
|
||||
if (!$array[5]) {
|
||||
$Script:H_Size=$array[4]
|
||||
$Script:bar.Value=$Script:H_Size
|
||||
$Script:gesamt.Text=$Array[2]
|
||||
$script:belegt.Text=$array[3]
|
||||
}else{
|
||||
$Script:offline.Visibility="Visible"
|
||||
}
|
||||
}
|
||||
|
||||
function Start_Scan {
|
||||
param ()
|
||||
if (!$Script:switch[0]) {
|
||||
Scan_Label_Swtich -scan
|
||||
$Script:switch[0]=$true
|
||||
Init_Scan_Process
|
||||
#Log "### Start Scan ###" -clear
|
||||
#### Variablen Deklaration Script ####
|
||||
#0=Ordner;1=Datei
|
||||
$Script:counter=@(0,0)
|
||||
$Script:Scan_prozess = 0
|
||||
|
||||
$Script:belegt.Visibility="Hidden"
|
||||
$Script:bar.Foreground="#008000"
|
||||
$Script:scantxt.Visibility="Visible"
|
||||
$Script:pbloading.Visibility="Visible"
|
||||
$Script:scannerscan.Content="Abbrechen"
|
||||
$Script:scannerscan.background="$Script:Delcolor"
|
||||
|
||||
renew_DB
|
||||
start_create_database
|
||||
Add_Root_Folder_Size
|
||||
Get_TreeView
|
||||
Browser_Path -path 0
|
||||
|
||||
$maintree.Items[0].IsExpanded = $true
|
||||
$maintree.Items[0].IsSelected = $true
|
||||
if ($Script:switch[0]) {
|
||||
$Script:switch[0]=$false
|
||||
$Script:bar.Foreground="#00b8d4"
|
||||
$Script:scantxt.Visibility="Hidden"
|
||||
$Script:pbloading.Visibility="Hidden"
|
||||
$Script:scannerscan.Content="Scannen"
|
||||
$Script:belegt.Visibility="Visible"
|
||||
$Script:bar.Value=$Script:H_Size
|
||||
$Script:Scan_prozess = 0
|
||||
Scan_process
|
||||
Scan_Label_Swtich
|
||||
$Script:scannerscan.background="$Script:Standardbtncolor"
|
||||
$Script:scanner.hide()
|
||||
|
||||
#Log "### Scan fertig ###" -clear
|
||||
$Script:main.ShowDialog() | Out-Null
|
||||
}
|
||||
}else {
|
||||
$Script:switch[0]=$false
|
||||
$Script:bar.Foreground="#00b8d4"
|
||||
$Script:scantxt.Visibility="Hidden"
|
||||
$Script:pbloading.Visibility="Hidden"
|
||||
$Script:scannerscan.Content="Scannen"
|
||||
$Script:belegt.Visibility="Visible"
|
||||
$Script:bar.Value=$Script:H_Size
|
||||
Scan_Label_Swtich
|
||||
$Script:scannerscan.background="$Script:Standardbtncolor"
|
||||
}
|
||||
}
|
||||
|
||||
function renew_DB {
|
||||
#Log "### Datenbank zurückgesetzt ###" -clear
|
||||
$Script:folderdb = @{
|
||||
Legende = @("Name","Größe","Pfad","Checked","Deleted","Vorgänger","Inhalt")
|
||||
}
|
||||
$Script:filedb = @{
|
||||
Legende = @("Name","Größe","Pfad","Checked","Deleted","Endung")
|
||||
}
|
||||
}
|
||||
|
||||
function Init_Scan_Process{
|
||||
$Script:Scan_prozess = 0
|
||||
$Scan_exclude_percent = 0.85
|
||||
$Script:Scan_used_exclude=$Script:used*$Scan_exclude_percent
|
||||
}
|
||||
|
||||
function Scan_Process {
|
||||
param ($Item)
|
||||
$Scan_Percent=0
|
||||
$Script:Scan_Prozess=$Script:Scan_Prozess+$Item
|
||||
if ($Script:Scan_Prozess -gt $Script:Scan_used_exclude) {
|
||||
$Scan_Percent = ($Script:Scan_Prozess/$Script:used)*100
|
||||
}else{
|
||||
$Scan_Percent = ($Script:Scan_Prozess/$Script:Scan_used_exclude)*100
|
||||
}
|
||||
$Script:bar.Value = $Scan_Percent
|
||||
#Log "Scan prozess: $Scan_Percent" -clear
|
||||
#Log "$Script:used $Script:Scan_Prozess" -clear
|
||||
}
|
||||
|
||||
function start_create_database {
|
||||
param ()
|
||||
$collection = Get-ChildItem -path G:\ -Directory
|
||||
$Script:folderdb[$Script:counter[0]] = @("H-Laufwerk",1,"H:",$false,$false)
|
||||
create_file_database "H:"
|
||||
foreach ($item in $collection){
|
||||
$Script:switch[1]=$false
|
||||
foreach ($itemex in $Script:exclude){
|
||||
if ($item.FullName -eq $itemex) {
|
||||
$Script:switch[1]=$true
|
||||
}
|
||||
[System.Windows.Forms.Application]::DoEvents()
|
||||
}
|
||||
if (!$Script:switch[1] -and $Script:switch[0]) {
|
||||
$Script:counter[0]++
|
||||
$Script:folderdb[$Script:counter[0]] = @($item.Name,$item.length,$item.FullName,$false,$false)
|
||||
$Script:folderdb[0] += "f"+$Script:counter[0]
|
||||
create_file_database $item.FullName
|
||||
create_folder_database $item.FullName $Script:counter[0]
|
||||
[System.Windows.Forms.Application]::DoEvents()
|
||||
}
|
||||
[System.Windows.Forms.Application]::DoEvents()
|
||||
}
|
||||
}
|
||||
|
||||
function create_folder_database {
|
||||
param ($folder,$davor)
|
||||
if ($Script:switch[0]) {
|
||||
$collection = Get-ChildItem -path $folder -Directory
|
||||
foreach ($item in $collection){
|
||||
$Script:counter[0]++
|
||||
$Script:folderdb[$Script:counter[0]] = @($item.Name,$item.length,$item.FullName,$false,$false)
|
||||
$text = " " + $Script:counter[0] + " " + $Script:folderdb[$Script:counter[0]]
|
||||
#Log $text
|
||||
$Script:folderdb[$davor] += "f"+$Script:counter[0]
|
||||
create_file_database $item.FullName
|
||||
create_folder_database $item.FullName $Script:counter[0]
|
||||
[System.Windows.Forms.Application]::DoEvents()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function create_file_database {
|
||||
param ($folder)
|
||||
$collection = Get-ChildItem -path $folder -File
|
||||
foreach ($item in $collection) {
|
||||
$Script:filedb[$Script:counter[1]] = @($item.Name,$item.length,$item.FullName,$false,$false,(get_icon $item.Name))
|
||||
Scan_Process $item.length
|
||||
$text = " " + $Script:counter[1] + " " + $Script:filedb[$Script:counter[1]]
|
||||
#Log $text
|
||||
$Script:folderdb[$Script:counter[0]] += $Script:counter[1]
|
||||
$Script:counter[1]++
|
||||
[System.Windows.Forms.Application]::DoEvents()
|
||||
}
|
||||
}
|
||||
|
||||
function Add_Root_Folder_Size {
|
||||
$size=0
|
||||
for ($i = 5; $i -lt $Script:folderdb[0].count; $i++) {
|
||||
if ($Script:folderdb[0][$i] -match "f") {
|
||||
$size=$size+(Add_Folder_Size $Script:folderdb[0][$i])
|
||||
}else {
|
||||
$size=$size+$Script:filedb[$Script:folderdb[0][$i]][1]
|
||||
}
|
||||
[System.Windows.Forms.Application]::DoEvents()
|
||||
}
|
||||
$Script:folderdb[0][1]=$Size
|
||||
}
|
||||
|
||||
function Add_Folder_Size {
|
||||
param ($Folder)
|
||||
$string=$Folder.Substring(1)
|
||||
$Folder = [int]$string
|
||||
$size=0
|
||||
for ($i = 5; $i -lt $Script:folderdb[$Folder].count; $i++) {
|
||||
if ($Script:folderdb[$Folder][$i] -match "f") {
|
||||
$size=$size+(Add_Folder_Size $Script:folderdb[$Folder][$i])
|
||||
}else {
|
||||
$size=$size+$Script:filedb[$Script:folderdb[$Folder][$i]][1]
|
||||
}
|
||||
[System.Windows.Forms.Application]::DoEvents()
|
||||
}
|
||||
$Script:folderdb[$Folder][1]=$size
|
||||
return $size
|
||||
}
|
||||
|
||||
function get_icon {
|
||||
param ($data)
|
||||
if ($data -match '.') {
|
||||
$trimdata = (($data.Split('.'))[1]).ToLower()
|
||||
$index=[array]::indexof($icontypes,$trimdata)
|
||||
if ($index -eq -1) {
|
||||
$return = -1
|
||||
}else{
|
||||
$return = $index
|
||||
}
|
||||
return $return
|
||||
}else{
|
||||
return $data
|
||||
}
|
||||
}
|
||||
|
||||
#Log "### Scanner geladen ###" -clear
|
||||
53
GUIS/scanner/scanner.xaml
Normal file
53
GUIS/scanner/scanner.xaml
Normal file
@@ -0,0 +1,53 @@
|
||||
<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 - Startseite" Height="182" Width="751.666" Icon="{Binding Icon}" ResizeMode="NoResize" BorderBrush="Blue">
|
||||
<Grid Background="#00344E">
|
||||
<Label HorizontalAlignment="Left" Margin="8,100,0,0" VerticalAlignment="Top" Height="47" Width="730" Background="#013C5A">
|
||||
<Label.Resources>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="CornerRadius" Value="5"/>
|
||||
</Style>
|
||||
</Label.Resources>
|
||||
</Label>
|
||||
<Image Name="Logo" Source="{Binding Logo}" HorizontalAlignment="Left" Margin="8,2,0,0" VerticalAlignment="Top" Height="60" Width="45"/>
|
||||
<Label Content="cleaner" HorizontalAlignment="Left" Margin="53,1,0,0" VerticalAlignment="Top" FontSize="25" Width="106" Foreground="#FFE1F7FE"/>
|
||||
<ProgressBar Name="pbbar" HorizontalAlignment="Left" Height="17" Margin="164,109,0,0" VerticalAlignment="Top" Width="451" Background="#00344E" Foreground="#00b8d4">
|
||||
<ProgressBar.Resources>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="CornerRadius" Value="5"/>
|
||||
</Style>
|
||||
</ProgressBar.Resources>
|
||||
</ProgressBar>
|
||||
<Image Name="Laufwerk" HorizontalAlignment="Left" Height="60" Margin="8,94,0,0" VerticalAlignment="Top" Width="65" Source="{Binding}"/>
|
||||
<Label Content="H-Laufwerk" HorizontalAlignment="Left" Margin="57,100,0,0" VerticalAlignment="Top" Foreground="White" Width="94" FontSize="16"/>
|
||||
<Label Name="lbanalyse1" Content="Starte jetzt die Analyse deines H-Laufwerks" HorizontalAlignment="Left" Margin="208,28,0,0" VerticalAlignment="Top" Foreground="White" FontSize="18" Visibility="Visible"/>
|
||||
<Label Name="lbanalyse2" Content="Die Analyse des H-Laufwerks läuft..." HorizontalAlignment="Left" Margin="208,28,0,0" VerticalAlignment="Top" Foreground="White" FontSize="18" Visibility="Hidden"/>
|
||||
<Label Content="Die Analyse kann je nach Anzahl der Dateien und Ordner auf dem H-Laufwerk länger dauern" HorizontalAlignment="Left" Margin="122,59,0,0" VerticalAlignment="Top" Foreground="#FFCFCFCF"/>
|
||||
<TextBlock Name="tbgesamt" Text="" HorizontalAlignment="Left" Margin="64,126,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="#FFCFCFCF"/>
|
||||
<TextBlock Name="tbbelegt" HorizontalAlignment="Left" Margin="566,126,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Foreground="#FF16D12F" TextAlignment="Right"/>
|
||||
<Button Name="btnscan" Content="Scannen" BorderThickness="0" HorizontalAlignment="Left" Margin="633,106,0,0" VerticalAlignment="Top" Width="99" Height="36" Background="#00b8d4" Foreground="White" FontSize="14">
|
||||
<Button.Resources>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="CornerRadius" Value="2"/>
|
||||
</Style>
|
||||
</Button.Resources>
|
||||
<Button.Style>
|
||||
<Style TargetType="Button">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Background" Value="Black"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
</Button>
|
||||
<Label Name="Scantxt" Content="Es wird mit längeren Laufzeiten gerechnet. Sie können währenddessen am PC weiterarbeiten." FontSize="11" HorizontalContentAlignment="Center" HorizontalAlignment="Left" Margin="151,116,0,0" VerticalAlignment="Top" VerticalContentAlignment="Center" Foreground="White" Visibility="Hidden" Height="38" Width="475"/>
|
||||
<Label Name="Offline" Content="Das H-Laufwerk ist offline" HorizontalAlignment="Left" Margin="275,5,0,0" VerticalAlignment="Top" Foreground="White" Background="red" FontSize="15" HorizontalContentAlignment="Center" Height="29" Width="218" Visibility="Hidden"/>
|
||||
<wfi:WindowsFormsHost Name="pbLoading" Height="40" Margin="700,8,0,0" Width="40" Visibility="Hidden" VerticalAlignment="Top">
|
||||
<winForms:PictureBox x:Name="pb"></winForms:PictureBox>
|
||||
</wfi:WindowsFormsHost>
|
||||
</Grid>
|
||||
</Window>
|
||||
Reference in New Issue
Block a user