Skip to content

Commit

Permalink
Code Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
emako committed Dec 11, 2024
1 parent c056438 commit 28ec765
Show file tree
Hide file tree
Showing 89 changed files with 6,843 additions and 6,745 deletions.
127 changes: 63 additions & 64 deletions QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/ArchiveFileEntry.cs
Original file line number Diff line number Diff line change
@@ -1,99 +1,98 @@
// 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.Collections.Generic;
using System.Linq;

namespace QuickLook.Plugin.ArchiveViewer
namespace QuickLook.Plugin.ArchiveViewer;

public class ArchiveFileEntry : IComparable<ArchiveFileEntry>
{
public class ArchiveFileEntry : IComparable<ArchiveFileEntry>
{
private readonly ArchiveFileEntry _parent;
private int _cachedDepth = -1;
private int _cachedLevel = -1;
private readonly ArchiveFileEntry _parent;
private int _cachedDepth = -1;
private int _cachedLevel = -1;

public ArchiveFileEntry(string name, bool isFolder, ArchiveFileEntry parent = null)
{
Name = name;
IsFolder = isFolder;
public ArchiveFileEntry(string name, bool isFolder, ArchiveFileEntry parent = null)
{
Name = name;
IsFolder = isFolder;

_parent = parent;
_parent?.Children.Add(this, false);
}
_parent = parent;
_parent?.Children.Add(this, false);
}

public SortedList<ArchiveFileEntry, bool> Children { get; set; } = new SortedList<ArchiveFileEntry, bool>();
public SortedList<ArchiveFileEntry, bool> Children { get; set; } = new SortedList<ArchiveFileEntry, bool>();

public string Name { get; set; }
public bool Encrypted { get; set; }
public bool IsFolder { get; set; }
public ulong Size { get; set; }
public DateTime ModifiedDate { get; set; }
public string Name { get; set; }
public bool Encrypted { get; set; }
public bool IsFolder { get; set; }
public ulong Size { get; set; }
public DateTime ModifiedDate { get; set; }

/// <summary>
/// Returns the maximum depth of all siblings
/// </summary>
public int Level
/// <summary>
/// Returns the maximum depth of all siblings
/// </summary>
public int Level
{
get
{
get
{
if (_cachedLevel != -1)
return _cachedLevel;
if (_cachedLevel != -1)
return _cachedLevel;

if (_parent == null)
_cachedLevel = GetDepth();
else
_cachedLevel = _parent.Level - 1;
if (_parent == null)
_cachedLevel = GetDepth();
else
_cachedLevel = _parent.Level - 1;

return _cachedLevel;
}
return _cachedLevel;
}
}

public int CompareTo(ArchiveFileEntry other)
{
if (IsFolder == other.IsFolder)
return string.Compare(Name, other.Name, StringComparison.CurrentCulture);

if (IsFolder)
return -1;
public int CompareTo(ArchiveFileEntry other)
{
if (IsFolder == other.IsFolder)
return string.Compare(Name, other.Name, StringComparison.CurrentCulture);

return 1;
}
if (IsFolder)
return -1;

/// <summary>
/// Returns the number of nodes in the longest path to a leaf
/// </summary>
private int GetDepth()
{
if (_cachedDepth != -1)
return _cachedDepth;
return 1;
}

var max = Children.Keys.Count == 0 ? 0 : Children.Keys.Max(r => r.GetDepth());
_cachedDepth = max + 1;
/// <summary>
/// Returns the number of nodes in the longest path to a leaf
/// </summary>
private int GetDepth()
{
if (_cachedDepth != -1)
return _cachedDepth;
}

public override string ToString()
{
if (IsFolder)
return $"{Name}";
var max = Children.Keys.Count == 0 ? 0 : Children.Keys.Max(r => r.GetDepth());
_cachedDepth = max + 1;
return _cachedDepth;
}

var en = Encrypted ? "*" : "";
return $"{Name}{en},{IsFolder},{Size},{ModifiedDate}";
}
public override string ToString()
{
if (IsFolder)
return $"{Name}";

var en = Encrypted ? "*" : "";
return $"{Name}{en},{IsFolder},{Size},{ModifiedDate}";
}
}
}
Original file line number Diff line number Diff line change
@@ -1,62 +1,61 @@
// 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.Windows.Controls;

namespace QuickLook.Plugin.ArchiveViewer
namespace QuickLook.Plugin.ArchiveViewer;

/// <summary>
/// Interaction logic for ArchiveFileListView.xaml
/// </summary>
public partial class ArchiveFileListView : UserControl, IDisposable
{
/// <summary>
/// Interaction logic for ArchiveFileListView.xaml
/// </summary>
public partial class ArchiveFileListView : UserControl, IDisposable
public ArchiveFileListView()
{
public ArchiveFileListView()
{
InitializeComponent();
}
InitializeComponent();
}

public void Dispose()
{
GC.SuppressFinalize(this);
public void Dispose()
{
GC.SuppressFinalize(this);

IconManager.ClearCache();
}
IconManager.ClearCache();
}

public void SetDataContext(object context)
{
treeGrid.DataContext = context;
public void SetDataContext(object context)
{
treeGrid.DataContext = context;

treeView.LayoutUpdated += (sender, e) =>
{
// return when empty
if (treeView.Items.Count == 0)
return;
treeView.LayoutUpdated += (sender, e) =>
{
// return when empty
if (treeView.Items.Count == 0)
return;

// return when there are more than one root nodes
if (treeView.Items.Count > 1)
return;
// return when there are more than one root nodes
if (treeView.Items.Count > 1)
return;

var root = (TreeViewItem) treeView.ItemContainerGenerator.ContainerFromItem(treeView.Items[0]);
if (root == null)
return;
var root = (TreeViewItem)treeView.ItemContainerGenerator.ContainerFromItem(treeView.Items[0]);
if (root == null)
return;

root.IsExpanded = true;
};
}
root.IsExpanded = true;
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,47 +1,73 @@
<UserControl x:Class="QuickLook.Plugin.ArchiveViewer.ArchiveInfoPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:QuickLook.Plugin.ArchiveViewer"
mc:Ignorable="d"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Name="infoPanel"
d:DesignHeight="600" d:DesignWidth="800">
d:DesignHeight="600"
d:DesignWidth="800"
mc:Ignorable="d">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- only for design -->
<!-- only for design -->
<ResourceDictionary Source="/QuickLook.Common;component/Styles/MainWindowStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
<local:Percent100ToVisibilityVisibleConverter x:Key="Percent100ToVisibilityVisibleConverter" />
<local:Percent100ToVisibilityCollapsedConverter x:Key="Percent100ToVisibilityCollapsedConverter" />
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Grid ZIndex="9999"
Visibility="{Binding ElementName=infoPanel, Path=LoadPercent, Mode=OneWay, Converter={StaticResource Percent100ToVisibilityCollapsedConverter}}">
<Grid Visibility="{Binding ElementName=infoPanel, Path=LoadPercent, Mode=OneWay, Converter={StaticResource Percent100ToVisibilityCollapsedConverter}}" ZIndex="9999">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<Label x:Name="lblLoading" FontSize="14" HorizontalAlignment="Center" Foreground="{DynamicResource WindowTextForeground}">Loading archive ...</Label>
<ProgressBar Height="13" Width="150"
<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 Visibility="{Binding ElementName=infoPanel, Path=LoadPercent, Mode=OneWay, Converter={StaticResource Percent100ToVisibilityVisibleConverter}}">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<local:ArchiveFileListView Grid.Row="0" x:Name="fileListView" Focusable="False" Foreground="{DynamicResource WindowTextForeground}" />
<local: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, solid, password-protected</Label>
<Label x:Name="archiveSizeC" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="{DynamicResource WindowTextForegroundAlternative}">Compressed size 0 bytes</Label>
<Label x:Name="archiveSizeU" Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="{DynamicResource WindowTextForegroundAlternative}">Uncompressed size 0 bytes</Label>
<Label x:Name="archiveCount"
Grid.Column="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="{DynamicResource WindowTextForegroundAlternative}">
0 folders and 0 files, solid, password-protected
</Label>
<Label x:Name="archiveSizeC"
Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="{DynamicResource WindowTextForegroundAlternative}">
Compressed size 0 bytes
</Label>
<Label x:Name="archiveSizeU"
Grid.Column="2"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="{DynamicResource WindowTextForegroundAlternative}">
Uncompressed size 0 bytes
</Label>
</Grid>
</Grid>
</Grid>
Expand Down
Loading

0 comments on commit 28ec765

Please sign in to comment.