Files
QuickLook/QuickLook.Plugin.LastResort/InfoPanel.xaml.cs
2017-04-26 00:48:40 +03:00

65 lines
1.8 KiB
C#

using System.IO;
using System.Threading.Tasks;
using System.Windows.Controls;
namespace QuickLook.Plugin.LastResort
{
/// <summary>
/// Interaction logic for InfoPanel.xaml
/// </summary>
public partial class InfoPanel : UserControl
{
private bool _stop;
public InfoPanel()
{
InitializeComponent();
}
public bool Stop
{
set => _stop = value;
get => _stop;
}
public void DisplayInfo(string path)
{
var icon = IconHelper.GetBitmapFromPath(path, IconHelper.IconSizeEnum.ExtraLargeIcon).ToBitmapSource();
image.Source = icon;
var name = Path.GetFileName(path);
filename.Content = string.IsNullOrEmpty(name) ? path : name;
var last = File.GetLastWriteTime(path);
modDate.Content = $"{last.ToLongDateString()} {last.ToLongTimeString()}";
Stop = false;
Task.Run(() =>
{
if (File.Exists(path))
{
var size = new FileInfo(path).Length;
Dispatcher.Invoke(() => { totalSize.Content = size.ToPrettySize(2); });
}
else if (Directory.Exists(path))
{
long totalDirsL;
long totalFilesL;
long totalSizeL;
FileHelper.CountFolder(path, ref _stop, out totalDirsL, out totalFilesL, out totalSizeL);
if (!Stop)
Dispatcher.Invoke(() =>
{
totalSize.Content =
$"{totalSizeL.ToPrettySize(2)} ({totalDirsL} folders and {totalFilesL} files)";
});
}
});
}
}
}