Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add package rankings #3368

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion>
<WindowsSdkPackageVersion>10.0.26100.56</WindowsSdkPackageVersion>
<WindowsSdkPackageVersion>10.0.26100.57</WindowsSdkPackageVersion>
<SdkVersion>8.0.405</SdkVersion>
<Authors>Martí Climent and the contributors</Authors>
<PublisherName>Martí Climent</PublisherName>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<Optimize>true</Optimize>
</PropertyGroup>

Expand Down
43 changes: 35 additions & 8 deletions src/UniGetUI.Core.Tools/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,11 @@
/// </summary>
/// <param name="name">A string containing the Id of a package</param>
/// <returns>The formatted string</returns>
public static string FormatAsName(string name)
public static string FormatAsName(string name, bool isWinget = false)
{
name =
name.Replace(".install", "").Replace(".portable", "").Replace("-", " ").Replace("_", " ").Split("/")[^1]
if (isWinget) name = string.Join(' ', name.Split('.')[1..]);

name = name.Replace(".install", "").Replace(".portable", "").Replace("-", " ").Replace("_", " ").Split("/")[^1]
.Split(":")[0];
string newName = "";
for (int i = 0; i < name.Length; i++)
Expand Down Expand Up @@ -195,20 +196,46 @@
}

string Error_String = $@"
OS: {Environment.OSVersion.Platform}
Version: {Environment.OSVersion.VersionString}
OS Architecture: {Environment.Is64BitOperatingSystem}
APP Architecture: {Environment.Is64BitProcess}
Windows version: {Environment.OSVersion.VersionString}
Language: {LangName}
APP Version: {CoreData.VersionName}
APP Build number: {CoreData.BuildNumber}
Executable: {Environment.ProcessPath}

Crash HResult: {(uint)e.HResult}
Crash HResult: 0x{(uint)e.HResult:X} ({(uint)e.HResult}, {e.HResult})
Crash Message: {e.Message}

Crash Traceback:
{e.StackTrace}";

try
{
int i = 0;
while (e.InnerException is not null)
{
i++;
e = e.InnerException;
Error_String += $@"


---------------------
Inner exception ({i}):
Crash HResult: 0x{(uint)e.HResult:X} ({(uint)e.HResult}, {e.HResult})
Crash Message: {e.Message}

Crash Traceback:
{e.StackTrace}";
}

if (i == 0)
{
Error_String += $"\n\n\nNo inner exceptions found";
}
} catch
{
// ignore
}

Console.WriteLine(Error_String);

string ErrorBody = "https://www.marticliment.com/error-report/?appName=UniGetUI^&errorBody=" +
Expand Down Expand Up @@ -314,7 +341,7 @@

return 0;
}

Check warning on line 344 in src/UniGetUI.Core.Tools/Tools.cs

View workflow job for this annotation

GitHub Actions / test-codebase

Avoid multiple blank lines (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide2000)

public struct Version: IComparable
{
Expand Down
1 change: 1 addition & 0 deletions src/UniGetUI.Interface.Telemetry/TelemetryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public enum TEL_InstallReferral
FROM_BUNDLE,
FROM_WEB_SHARE,
ALREADY_INSTALLED,
FROM_RANKING
}

public enum TEL_OP_RESULT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System.Collections.Concurrent;
using UniGetUI.PackageEngine.Interfaces;
using UniGetUI.PackageEngine.PackageClasses;

namespace UniGetUI.PackageEngine.Classes.Packages
{
internal static class PackageCacher
public static class PackageCacher
{
private static readonly ConcurrentDictionary<long, Package> __available_pkgs = [];
private static readonly ConcurrentDictionary<long, Package> __upgradable_pkgs = [];
Expand Down Expand Up @@ -116,5 +117,15 @@ private static void AddPackageToCache(Package package, ConcurrentDictionary<long
long hash = map == __installed_pkgs ? package.GetVersionedHash() : package.GetHash();
map.TryAdd(hash, package);
}

public static IPackage? GetExistingOne(IPackage? sample)
{
foreach (Package found in __installed_pkgs.Values)
{
if (found.IsEquivalentTo(sample)) return found;
}

return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,7 @@ public Package(

ignoredId = IgnoredUpdatesDatabase.GetIgnoredIdForPackage(this);

_iconId = Manager.Name switch
{
"Winget" => Source.Name switch
{
"Steam" => id.ToLower().Split("\\")[^1].Replace("steam app ", "steam:").Trim(),
"Local PC" => id.ToLower().Split("\\")[^1],
"Microsoft Store" => id.IndexOf('_') < id.IndexOf('.') ? // If the first underscore is before the period, this ID has no publisher
string.Join('_', id.ToLower().Split("\\")[1].Split("_")[0..^4]) : // no publisher: remove `MSIX\`, then the standard ending _version_arch__{random id}
string.Join('_', string.Join('.', id.ToLower().Split(".")[1..]).Split("_")[0..^4]), // remove the publisher (before the first .), then the standard _version_arch__{random id}
_ => string.Join('.', id.ToLower().Split(".")[1..]),
},
"Scoop" => id.ToLower().Replace(".app", ""),
"Chocolatey" => id.ToLower().Replace(".install", "").Replace(".portable", ""),
"vcpkg" => id.ToLower().Split(":")[0].Split("[")[0],
_ => id.ToLower()
};
_iconId = NormalizeIconId(id, Manager.Name, Source.Name);
}

/// <summary>
Expand All @@ -134,6 +119,26 @@ public Package(
NormalizedNewVersion = CoreTools.VersionStringToStruct(new_version);
}

public static string NormalizeIconId(string id, string managerName, string sourceName = "")
{
return managerName switch
{
"Winget" => sourceName switch
{
"Steam" => id.ToLower().Split("\\")[^1].Replace("steam app ", "steam:").Trim(),
"Local PC" => id.ToLower().Split("\\")[^1],
"Microsoft Store" => id.IndexOf('_') < id.IndexOf('.') ? // If the first underscore is before the period, this ID has no publisher
string.Join('_', id.ToLower().Split("\\")[1].Split("_")[0..^4]) : // no publisher: remove `MSIX\`, then the standard ending _version_arch__{random id}
string.Join('_', string.Join('.', id.ToLower().Split(".")[1..]).Split("_")[0..^4]), // remove the publisher (before the first .), then the standard _version_arch__{random id}
_ => string.Join('.', id.ToLower().Split(".")[1..]),
},
"Scoop" => id.ToLower().Replace(".app", ""),
"Chocolatey" => id.ToLower().Replace(".install", "").Replace(".portable", ""),
"vcpkg" => id.ToLower().Split(":")[0].Split("[")[0],
_ => id.ToLower()
};
}

public long GetHash()
=> __hash;

Expand Down
84 changes: 84 additions & 0 deletions src/UniGetUI/Controls/PackageRanking.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<UserControl
x:Class="UniGetUI.Controls.PackagesRanking"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UniGetUI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:widgets="using:UniGetUI.Interface.Widgets"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
mc:Ignorable="d">

<UserControl.Resources>
<DataTemplate x:Key="PackageRankingEntry" x:DataType="local:PackageRankingItem">
<Button HorizontalAlignment="Stretch" Margin="0,5,0,0" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Padding="0" Click="{x:Bind ShowDetails}">
<Grid Margin="8" ColumnSpacing="16" RowSpacing="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Grid.Row="0" Grid.RowSpan="2" Height="44" Width="44" Margin="4">
<Image.Source>
<BitmapImage UriSource="{x:Bind IconUri, Mode=OneWay}"/>
</Image.Source>
</Image>
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="{x:Bind Name}" Grid.Row="1" FontWeight="SemiBold" FontSize="18" VerticalAlignment="Bottom" TextWrapping="Wrap"/>
<TextBlock Text="{x:Bind ManagerName}" Grid.Row="2" FontSize="12" Opacity="0.8" VerticalAlignment="Top" TextWrapping="Wrap"/>
</Grid>
</Grid>
</Button>
</DataTemplate>
</UserControl.Resources>

<ScrollViewer HorizontalScrollMode="Disabled" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Grid ColumnSpacing="16" Margin="0,20,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="1000*" MaxWidth="350"/>
<ColumnDefinition Width="1000*" MaxWidth="350"/>
<ColumnDefinition Width="1000*" MaxWidth="350"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Vertical" Grid.Column="1" Spacing="8">
<widgets:TranslatedTextBlock HorizontalAlignment="Center" Text="Popular packages" FontWeight="Bold" FontSize="20" MinHeight="32"/>
<RichTextBlock Name="PopularDescription" TextAlignment="Center">
<Paragraph/>
</RichTextBlock>
<ItemsRepeater ItemTemplate="{StaticResource PackageRankingEntry}" ItemsSource="{x:Bind PopularRank}"/>
<HyperlinkButton HorizontalAlignment="Stretch">
<widgets:TranslatedTextBlock Text="View more packages"/>
</HyperlinkButton>
</StackPanel>
<StackPanel Orientation="Vertical" Grid.Column="2" Spacing="8">
<widgets:TranslatedTextBlock HorizontalAlignment="Center" Text="The most installed" FontWeight="Bold" FontSize="20" MinHeight="32"/>
<RichTextBlock Name="InstalledDescription" TextAlignment="Center">
<Paragraph/>
</RichTextBlock>
<ItemsRepeater ItemTemplate="{StaticResource PackageRankingEntry}" ItemsSource="{x:Bind InstalledRank}"/>
<HyperlinkButton HorizontalAlignment="Stretch" >
<widgets:TranslatedTextBlock Text="View more packages"/>
</HyperlinkButton>
</StackPanel>
<StackPanel Orientation="Vertical" Grid.Column="3" Spacing="8">
<widgets:TranslatedTextBlock HorizontalAlignment="Center" Text="The wall of shame" FontWeight="Bold" FontSize="20" MinHeight="32"/>
<RichTextBlock Name="UninstalledDescription" TextAlignment="Center">
<Paragraph/>
</RichTextBlock>
<ItemsRepeater ItemTemplate="{StaticResource PackageRankingEntry}" ItemsSource="{x:Bind WallOfShame}"/>
<HyperlinkButton HorizontalAlignment="Stretch" >
<widgets:TranslatedTextBlock Text="View more packages"/>
</HyperlinkButton>
</StackPanel>
<Button VerticalAlignment="Top" HorizontalAlignment="Right" Grid.Column="4" Name="ReloadButton" Click="ReloadButton_Click">Reload</Button>
<ProgressRing IsIndeterminate="True" Visibility="Collapsed" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="5" Width="100" Height="100" Name="ReloadRing"/>
</Grid>
</ScrollViewer>
</UserControl>
Loading
Loading