Skip to content

Commit

Permalink
Merge pull request #3070 from marticliment/operations-redesign
Browse files Browse the repository at this point in the history
marticliment authored Dec 31, 2024
2 parents cd685b5 + daa6028 commit a7b6379
Showing 89 changed files with 2,568 additions and 1,827 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
2 changes: 1 addition & 1 deletion src/UniGetUI.Core.Classes/UniGetUI.Core.Classes.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
2 changes: 1 addition & 1 deletion src/UniGetUI.Core.Data/UniGetUI.Core.Data.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
@@ -29,6 +29,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="PhotoSauce.MagicScaler" Version="0.15.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.analyzers" Version="1.17.0">
<PrivateAssets>all</PrivateAssets>
4 changes: 2 additions & 2 deletions src/UniGetUI.Core.IconStore/UniGetUI.Core.IconEngine.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
@@ -30,7 +30,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="PhotoSauce.MagicScaler" Version="0.14.2" />
<PackageReference Include="PhotoSauce.MagicScaler" Version="0.15.0" />
<PackageReference Include="System.Drawing.Common" Version="9.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
1 change: 0 additions & 1 deletion src/UniGetUI.Core.LanguageEngine/LanguageData.cs
Original file line number Diff line number Diff line change
@@ -116,7 +116,6 @@ private static Person[] LoadLanguageTranslatorList()
result.Add(person);
}
}

return result.ToArray();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
2 changes: 1 addition & 1 deletion src/UniGetUI.Core.Logger/UniGetUI.Core.Logging.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
2 changes: 1 addition & 1 deletion src/UniGetUI.Core.Settings/UniGetUI.Core.Settings.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
2 changes: 1 addition & 1 deletion src/UniGetUI.Core.Tools/UniGetUI.Core.Tools.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
@@ -22,6 +22,11 @@
<PackageReference Include="Nancy.Hosting.Self" Version="2.0.0">
<NoWarn>NU1701</NoWarn>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="PhotoSauce.MagicScaler" Version="0.15.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Private.Uri" Version="4.3.2" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
</ItemGroup>

<ItemGroup>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
@@ -22,6 +22,10 @@
<Configurations>Debug;Release</Configurations>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="PhotoSauce.MagicScaler" Version="0.15.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\UniGetUI.Core.Classes\UniGetUI.Core.Classes.csproj" />
<ProjectReference Include="..\UniGetUI.Core.Data\UniGetUI.Core.Data.csproj" />
9 changes: 5 additions & 4 deletions src/UniGetUI.PackageEngine.Enums/Enums.cs
Original file line number Diff line number Diff line change
@@ -29,15 +29,16 @@ public enum BundleFormatType

public enum OperationVeredict
{
Succeeded,
Failed,
Success,
Failure,
Canceled,
RestartRequired,
// RestartRequired,
AutoRetry,
}

public enum OperationStatus
{
Pending,
InQueue,
Running,
Succeeded,
Failed,
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
6 changes: 3 additions & 3 deletions src/UniGetUI.PackageEngine.Managers.Cargo/Cargo.cs
Original file line number Diff line number Diff line change
@@ -146,10 +146,10 @@ private IEnumerable<Package> GetPackages(LoggableTaskType taskType)
List<Package> Packages = [];
foreach(var match in TaskRecycler<List<Match>>.RunOrAttach(GetInstalledCommandOutput, 15))
{
var id = match.Groups[1].Value.Trim();
var id = match.Groups[1]?.Value?.Trim() ?? "";
var name = CoreTools.FormatAsName(id);
var oldVersion = match.Groups[2].Value;
var newVersion = match.Groups[3].Value;
var oldVersion = match.Groups[2]?.Value?.Trim() ?? "";
var newVersion = match.Groups[3]?.Value?.Trim() ?? "";
if(taskType is LoggableTaskType.ListUpdates && oldVersion != newVersion)
Packages.Add(new Package(name, id, oldVersion, newVersion, DefaultSource, this));
else if(taskType is LoggableTaskType.ListInstalledPackages)
Original file line number Diff line number Diff line change
@@ -22,6 +22,6 @@ protected override IEnumerable<string> _getOperationParameters(IPackage package,

protected override OperationVeredict _getOperationResult(IPackage package, OperationType operation, IEnumerable<string> processOutput, int returnCode)
{
return returnCode == 0 ? OperationVeredict.Succeeded : OperationVeredict.Failed;
return returnCode == 0 ? OperationVeredict.Success : OperationVeredict.Failure;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
@@ -35,4 +35,8 @@
<ItemGroup>
<Compile Include="..\SharedAssemblyInfo.cs" Link="SharedAssemblyInfo.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="PhotoSauce.MagicScaler" Version="0.15.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -55,12 +55,13 @@ protected override OperationVeredict _getOperationResult(
{
if(returnCode is 3010)
{
return OperationVeredict.RestartRequired;
return OperationVeredict.Success;
// return OperationVeredict.RestartRequired;
}

if (returnCode is 1641 or 1614 or 1605 or 0)
{
return OperationVeredict.Succeeded;
return OperationVeredict.Success;
}

string output_string = string.Join("\n", processOutput);
@@ -76,6 +77,6 @@ protected override OperationVeredict _getOperationResult(
return OperationVeredict.AutoRetry;
}

return OperationVeredict.Failed;
return OperationVeredict.Failure;
}
}
Original file line number Diff line number Diff line change
@@ -23,12 +23,12 @@ public override string[] GetRemoveSourceParameters(IManagerSource source)

protected override OperationVeredict _getAddSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output)
{
return ReturnCode == 0 ? OperationVeredict.Succeeded : OperationVeredict.Failed;
return ReturnCode == 0 ? OperationVeredict.Success : OperationVeredict.Failure;
}

protected override OperationVeredict _getRemoveSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output)
{
return ReturnCode == 0 ? OperationVeredict.Succeeded : OperationVeredict.Failed;
return ReturnCode == 0 ? OperationVeredict.Success : OperationVeredict.Failure;
}

protected override IEnumerable<IManagerSource> GetSources_UnSafe()
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
@@ -42,4 +42,8 @@
<ItemGroup>
<Compile Include="..\SharedAssemblyInfo.cs" Link="SharedAssemblyInfo.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="PhotoSauce.MagicScaler" Version="0.15.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -52,6 +52,6 @@ protected override OperationVeredict _getOperationResult(
IEnumerable<string> processOutput,
int returnCode)
{
return returnCode == 0 ? OperationVeredict.Succeeded : OperationVeredict.Failed;
return returnCode == 0 ? OperationVeredict.Success : OperationVeredict.Failure;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
@@ -36,4 +36,8 @@
<ItemGroup>
<Compile Include="..\SharedAssemblyInfo.cs" Link="SharedAssemblyInfo.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="PhotoSauce.MagicScaler" Version="0.15.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
@@ -26,4 +26,8 @@
<ItemGroup>
<Compile Include="..\SharedAssemblyInfo.cs" Link="SharedAssemblyInfo.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="PhotoSauce.MagicScaler" Version="0.15.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -36,6 +36,6 @@ protected override OperationVeredict _getOperationResult(
IEnumerable<string> processOutput,
int returnCode)
{
return returnCode == 0 ? OperationVeredict.Succeeded : OperationVeredict.Failed;
return returnCode == 0 ? OperationVeredict.Success : OperationVeredict.Failure;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
@@ -35,4 +35,8 @@
<ItemGroup>
<Compile Include="..\SharedAssemblyInfo.cs" Link="SharedAssemblyInfo.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="PhotoSauce.MagicScaler" Version="0.15.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ protected override OperationVeredict _getOperationResult(
{
if (returnCode == 0)
{
return OperationVeredict.Succeeded;
return OperationVeredict.Success;
}

string output_string = string.Join("\n", processOutput);
@@ -64,7 +64,7 @@ protected override OperationVeredict _getOperationResult(
package.OverridenOptions.Scope = PackageScope.User;
return OperationVeredict.AutoRetry;
}
return OperationVeredict.Failed;
return OperationVeredict.Failure;

}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
@@ -35,4 +35,8 @@
<ItemGroup>
<Compile Include="..\SharedAssemblyInfo.cs" Link="SharedAssemblyInfo.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="PhotoSauce.MagicScaler" Version="0.15.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -67,6 +67,6 @@ protected override OperationVeredict _getOperationResult(
return OperationVeredict.AutoRetry;
}

return returnCode == 0 ? OperationVeredict.Succeeded : OperationVeredict.Failed;
return returnCode == 0 ? OperationVeredict.Success : OperationVeredict.Failure;
}
}
Original file line number Diff line number Diff line change
@@ -30,12 +30,12 @@ public override string[] GetRemoveSourceParameters(IManagerSource source)

protected override OperationVeredict _getAddSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output)
{
return ReturnCode == 0 ? OperationVeredict.Succeeded : OperationVeredict.Failed;
return ReturnCode == 0 ? OperationVeredict.Success : OperationVeredict.Failure;
}

protected override OperationVeredict _getRemoveSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output)
{
return ReturnCode == 0 ? OperationVeredict.Succeeded : OperationVeredict.Failed;
return ReturnCode == 0 ? OperationVeredict.Success : OperationVeredict.Failure;
}

protected override IEnumerable<IManagerSource> GetSources_UnSafe()
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
@@ -36,4 +36,8 @@
<ItemGroup>
<Compile Include="..\SharedAssemblyInfo.cs" Link="SharedAssemblyInfo.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="PhotoSauce.MagicScaler" Version="0.15.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -58,6 +58,6 @@ protected override OperationVeredict _getOperationResult(
return OperationVeredict.AutoRetry;
}

return returnCode == 0 ? OperationVeredict.Succeeded : OperationVeredict.Failed;
return returnCode == 0 ? OperationVeredict.Success : OperationVeredict.Failure;
}
}
Original file line number Diff line number Diff line change
@@ -30,12 +30,12 @@ public override string[] GetRemoveSourceParameters(IManagerSource source)

protected override OperationVeredict _getAddSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output)
{
return ReturnCode == 0 ? OperationVeredict.Succeeded : OperationVeredict.Failed;
return ReturnCode == 0 ? OperationVeredict.Success : OperationVeredict.Failure;
}

protected override OperationVeredict _getRemoveSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output)
{
return ReturnCode == 0 ? OperationVeredict.Succeeded : OperationVeredict.Failed;
return ReturnCode == 0 ? OperationVeredict.Success : OperationVeredict.Failure;
}

protected override IEnumerable<IManagerSource> GetSources_UnSafe()
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
@@ -35,4 +35,8 @@
<ItemGroup>
<Compile Include="..\SharedAssemblyInfo.cs" Link="SharedAssemblyInfo.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="PhotoSauce.MagicScaler" Version="0.15.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -81,16 +81,16 @@ protected override OperationVeredict _getOperationResult(
if (operation is OperationType.Uninstall)
{
if (output_string.Contains("was uninstalled"))
return OperationVeredict.Succeeded;
return OperationVeredict.Success;

return OperationVeredict.Failed;
return OperationVeredict.Failure;
}
else
{
if (output_string.Contains("ERROR"))
return OperationVeredict.Failed;
return OperationVeredict.Failure;

return OperationVeredict.Succeeded;
return OperationVeredict.Success;
}
}
}
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ public ScoopSourceHelper(Scoop manager) : base(manager) { }

protected override OperationVeredict _getAddSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output)
{
return ReturnCode == 0 ? OperationVeredict.Succeeded : OperationVeredict.Failed;
return ReturnCode == 0 ? OperationVeredict.Success : OperationVeredict.Failure;
}

public override string[] GetAddSourceParameters(IManagerSource source)
@@ -25,7 +25,7 @@ public override string[] GetAddSourceParameters(IManagerSource source)

protected override OperationVeredict _getRemoveSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output)
{
return ReturnCode == 0 ? OperationVeredict.Succeeded : OperationVeredict.Failed;
return ReturnCode == 0 ? OperationVeredict.Success : OperationVeredict.Failure;
}

public override string[] GetRemoveSourceParameters(IManagerSource source)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
@@ -35,4 +35,8 @@
<ItemGroup>
<Compile Include="..\SharedAssemblyInfo.cs" Link="SharedAssemblyInfo.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="PhotoSauce.MagicScaler" Version="0.15.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -26,6 +26,6 @@ protected override OperationVeredict _getOperationResult(
IEnumerable<string> processOutput,
int returnCode)
{
return returnCode == 0 ? OperationVeredict.Succeeded : OperationVeredict.Failed;
return returnCode == 0 ? OperationVeredict.Success : OperationVeredict.Failure;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
2 changes: 1 addition & 1 deletion src/UniGetUI.PackageEngine.Managers.Vcpkg/Vcpkg.cs
Original file line number Diff line number Diff line change
@@ -339,7 +339,7 @@ protected override ManagerStatus LoadManager()

public override void RefreshPackageIndexes()
{
var (found, path) = GetVcpkgPath();
var (found, _) = GetVcpkgPath();
var (vcpkgRootFound, vcpkgRoot) = GetVcpkgRoot();
var (gitFound, gitPath) = CoreTools.Which("git");

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Runtime.InteropServices;
using Microsoft.Management.Deployment;
using UniGetUI.Core.Logging;
using UniGetUI.Core.SettingsEngine;
using UniGetUI.Core.Tools;
using UniGetUI.PackageEngine.Classes.Manager.BaseProviders;
@@ -86,26 +87,35 @@ protected override IEnumerable<string> _getOperationParameters(IPackage package,
});
}

var installOptions = NativePackageHandler.GetInstallationOptions(package, operation);
if (installOptions?.ElevationRequirement is ElevationRequirement.ElevationRequired
or ElevationRequirement.ElevatesSelf)
try
{
package.OverridenOptions.RunAsAdministrator = true;
var installOptions = NativePackageHandler.GetInstallationOptions(package, operation);
if (installOptions?.ElevationRequirement is ElevationRequirement.ElevationRequired
or ElevationRequirement.ElevatesSelf)
{
package.OverridenOptions.RunAsAdministrator = true;
}
else if (installOptions?.ElevationRequirement is ElevationRequirement.ElevationProhibited)
{
if (CoreTools.IsAdministrator())
throw new UnauthorizedAccessException(
CoreTools.Translate("This package cannot be installed from an elevated context.")
+ CoreTools.Translate("Please run UniGetUI as a regular user and try again."));

if (options.RunAsAdministrator)
throw new UnauthorizedAccessException(
CoreTools.Translate("This package cannot be installed from an elevated context.")
+ CoreTools.Translate("Please check the installation options for this package and try again"));
package.OverridenOptions.RunAsAdministrator = false;
}
}
else if (installOptions?.ElevationRequirement is ElevationRequirement.ElevationProhibited)
catch (Exception ex)
{
if (CoreTools.IsAdministrator())
throw new UnauthorizedAccessException(
CoreTools.Translate("This package cannot be installed from an elevated context.")
+ CoreTools.Translate("Please run UniGetUI as a regular user and try again."));

if (options.RunAsAdministrator)
throw new UnauthorizedAccessException(
CoreTools.Translate("This package cannot be installed from an elevated context.")
+ CoreTools.Translate("Please check the installation options for this package and try again"));
package.OverridenOptions.RunAsAdministrator = false;
Logger.Error("Recovered from fatal WinGet exception:");
Logger.Error(ex);
}


return parameters;
}

@@ -122,7 +132,8 @@ protected override OperationVeredict _getOperationResult(
{
// If the user is required to restart the system to complete the installation
if(operation is OperationType.Update) MarkUpgradeAsDone(package);
return OperationVeredict.RestartRequired;
//return OperationVeredict.RestartRequired;
return OperationVeredict.Success;
}

if (uintCode == 0x8A150077 || uintCode == 0x8A15010C || uintCode == 0x8A150005)
@@ -133,26 +144,26 @@ protected override OperationVeredict _getOperationResult(
if (uintCode == 0x8A150011)
{
// TODO: Needs skip checksum
return OperationVeredict.Failed;
return OperationVeredict.Failure;
}

if (uintCode == 0x8A15002B)
{
return OperationVeredict.Failed;
return OperationVeredict.Failure;
}

if (uintCode == 0x8A15010D || uintCode == 0x8A15004F || uintCode == 0x8A15010E)
{
// Application is already installed
if(operation is OperationType.Update) MarkUpgradeAsDone(package);
return OperationVeredict.Succeeded;
return OperationVeredict.Success;
}

if (returnCode == 0)
{
// Operation succeeded
if(operation is OperationType.Update) MarkUpgradeAsDone(package);
return OperationVeredict.Succeeded;
return OperationVeredict.Success;
}

if(uintCode == 0x8A150056 && package.OverridenOptions.RunAsAdministrator != false && !CoreTools.IsAdministrator())
@@ -169,7 +180,7 @@ protected override OperationVeredict _getOperationResult(
return OperationVeredict.AutoRetry;
}

return OperationVeredict.Failed;
return OperationVeredict.Failure;
}

private static void MarkUpgradeAsDone(IPackage package)
Original file line number Diff line number Diff line change
@@ -26,12 +26,12 @@ public override string[] GetRemoveSourceParameters(IManagerSource source)

protected override OperationVeredict _getAddSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output)
{
return ReturnCode == 0 ? OperationVeredict.Succeeded : OperationVeredict.Failed;
return ReturnCode == 0 ? OperationVeredict.Success : OperationVeredict.Failure;
}

protected override OperationVeredict _getRemoveSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output)
{
return ReturnCode == 0 ? OperationVeredict.Succeeded : OperationVeredict.Failed;
return ReturnCode == 0 ? OperationVeredict.Success : OperationVeredict.Failure;
}

protected override IEnumerable<IManagerSource> GetSources_UnSafe()
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
@@ -87,4 +87,8 @@
<ItemGroup>
<Compile Include="..\SharedAssemblyInfo.cs" Link="SharedAssemblyInfo.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="PhotoSauce.MagicScaler" Version="0.15.0" />
</ItemGroup>
</Project>
356 changes: 356 additions & 0 deletions src/UniGetUI.PackageEngine.Operations/AbstractOperation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,356 @@
using UniGetUI.Core.Logging;
using UniGetUI.Core.SettingsEngine;
using UniGetUI.Core.Tools;
using UniGetUI.PackageEngine.Enums;

namespace UniGetUI.PackageOperations;

public abstract class AbstractOperation : IDisposable
{
public static class RetryMode
{
public const string NoRetry = "";
public const string Retry = "Retry";
public const string Retry_AsAdmin = "RetryAsAdmin";
public const string Retry_Interactive = "RetryInteractive";
public const string Retry_SkipIntegrity = "RetryNoHashCheck";
}

public class OperationMetadata
{
/// <summary>
/// Installation of X
/// </summary>
public string Title = "";

/// <summary>
/// X is being installed/upated/removed
/// </summary>
public string Status = "";

/// <summary>
/// X was installed
/// </summary>
public string SuccessTitle = "";

/// <summary>
/// X has been installed successfully
/// </summary>
public string SuccessMessage = "";

/// <summary>
/// X could not be installed.
/// </summary>
public string FailureTitle = "";

/// <summary>
/// X Could not be installed
/// </summary>
public string FailureMessage = "";

/// <summary>
/// Starting operation X with options Y
/// </summary>
public string OperationInformation = "";

public readonly string Identifier;

public OperationMetadata()
{
Identifier = new Random().NextInt64(1000000, 9999999).ToString();
}
}

public readonly OperationMetadata Metadata = new();
public static readonly List<AbstractOperation> OperationQueue = new();

public event EventHandler<OperationStatus>? StatusChanged;
public event EventHandler<EventArgs>? CancelRequested;
public event EventHandler<(string, LineType)>? LogLineAdded;
public event EventHandler<EventArgs>? OperationStarting;
public event EventHandler<EventArgs>? OperationFinished;
public event EventHandler<EventArgs>? Enqueued;
public event EventHandler<EventArgs>? OperationSucceeded;
public event EventHandler<EventArgs>? OperationFailed;

public static int MAX_OPERATIONS;

public event EventHandler<BadgeCollection>? BadgesChanged;

public class BadgeCollection
{
public readonly bool AsAdministrator;
public readonly bool Interactive;
public readonly bool SkipHashCheck;
public readonly PackageScope? Scope;

public BadgeCollection(bool admin, bool interactive, bool skiphash, PackageScope? scope)
{
AsAdministrator = admin;
Interactive = interactive;
SkipHashCheck = skiphash;
Scope = scope;
}
}
public void ApplyCapabilities(bool admin, bool interactive, bool skiphash, PackageScope? scope)
{
BadgesChanged?.Invoke(this, new BadgeCollection(admin, interactive, skiphash, scope));
}

public enum LineType
{
OperationInfo,
Progress,
StdOUT,
StdERR
}

private List<(string, LineType)> LogList = new();
private OperationStatus _status = OperationStatus.InQueue;
public OperationStatus Status
{
get => _status;
set { _status = value; StatusChanged?.Invoke(this, value); }
}

public bool Started { get; private set; }
protected bool QUEUE_ENABLED;
protected bool FORCE_HOLD_QUEUE;

public AbstractOperation(bool queue_enabled)
{
QUEUE_ENABLED = queue_enabled;
Status = OperationStatus.InQueue;
Line("Please wait...", LineType.Progress);

if(int.TryParse(Settings.GetValue("ParallelOperationCount"), out int _maxPps))
{
Logger.Debug("Parallel operation limit not set, defaulting to 1");
MAX_OPERATIONS = _maxPps;
}
else
{
MAX_OPERATIONS = 1;
Logger.Debug($"Parallel operation limit set to {MAX_OPERATIONS}");
}
}

public void Cancel()
{
switch (_status)
{
case OperationStatus.Canceled:
break;
case OperationStatus.Failed:
break;
case OperationStatus.Running:
Status = OperationStatus.Canceled;
while(OperationQueue.Remove(this));
CancelRequested?.Invoke(this, EventArgs.Empty);
Status = OperationStatus.Canceled;
break;
case OperationStatus.InQueue:
Status = OperationStatus.Canceled;
while(OperationQueue.Remove(this));
Status = OperationStatus.Canceled;
break;
case OperationStatus.Succeeded:
break;
}
}

protected void Line(string line, LineType type)
{
if(type != LineType.Progress) LogList.Add((line, type));
LogLineAdded?.Invoke(this, (line, type));
}

public IReadOnlyList<(string, LineType)> GetOutput()
{
return LogList;
}

public async Task MainThread()
{
try
{
if (Metadata.Status == "") throw new InvalidDataException("Metadata.Status was not set!");
if (Metadata.Title == "") throw new InvalidDataException("Metadata.Title was not set!");
if (Metadata.OperationInformation == "")
throw new InvalidDataException("Metadata.OperationInformation was not set!");
if (Metadata.SuccessTitle == "") throw new InvalidDataException("Metadata.SuccessTitle was not set!");
if (Metadata.SuccessMessage == "") throw new InvalidDataException("Metadata.SuccessMessage was not set!");
if (Metadata.FailureTitle == "") throw new InvalidDataException("Metadata.FailureTitle was not set!");
if (Metadata.FailureMessage == "") throw new InvalidDataException("Metadata.FailureMessage was not set!");

Started = true;

if (OperationQueue.Contains(this))
throw new InvalidOperationException("This operation was already on the queue");

Status = OperationStatus.InQueue;
Line(Metadata.OperationInformation, LineType.OperationInfo);
Line(Metadata.Status, LineType.Progress);

// BEGIN QUEUE HANDLER
if (QUEUE_ENABLED)
{
SKIP_QUEUE = false;
OperationQueue.Add(this);
Enqueued?.Invoke(this, EventArgs.Empty);
int lastPos = -2;

while (FORCE_HOLD_QUEUE || (OperationQueue.IndexOf(this) >= MAX_OPERATIONS && !SKIP_QUEUE))
{
int pos = OperationQueue.IndexOf(this) - MAX_OPERATIONS + 1;

if (pos == -1) return;
// In this case, operation was canceled;

if (pos != lastPos)
{
lastPos = pos;
Line(CoreTools.Translate("Operation on queue (position {0})...", pos), LineType.Progress);
}

await Task.Delay(100);
}
}
// END QUEUE HANDLER

// BEGIN ACTUAL OPERATION
OperationVeredict result;
Line(CoreTools.Translate("Starting operation..."), LineType.Progress);
if(Status is OperationStatus.InQueue) Status = OperationStatus.Running;
OperationStarting?.Invoke(this, EventArgs.Empty);

do
{
try
{
// Check if the operation was canceled
if (Status is OperationStatus.Canceled)
{
result = OperationVeredict.Canceled;
break;
}

Task<OperationVeredict> op = PerformOperation();
while (Status != OperationStatus.Canceled && !op.IsCompleted) await Task.Delay(100);

if (Status is OperationStatus.Canceled) result = OperationVeredict.Canceled;
else result = op.GetAwaiter().GetResult();
}
catch (Exception e)
{
result = OperationVeredict.Failure;
Logger.Error(e);
foreach (string l in e.ToString().Split("\n")) Line(l, LineType.StdERR);
}
} while (result == OperationVeredict.AutoRetry);

OperationFinished?.Invoke(this, EventArgs.Empty);

while (OperationQueue.Remove(this));
// END OPERATION

if (result == OperationVeredict.Success)
{
Status = OperationStatus.Succeeded;
OperationSucceeded?.Invoke(this, EventArgs.Empty);
Line(Metadata.SuccessMessage, LineType.StdOUT);
}
else if (result == OperationVeredict.Failure)
{
Status = OperationStatus.Failed;
OperationFailed?.Invoke(this, EventArgs.Empty);
Line(Metadata.FailureMessage, LineType.StdERR);
Line(Metadata.FailureMessage + " - " + CoreTools.Translate("Click here for more details"),
LineType.Progress);
}
else if (result == OperationVeredict.Canceled)
{
Status = OperationStatus.Canceled;
Line(CoreTools.Translate("Operation canceled by user"), LineType.StdERR);
}
}
catch (Exception ex)
{
Line("An internal error occurred:", LineType.StdERR);
foreach (var line in ex.ToString().Split("\n"))
Line(line, LineType.StdERR);

while (OperationQueue.Remove(this)) ;

Status = OperationStatus.Failed;
try
{
OperationFinished?.Invoke(this, EventArgs.Empty);
OperationFailed?.Invoke(this, EventArgs.Empty);
}
catch (Exception e2)
{
Line("An internal error occurred while handling an internal error:", LineType.StdERR);
foreach (var line in e2.ToString().Split("\n"))
Line(line, LineType.StdERR);
}

Line(Metadata.FailureMessage, LineType.StdERR);
Line(Metadata.FailureMessage + " - " + CoreTools.Translate("Click here for more details"),
LineType.Progress);
}
}

private bool SKIP_QUEUE;

public void SkipQueue()
{
if (Status != OperationStatus.InQueue) return;
while(OperationQueue.Remove(this));
SKIP_QUEUE = true;
}

public void RunNext()
{
if (Status != OperationStatus.InQueue) return;
if (!OperationQueue.Contains(this)) return;

FORCE_HOLD_QUEUE = true;
while(OperationQueue.Remove(this));
OperationQueue.Insert(Math.Min(MAX_OPERATIONS, OperationQueue.Count), this);
FORCE_HOLD_QUEUE = false;
}

public void BackOfTheQueue()
{
if (Status != OperationStatus.InQueue) return;
if (!OperationQueue.Contains(this)) return;

FORCE_HOLD_QUEUE = true;
while(OperationQueue.Remove(this));
OperationQueue.Add(this);
FORCE_HOLD_QUEUE = false;
}

public void Retry(string retryMode)
{
if (retryMode is RetryMode.NoRetry)
throw new InvalidOperationException("We weren't supposed to reach this, weren't we?");

ApplyRetryAction(retryMode);
Line($"", LineType.OperationInfo);
Line($"-----------------------", LineType.OperationInfo);
Line($"Retrying operation with RetryMode={retryMode}", LineType.OperationInfo);
Line($"", LineType.OperationInfo);
if (Status is OperationStatus.Running or OperationStatus.InQueue) return;
_ = MainThread();
}

protected abstract void ApplyRetryAction(string retryMode);
protected abstract Task<OperationVeredict> PerformOperation();
public abstract Task<Uri> GetOperationIcon();
public void Dispose()
{
while(OperationQueue.Remove(this));
}
}
289 changes: 289 additions & 0 deletions src/UniGetUI.PackageEngine.Operations/PackageOperations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,289 @@
using System.Diagnostics;
using UniGetUI.Core.Classes;
using UniGetUI.Core.Data;
using UniGetUI.Core.Logging;
using UniGetUI.Core.SettingsEngine;
using UniGetUI.Core.Tools;
using UniGetUI.Interface;
using UniGetUI.Interface.Enums;
using UniGetUI.PackageEngine.Classes.Packages.Classes;
using UniGetUI.PackageEngine.Enums;
using UniGetUI.PackageEngine.Interfaces;
using UniGetUI.PackageEngine.PackageClasses;
using UniGetUI.PackageEngine.PackageLoader;
using UniGetUI.PackageOperations;

namespace UniGetUI.PackageEngine.Operations
{
public abstract class PackageOperation : AbstractProcessOperation
{
protected List<string> DesktopShortcutsBeforeStart = [];

public readonly IPackage Package;
public readonly IInstallationOptions Options;
public readonly OperationType Role;

protected abstract Task HandleSuccess();
protected abstract Task HandleFailure();
protected abstract void Initialize();

public PackageOperation(
IPackage package,
IInstallationOptions options,
OperationType role,
bool IgnoreParallelInstalls = false)
: base(!IgnoreParallelInstalls)
{
Package = package;
Options = options;
Role = role;

Initialize();

Enqueued += (_, _) =>
{
ApplyCapabilities(RequiresAdminRights(),
Options.InteractiveInstallation,
(Options.SkipHashCheck && Role is not OperationType.Uninstall),
Package.OverridenOptions.Scope ?? Options.InstallationScope);

Package.SetTag(PackageTag.OnQueue);
};
CancelRequested += (_, _) => Package.SetTag(PackageTag.Default);
OperationSucceeded += (_, _) => HandleSuccess();
OperationFailed += (_, _) => HandleFailure();
}

public PackageOperation(
IPackage package,
OperationType role,
bool IgnoreParallelInstalls = false)
: this(package, InstallationOptions.FromPackage(package), role, IgnoreParallelInstalls) { }

private bool RequiresAdminRights()
{
return Package.OverridenOptions.RunAsAdministrator is true
|| Options.RunAsAdministrator
|| (Settings.Get("AlwaysElevate" + Package.Manager.Name) && !Package.OverridenOptions.RunAsAdministrator is false);
}

protected override void ApplyRetryAction(string retryMode)
{
switch (retryMode)
{
case RetryMode.Retry_AsAdmin:
Options.RunAsAdministrator = true;
break;
case RetryMode.Retry_Interactive:
Options.InteractiveInstallation = true;
break;
case RetryMode.Retry_SkipIntegrity:
Options.SkipHashCheck = true;
break;
case RetryMode.Retry:
break;
default:
throw new InvalidOperationException($"Retry mode {retryMode} is not supported in this context");
}
Metadata.OperationInformation = "Retried package operation for Package=" + Package.Id + " with Manager=" +
Package.Manager.Name + "\nUpdated installation options: " + Options.ToString();

}

protected sealed override void PrepareProcessStartInfo()
{
bool admin = false;
Package.SetTag(PackageTag.OnQueue);
string operation_args = string.Join(" ", Package.Manager.OperationHelper.GetParameters(Package, Options, Role));

if (RequiresAdminRights())
{
admin = true;
if (Settings.Get("DoCacheAdminRights") || Settings.Get("DoCacheAdminRightsForBatches"))
{
CoreTools.CacheUACForCurrentProcess().GetAwaiter().GetResult();
}

process.StartInfo.FileName = CoreData.GSudoPath;
process.StartInfo.Arguments =
$"\"{Package.Manager.Status.ExecutablePath}\" {Package.Manager.Properties.ExecutableCallArgs} {operation_args}";
}
else
{
process.StartInfo.FileName = Package.Manager.Status.ExecutablePath;
process.StartInfo.Arguments = $"{Package.Manager.Properties.ExecutableCallArgs} {operation_args}";
}
ApplyCapabilities(admin,
Options.InteractiveInstallation,
(Options.SkipHashCheck && Role is not OperationType.Uninstall),
Package.OverridenOptions.Scope ?? Options.InstallationScope);
}

protected sealed override Task<OperationVeredict> GetProcessVeredict(int ReturnCode, string[] Output)
{
return Task.FromResult(Package.Manager.OperationHelper.GetResult(Package, Role, Output, ReturnCode));
}

public override Task<Uri> GetOperationIcon()
{
return TaskRecycler<Uri>.RunOrAttachAsync(Package.GetIconUrl);
}
}

public class InstallPackageOperation : PackageOperation
{

public InstallPackageOperation(
IPackage package,
IInstallationOptions options,
bool IgnoreParallelInstalls = false)
: base(package, options, OperationType.Install, IgnoreParallelInstalls)
{ }

public InstallPackageOperation(
IPackage package,
bool IgnoreParallelInstalls = false)
: base(package, OperationType.Install, IgnoreParallelInstalls)
{ }

protected override Task HandleFailure()
{
Package.SetTag(PackageTag.Failed);
return Task.CompletedTask;
}

protected override Task HandleSuccess()
{
Package.SetTag(PackageTag.AlreadyInstalled);
InstalledPackagesLoader.Instance.AddForeign(Package);

if (Settings.Get("AskToDeleteNewDesktopShortcuts"))
{
DesktopShortcutsDatabase.TryRemoveNewShortcuts(DesktopShortcutsBeforeStart);
}
return Task.CompletedTask;
}

protected override void Initialize()
{
Metadata.OperationInformation = "Package install operation for Package=" + Package.Id + " with Manager=" +
Package.Manager.Name + "\nInstallation options: " + Options.ToString();

Metadata.Title = CoreTools.Translate("{package} Installation", new Dictionary<string, object?> { { "package", Package.Name } });
Metadata.Status = CoreTools.Translate("{0} is being installed", Package.Name);
Metadata.SuccessTitle = CoreTools.Translate("Installation succeeded");
Metadata.SuccessMessage = CoreTools.Translate("{package} was installed successfully", new Dictionary<string, object?> { { "package", Package.Name } });
Metadata.FailureTitle = CoreTools.Translate("Installation failed", new Dictionary<string, object?> { { "package", Package.Name } });
Metadata.FailureMessage = CoreTools.Translate("{package} could not be installed", new Dictionary<string, object?> { { "package", Package.Name } });

if (Settings.Get("AskToDeleteNewDesktopShortcuts"))
{
DesktopShortcutsBeforeStart = DesktopShortcutsDatabase.GetShortcuts();
}
}
}

public class UpdatePackageOperation : PackageOperation
{

public UpdatePackageOperation(
IPackage package,
IInstallationOptions options,
bool IgnoreParallelInstalls = false)
: base(package, options, OperationType.Update, IgnoreParallelInstalls)
{ }

public UpdatePackageOperation(
IPackage package,
bool IgnoreParallelInstalls = false)
: base(package, OperationType.Update, IgnoreParallelInstalls)
{ }

protected override Task HandleFailure()
{
Package.SetTag(PackageTag.Failed);
return Task.CompletedTask;
}

protected override async Task HandleSuccess()
{
Package.SetTag(PackageTag.Default);
Package.GetInstalledPackage()?.SetTag(PackageTag.Default);
Package.GetAvailablePackage()?.SetTag(PackageTag.AlreadyInstalled);

UpgradablePackagesLoader.Instance.Remove(Package);

if (await Package.HasUpdatesIgnoredAsync() && await Package.GetIgnoredUpdatesVersionAsync() != "*")
await Package.RemoveFromIgnoredUpdatesAsync();

if (Settings.Get("AskToDeleteNewDesktopShortcuts"))
{
DesktopShortcutsDatabase.TryRemoveNewShortcuts(DesktopShortcutsBeforeStart);
}
}

protected override void Initialize()
{
Metadata.OperationInformation = "Package update operation for Package=" + Package.Id + " with Manager=" +
Package.Manager.Name + "\nInstallation options: " + Options.ToString();

Metadata.Title = CoreTools.Translate("{package} Update", new Dictionary<string, object?> { { "package", Package.Name } });
Metadata.Status = CoreTools.Translate("{0} is being updated to version {1}", Package.Name, Package.NewVersion);
Metadata.SuccessTitle = CoreTools.Translate("Update succeeded");
Metadata.SuccessMessage = CoreTools.Translate("{package} was updated successfully", new Dictionary<string, object?> { { "package", Package.Name } });
Metadata.FailureTitle = CoreTools.Translate("Update failed", new Dictionary<string, object?> { { "package", Package.Name } });
Metadata.FailureMessage = CoreTools.Translate("{package} could not be updated", new Dictionary<string, object?> { { "package", Package.Name } });

if (Settings.Get("AskToDeleteNewDesktopShortcuts"))
{
DesktopShortcutsBeforeStart = DesktopShortcutsDatabase.GetShortcuts();
}
}
}

public class UninstallPackageOperation : PackageOperation
{

public UninstallPackageOperation(
IPackage package,
IInstallationOptions options,
bool IgnoreParallelInstalls = false)
: base(package, options, OperationType.Uninstall, IgnoreParallelInstalls)
{ }

public UninstallPackageOperation(
IPackage package,
bool IgnoreParallelInstalls = false)
: base(package, OperationType.Uninstall, IgnoreParallelInstalls)
{ }

protected override Task HandleFailure()
{
Package.SetTag(PackageTag.Failed);
return Task.CompletedTask;
}

protected override Task HandleSuccess()
{
Package.SetTag(PackageTag.Default);
Package.GetAvailablePackage()?.SetTag(PackageTag.Default);
UpgradablePackagesLoader.Instance.Remove(Package);
InstalledPackagesLoader.Instance.Remove(Package);

return Task.CompletedTask;
}

protected override void Initialize()
{
Metadata.OperationInformation = "Package uninstall operation for Package=" + Package.Id + " with Manager=" +
Package.Manager.Name + "\nInstallation options: " + Options.ToString();

Metadata.Title = CoreTools.Translate("{package} Uninstall", new Dictionary<string, object?> { { "package", Package.Name } });
Metadata.Status = CoreTools.Translate("{0} is being uninstalled", Package.Name);
Metadata.SuccessTitle = CoreTools.Translate("Uninstall succeeded");
Metadata.SuccessMessage = CoreTools.Translate("{package} was uninstalled successfully", new Dictionary<string, object?> { { "package", Package.Name } });
Metadata.FailureTitle = CoreTools.Translate("Uninstall failed", new Dictionary<string, object?> { { "package", Package.Name } });
Metadata.FailureMessage = CoreTools.Translate("{package} could not be uninstalled", new Dictionary<string, object?> { { "package", Package.Name } });
}
}
}
100 changes: 100 additions & 0 deletions src/UniGetUI.PackageEngine.Operations/ProcessOperation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System.Diagnostics;
using UniGetUI.PackageEngine.Enums;

namespace UniGetUI.PackageOperations;

public abstract class AbstractProcessOperation : AbstractOperation
{
protected Process process { get; private set; }
private bool ProcessKilled;
protected AbstractProcessOperation(bool queue_enabled) : base(queue_enabled)
{
process = new();
CancelRequested += (_, _) =>
{
try
{
process.Kill();
ProcessKilled = true;
}
catch (InvalidOperationException e)
{
Line("Attempted to cancel a process that hasn't ben created yet: " + e.Message, LineType.StdERR);
}
};
OperationStarting += (_, _) =>
{
ProcessKilled = false;
process = new();
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.FileName = "lol";
process.StartInfo.Arguments = "lol";
process.OutputDataReceived += (_, e) =>
{
if (e.Data is null) return;
string line = e.Data.ToString().Trim();
if (line.Contains("For the question below") ||
line.Contains("Would remove:"))
{ // Mitigate chocolatey timeouts
process.StandardInput.WriteLine("");
}

var lineType = LineType.StdOUT;
if (line.Length < 6 || line.EndsWith("install/uninstall to complete..."))
{
lineType = LineType.Progress;
}

Line(line, lineType);
};
process.ErrorDataReceived += (_, e) =>
{
if (e.Data is null) return;
string line = e.Data.ToString().Trim();
var lineType = LineType.StdERR;
if (line.Length < 6 || line.Contains("Waiting for another install..."))
{
lineType = LineType.Progress;
}

Line(line, lineType);
};
PrepareProcessStartInfo();
};
}

protected override async Task<OperationVeredict> PerformOperation()
{
if(process.StartInfo.UseShellExecute) throw new InvalidOperationException("UseShellExecute must be set to false");
if(!process.StartInfo.RedirectStandardOutput) throw new InvalidOperationException("RedirectStandardOutput must be set to true");
if(!process.StartInfo.RedirectStandardInput) throw new InvalidOperationException("RedirectStandardInput must be set to true");
if(!process.StartInfo.RedirectStandardError) throw new InvalidOperationException("RedirectStandardError must be set to true");
if (process.StartInfo.FileName == "lol") throw new InvalidOperationException("StartInfo.FileName has not been set");
if (process.StartInfo.Arguments == "lol") throw new InvalidOperationException("StartInfo.Arguments has not been set");

Line($"Executing process with StartInfo:", LineType.OperationInfo);
Line($" - FileName: \"{process.StartInfo.FileName.Trim()}\"", LineType.OperationInfo);
Line($" - Arguments: \"{process.StartInfo.Arguments.Trim()}\"", LineType.OperationInfo);
Line($"Start Time: \"{DateTime.Now}\"", LineType.OperationInfo);

process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
await process.WaitForExitAsync();

Line($"End Time: \"{DateTime.Now}\"", LineType.OperationInfo);
Line($"Process return value: \"{process.ExitCode}\" (0x{process.ExitCode:X})", LineType.OperationInfo);

if (ProcessKilled)
return OperationVeredict.Canceled;

return await GetProcessVeredict(process.ExitCode, []);
}

protected abstract Task<OperationVeredict> GetProcessVeredict(int ReturnCode, string[] Output);
protected abstract void PrepareProcessStartInfo();
}
141 changes: 141 additions & 0 deletions src/UniGetUI.PackageEngine.Operations/SourceOperations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
using System.Diagnostics;
using Windows.Media.Capture;
using UniGetUI.Core.Data;
using UniGetUI.Core.Logging;
using UniGetUI.Core.SettingsEngine;
using UniGetUI.Core.Tools;
using UniGetUI.Interface;
using UniGetUI.Interface.Enums;
using UniGetUI.PackageEngine.Enums;
using UniGetUI.PackageEngine.Interfaces;
using UniGetUI.PackageOperations;

namespace UniGetUI.PackageEngine.Operations
{

public abstract class SourceOperation : AbstractProcessOperation
{
protected abstract void Initialize();

protected IManagerSource Source;
public bool ForceAsAdministrator { get; private set; }

public SourceOperation(IManagerSource source) : base(false)
{
Source = source;
Initialize();
}

public override Task<Uri> GetOperationIcon()
{
return Task.FromResult(new Uri($"ms-appx:///Assets/Images/{Source.Manager.Properties.ColorIconId}.png"));
}

protected override void ApplyRetryAction(string retryMode)
{
switch (retryMode)
{
case RetryMode.Retry:
break;
case RetryMode.Retry_AsAdmin:
ForceAsAdministrator = true;
break;
default:
throw new InvalidOperationException($"Retry mode {retryMode} is not supported in this context");
}
}
}

public class AddSourceOperation : SourceOperation
{
public AddSourceOperation(IManagerSource source) : base(source)
{ }

protected override void PrepareProcessStartInfo()
{
bool admin = false;
if (ForceAsAdministrator || Source.Manager.Capabilities.Sources.MustBeInstalledAsAdmin)
{
if (Settings.Get("DoCacheAdminRights") || Settings.Get("DoCacheAdminRightsForBatches"))
{
CoreTools.CacheUACForCurrentProcess().GetAwaiter().GetResult();
}

admin = true;
process.StartInfo.FileName = CoreData.GSudoPath;
process.StartInfo.Arguments = $"\"{Source.Manager.Status.ExecutablePath}\" " + Source.Manager.Properties.ExecutableCallArgs + " " + string.Join(" ", Source.Manager.SourcesHelper.GetAddSourceParameters(Source));
}
else
{
process.StartInfo.FileName = Source.Manager.Status.ExecutablePath;
process.StartInfo.Arguments = Source.Manager.Properties.ExecutableCallArgs + " " + string.Join(" ", Source.Manager.SourcesHelper.GetAddSourceParameters(Source));
}

ApplyCapabilities(admin, false, false, null);
}

protected override Task<OperationVeredict> GetProcessVeredict(int ReturnCode, string[] Output)
{
return Task.Run(() => Source.Manager.SourcesHelper.GetAddOperationVeredict(Source, ReturnCode, Output));
}

protected override void Initialize()
{
Metadata.OperationInformation = "Starting adding source operation for source=" + Source.Name +
"with Manager=" + Source.Manager.Name;

Metadata.Title = CoreTools.Translate("Adding source {source}", new Dictionary<string, object?> { { "source", Source.Name } });
Metadata.Status = CoreTools.Translate("Adding source {source} to {manager}", new Dictionary<string, object?> { { "source", Source.Name }, { "manager", Source.Manager.Name } });;
Metadata.SuccessTitle = CoreTools.Translate("Source added successfully");
Metadata.SuccessMessage = CoreTools.Translate("The source {source} was added to {manager} successfully",
new Dictionary<string, object?> { { "source", Source.Name }, { "manager", Source.Manager.Name } });
Metadata.FailureTitle = CoreTools.Translate("Could not add source");
Metadata.FailureMessage = CoreTools.Translate("Could not add source {source} to {manager}",
new Dictionary<string, object?> { { "source", Source.Name }, { "manager", Source.Manager.Name } });
}
}

public class RemoveSourceOperation : SourceOperation
{
public RemoveSourceOperation(IManagerSource source) : base(source)
{ }

protected override void PrepareProcessStartInfo()
{
if (ForceAsAdministrator || Source.Manager.Capabilities.Sources.MustBeInstalledAsAdmin)
{
if (Settings.Get("DoCacheAdminRights") || Settings.Get("DoCacheAdminRightsForBatches"))
{
CoreTools.CacheUACForCurrentProcess().GetAwaiter().GetResult();
}
process.StartInfo.FileName = CoreData.GSudoPath;
process.StartInfo.Arguments = $"\"{Source.Manager.Status.ExecutablePath}\" " + Source.Manager.Properties.ExecutableCallArgs + " " + string.Join(" ", Source.Manager.SourcesHelper.GetRemoveSourceParameters(Source));

}
else
{
process.StartInfo.FileName = Source.Manager.Status.ExecutablePath;
process.StartInfo.Arguments = Source.Manager.Properties.ExecutableCallArgs + " " + string.Join(" ", Source.Manager.SourcesHelper.GetRemoveSourceParameters(Source));
}
}

protected override Task<OperationVeredict> GetProcessVeredict(int ReturnCode, string[] Output)
{
return Task.Run(() => Source.Manager.SourcesHelper.GetRemoveOperationVeredict(Source, ReturnCode, Output));
}

protected override void Initialize()
{
Metadata.OperationInformation = "Starting remove source operation for source=" + Source.Name + "with Manager=" + Source.Manager.Name;

Metadata.Title = CoreTools.Translate("Removing source {source}", new Dictionary<string, object?> { { "source", Source.Name } });
Metadata.Status = CoreTools.Translate("Removing source {source} from {manager}", new Dictionary<string, object?> { { "source", Source.Name }, { "manager", Source.Manager.Name } });;
Metadata.SuccessTitle = CoreTools.Translate("Source removed successfully");
Metadata.SuccessMessage = CoreTools.Translate("The source {source} was removed from {manager} successfully",
new Dictionary<string, object?> { { "source", Source.Name }, { "manager", Source.Manager.Name } });
Metadata.FailureTitle = CoreTools.Translate("Could not remove source");
Metadata.FailureMessage = CoreTools.Translate("Could not remove source {source} from {manager}",
new Dictionary<string, object?> { { "source", Source.Name }, { "manager", Source.Manager.Name } });
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
<Platforms>x64</Platforms>
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion>
<WindowsSdkPackageVersion>10.0.26100.53</WindowsSdkPackageVersion>
<SdkVersion>8.0.401</SdkVersion>
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
<PublishSelfContained>true</PublishSelfContained>
<Authors>Martí Climent and the contributors</Authors>
<PublisherName>Martí Climent</PublisherName>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\UniGetUI.Core.Classes\UniGetUI.Core.Classes.csproj" />
<ProjectReference Include="..\UniGetUI.Core.Data\UniGetUI.Core.Data.csproj" />
<ProjectReference Include="..\UniGetUI.Core.Logger\UniGetUI.Core.Logging.csproj" />
<ProjectReference Include="..\UniGetUI.Core.Settings\UniGetUI.Core.Settings.csproj" />
<ProjectReference Include="..\UniGetUI.Core.Tools\UniGetUI.Core.Tools.csproj" />
<ProjectReference Include="..\UniGetUI.PackageEngine.Enums\UniGetUI.PackageEngine.Structs.csproj" />
<ProjectReference Include="..\UniGetUI.PackageEngine.Managers.Cargo\UniGetUI.PackageEngine.Managers.Cargo.csproj" />
<ProjectReference Include="..\UniGetUI.PackageEngine.Managers.Chocolatey\UniGetUI.PackageEngine.Managers.Chocolatey.csproj" />
<ProjectReference Include="..\UniGetUI.PackageEngine.Managers.Dotnet\UniGetUI.PackageEngine.Managers.Dotnet.csproj" />
<ProjectReference Include="..\UniGetUI.PackageEngine.Managers.Generic.NuGet\UniGetUI.PackageEngine.Managers.Generic.NuGet.csproj" />
<ProjectReference Include="..\UniGetUI.PackageEngine.Managers.Npm\UniGetUI.PackageEngine.Managers.Npm.csproj" />
<ProjectReference Include="..\UniGetUI.PackageEngine.Managers.Pip\UniGetUI.PackageEngine.Managers.Pip.csproj" />
<ProjectReference Include="..\UniGetUI.PackageEngine.Managers.PowerShell\UniGetUI.PackageEngine.Managers.PowerShell.csproj" />
<ProjectReference Include="..\UniGetUI.PackageEngine.Managers.Scoop\UniGetUI.PackageEngine.Managers.Scoop.csproj" />
<ProjectReference Include="..\UniGetUI.PackageEngine.Managers.WinGet\UniGetUI.PackageEngine.Managers.WinGet.csproj" />
<ProjectReference Include="..\UniGetUI.PackageEngine.PackageLoader\UniGetUI.PackageEngine.PackageLoaders.csproj" />
<ProjectReference Include="..\UniGetUI.PackageEngine.PackageManagerClasses\UniGetUI.PackageEngine.Classes.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\SharedAssemblyInfo.cs" Link="SharedAssemblyInfo.cs" />
</ItemGroup>
</Project>
6 changes: 4 additions & 2 deletions src/UniGetUI.PackageEngine.PackageEngine/PEInterface.cs
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@
using UniGetUI.PackageEngine.Managers.WingetManager;
using UniGetUI.PackageEngine.Managers.VcpkgManager;
using UniGetUI.PackageEngine.PackageLoader;
using System.Collections.ObjectModel;
using UniGetUI.PackageOperations;

namespace UniGetUI.PackageEngine
{
@@ -30,7 +32,7 @@ public static class PEInterface
public static readonly PowerShell PowerShell = new();
public static readonly PowerShell7 PowerShell7 = new();
public static readonly Cargo Cargo = new();
public static readonly Vcpkg Vcpkg = new();
public static readonly Vcpkg Vcpkg = new();

public static readonly IPackageManager[] Managers = [WinGet, Scoop, Chocolatey, Npm, Pip, Cargo, Vcpkg, DotNet, PowerShell, PowerShell7];

@@ -45,7 +47,7 @@ public static void Initialize()

foreach (IPackageManager manager in Managers)
{
initializeTasks.Add(Task.Run(() => manager.Initialize()));
initializeTasks.Add(Task.Run(manager.Initialize));
}

Task ManagersMetaTask = Task.WhenAll(initializeTasks);
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
@@ -37,11 +37,16 @@
<ProjectReference Include="..\UniGetUI.PackageEngine.Managers.Scoop\UniGetUI.PackageEngine.Managers.Scoop.csproj" />
<ProjectReference Include="..\UniGetUI.PackageEngine.Managers.WinGet\UniGetUI.PackageEngine.Managers.WinGet.csproj" />
<ProjectReference Include="..\UniGetUI.PackageEngine.Managers.Vcpkg\UniGetUI.PackageEngine.Managers.Vcpkg.csproj" />
<ProjectReference Include="..\UniGetUI.PackageEngine.Operations\UniGetUI.PackageEngine.Operations.csproj" />
<ProjectReference Include="..\UniGetUI.PackageEngine.PackageLoader\UniGetUI.PackageEngine.PackageLoaders.csproj" />
<ProjectReference Include="..\UniGetUI.PackageEngine.PackageManagerClasses\UniGetUI.PackageEngine.Classes.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\SharedAssemblyInfo.cs" Link="SharedAssemblyInfo.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="PhotoSauce.MagicScaler" Version="0.15.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -6,11 +6,15 @@ namespace UniGetUI.PackageEngine.PackageLoader
{
public class DiscoverablePackagesLoader : AbstractPackageLoader
{
public static DiscoverablePackagesLoader Instance = null!;

private string QUERY_TEXT = string.Empty;

public DiscoverablePackagesLoader(IEnumerable<IPackageManager> managers)
: base(managers, "DISCOVERABLE_PACKAGES", AllowMultiplePackageVersions: false, CheckedBydefault: false)
{ }
: base(managers, "DISCOVERABLE_PACKAGES", AllowMultiplePackageVersions: false, CheckedBydefault: false)
{
Instance = this;
}

public async Task ReloadPackages(string query)
{
Original file line number Diff line number Diff line change
@@ -6,9 +6,12 @@ namespace UniGetUI.PackageEngine.PackageLoader
{
public class InstalledPackagesLoader : AbstractPackageLoader
{
public static InstalledPackagesLoader Instance = null!;

public InstalledPackagesLoader(IEnumerable<IPackageManager> managers)
: base(managers, "INSTALLED_PACKAGES", AllowMultiplePackageVersions: true, CheckedBydefault: false)
{
Instance = this;
}

protected override Task<bool> IsPackageValid(IPackage package)
Original file line number Diff line number Diff line change
@@ -7,9 +7,12 @@ namespace UniGetUI.PackageEngine.PackageLoader
{
public class PackageBundlesLoader : AbstractPackageLoader
{
public static PackageBundlesLoader Instance = null!;

public PackageBundlesLoader(IEnumerable<IPackageManager> managers)
: base(managers, "PACKAGE_BUNDLES", AllowMultiplePackageVersions: true, DisableReload: true, CheckedBydefault: false)
{
Instance = this;
}

protected override Task<bool> IsPackageValid(IPackage package)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
@@ -38,4 +38,8 @@
<ItemGroup>
<Compile Include="..\SharedAssemblyInfo.cs" Link="SharedAssemblyInfo.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="PhotoSauce.MagicScaler" Version="0.15.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ namespace UniGetUI.PackageEngine.PackageLoader
public class UpgradablePackagesLoader : AbstractPackageLoader
{
private System.Timers.Timer? UpdatesTimer;
public static UpgradablePackagesLoader Instance = null!;

/// <summary>
/// The collection of packages with updates ignored
@@ -18,6 +19,7 @@ public class UpgradablePackagesLoader : AbstractPackageLoader
public UpgradablePackagesLoader(IEnumerable<IPackageManager> managers)
: base(managers, "DISCOVERABLE_PACKAGES", AllowMultiplePackageVersions: false, CheckedBydefault: !Settings.Get("DisableSelectingUpdatesByDefault"))
{
Instance = this;
FinishedLoading += (_, _) => StartAutoCheckTimeout();
}

Original file line number Diff line number Diff line change
@@ -30,21 +30,12 @@ public IEnumerable<string> GetParameters(
IInstallationOptions options,
OperationType operation)
{
try
{
var parameters = _getOperationParameters(package, options, operation);
Logger.Info(
$"Loaded operation parameters for package id={package.Id} on manager {Manager.Name} and operation {operation}: " +
string.Join(' ', parameters));
return parameters;
}
catch (Exception ex)
{
Logger.Error(
$"A fatal error ocurred while loading operation parameters for package id={package.Id} on manager {Manager.Name} and operation {operation}");
Logger.Error(ex);
return [];
}
var parameters = _getOperationParameters(package, options, operation);
Logger.Info(
$"Loaded operation parameters for package id={package.Id} on manager {Manager.Name} and operation {operation}: " +
string.Join(' ', parameters));
return parameters;

}

public OperationVeredict GetResult(
@@ -53,22 +44,13 @@ public OperationVeredict GetResult(
IEnumerable<string> processOutput,
int returnCode)
{
try
{
if (returnCode is 999 && processOutput.Last() == "Error: The operation was canceled by the user.")
{
Logger.Warn("Elevator [or GSudo] UAC prompt was canceled, not showing error message...");
return OperationVeredict.Canceled;
}

return _getOperationResult(package, operation, processOutput, returnCode);
}
catch (Exception ex)
if (returnCode is 999 && (!processOutput.Any() || processOutput.Last() == "Error: The operation was canceled by the user."))
{
Logger.Error(
$"A fatal error ocurred while loading operation parameters for package id={package.Id} on manager {Manager.Name} and operation {operation}");
Logger.Error(ex);
return OperationVeredict.Failed;
Logger.Warn("Elevator [or GSudo] UAC prompt was canceled, not showing error message...");
return OperationVeredict.Canceled;
}

return _getOperationResult(package, operation, processOutput, returnCode);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
@@ -34,4 +34,8 @@
<ItemGroup>
<Compile Include="..\SharedAssemblyInfo.cs" Link="SharedAssemblyInfo.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="PhotoSauce.MagicScaler" Version="0.15.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
7 changes: 7 additions & 0 deletions src/UniGetUI.sln
Original file line number Diff line number Diff line change
@@ -96,6 +96,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniGetUI.PackageEngine.Mana
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniGetUI.PackageEngine.Managers.Vcpkg", "UniGetUI.PackageEngine.Managers.Vcpkg\UniGetUI.PackageEngine.Managers.Vcpkg.csproj", "{E337A71E-3C30-4315-B8F1-57CBC5CF50A6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniGetUI.PackageEngine.Operations", "UniGetUI.PackageEngine.Operations\UniGetUI.PackageEngine.Operations.csproj", "{727866B8-BBD5-43B9-933A-78199F65429C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@@ -250,6 +252,10 @@ Global
{E337A71E-3C30-4315-B8F1-57CBC5CF50A6}.Debug|x64.Build.0 = Debug|x64
{E337A71E-3C30-4315-B8F1-57CBC5CF50A6}.Release|x64.ActiveCfg = Release|x64
{E337A71E-3C30-4315-B8F1-57CBC5CF50A6}.Release|x64.Build.0 = Release|x64
{727866B8-BBD5-43B9-933A-78199F65429C}.Debug|x64.ActiveCfg = Debug|x64
{727866B8-BBD5-43B9-933A-78199F65429C}.Debug|x64.Build.0 = Debug|x64
{727866B8-BBD5-43B9-933A-78199F65429C}.Release|x64.ActiveCfg = Release|x64
{727866B8-BBD5-43B9-933A-78199F65429C}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -294,6 +300,7 @@ Global
{C396E5F6-C6D9-465D-9903-7E33D0841E6A} = {7940E867-EEBA-4AFD-9904-1536F003239C}
{54DA0549-366F-4E70-B5D1-0B8891D0A2A5} = {95168D0B-1B2C-4295-B6D4-D5BAF781B9FA}
{E337A71E-3C30-4315-B8F1-57CBC5CF50A6} = {95168D0B-1B2C-4295-B6D4-D5BAF781B9FA}
{727866B8-BBD5-43B9-933A-78199F65429C} = {7940E867-EEBA-4AFD-9904-1536F003239C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D044BB14-0B37-47E5-A579-8B30FCBA1F9F}
67 changes: 51 additions & 16 deletions src/UniGetUI/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Text.RegularExpressions;
using Windows.ApplicationModel.Activation;
using CommunityToolkit.WinUI.Helpers;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using UniGetUI.Core.Data;
@@ -15,26 +17,64 @@
using UniGetUI.PackageEngine.Operations;
using Microsoft.Windows.AppLifecycle;
using Microsoft.Windows.AppNotifications;
using UniGetUI.Controls.OperationWidgets;
using UniGetUI.PackageEngine.Interfaces;
using AbstractOperation = UniGetUI.PackageOperations.AbstractOperation;
using LaunchActivatedEventArgs = Microsoft.UI.Xaml.LaunchActivatedEventArgs;

namespace UniGetUI
{
public partial class MainApp
{
public class __tooltip_options
public static DispatcherQueue Dispatcher = null!;

public static class Tooltip
{
private int _errors_occurred;
public int ErrorsOccurred { get { return _errors_occurred; } set { _errors_occurred = value; Instance.MainWindow.UpdateSystemTrayStatus(); } }
private bool _restart_required;
public bool RestartRequired { get { return _restart_required; } set { _restart_required = value; Instance.MainWindow.UpdateSystemTrayStatus(); } }
private int _operations_in_progress;
public int OperationsInProgress { get { return _operations_in_progress; } set { _operations_in_progress = value; Instance.MainWindow.UpdateSystemTrayStatus(); } }
private int _available_updates;
public int AvailableUpdates { get { return _available_updates; } set { _available_updates = value; Instance.MainWindow.UpdateSystemTrayStatus(); } }
private static int _errors_occurred;
public static int ErrorsOccurred
{
get => _errors_occurred;
set { _errors_occurred = value; Instance?.MainWindow?.UpdateSystemTrayStatus(); }
}

private static bool _restart_required;
public static bool RestartRequired
{
get => _restart_required;
set { _restart_required = value; Instance?.MainWindow?.UpdateSystemTrayStatus(); }
}

private static int _operations_in_progress;
public static int OperationsInProgress
{
get => _operations_in_progress;
set { _operations_in_progress = value; Instance?.MainWindow?.UpdateSystemTrayStatus(); }
}

private static int _available_updates;
public static int AvailableUpdates
{
get => _available_updates;
set { _available_updates = value; Instance?.MainWindow?.UpdateSystemTrayStatus(); }
}
}

public List<AbstractOperation> OperationQueue = [];
public static class Operations
{
public static ObservableCollection<OperationControl> _operationList = new();

public static void Add(AbstractOperation op)
=> _operationList.Add(new(op));

public static void Remove(OperationControl control)
=> _operationList.Remove(control);

public static void Remove(AbstractOperation op)
{
foreach(var control in _operationList.Where(x => x.Operation == op).ToArray())
_operationList.Remove(control);
}
}

public bool RaiseExceptionAsFatal = true;

@@ -44,13 +84,13 @@ public class __tooltip_options

private readonly BackgroundApiRunner BackgroundApi = new();
public static MainApp Instance = null!;
public __tooltip_options TooltipStatus = new();

public MainApp()
{
try
{
Instance = this;
Dispatcher = DispatcherQueue.GetForCurrentThread();

InitializeComponent();

@@ -212,11 +252,6 @@ private void RegisterNotificationService()
}
}

public void AddOperationToList(AbstractOperation operation)
{
MainWindow.NavigationPage.OperationStackPanel.Children.Add(operation);
}

/// <summary>
/// Background component loader
/// </summary>
33 changes: 33 additions & 0 deletions src/UniGetUI/Controls/OperationWidgets/OperationBadge.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UniGetUI.Interface.Enums;

namespace UniGetUI.Controls.OperationWidgets;
public class OperationBadge
{
public string Tooltip;
public string PrimaryBanner;
public string SecondaryBanner;
public bool SecondaryBannerVisible;
public IconType Icon;

public OperationBadge(string tooltip, IconType icon, string primaryBanner, string? secondaryBanner = null)
{
Tooltip = tooltip;
Icon = icon;
PrimaryBanner = primaryBanner;
if(secondaryBanner is null || secondaryBanner == String.Empty)
{
SecondaryBannerVisible = false;
SecondaryBanner = "";
}
else
{
SecondaryBanner = secondaryBanner;
SecondaryBannerVisible = true;
}
}
}
579 changes: 579 additions & 0 deletions src/UniGetUI/Controls/OperationWidgets/OperationControl.cs

Large diffs are not rendered by default.

49 changes: 0 additions & 49 deletions src/UniGetUI/Controls/OperationWidgets/OperationControl.xaml

This file was deleted.

626 changes: 0 additions & 626 deletions src/UniGetUI/Controls/OperationWidgets/OperationControl.xaml.cs

This file was deleted.

463 changes: 0 additions & 463 deletions src/UniGetUI/Controls/OperationWidgets/PackageOperations.cs

This file was deleted.

282 changes: 0 additions & 282 deletions src/UniGetUI/Controls/OperationWidgets/SourceOperations.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/UniGetUI/Controls/SettingsWidgets/CheckboxCard.cs
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@

namespace UniGetUI.Interface.Widgets
{
public sealed class CheckboxCard : SettingsCard
public sealed partial class CheckboxCard : SettingsCard
{
public CheckBox _checkbox;
private bool IS_INVERTED;
1 change: 1 addition & 0 deletions src/UniGetUI/Controls/SettingsWidgets/ComboboxCard.cs
Original file line number Diff line number Diff line change
@@ -84,5 +84,6 @@ public void ShowAddedItems()
};
}

public string SelectedValue() => _combobox.SelectedValue.ToString() ?? throw new InvalidCastException();
}
}
18 changes: 7 additions & 11 deletions src/UniGetUI/Controls/SourceManager.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.ObjectModel;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using UniGetUI.Controls.OperationWidgets;
using UniGetUI.Core.Logging;
using UniGetUI.Core.Tools;
using UniGetUI.PackageEngine.Classes.Manager;
@@ -25,9 +26,9 @@ public SourceItem(SourceManager Parent, IManagerSource Source)

public void Remove(object sender, RoutedEventArgs e)
{
RemoveSourceOperation op = new(Source);
MainApp.Instance.AddOperationToList(op);
op.OperationSucceeded += (_, _) => { Parent.RemoveSourceItem(this); };
var op = new OperationControl(new RemoveSourceOperation(Source));
MainApp.Operations._operationList.Add(op);
op.Operation.OperationSucceeded += (_, _) => { Parent.RemoveSourceItem(this); };
}
}

@@ -124,19 +125,14 @@ public SourceManager(IPackageManager Manager)

if (await MainApp.Instance.MainWindow.ShowDialogAsync(d) == ContentDialogResult.Primary)
{
AddSourceOperation op;
PackageOperations.AbstractOperation op;
if (CoreTools.Translate("Other") != SourcesCombo.SelectedValue.ToString())
{
op = new AddSourceOperation(NameSourceRef[SourcesCombo.SelectedValue.ToString() ?? ""]);
}
else
{
op = new AddSourceOperation(new ManagerSource(this.Manager, SourceNameTextBox.Text, new Uri(SourceUrlTextBox.Text)));
}

MainApp.Instance.AddOperationToList(op);
op.OperationSucceeded += (_, _) => { LoadSources(); };

MainApp.Operations.Add(op);
op.OperationSucceeded += (_, _) => LoadSources();
}
}
catch (Exception ex)
134 changes: 74 additions & 60 deletions src/UniGetUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -45,7 +45,6 @@ public XamlRoot XamlRoot
public int LoadingDialogCount;

public List<ContentDialog> DialogQueue = [];

public List<NavButton> NavButtonList = [];

public static readonly ObservableQueue<string> ParametersToProcess = new();
@@ -210,7 +209,7 @@ public async void HandleClosingEvent(AppWindow sender, AppWindowClosingEventArgs
}
else
{
if (MainApp.Instance.OperationQueue.Count > 0)
if (MainApp.Operations._operationList.Count > 0)
{
args.Cancel = true;
ContentDialog d = new()
@@ -461,80 +460,95 @@ private void LoadTrayMenu()
UpdateSystemTrayStatus();
}

private string LastTrayIcon = "";
public void UpdateSystemTrayStatus()
{
string modifier = "_empty";
string tooltip = CoreTools.Translate("Everything is up to date") + " - " + Title;

if (MainApp.Instance.TooltipStatus.OperationsInProgress > 0)
{
modifier = "_blue";
tooltip = CoreTools.Translate("Operation in progress") + " - " + Title;
}
else if (MainApp.Instance.TooltipStatus.ErrorsOccurred > 0)
{
modifier = "_orange";
tooltip = CoreTools.Translate("Attention required") + " - " + Title;
}
else if (MainApp.Instance.TooltipStatus.RestartRequired)
{
modifier = "_turquoise";
tooltip = CoreTools.Translate("Restart required") + " - " + Title;
}
else if (MainApp.Instance.TooltipStatus.AvailableUpdates > 0)
try
{
modifier = "_green";
if (MainApp.Instance.TooltipStatus.AvailableUpdates == 1)
string modifier = "_empty";
string tooltip = CoreTools.Translate("Everything is up to date") + " - " + Title;

if (MainApp.Tooltip.OperationsInProgress > 0)
{
tooltip = CoreTools.Translate("1 update is available") + " - " + Title;
modifier = "_blue";
tooltip = CoreTools.Translate("Operation in progress") + " - " + Title;
}
else
else if (MainApp.Tooltip.ErrorsOccurred > 0)
{
tooltip = CoreTools.Translate("{0} updates are available",
MainApp.Instance.TooltipStatus.AvailableUpdates) + " - " + Title;
modifier = "_orange";
tooltip = CoreTools.Translate("Attention required") + " - " + Title;
}
else if (MainApp.Tooltip.RestartRequired)
{
modifier = "_turquoise";
tooltip = CoreTools.Translate("Restart required") + " - " + Title;
}
else if (MainApp.Tooltip.AvailableUpdates > 0)
{
modifier = "_green";
if (MainApp.Tooltip.AvailableUpdates == 1)
{
tooltip = CoreTools.Translate("1 update is available") + " - " + Title;
}
else
{
tooltip = CoreTools.Translate("{0} updates are available",
MainApp.Tooltip.AvailableUpdates) + " - " + Title;
}
}
}

if (TrayIcon is null)
{
Logger.Warn("Attempting to update a null taskbar icon tray, aborting!");
return;
}
if (TrayIcon is null)
{
Logger.Warn("Attempting to update a null taskbar icon tray, aborting!");
return;
}

TrayIcon.ToolTipText = tooltip;
TrayIcon.ToolTipText = tooltip;

ApplicationTheme theme = ApplicationTheme.Light;
string RegistryKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize";
string RegistryValueName = "SystemUsesLightTheme";
RegistryKey? key = Registry.CurrentUser.OpenSubKey(RegistryKeyPath);
object? registryValueObject = key?.GetValue(RegistryValueName) ?? null;
if (registryValueObject is not null)
{
int registryValue = (int)registryValueObject;
theme = registryValue > 0 ? ApplicationTheme.Light : ApplicationTheme.Dark;
}
ApplicationTheme theme = ApplicationTheme.Light;
string RegistryKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize";
string RegistryValueName = "SystemUsesLightTheme";
RegistryKey? key = Registry.CurrentUser.OpenSubKey(RegistryKeyPath);
object? registryValueObject = key?.GetValue(RegistryValueName) ?? null;
if (registryValueObject is not null)
{
int registryValue = (int)registryValueObject;
theme = registryValue > 0 ? ApplicationTheme.Light : ApplicationTheme.Dark;
}

if (theme == ApplicationTheme.Light)
{
modifier += "_black";
}
else
{
modifier += "_white";
}
if (theme == ApplicationTheme.Light)
{
modifier += "_black";
}
else
{
modifier += "_white";
}

string FullIconPath = Path.Join(CoreData.UniGetUIExecutableDirectory,
"\\Assets\\Images\\tray" + modifier + ".ico");
string FullIconPath = Path.Join(CoreData.UniGetUIExecutableDirectory, "\\Assets\\Images\\tray" + modifier + ".ico");
if (LastTrayIcon != FullIconPath)
{
LastTrayIcon = FullIconPath;
if (File.Exists(FullIconPath))
{
TrayIcon.SetValue(TaskbarIcon.IconSourceProperty, new BitmapImage { UriSource = new Uri(FullIconPath) });
}
}

TrayIcon.SetValue(TaskbarIcon.IconSourceProperty, new BitmapImage { UriSource = new Uri(FullIconPath) });
if (Settings.Get("DisableSystemTray"))
{
TrayIcon.Visibility = Visibility.Collapsed;
}
else
{
TrayIcon.Visibility = Visibility.Visible;
}

if (Settings.Get("DisableSystemTray"))
{
TrayIcon.Visibility = Visibility.Collapsed;
}
else
catch (Exception ex)
{
TrayIcon.Visibility = Visibility.Visible;
Logger.Error("An error occurred while updating the System Tray icon:");
Logger.Error(ex);
}
}

Loading

0 comments on commit a7b6379

Please sign in to comment.