mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-11 17:59:17 +00:00
129 lines
4.7 KiB
C#
129 lines
4.7 KiB
C#
// Copyright © 2017 Paddy Xu
|
|
//
|
|
// This file is part of QuickLook program.
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
using System;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Controls;
|
|
using QuickLook.ExtensionMethods;
|
|
using QuickLook.Helpers;
|
|
|
|
namespace QuickLook.Plugin.InfoPanel
|
|
{
|
|
/// <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)
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
var scale = DpiHelper.GetCurrentScaleFactor();
|
|
|
|
var icon =
|
|
WindowsThumbnailProvider.GetThumbnail(path,
|
|
(int) (128 * scale.Horizontal),
|
|
(int) (128 * scale.Vertical),
|
|
ThumbnailOptions.ScaleUp);
|
|
|
|
var source = icon.ToBitmapSource();
|
|
icon.Dispose();
|
|
|
|
Dispatcher.BeginInvoke(new Action(() => image.Source = source));
|
|
});
|
|
|
|
var name = Path.GetFileName(path);
|
|
filename.Text = string.IsNullOrEmpty(name) ? path : name;
|
|
|
|
var last = File.GetLastWriteTime(path);
|
|
modDate.Text = string.Format(TranslationHelper.GetString("InfoPanel_LastModified"),
|
|
last.ToString(CultureInfo.CurrentCulture));
|
|
|
|
Stop = false;
|
|
|
|
Task.Run(() =>
|
|
{
|
|
if (File.Exists(path))
|
|
{
|
|
var size = new FileInfo(path).Length;
|
|
|
|
Dispatcher.Invoke(() => { totalSize.Text = size.ToPrettySize(2); });
|
|
}
|
|
else if (Path.GetPathRoot(path) == path) // is this a drive?
|
|
{
|
|
long totalSpace;
|
|
long totalFreeSpace;
|
|
|
|
FileHelper.GetDriveSpace(path, out totalSpace, out totalFreeSpace);
|
|
|
|
Dispatcher.Invoke(() =>
|
|
{
|
|
totalSize.Text =
|
|
string.Format(TranslationHelper.GetString("InfoPanel_DriveSize"),
|
|
totalSpace.ToPrettySize(2),
|
|
totalFreeSpace.ToPrettySize(2));
|
|
});
|
|
}
|
|
else if (Directory.Exists(path))
|
|
{
|
|
FileHelper.CountFolder(path, ref _stop,
|
|
out long totalDirsL, out long totalFilesL, out long totalSizeL);
|
|
|
|
if (!Stop)
|
|
Dispatcher.Invoke(() =>
|
|
{
|
|
string t;
|
|
var folders = totalDirsL == 0
|
|
? string.Empty
|
|
: string.Format(TranslationHelper.GetString(
|
|
totalDirsL == 1 ? "InfoPanel_Folder" : "InfoPanel_Folders"), totalDirsL);
|
|
var files = totalFilesL == 0
|
|
? string.Empty
|
|
: string.Format(TranslationHelper.GetString(
|
|
totalFilesL == 1 ? "InfoPanel_File" : "InfoPanel_Files"), totalFilesL);
|
|
|
|
if (!string.IsNullOrEmpty(folders) && !string.IsNullOrEmpty(files))
|
|
t = string.Format(
|
|
TranslationHelper.GetString("InfoPanel_FolderAndFile"), folders, files);
|
|
else if (string.IsNullOrEmpty(folders) && string.IsNullOrEmpty(files))
|
|
t = string.Empty;
|
|
else
|
|
t = $"({folders}{files})";
|
|
|
|
totalSize.Text =
|
|
$"{totalSizeL.ToPrettySize(2)} {t}";
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
} |