init
This commit is contained in:
150
Cleaner-IconAdd/root.ps1
Normal file
150
Cleaner-IconAdd/root.ps1
Normal file
@@ -0,0 +1,150 @@
|
||||
Add-Type -AssemblyName PresentationFramework
|
||||
Add-Type -AssemblyName System.Windows.Forms
|
||||
[System.Reflection.Assembly]::LoadWithPartialName('System.Drawing') | Out-Null
|
||||
|
||||
function Load_root {
|
||||
[xml]$Form = Get-Content "$PSScriptRoot\root.xaml" -Encoding utf8
|
||||
$NR=(New-Object System.Xml.XmlNodeReader $Form)
|
||||
$window=[Windows.Markup.XamlReader]::Load($NR)
|
||||
$Script:btncleaner = $window.FindName("btncleaner")
|
||||
$Script:btnfile = $window.findName("btnfile")
|
||||
$Script:btnok = $window.FindName("btnok")
|
||||
$Script:tbcleaner = $window.FindName("tbcleaner")
|
||||
$Script:tbfile = $window.FindName("tbfile")
|
||||
$Script:cbo = $window.FindName("cbo")
|
||||
$Script:cbb = $window.FindName("cbb")
|
||||
$Script:cbv = $window.FindName("cbv")
|
||||
$Script:cba = $window.FindName("cba")
|
||||
return $window
|
||||
}
|
||||
$main = Load_root
|
||||
|
||||
$Script:btncleaner.Add_Click({
|
||||
$Script:cleaner=Select-FolderDialog
|
||||
if (test-path "$Script:cleaner\icons.csv") {
|
||||
$Script:tbcleaner.Text = "Cleaner: $Script:Cleaner"
|
||||
}else{
|
||||
$Script:tbcleaner.Text = "Cleaner: not valid"
|
||||
}
|
||||
})
|
||||
$Script:btnfile.Add_Click({
|
||||
$Script:file=Select-FileDialog
|
||||
$Script:tbfile.Text = "Icon: $Script:file"
|
||||
})
|
||||
$Script:btnok.Add_Click({
|
||||
$csv=import-csv path $Script:Cleaner\icons.csv
|
||||
$type=$null
|
||||
Write-host "$Script:file"
|
||||
$name = get_icon $Script:file
|
||||
Export-Icon -Path $Script:file -Destination "$Script:Cleaner\icons\$name.ico"
|
||||
if ($cbo.IsSelected) {
|
||||
$type=0
|
||||
}elseif ($cbb.IsSelected) {
|
||||
$type=1
|
||||
}elseif ($cbv.IsSelected) {
|
||||
$type=2
|
||||
}elseif ($cba.IsSelected) {
|
||||
$type=3
|
||||
}
|
||||
$id=($csv.ID[-1])+1
|
||||
$item = "$id,$name,$type"
|
||||
$item | Export-Csv -Path "$Script:Cleaner\icons.csv" -Append
|
||||
|
||||
})
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Function Select-FileDialog{
|
||||
[void] [System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
|
||||
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
|
||||
if ($initialDirectory) { $OpenFileDialog.initialDirectory = $initialDirectory }
|
||||
$OpenFileDialog.filter = 'All files (*.*)|*.*'
|
||||
[void] $OpenFileDialog.ShowDialog()
|
||||
return $OpenFileDialog.FileName
|
||||
}
|
||||
|
||||
function get_icon {
|
||||
param ($data)
|
||||
$data = $data -replace '\s',''
|
||||
$found = $false
|
||||
for ($c = -1; $c -gt -10; $c--) {
|
||||
$char = $data[$c]
|
||||
if ($char -eq ".") {
|
||||
$trim=$data.Length+$c
|
||||
$trimdata=$data.Remove(0,$trim+1)
|
||||
$c=-10
|
||||
$found = $true
|
||||
}
|
||||
}
|
||||
if (!$found) {
|
||||
$return = 0
|
||||
}else {
|
||||
$return=$trimdata
|
||||
}
|
||||
return $return
|
||||
}
|
||||
|
||||
function Export-Icon {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Exports a file icon to a specified format.
|
||||
.DESCRIPTION
|
||||
Exports the icon associated with a while to a specified image format.
|
||||
.NOTES
|
||||
Author : Paul Broadwith (https://github.com/pauby)
|
||||
History : 1.0 - 25/07/17 - Initial version.
|
||||
.LINK
|
||||
https://www.github.com/pauby
|
||||
.EXAMPLE
|
||||
Export-Icon -Path "C:\Windows\Notepad.exe"
|
||||
|
||||
Exports the icon for "C:\Windows\Notepad.exe" and saves it in bitmap
|
||||
(BMP) format to "Notepad.bmp" in the current current directory.
|
||||
|
||||
.EXAMPLE
|
||||
Export-Icon -Path "C:\Windows\Notepad.exe" `
|
||||
-Destination "C:\Temp\Notepad-Icon.jpg" -Format JPEG
|
||||
|
||||
Exports the icon for "C:\Windows\Notepad.exe" and saves it in JPEG
|
||||
format to "C:\Temp\Notepad-Icon.jpg"
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
Param (
|
||||
# Path of the source file the icon is to be exported from.
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]$Path,
|
||||
|
||||
# Path to where the icon will be saved to. If this is blank or missing
|
||||
# the file will be saved in the current directory with the basename of
|
||||
# the $Path with the correct format extension.
|
||||
[string]$Destination,
|
||||
|
||||
# Format to save the icon as. Defaults to a bitmap (BMP).
|
||||
[System.Drawing.Imaging.ImageFormat]$Format = "Bmp"
|
||||
)
|
||||
|
||||
if (!$Destination) {
|
||||
$basename = (Get-Item $Path).BaseName
|
||||
$extension = $format.ToString().ToLower()
|
||||
$Destination = "$basename.$extension"
|
||||
}
|
||||
|
||||
# Extract the icon from the source file.
|
||||
$icon = [System.Drawing.Icon]::ExtractAssociatedIcon($Path)
|
||||
|
||||
# Save the icon in the specified format
|
||||
$icon.ToBitmap().Save($Destination, [System.Drawing.Imaging.ImageFormat]::$Format)
|
||||
}
|
||||
|
||||
$main.ShowDialog() | Out-Null
|
||||
35
Cleaner-IconAdd/root.xaml
Normal file
35
Cleaner-IconAdd/root.xaml
Normal file
@@ -0,0 +1,35 @@
|
||||
<?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="IconAdd" Title="Cleaner - IconAdd" Height="291.5" Width="238.5" 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">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Content="Pfade auswählen" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Height="154" Width="200" Background="#013C5A" Foreground="White" FontSize="16" FontWeight="Bold" HorizontalContentAlignment="Center"/>
|
||||
<Button TabIndex="7" Name="btnok" Content="Übernehmen" BorderThickness="0" HorizontalAlignment="Left" Margin="10,209,0,0" VerticalAlignment="Top" Width="200" Height="33" FontSize="20" FontWeight="Bold" Background="green" Foreground="white">
|
||||
<Button.Resources>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="CornerRadius" Value="2"/>
|
||||
</Style>
|
||||
</Button.Resources>
|
||||
</Button>
|
||||
<Button Name="btncleaner" Content="..." HorizontalAlignment="Left" Margin="171,49,0,0" VerticalAlignment="Top" Width="23"/>
|
||||
<Button Name="btnfile" Content="..." HorizontalAlignment="Left" Margin="171,74,0,0" VerticalAlignment="Top" Width="23"/>
|
||||
<Label Content="Cleaner Ordner" HorizontalAlignment="Left" Margin="19,46,0,0" VerticalAlignment="Top" Width="147" Foreground="white"/>
|
||||
<Label Content="Icon Vorlage" HorizontalAlignment="Left" Margin="19,71,0,0" VerticalAlignment="Top" Width="147" Foreground="white"/>
|
||||
<TextBlock Name="tbcleaner" HorizontalAlignment="Left" Margin="24,97,0,0" TextWrapping="Wrap" Text="Cleaner:" VerticalAlignment="Top" Width="170" Foreground="white" Height="31"/>
|
||||
<TextBlock Name="tbfile" HorizontalAlignment="Left" Margin="24,128,0,0" TextWrapping="Wrap" Text="Icon:" VerticalAlignment="Top" Width="170" Foreground="white" Height="32"/>
|
||||
<CheckBox Name="cbo" Content="Office" HorizontalAlignment="Left" Margin="39,169,0,0" VerticalAlignment="Top" Width="56" Foreground="white"/>
|
||||
<CheckBox Name="cbb" Content="Bilder" HorizontalAlignment="Left" Margin="122,169,0,0" VerticalAlignment="Top" Width="58" Foreground="white"/>
|
||||
<CheckBox Name="cbv" Content="Videos" HorizontalAlignment="Left" Margin="39,189,0,0" VerticalAlignment="Top" Width="58" Foreground="white"/>
|
||||
<CheckBox Name="cba" Content="Audios" HorizontalAlignment="Left" Margin="122,189,0,0" VerticalAlignment="Top" Width="58" Foreground="white"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
Reference in New Issue
Block a user