mirror of
https://github.com/QL-Win/QuickLook.git
synced 2026-01-29 02:06:48 +08:00
Add PAK file support to ArchiveViewer plugin
Introduced PakInfoPanel for displaying PAK archive contents, including new XAML and code-behind files. Updated Plugin.cs to use PakInfoPanel when opening .pak files, enabling preview and basic information display for Chromium resource packages.
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<UserControl x:Class="QuickLook.Plugin.ArchiveViewer.ChromiumResourcePackage.PakInfoPanel"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:archive="clr-namespace:QuickLook.Plugin.ArchiveViewer.ArchiveFile"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:QuickLook.Plugin.ArchiveViewer.ChromiumResourcePackage"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
x:Name="infoPanel"
|
||||
d:DesignHeight="600"
|
||||
d:DesignWidth="800"
|
||||
mc:Ignorable="d">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/QuickLook.Common;component/Styles/MainWindowStyles.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<archive:Percent100ToVisibilityVisibleConverter x:Key="Percent100ToVisibilityVisibleConverter" />
|
||||
<archive:Percent100ToVisibilityCollapsedConverter x:Key="Percent100ToVisibilityCollapsedConverter" />
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid Visibility="{Binding ElementName=infoPanel, Path=LoadPercent, Mode=OneWay, Converter={StaticResource Percent100ToVisibilityCollapsedConverter}}" ZIndex="9999">
|
||||
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<Label x:Name="lblLoading"
|
||||
HorizontalAlignment="Center"
|
||||
FontSize="14"
|
||||
Foreground="{DynamicResource WindowTextForeground}">
|
||||
Loading archive ...
|
||||
</Label>
|
||||
<ProgressBar Width="150"
|
||||
Height="13"
|
||||
Value="{Binding ElementName=infoPanel, Path=LoadPercent, Mode=OneWay}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<Grid Visibility="{Binding ElementName=infoPanel, Path=LoadPercent, Mode=OneWay, Converter={StaticResource Percent100ToVisibilityVisibleConverter}}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition Height="30" />
|
||||
</Grid.RowDefinitions>
|
||||
<archive:ArchiveFileListView x:Name="fileListView"
|
||||
Grid.Row="0"
|
||||
Focusable="False"
|
||||
Foreground="{DynamicResource WindowTextForeground}" />
|
||||
<Grid Grid.Row="1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="40*" />
|
||||
<ColumnDefinition Width="30*" />
|
||||
<ColumnDefinition Width="30*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label x:Name="archiveCount"
|
||||
Grid.Column="0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{DynamicResource WindowTextForegroundAlternative}">
|
||||
0 folders and 0 files
|
||||
</Label>
|
||||
<Label x:Name="archiveSizeC"
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{DynamicResource WindowTextForegroundAlternative}" />
|
||||
<Label x:Name="archiveSizeU"
|
||||
Grid.Column="2"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{DynamicResource WindowTextForegroundAlternative}">
|
||||
Uncompressed size 0 bytes
|
||||
</Label>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,136 @@
|
||||
// Copyright © 2017-2026 QL-Win Contributors
|
||||
//
|
||||
// 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 QuickLook.Common.ExtensionMethods;
|
||||
using QuickLook.Common.Helpers;
|
||||
using QuickLook.Plugin.ArchiveViewer.ArchiveFile;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace QuickLook.Plugin.ArchiveViewer.ChromiumResourcePackage;
|
||||
|
||||
public partial class PakInfoPanel : UserControl, IDisposable, INotifyPropertyChanged
|
||||
{
|
||||
private readonly Dictionary<string, ArchiveFileEntry> _fileEntries = [];
|
||||
private bool _disposed;
|
||||
private double _loadPercent;
|
||||
private ulong _totalSize;
|
||||
|
||||
public PakInfoPanel(string path)
|
||||
{
|
||||
InitializeComponent();
|
||||
Resources.MergedDictionaries.Clear();
|
||||
BeginLoadPak(path);
|
||||
}
|
||||
|
||||
public double LoadPercent
|
||||
{
|
||||
get => _loadPercent;
|
||||
private set
|
||||
{
|
||||
if (value == _loadPercent) return;
|
||||
_loadPercent = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
_disposed = true;
|
||||
fileListView?.Dispose();
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private void BeginLoadPak(string path)
|
||||
{
|
||||
new Task(() =>
|
||||
{
|
||||
_totalSize = (ulong)new FileInfo(path).Length;
|
||||
var root = new ArchiveFileEntry(Path.GetFileName(path), true);
|
||||
_fileEntries.Add(string.Empty, root);
|
||||
try
|
||||
{
|
||||
LoadItemsFromPak(path);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ProcessHelper.WriteLog(e.ToString());
|
||||
Dispatcher.Invoke(() => { lblLoading.Content = "Preview failed. See log for more details."; });
|
||||
return;
|
||||
}
|
||||
|
||||
var folders = -1; // do not count root node
|
||||
var files = 0;
|
||||
ulong sizeU = 0L;
|
||||
foreach (var item in _fileEntries)
|
||||
{
|
||||
if (item.Value.IsFolder)
|
||||
folders++;
|
||||
else
|
||||
files++;
|
||||
sizeU += item.Value.Size;
|
||||
}
|
||||
|
||||
string t;
|
||||
var d = folders != 0 ? $"{folders} folders" : string.Empty;
|
||||
var f = files != 0 ? $"{files} files" : string.Empty;
|
||||
if (!string.IsNullOrEmpty(d) && !string.IsNullOrEmpty(f))
|
||||
t = $", {d} folders and {f} files";
|
||||
else if (string.IsNullOrEmpty(d) && string.IsNullOrEmpty(f))
|
||||
t = string.Empty;
|
||||
else
|
||||
t = $", {d}{f}";
|
||||
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
if (_disposed)
|
||||
return;
|
||||
fileListView?.SetDataContext(_fileEntries[string.Empty].Children.Keys);
|
||||
archiveCount.Content = $"PAK File{t}";
|
||||
archiveSizeC.Content = string.Empty;
|
||||
archiveSizeU.Content = $"Total resource size {((long)sizeU).ToPrettySize(2)}";
|
||||
});
|
||||
LoadPercent = 100d;
|
||||
}).Start();
|
||||
}
|
||||
|
||||
private void LoadItemsFromPak(string path)
|
||||
{
|
||||
var dict = PakExtractor.ExtractToDictionary(path, true);
|
||||
foreach (var kv in dict)
|
||||
{
|
||||
_fileEntries.TryGetValue(string.Empty, out var parent);
|
||||
var entry = new ArchiveFileEntry(kv.Key, false, parent)
|
||||
{
|
||||
Size = (ulong)kv.Value.Length
|
||||
};
|
||||
_fileEntries.Add(kv.Key, entry);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
@@ -92,10 +92,7 @@ public sealed partial class Plugin : IViewer, IMoreMenu
|
||||
}
|
||||
else if (path.EndsWith(".pak", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var dict = PakExtractor.ExtractToDictionary(path);
|
||||
|
||||
// TODO
|
||||
_ = dict;
|
||||
_panel = new PakInfoPanel(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user