mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-13 19:19:10 +00:00
Prepare support .rpm
This commit is contained in:
@@ -0,0 +1,241 @@
|
|||||||
|
<UserControl x:Class="QuickLook.Plugin.AppViewer.InfoPanels.RpmInfoPanel"
|
||||||
|
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:local="clr-namespace:QuickLook.Plugin.AppViewer"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
FontSize="14"
|
||||||
|
UseLayoutRounding="True"
|
||||||
|
mc:Ignorable="d">
|
||||||
|
<UserControl.Resources>
|
||||||
|
<ResourceDictionary>
|
||||||
|
<ResourceDictionary.MergedDictionaries>
|
||||||
|
<ResourceDictionary Source="GroupBox.xaml" />
|
||||||
|
</ResourceDictionary.MergedDictionaries>
|
||||||
|
</ResourceDictionary>
|
||||||
|
</UserControl.Resources>
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="15" />
|
||||||
|
<RowDefinition Height="*" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="150" />
|
||||||
|
<ColumnDefinition Width="*" />
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Image x:Name="image"
|
||||||
|
Grid.Row="1"
|
||||||
|
Grid.Column="0"
|
||||||
|
Width="120"
|
||||||
|
Height="120"
|
||||||
|
Margin="8"
|
||||||
|
VerticalAlignment="Top"
|
||||||
|
Opacity="0"
|
||||||
|
RenderOptions.BitmapScalingMode="HighQuality"
|
||||||
|
SnapsToDevicePixels="True"
|
||||||
|
Stretch="Fill"
|
||||||
|
UseLayoutRounding="True">
|
||||||
|
<Image.Style>
|
||||||
|
<Style TargetType="{x:Type Image}">
|
||||||
|
<Style.Triggers>
|
||||||
|
<DataTrigger Binding="{Binding Source, ElementName=image}" Value="{x:Null}">
|
||||||
|
<DataTrigger.ExitActions>
|
||||||
|
<BeginStoryboard>
|
||||||
|
<Storyboard>
|
||||||
|
<DoubleAnimation BeginTime="0:0:0"
|
||||||
|
Storyboard.TargetProperty="Opacity"
|
||||||
|
From="0"
|
||||||
|
To="1"
|
||||||
|
Duration="0:0:0.05" />
|
||||||
|
</Storyboard>
|
||||||
|
</BeginStoryboard>
|
||||||
|
</DataTrigger.ExitActions>
|
||||||
|
</DataTrigger>
|
||||||
|
</Style.Triggers>
|
||||||
|
</Style>
|
||||||
|
</Image.Style>
|
||||||
|
</Image>
|
||||||
|
<Grid Grid.Row="1" Grid.Column="1">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="5" />
|
||||||
|
<ColumnDefinition Width="Auto" />
|
||||||
|
<ColumnDefinition Width="*" />
|
||||||
|
<ColumnDefinition Width="10" />
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="10" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="10" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="*" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Grid Grid.Row="1"
|
||||||
|
Grid.Column="1"
|
||||||
|
Grid.ColumnSpan="2">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="*" />
|
||||||
|
<ColumnDefinition Width="Auto" />
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<TextBlock Grid.Column="0"
|
||||||
|
MaxHeight="60"
|
||||||
|
Padding="3"
|
||||||
|
FontSize="19"
|
||||||
|
FontWeight="SemiBold"
|
||||||
|
LineHeight="25"
|
||||||
|
TextTrimming="CharacterEllipsis"
|
||||||
|
TextWrapping="Wrap">
|
||||||
|
<TextBlock.Inlines>
|
||||||
|
<Run x:Name="filename" Text="FilenameFilenameFilenameFilenameFilenameFilenameFilenameFilenameFilenameFilename.ext" />
|
||||||
|
</TextBlock.Inlines>
|
||||||
|
</TextBlock>
|
||||||
|
</Grid>
|
||||||
|
<!-- Application Name -->
|
||||||
|
<TextBlock x:Name="applicationNameTitle"
|
||||||
|
Grid.Row="3"
|
||||||
|
Grid.Column="1"
|
||||||
|
Padding="3"
|
||||||
|
Foreground="{DynamicResource WindowTextForegroundAlternative}"
|
||||||
|
Text="Application Name" />
|
||||||
|
<TextBlock x:Name="applicationName"
|
||||||
|
Grid.Row="3"
|
||||||
|
Grid.Column="2"
|
||||||
|
Margin="8,0,0,0"
|
||||||
|
Padding="3"
|
||||||
|
Foreground="{DynamicResource WindowTextForegroundAlternative}"
|
||||||
|
Text="Searching..."
|
||||||
|
TextTrimming="CharacterEllipsis"
|
||||||
|
TextWrapping="Wrap" />
|
||||||
|
<!-- Version -->
|
||||||
|
<TextBlock x:Name="versionTitle"
|
||||||
|
Grid.Row="4"
|
||||||
|
Grid.Column="1"
|
||||||
|
Padding="3"
|
||||||
|
Foreground="{DynamicResource WindowTextForegroundAlternative}"
|
||||||
|
Text="Version" />
|
||||||
|
<TextBlock x:Name="version"
|
||||||
|
Grid.Row="4"
|
||||||
|
Grid.Column="2"
|
||||||
|
Margin="8,0,0,0"
|
||||||
|
Padding="3"
|
||||||
|
Foreground="{DynamicResource WindowTextForegroundAlternative}"
|
||||||
|
Text="Searching..."
|
||||||
|
TextTrimming="CharacterEllipsis"
|
||||||
|
TextWrapping="Wrap" />
|
||||||
|
<!-- Architecture -->
|
||||||
|
<TextBlock x:Name="architectureTitle"
|
||||||
|
Grid.Row="5"
|
||||||
|
Grid.Column="1"
|
||||||
|
Padding="3"
|
||||||
|
Foreground="{DynamicResource WindowTextForegroundAlternative}"
|
||||||
|
Text="Architecture" />
|
||||||
|
<TextBlock x:Name="architectureName"
|
||||||
|
Grid.Row="5"
|
||||||
|
Grid.Column="2"
|
||||||
|
Margin="8,0,0,0"
|
||||||
|
Padding="3"
|
||||||
|
Foreground="{DynamicResource WindowTextForegroundAlternative}"
|
||||||
|
Text="Searching..."
|
||||||
|
TextTrimming="CharacterEllipsis"
|
||||||
|
TextWrapping="Wrap" />
|
||||||
|
<!-- Type -->
|
||||||
|
<TextBlock x:Name="typeTitle"
|
||||||
|
Grid.Row="6"
|
||||||
|
Grid.Column="1"
|
||||||
|
Padding="3"
|
||||||
|
Foreground="{DynamicResource WindowTextForegroundAlternative}"
|
||||||
|
Text="Type" />
|
||||||
|
<TextBlock x:Name="type"
|
||||||
|
Grid.Row="6"
|
||||||
|
Grid.Column="2"
|
||||||
|
Margin="8,0,0,0"
|
||||||
|
Padding="3"
|
||||||
|
Foreground="{DynamicResource WindowTextForegroundAlternative}"
|
||||||
|
Text="Searching..."
|
||||||
|
TextTrimming="CharacterEllipsis"
|
||||||
|
TextWrapping="Wrap" />
|
||||||
|
<!-- Terminal -->
|
||||||
|
<TextBlock x:Name="terminalTitle"
|
||||||
|
Grid.Row="7"
|
||||||
|
Grid.Column="1"
|
||||||
|
Padding="3"
|
||||||
|
Foreground="{DynamicResource WindowTextForegroundAlternative}"
|
||||||
|
Text="Terminal" />
|
||||||
|
<TextBlock x:Name="terminal"
|
||||||
|
Grid.Row="7"
|
||||||
|
Grid.Column="2"
|
||||||
|
Margin="8,0,0,0"
|
||||||
|
Padding="3"
|
||||||
|
Foreground="{DynamicResource WindowTextForegroundAlternative}"
|
||||||
|
Text="Searching..."
|
||||||
|
TextTrimming="CharacterEllipsis"
|
||||||
|
TextWrapping="Wrap" />
|
||||||
|
<!-- Total Size -->
|
||||||
|
<TextBlock x:Name="totalSizeTitle"
|
||||||
|
Grid.Row="8"
|
||||||
|
Grid.Column="1"
|
||||||
|
Padding="3"
|
||||||
|
Foreground="{DynamicResource WindowTextForegroundAlternative}"
|
||||||
|
Text="Total Size" />
|
||||||
|
<TextBlock x:Name="totalSize"
|
||||||
|
Grid.Row="8"
|
||||||
|
Grid.Column="2"
|
||||||
|
Margin="8,0,0,0"
|
||||||
|
Padding="3"
|
||||||
|
Foreground="{DynamicResource WindowTextForegroundAlternative}"
|
||||||
|
Text="Calculating size..." />
|
||||||
|
<!-- Last Modified -->
|
||||||
|
<TextBlock x:Name="modDateTitle"
|
||||||
|
Grid.Row="9"
|
||||||
|
Grid.Column="1"
|
||||||
|
Padding="3"
|
||||||
|
Foreground="{DynamicResource WindowTextForegroundAlternative}"
|
||||||
|
Text="Last Modified" />
|
||||||
|
<TextBlock x:Name="modDate"
|
||||||
|
Grid.Row="9"
|
||||||
|
Grid.Column="2"
|
||||||
|
Margin="8,0,0,0"
|
||||||
|
Padding="3"
|
||||||
|
Foreground="{DynamicResource WindowTextForegroundAlternative}"
|
||||||
|
Text="Searching..."
|
||||||
|
TextTrimming="CharacterEllipsis" />
|
||||||
|
<!-- Environment -->
|
||||||
|
<GroupBox x:Name="environmentGroupBox"
|
||||||
|
Grid.Row="10"
|
||||||
|
Grid.Column="1"
|
||||||
|
Grid.ColumnSpan="2"
|
||||||
|
Margin="3,3,16,16"
|
||||||
|
Padding="3"
|
||||||
|
Background="{DynamicResource CardBackgroundFillColorDefaultBrush}"
|
||||||
|
BorderBrush="{DynamicResource CardStrokeColorDefaultBrush}"
|
||||||
|
Foreground="{DynamicResource WindowTextForegroundAlternative}"
|
||||||
|
Header="Environment"
|
||||||
|
Visibility="Collapsed">
|
||||||
|
<ScrollViewer VerticalScrollBarVisibility="Auto" Visibility="Collapsed">
|
||||||
|
<ScrollViewer.Resources>
|
||||||
|
<Style TargetType="{x:Type TextBox}">
|
||||||
|
<Setter Property="Background" Value="Transparent" />
|
||||||
|
<Setter Property="Foreground" Value="{DynamicResource TextFillColorPrimaryBrush}" />
|
||||||
|
<Setter Property="BorderThickness" Value="0" />
|
||||||
|
<Setter Property="BorderBrush" Value="Transparent" />
|
||||||
|
</Style>
|
||||||
|
</ScrollViewer.Resources>
|
||||||
|
<ItemsControl x:Name="permissions">
|
||||||
|
<ItemsControl.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<TextBox Margin="8,3,16,3"
|
||||||
|
IsReadOnly="True"
|
||||||
|
Text="{Binding ., Mode=OneTime}" />
|
||||||
|
</DataTemplate>
|
||||||
|
</ItemsControl.ItemTemplate>
|
||||||
|
</ItemsControl>
|
||||||
|
</ScrollViewer>
|
||||||
|
</GroupBox>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</UserControl>
|
@@ -0,0 +1,93 @@
|
|||||||
|
// Copyright © 2017-2025 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.Common.Plugin;
|
||||||
|
using QuickLook.Plugin.AppViewer.PackageParsers.AppImage;
|
||||||
|
using QuickLook.Plugin.AppViewer.PackageParsers.Rpm;
|
||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
|
||||||
|
namespace QuickLook.Plugin.AppViewer.InfoPanels;
|
||||||
|
|
||||||
|
public partial class RpmInfoPanel : UserControl, IAppInfoPanel
|
||||||
|
{
|
||||||
|
private readonly ContextObject _context;
|
||||||
|
|
||||||
|
public RpmInfoPanel(ContextObject context)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
|
||||||
|
DataContext = this;
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
string translationFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Translations.config");
|
||||||
|
applicationNameTitle.Text = TranslationHelper.Get("APP_NAME", translationFile);
|
||||||
|
versionTitle.Text = TranslationHelper.Get("APP_VERSION", translationFile);
|
||||||
|
architectureTitle.Text = TranslationHelper.Get("ARCHITECTURE", translationFile);
|
||||||
|
typeTitle.Text = TranslationHelper.Get("TYPE", translationFile);
|
||||||
|
terminalTitle.Text = TranslationHelper.Get("TERMINAL", translationFile);
|
||||||
|
totalSizeTitle.Text = TranslationHelper.Get("TOTAL_SIZE", translationFile);
|
||||||
|
modDateTitle.Text = TranslationHelper.Get("LAST_MODIFIED", translationFile);
|
||||||
|
environmentGroupBox.Header = TranslationHelper.Get("ENVIRONMENT", translationFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DisplayInfo(string path)
|
||||||
|
{
|
||||||
|
var name = Path.GetFileName(path);
|
||||||
|
filename.Text = string.IsNullOrEmpty(name) ? path : name;
|
||||||
|
|
||||||
|
_ = Task.Run(() =>
|
||||||
|
{
|
||||||
|
if (File.Exists(path))
|
||||||
|
{
|
||||||
|
var size = new FileInfo(path).Length;
|
||||||
|
RpmInfo rpmInfo = RpmParser.Parse(path);
|
||||||
|
var last = File.GetLastWriteTime(path);
|
||||||
|
|
||||||
|
Dispatcher.Invoke(() =>
|
||||||
|
{
|
||||||
|
applicationName.Text = rpmInfo.Name;
|
||||||
|
version.Text = rpmInfo.Version;
|
||||||
|
architectureName.Text = rpmInfo.Arch;
|
||||||
|
type.Text = rpmInfo.Type;
|
||||||
|
terminal.Text = rpmInfo.Terminal;
|
||||||
|
totalSize.Text = size.ToPrettySize(2);
|
||||||
|
modDate.Text = last.ToString(CultureInfo.CurrentCulture);
|
||||||
|
permissions.ItemsSource = rpmInfo.Env;
|
||||||
|
|
||||||
|
if (rpmInfo.HasIcon)
|
||||||
|
{
|
||||||
|
image.Source = rpmInfo.Logo.ToBitmapSource();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
image.Source = new BitmapImage(new Uri("pack://application:,,,/QuickLook.Plugin.AppViewer;component/Resources/rpm.png"));
|
||||||
|
}
|
||||||
|
|
||||||
|
_context.IsBusy = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,43 @@
|
|||||||
|
// Copyright © 2017-2025 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 System.Drawing;
|
||||||
|
|
||||||
|
namespace QuickLook.Plugin.AppViewer.PackageParsers.Rpm;
|
||||||
|
|
||||||
|
public class RpmInfo
|
||||||
|
{
|
||||||
|
public string Arch { get; set; }
|
||||||
|
|
||||||
|
public string Version { get; set; }
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public string Exec { get; set; }
|
||||||
|
|
||||||
|
public string Icon { get; set; }
|
||||||
|
|
||||||
|
public Bitmap Logo { get; set; }
|
||||||
|
|
||||||
|
public bool HasIcon => !string.IsNullOrEmpty(Icon) && Logo != null;
|
||||||
|
|
||||||
|
public string Type { get; set; }
|
||||||
|
|
||||||
|
public string Terminal { get; set; }
|
||||||
|
|
||||||
|
public string[] Env { get; set; }
|
||||||
|
}
|
@@ -0,0 +1,41 @@
|
|||||||
|
// Copyright © 2017-2025 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.Plugin.AppViewer.PackageParsers.AppImage;
|
||||||
|
|
||||||
|
namespace QuickLook.Plugin.AppViewer.PackageParsers.Rpm;
|
||||||
|
|
||||||
|
public class RpmParser
|
||||||
|
{
|
||||||
|
public static RpmInfo Parse(string path)
|
||||||
|
{
|
||||||
|
var reader = new RpmReader(path);
|
||||||
|
|
||||||
|
return new RpmInfo()
|
||||||
|
{
|
||||||
|
Arch = reader.Arch,
|
||||||
|
Version = reader.Version,
|
||||||
|
Name = reader.Name,
|
||||||
|
Exec = reader.Exec,
|
||||||
|
Icon = reader.Icon,
|
||||||
|
Logo = reader.Logo,
|
||||||
|
Type = reader.Type,
|
||||||
|
Terminal = reader.Terminal,
|
||||||
|
Env = reader.Env,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,117 @@
|
|||||||
|
// Copyright © 2017-2025 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 PureSharpCompress.Common;
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace QuickLook.Plugin.AppViewer.PackageParsers.Rpm;
|
||||||
|
|
||||||
|
public class RpmReader
|
||||||
|
{
|
||||||
|
public string Arch { get; set; }
|
||||||
|
|
||||||
|
public string Version { get; set; }
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public string Exec { get; set; }
|
||||||
|
|
||||||
|
public string Icon { get; set; }
|
||||||
|
|
||||||
|
public Bitmap Logo { get; set; }
|
||||||
|
|
||||||
|
public string Type { get; set; }
|
||||||
|
|
||||||
|
public string Terminal { get; set; }
|
||||||
|
|
||||||
|
public string[] Env { get; set; }
|
||||||
|
|
||||||
|
public RpmReader(Stream stream)
|
||||||
|
{
|
||||||
|
Open(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RpmReader(string path)
|
||||||
|
{
|
||||||
|
using FileStream fs = File.OpenRead(path);
|
||||||
|
Open(fs);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Open(Stream stream)
|
||||||
|
{
|
||||||
|
using var br = new BinaryReader(stream);
|
||||||
|
|
||||||
|
// Step 1: Read the lead (96 bytes)
|
||||||
|
byte[] lead = br.ReadBytes(96);
|
||||||
|
Debug.WriteLine($"[lead] 96 bytes read, magic: {BitConverter.ToString(lead, 0, 4)}");
|
||||||
|
|
||||||
|
// Step 2: Read signature header
|
||||||
|
RpmHeader sigHeader = ReadHeader(br);
|
||||||
|
Debug.WriteLine($"[signature header] IndexCount: {sigHeader.IndexCount}, DataSize: {sigHeader.DataSize}");
|
||||||
|
|
||||||
|
// Step 3: Read main header
|
||||||
|
RpmHeader mainHeader = ReadHeader(br);
|
||||||
|
Debug.WriteLine($"[main header] IndexCount: {mainHeader.IndexCount}, DataSize: {mainHeader.DataSize}");
|
||||||
|
|
||||||
|
// Step 4: Remaining is the payload (cpio archive + compression)
|
||||||
|
long payloadSize = stream.Length - stream.Position;
|
||||||
|
Debug.WriteLine($"[payload] Size: {payloadSize} bytes at offset: {stream.Position}");
|
||||||
|
|
||||||
|
// (Optional) Detect compression (e.g. gzip, xz, zstd)
|
||||||
|
byte[] magic = br.ReadBytes(6);
|
||||||
|
string type = magic[0] switch
|
||||||
|
{
|
||||||
|
0x1F when magic[1] == 0x8B => "gzip",
|
||||||
|
0xFD when magic[1] == 0x37 => "xz",
|
||||||
|
0x28 when magic[1] == 0xB5 => "zstd",
|
||||||
|
_ => "unknown"
|
||||||
|
};
|
||||||
|
Debug.WriteLine($"Detected payload compression: {type}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static RpmHeader ReadHeader(BinaryReader br)
|
||||||
|
{
|
||||||
|
// ed ab ee db 03
|
||||||
|
byte[] magic = br.ReadBytes(3);
|
||||||
|
//if (Encoding.ASCII.GetString(magic) != "\x8e\xad\xe8")
|
||||||
|
//throw new InvalidDataException("Invalid RPM header magic");
|
||||||
|
|
||||||
|
byte version = br.ReadByte(); // Usually 1
|
||||||
|
byte[] reserved = br.ReadBytes(4);
|
||||||
|
int indexCount = ReadBigEndianInt32(br);
|
||||||
|
int dataSize = ReadBigEndianInt32(br);
|
||||||
|
return new RpmHeader { IndexCount = indexCount, DataSize = dataSize };
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int ReadBigEndianInt32(BinaryReader br)
|
||||||
|
{
|
||||||
|
byte[] b = br.ReadBytes(4);
|
||||||
|
if (b.Length < 4) throw new EndOfStreamException();
|
||||||
|
return (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3];
|
||||||
|
}
|
||||||
|
|
||||||
|
private class RpmHeader
|
||||||
|
{
|
||||||
|
public int IndexCount { get; set; }
|
||||||
|
|
||||||
|
public int DataSize { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@@ -51,6 +51,7 @@ public class Plugin : IViewer
|
|||||||
// Ubuntu
|
// Ubuntu
|
||||||
".deb", // Debian Package
|
".deb", // Debian Package
|
||||||
".appimage", // AppImage Format
|
".appimage", // AppImage Format
|
||||||
|
// ".rpm", // Red Hat Package Manager
|
||||||
|
|
||||||
// Others
|
// Others
|
||||||
".wgt", ".wgtu", // UniApp Widget
|
".wgt", ".wgtu", // UniApp Widget
|
||||||
@@ -82,6 +83,7 @@ public class Plugin : IViewer
|
|||||||
".deb" => new Size { Width = 600, Height = 345 },
|
".deb" => new Size { Width = 600, Height = 345 },
|
||||||
".dmg" => new Size { Width = 560, Height = 510 },
|
".dmg" => new Size { Width = 560, Height = 510 },
|
||||||
".appimage" => new Size { Width = 600, Height = 300 },
|
".appimage" => new Size { Width = 600, Height = 300 },
|
||||||
|
".rpm" => new Size { Width = 600, Height = 300 },
|
||||||
".wgt" or ".wgtu" => new Size { Width = 600, Height = 345 },
|
".wgt" or ".wgtu" => new Size { Width = 600, Height = 345 },
|
||||||
_ => throw new NotSupportedException("Extension is not supported."),
|
_ => throw new NotSupportedException("Extension is not supported."),
|
||||||
};
|
};
|
||||||
@@ -105,6 +107,7 @@ public class Plugin : IViewer
|
|||||||
".deb" => new DebInfoPanel(context),
|
".deb" => new DebInfoPanel(context),
|
||||||
".dmg" => new DmgInfoPanel(context),
|
".dmg" => new DmgInfoPanel(context),
|
||||||
".appimage" => new AppImageInfoPanel(context),
|
".appimage" => new AppImageInfoPanel(context),
|
||||||
|
".rpm" => new RpmInfoPanel(context),
|
||||||
".wgt" or ".wgtu" => new WgtInfoPanel(context),
|
".wgt" or ".wgtu" => new WgtInfoPanel(context),
|
||||||
_ => throw new NotSupportedException("Extension is not supported."),
|
_ => throw new NotSupportedException("Extension is not supported."),
|
||||||
};
|
};
|
||||||
|
BIN
QuickLook.Plugin/QuickLook.Plugin.AppViewer/Resources/rpm.png
Normal file
BIN
QuickLook.Plugin/QuickLook.Plugin.AppViewer/Resources/rpm.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.8 KiB |
Reference in New Issue
Block a user