Squashed 'FSI.Lib/' content from commit 6aa4846
git-subtree-dir: FSI.Lib git-subtree-split: 6aa48465a834a7bfdd9cbeae8d2e4f769d0c0ff8
This commit is contained in:
116
FSI.Lib/Guis/Pdf.Mgt/Cmds.cs
Normal file
116
FSI.Lib/Guis/Pdf.Mgt/Cmds.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FSI.Lib.Guis.Pdf.Mgt
|
||||
{
|
||||
public class Cmds
|
||||
{
|
||||
public static Task DelDirectoriesAsync(string path)
|
||||
{
|
||||
return Task.Factory.StartNew(() =>
|
||||
{
|
||||
Action<string> DelPath = null;
|
||||
DelPath = p =>
|
||||
{
|
||||
Directory.EnumerateFiles(p).ToList().ForEach(System.IO.File.Delete); // Dateien im Verzeichnis löschen
|
||||
Directory.EnumerateDirectories(p).ToList().ForEach(DelPath);
|
||||
Directory.EnumerateDirectories(p).ToList().ForEach(Directory.Delete); // Verzeichnis löschen
|
||||
};
|
||||
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
string[] directories = Directory.GetDirectories(path); // Alle Unterverzeichniss auslesen
|
||||
|
||||
foreach (string directory in directories)
|
||||
{
|
||||
if (!(directory.Replace(path, "")).StartsWith(".")) // Überprüfen ob Verzeichnis mit "." startet
|
||||
{
|
||||
DelPath(directory); // Unterverzeichnisse inkl. Dateien löschen
|
||||
Directory.Delete(directory); // Verzeichnis löschen
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Task DelFilesAsync(string path)
|
||||
{
|
||||
return Task.Factory.StartNew(() =>
|
||||
{
|
||||
var files = Directory.GetFiles(path);
|
||||
|
||||
foreach (string file in files)
|
||||
{
|
||||
FileInfo fileInfo = new FileInfo(file);
|
||||
|
||||
const int STR_LENGTH = 27; // min. Dateinamen Länge (Zahlen inkl. Bindestriche)
|
||||
|
||||
if (!fileInfo.Name.StartsWith(".")) // Überprüfen ob Datei mit "." startet
|
||||
{
|
||||
if (fileInfo.Extension != ".pdf" || fileInfo.Name.Length <= STR_LENGTH) // Überprüfen ob es sich um eine PDF-Datei handelt
|
||||
{
|
||||
System.IO.File.Delete(fileInfo.FullName); // ... wenn nicht Datei löschen
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] fileStrings = fileInfo.Name.Substring(0, STR_LENGTH - 1).Split('-'); // Zahlenblock splitten für Überprüfung
|
||||
|
||||
if (fileStrings.Length == 3) // 3 Zahlenblöcke vorhanden?
|
||||
{
|
||||
if (fileStrings[0].Length != 10 || !Int64.TryParse(fileStrings[0], out _) || fileStrings[1].Length != 10 || !Int64.TryParse(fileStrings[1], out _) || fileStrings[2].Length != 4 || !Int64.TryParse(fileStrings[2], out _)) // Länge der Zahlenblöcke überprüfen
|
||||
{
|
||||
System.IO.File.Delete(fileInfo.FullName); // ..., wenn Länge nicht passt, Datei löschen
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
System.IO.File.Delete(fileInfo.FullName); // ..., wenn nicht Datei löschen
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Task CreatePdfShortcutsAsync(string path)
|
||||
{
|
||||
return Task.Factory.StartNew(() =>
|
||||
{
|
||||
var files = Directory.GetFiles(path, "*.pdf"); // alle PDF-Dateien einlesen
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
FileInfo fileInfo = new FileInfo(file);
|
||||
|
||||
string[] fileStrings = System.IO.Path.GetFileNameWithoutExtension(fileInfo.Name).Split(' '); // Datei-Namen für Verzeichnis Bezeichnung aufteilen
|
||||
|
||||
string tmpPath = path + fileStrings[1] + " " + fileStrings[2]; // Verzeichnis Bezeichnung zusammenstellen
|
||||
|
||||
if (Convert.ToBoolean(ConfigurationManager.AppSettings["SubDir"])) // mit/ohne Unterverzeichnis
|
||||
{
|
||||
tmpPath = path + fileStrings[1] + @"\" + fileStrings[2]; // mit Unterverzeichnis
|
||||
}
|
||||
else
|
||||
{
|
||||
tmpPath = path + fileStrings[1] + " " + fileStrings[2]; // ohne Unterverzeichnis
|
||||
}
|
||||
|
||||
Directory.CreateDirectory(tmpPath); // Verzeichnis erstellen
|
||||
|
||||
// Shortcut erstellen
|
||||
if (Convert.ToBoolean(ConfigurationManager.AppSettings["WithNo"]))
|
||||
{
|
||||
LnkParser.ShortCut.Create(System.IO.Path.GetFileNameWithoutExtension(tmpPath + "\\" + fileInfo.Name), tmpPath, fileInfo.FullName, System.IO.Path.GetFileNameWithoutExtension(fileInfo.FullName));
|
||||
}
|
||||
else
|
||||
{
|
||||
LnkParser.ShortCut.Create(System.IO.Path.GetFileNameWithoutExtension(fileInfo.Name.Replace(fileStrings[0], "")), tmpPath, fileInfo.FullName, System.IO.Path.GetFileNameWithoutExtension(fileInfo.FullName));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
68
FSI.Lib/Guis/Pdf.Mgt/FrmMain.xaml
Normal file
68
FSI.Lib/Guis/Pdf.Mgt/FrmMain.xaml
Normal file
@@ -0,0 +1,68 @@
|
||||
<Window x:Class="FSI.Lib.Guis.Pdf.Mgt.FrmMain"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:FSI.Lib.Guis.Pdf.Mgt"
|
||||
mc:Ignorable="d"
|
||||
Title="FSI Eplan PDF Mgt"
|
||||
SizeToContent="WidthAndHeight"
|
||||
Height="Auto"
|
||||
Width="Auto"
|
||||
Icon="../../Icons/FondiumU.ico"
|
||||
WindowStyle="ToolWindow">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition MaxHeight="30"
|
||||
Height="*" />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Button x:Name="btnCleanUp"
|
||||
Content="aufräumen"
|
||||
Margin="5 5 5 5 "
|
||||
Click="btnCleanUp_Click" />
|
||||
<Button x:Name="btnCreateShortcuts"
|
||||
Content="Verknüpfungen erstellen"
|
||||
Margin="5 5 5 5 "
|
||||
Click="btnCreateShortcuts_Click" />
|
||||
<Button x:Name="btnStart"
|
||||
Content="alles ausführen"
|
||||
Margin="5 5 5 5 "
|
||||
Click="btnStart_Click" />
|
||||
</StackPanel>
|
||||
<StatusBar Grid.Row="2">
|
||||
<StatusBar.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="4*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
|
||||
</Grid.ColumnDefinitions>
|
||||
</Grid>
|
||||
</ItemsPanelTemplate>
|
||||
</StatusBar.ItemsPanel>
|
||||
<StatusBarItem>
|
||||
<TextBlock x:Name="tbStatus" />
|
||||
</StatusBarItem>
|
||||
<StatusBarItem Grid.Column="1">
|
||||
<ProgressBar x:Name="pgProgress"
|
||||
Width="80"
|
||||
Height="18" />
|
||||
</StatusBarItem>
|
||||
|
||||
|
||||
<StatusBarItem HorizontalAlignment="Right">
|
||||
<TextBlock Text="{Binding CurrentTime}" />
|
||||
</StatusBarItem>
|
||||
|
||||
|
||||
</StatusBar>
|
||||
</Grid>
|
||||
</Window>
|
||||
71
FSI.Lib/Guis/Pdf.Mgt/FrmMain.xaml.cs
Normal file
71
FSI.Lib/Guis/Pdf.Mgt/FrmMain.xaml.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using System.Configuration;
|
||||
using System.Reflection;
|
||||
using System.Windows;
|
||||
|
||||
namespace FSI.Lib.Guis.Pdf.Mgt
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaktionslogik für FrmMain.xaml
|
||||
/// </summary>
|
||||
public partial class FrmMain : Window
|
||||
{
|
||||
public bool CloseAtLostFocus { get; set; }
|
||||
|
||||
public FrmMain()
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = new MVVM.ViewModel.CurrentTimeViewModel();
|
||||
Title += " v" + Assembly.GetExecutingAssembly().GetName().Version; // Version in Titel eintragen
|
||||
Deactivated += FrmMain_Deactivated;
|
||||
}
|
||||
|
||||
private void FrmMain_Deactivated(object sender, System.EventArgs e)
|
||||
{
|
||||
if (CloseAtLostFocus)
|
||||
Visibility = Visibility.Hidden;
|
||||
}
|
||||
|
||||
private async void btnCleanUp_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
BtnMgt(false); // Schaltflächen sperren
|
||||
|
||||
await Cmds.DelDirectoriesAsync(ConfigurationManager.AppSettings["PdfPath"]); // nicht benötigte/zulässige Verzeichnisse löschen
|
||||
await Cmds.DelFilesAsync(ConfigurationManager.AppSettings["PdfPath"]); // nicht benötigte/zulässige Datien löschen
|
||||
BtnMgt(true); // Schaltflächen freigeben
|
||||
}
|
||||
|
||||
private async void btnCreateShortcuts_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
BtnMgt(false); // Schaltflächen sperren
|
||||
await Cmds.CreatePdfShortcutsAsync(ConfigurationManager.AppSettings["PdfPath"]); // Verzeichnisstruktur und Verknüpfungen erstellen
|
||||
BtnMgt(true); // Schaltflächen freigeben
|
||||
}
|
||||
|
||||
private async void btnStart_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
BtnMgt(false); // Schaltflächen sperren
|
||||
await Cmds.DelDirectoriesAsync(ConfigurationManager.AppSettings["PdfPath"]); // nicht benötigte/zulässige Verzeichnisse löschen
|
||||
await Cmds.DelFilesAsync(ConfigurationManager.AppSettings["PdfPath"]); // nicht benötigte/zulässige Datien lösche
|
||||
await Cmds.CreatePdfShortcutsAsync(ConfigurationManager.AppSettings["PdfPath"]); // Verzeichnisstruktur und Verknüpfungen erstellen
|
||||
BtnMgt(true); // Schaltflächen freigeben
|
||||
}
|
||||
|
||||
private void BtnMgt(bool enable)
|
||||
{
|
||||
btnCleanUp.IsEnabled =
|
||||
btnCreateShortcuts.IsEnabled =
|
||||
btnStart.IsEnabled = enable;
|
||||
pgProgress.IsIndeterminate = !enable;
|
||||
|
||||
// Status anzeige
|
||||
if (enable)
|
||||
{
|
||||
tbStatus.Text = "beendet";
|
||||
}
|
||||
else
|
||||
{
|
||||
tbStatus.Text = "gestartet";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user