mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-16 13:22:40 +00:00
finish LastResort
This commit is contained in:
74
QuickLook.Plugin.LastResort/FileHelper.cs
Normal file
74
QuickLook.Plugin.LastResort/FileHelper.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace QuickLook.Plugin.LastResort
|
||||
{
|
||||
public static class FileHelper
|
||||
{
|
||||
public static void CountFolder(string root, ref bool stop, out long totalDirs, out long totalFiles,
|
||||
out long totalSize)
|
||||
{
|
||||
totalDirs = totalFiles = totalSize = 0L;
|
||||
|
||||
var stack = new Stack<DirectoryInfo>();
|
||||
stack.Push(new DirectoryInfo(root));
|
||||
|
||||
totalDirs++; // self
|
||||
|
||||
do
|
||||
{
|
||||
if (stop)
|
||||
break;
|
||||
|
||||
var pos = stack.Pop();
|
||||
|
||||
try
|
||||
{
|
||||
// process files in current directory
|
||||
foreach (var file in pos.EnumerateFiles())
|
||||
{
|
||||
totalFiles++;
|
||||
totalSize += file.Length;
|
||||
}
|
||||
|
||||
// then push all sub-directories
|
||||
foreach (var dir in pos.EnumerateDirectories())
|
||||
{
|
||||
totalDirs++;
|
||||
stack.Push(dir);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
totalDirs++;
|
||||
//pos = stack.Pop();
|
||||
}
|
||||
} while (stack.Count != 0);
|
||||
}
|
||||
|
||||
public static string ToPrettySize(this long value, int decimalPlaces = 0)
|
||||
{
|
||||
const long OneKb = 1024;
|
||||
const long OneMb = OneKb * 1024;
|
||||
const long OneGb = OneMb * 1024;
|
||||
const long OneTb = OneGb * 1024;
|
||||
|
||||
var asTb = Math.Round((double) value / OneTb, decimalPlaces);
|
||||
var asGb = Math.Round((double) value / OneGb, decimalPlaces);
|
||||
var asMb = Math.Round((double) value / OneMb, decimalPlaces);
|
||||
var asKb = Math.Round((double) value / OneKb, decimalPlaces);
|
||||
var chosenValue = asTb > 1
|
||||
? $"{asTb} TB"
|
||||
: asGb > 1
|
||||
? $"{asGb} GB"
|
||||
: asMb > 1
|
||||
? $"{asMb} MB"
|
||||
: asKb > 1
|
||||
? $"{asKb} KB"
|
||||
: $"{Math.Round((double) value, decimalPlaces)} bytes";
|
||||
|
||||
return chosenValue;
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,6 +2,7 @@
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace QuickLook.Plugin.LastResort
|
||||
@@ -211,8 +212,8 @@ namespace QuickLook.Plugin.LastResort
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct POINT
|
||||
{
|
||||
private int X;
|
||||
private int Y;
|
||||
private readonly int X;
|
||||
private readonly int Y;
|
||||
|
||||
public POINT(int x, int y)
|
||||
{
|
||||
|
@@ -4,9 +4,32 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:QuickLook.Plugin.LastResort"
|
||||
|
||||
mc:Ignorable="d" Width="450" Height="250" UseLayoutRounding="True">
|
||||
mc:Ignorable="d" Width="484.5" Height="172" UseLayoutRounding="True">
|
||||
<Grid>
|
||||
<Image x:Name="image" Width="128" Height="128"/>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="150" />
|
||||
<ColumnDefinition Width="65*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image x:Name="image" Grid.Column="0" Height="128" Width="128" Stretch="Fill" />
|
||||
<Grid Grid.Column="1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="20*" />
|
||||
<ColumnDefinition Width="80*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<Label Grid.Row="1" VerticalContentAlignment="Center" Grid.Column="0">Name:</Label>
|
||||
<Label Grid.Row="2" VerticalContentAlignment="Center" Grid.Column="0">Modified:</Label>
|
||||
<Label Grid.Row="3" VerticalContentAlignment="Center" Grid.Column="0">Size:</Label>
|
||||
<Label x:Name="filename" Grid.Row="1" VerticalContentAlignment="Center" Grid.Column="1">Filename.ext</Label>
|
||||
<Label x:Name="modDate" Grid.Row="2" VerticalContentAlignment="Center" Grid.Column="1">01/01/2017 00:00:00</Label>
|
||||
<Label x:Name="totalSize" Grid.Row="3" VerticalContentAlignment="Center" Grid.Column="1">Calculating...</Label>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
@@ -1,18 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace QuickLook.Plugin.LastResort
|
||||
{
|
||||
@@ -21,11 +7,9 @@ namespace QuickLook.Plugin.LastResort
|
||||
/// </summary>
|
||||
public partial class InfoPanel : UserControl
|
||||
{
|
||||
public InfoPanel()
|
||||
public InfoPanel(string path)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
var i = 0;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,12 +1,13 @@
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using Size = System.Windows.Size;
|
||||
|
||||
namespace QuickLook.Plugin.LastResort
|
||||
{
|
||||
public class Plugin : IViewer
|
||||
{
|
||||
private InfoPanel ip;
|
||||
private bool stop;
|
||||
public int Priority => -9999;
|
||||
|
||||
public bool CanHandle(string sample)
|
||||
@@ -16,18 +17,59 @@ namespace QuickLook.Plugin.LastResort
|
||||
|
||||
public void View(string path, ViewContentContainer container)
|
||||
{
|
||||
var s = IconHelper.GetBitmapFromPath(path, IconHelper.IconSizeEnum.ExtraLargeIcon).ToBitmapSource();
|
||||
ip = new InfoPanel(path);
|
||||
|
||||
ip = new InfoPanel();
|
||||
ip.image.Source = s;
|
||||
DisplayInfo(path);
|
||||
|
||||
container.SetContent(ip);
|
||||
container.CanResize = false;
|
||||
container.PreferedSize = new Size {Width = ip.Width, Height = ip.Height};
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
//ip.Dispose();
|
||||
stop = true;
|
||||
}
|
||||
|
||||
|
||||
private void DisplayInfo(string path)
|
||||
{
|
||||
var icon = IconHelper.GetBitmapFromPath(path, IconHelper.IconSizeEnum.ExtraLargeIcon).ToBitmapSource();
|
||||
|
||||
ip.image.Source = icon;
|
||||
|
||||
var name = Path.GetFileName(path);
|
||||
ip.filename.Content = string.IsNullOrEmpty(name) ? path : name;
|
||||
|
||||
var last = File.GetLastWriteTime(path);
|
||||
ip.modDate.Content = $"{last.ToLongDateString()} {last.ToLongTimeString()}";
|
||||
|
||||
stop = false;
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
if (File.Exists(path))
|
||||
{
|
||||
var size = new FileInfo(path).Length;
|
||||
|
||||
ip.Dispatcher.Invoke(() => { ip.totalSize.Content = size.ToPrettySize(2); });
|
||||
}
|
||||
else if (Directory.Exists(path))
|
||||
{
|
||||
long totalDirs;
|
||||
long totalFiles;
|
||||
long totalSize;
|
||||
|
||||
FileHelper.CountFolder(path, ref stop, out totalDirs, out totalFiles, out totalSize);
|
||||
|
||||
if (!stop)
|
||||
ip.Dispatcher.Invoke(() =>
|
||||
{
|
||||
ip.totalSize.Content =
|
||||
$"{totalSize.ToPrettySize(2)} ({totalDirs} folders and {totalFiles} files.)";
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,4 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
|
@@ -48,6 +48,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Extensions.cs" />
|
||||
<Compile Include="FileHelper.cs" />
|
||||
<Compile Include="InfoPanel.xaml.cs">
|
||||
<DependentUpon>InfoPanel.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
@@ -6,12 +6,24 @@ namespace QuickLook.Plugin.PDFViewer
|
||||
{
|
||||
internal static class DpiHelper
|
||||
{
|
||||
public enum DeviceCap
|
||||
{
|
||||
/// <summary>
|
||||
/// Logical pixels inch in X
|
||||
/// </summary>
|
||||
LOGPIXELSX = 88,
|
||||
/// <summary>
|
||||
/// Logical pixels inch in Y
|
||||
/// </summary>
|
||||
LOGPIXELSY = 90
|
||||
}
|
||||
|
||||
public const float DEFAULT_DPI = 96;
|
||||
|
||||
public static Dpi GetCurrentDpi()
|
||||
{
|
||||
Graphics g = Graphics.FromHwnd(IntPtr.Zero);
|
||||
IntPtr desktop = g.GetHdc();
|
||||
var g = Graphics.FromHwnd(IntPtr.Zero);
|
||||
var desktop = g.GetHdc();
|
||||
|
||||
var dpi = new Dpi
|
||||
{
|
||||
@@ -24,18 +36,6 @@ namespace QuickLook.Plugin.PDFViewer
|
||||
|
||||
[DllImport("gdi32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
|
||||
public static extern int GetDeviceCaps(IntPtr hDC, int nIndex);
|
||||
|
||||
public enum DeviceCap
|
||||
{
|
||||
/// <summary>
|
||||
/// Logical pixels inch in X
|
||||
/// </summary>
|
||||
LOGPIXELSX = 88,
|
||||
/// <summary>
|
||||
/// Logical pixels inch in Y
|
||||
/// </summary>
|
||||
LOGPIXELSY = 90
|
||||
}
|
||||
}
|
||||
|
||||
internal class Dpi
|
||||
|
@@ -26,7 +26,7 @@
|
||||
ScrollViewer.IsDeferredScrollingEnabled="False"
|
||||
SelectedIndex="0"
|
||||
Focusable="False"
|
||||
Background="#9FFFFFFF"
|
||||
Background="#00FFFFFF"
|
||||
ItemsSource="{Binding PageIds, ElementName=thisPdfViewer}"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled" BorderThickness="0,0,1,0"
|
||||
ItemContainerStyle="{Binding Mode=OneWay, Source={StaticResource ListBoxItemStyleNoFocusedBorder}}">
|
||||
@@ -61,10 +61,10 @@
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<Grid Grid.Column="1" Background="#DFEFEFEF">
|
||||
<ScrollViewer x:Name="pageViewPanel" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Focusable="False">
|
||||
<Image x:Name="pageViewPanelImage" Stretch="None" RenderOptions.BitmapScalingMode="NearestNeighbor">
|
||||
</Image>
|
||||
<Grid Grid.Column="1" Background="#00EFEFEF">
|
||||
<ScrollViewer x:Name="pageViewPanel" HorizontalScrollBarVisibility="Auto"
|
||||
VerticalScrollBarVisibility="Auto" Focusable="False">
|
||||
<Image x:Name="pageViewPanelImage" Stretch="None" RenderOptions.BitmapScalingMode="NearestNeighbor" />
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
@@ -32,7 +32,7 @@ namespace QuickLook
|
||||
return;
|
||||
}
|
||||
|
||||
var path = String.Empty;
|
||||
var path = string.Empty;
|
||||
|
||||
// communicate with COM in a separate thread
|
||||
Task.Run(() =>
|
||||
@@ -41,10 +41,10 @@ namespace QuickLook
|
||||
|
||||
if (paths.Any())
|
||||
path = paths.First();
|
||||
})
|
||||
.Wait();
|
||||
|
||||
}).Wait();
|
||||
|
||||
if (String.IsNullOrEmpty(path))
|
||||
if (string.IsNullOrEmpty(path))
|
||||
return;
|
||||
|
||||
var matched = PluginManager.FindMatch(path);
|
||||
|
@@ -14,14 +14,14 @@
|
||||
ResizeMode="CanResizeWithGrip"
|
||||
x:ClassModifier="internal">
|
||||
<Window.Background>
|
||||
<SolidColorBrush Color="#7FFFFFFF" />
|
||||
<SolidColorBrush Color="#BFFFFFFF" />
|
||||
</Window.Background>
|
||||
<Border BorderThickness="1" BorderBrush="#FF7B7B7B">
|
||||
<Grid>
|
||||
<DockPanel Opacity="1">
|
||||
<DockPanel x:Name="titlebar" Height="28" Dock="Top">
|
||||
<DockPanel.Background>
|
||||
<SolidColorBrush Color="#FFB8B8B8" />
|
||||
<SolidColorBrush Color="#00B8B8B8" />
|
||||
</DockPanel.Background>
|
||||
<!--<DockPanel.Style>
|
||||
<Style TargetType="{x:Type DockPanel}">
|
||||
@@ -47,9 +47,11 @@
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DockPanel.Style>-->
|
||||
<fa:ImageAwesome DockPanel.Dock="Right" x:Name="buttonCloseWindow" Icon="WindowClose" Height="15" Margin="10,0"
|
||||
<fa:ImageAwesome DockPanel.Dock="Right" x:Name="buttonCloseWindow" Icon="WindowClose" Height="15"
|
||||
Margin="10,0"
|
||||
Cursor="Hand" />
|
||||
<Label x:Name="titlebarTitleArea" Content="{Binding Title, ElementName=viewContentContainer}" FontSize="14" HorizontalContentAlignment="Center"
|
||||
<Label x:Name="titlebarTitleArea" Content="{Binding Title, ElementName=viewContentContainer}"
|
||||
FontSize="14" HorizontalContentAlignment="Center"
|
||||
VerticalContentAlignment="Center" />
|
||||
</DockPanel>
|
||||
<Grid>
|
||||
@@ -60,7 +62,8 @@
|
||||
<Grid.Background>
|
||||
<SolidColorBrush Color="#FFFFFFFF" />
|
||||
</Grid.Background>
|
||||
<Grid x:Name="loadingIcon" Height="50" Width="50" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<Grid x:Name="loadingIcon" Height="50" Width="50" HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center">
|
||||
<fa:ImageAwesome Icon="CircleOutlineNotch" Spin="True" SpinDuration="1" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Remoting.Channels;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media.Animation;
|
||||
@@ -30,6 +29,8 @@ namespace QuickLook
|
||||
titlebarTitleArea.MouseDown += (sender, e) => DragMove();
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private void MainWindow_Closed(object sender, EventArgs e)
|
||||
{
|
||||
viewContentContainer.ViewerPlugin.Close();
|
||||
@@ -42,6 +43,8 @@ namespace QuickLook
|
||||
Height = viewContentContainer.PreferedSize.Height + titlebar.Height;
|
||||
Width = viewContentContainer.PreferedSize.Width;
|
||||
|
||||
ResizeMode = viewContentContainer.CanResize ? ResizeMode.CanResizeWithGrip : ResizeMode.NoResize;
|
||||
|
||||
base.Show();
|
||||
}
|
||||
|
||||
@@ -77,8 +80,6 @@ namespace QuickLook
|
||||
Close();
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
[NotifyPropertyChangedInvocator]
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
|
@@ -12,7 +12,7 @@ namespace QuickLook.Plugin
|
||||
/// </summary>
|
||||
public partial class ViewContentContainer : UserControl, INotifyPropertyChanged
|
||||
{
|
||||
private string _title = String.Empty;
|
||||
private string _title = string.Empty;
|
||||
|
||||
public ViewContentContainer()
|
||||
{
|
||||
@@ -29,6 +29,14 @@ namespace QuickLook.Plugin
|
||||
get => _title;
|
||||
}
|
||||
|
||||
public IViewer ViewerPlugin { get; set; }
|
||||
|
||||
public Size PreferedSize { get; set; }
|
||||
|
||||
public bool CanResize { get; set; } = true;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public void SetContent(object content)
|
||||
{
|
||||
container.Content = content;
|
||||
@@ -41,8 +49,8 @@ namespace QuickLook.Plugin
|
||||
|
||||
var max = GetMaximumDisplayBound();
|
||||
|
||||
var widthRatio = (max.Width * maxRatio) / size.Width;
|
||||
var heightRatio = (max.Height * maxRatio) / size.Height;
|
||||
var widthRatio = max.Width * maxRatio / size.Width;
|
||||
var heightRatio = max.Height * maxRatio / size.Height;
|
||||
|
||||
var ratio = Math.Min(widthRatio, heightRatio);
|
||||
|
||||
@@ -51,17 +59,11 @@ namespace QuickLook.Plugin
|
||||
return ratio;
|
||||
}
|
||||
|
||||
public IViewer ViewerPlugin { get; set; }
|
||||
|
||||
public Size PreferedSize { get; set; }
|
||||
|
||||
public Size GetMaximumDisplayBound()
|
||||
{
|
||||
return new Size(SystemParameters.VirtualScreenWidth, SystemParameters.VirtualScreenHeight);
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
[NotifyPropertyChangedInvocator]
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -59,9 +59,9 @@ namespace QuickLook.Utilities
|
||||
private struct AccentPolicy
|
||||
{
|
||||
public AccentState AccentState;
|
||||
public int AccentFlags;
|
||||
public int GradientColor;
|
||||
public int AnimationId;
|
||||
public readonly int AccentFlags;
|
||||
public readonly int GradientColor;
|
||||
public readonly int AnimationId;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user