Skip to content

Commit

Permalink
Merge pull request #2752 from marticliment/trim-support-and-aot
Browse files Browse the repository at this point in the history
Add Trim support
  • Loading branch information
marticliment authored Sep 18, 2024
2 parents e1d6bff + 4520b95 commit a5098ed
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ src/UniGetUI/choco-cli/extensions/chocolatey-visualstudio/
src/UniGetUI/choco-cli/extensions/chocolatey-dotnetfx/

*.user
/src/UniGetUI/Generated Files
8 changes: 8 additions & 0 deletions src/UniGetUI.Core.Data/CoreData.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Diagnostics;
using System.Net;
using System.Runtime.InteropServices.JavaScript;
using System.Text.Json;
using System.Text.Json.Serialization.Metadata;
using UniGetUI.Core.Logging;

namespace UniGetUI.Core.Data
Expand Down Expand Up @@ -312,5 +314,11 @@ private static string GetNewDataDirectoryOrMoveOld(string old_path, string new_p
return new_path;
}
}

public static JsonSerializerOptions SerializingOptions = new()
{
TypeInfoResolverChain = { new DefaultJsonTypeInfoResolver() },
WriteIndented = true,
};
}
}
5 changes: 4 additions & 1 deletion src/UniGetUI.Core.IconStore/IconDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ public async Task LoadIconAndScreenshotsDatabaseAsync()

try
{
IconScreenshotDatabase_v2 JsonData = JsonSerializer.Deserialize<IconScreenshotDatabase_v2>(await File.ReadAllTextAsync(IconsAndScreenshotsFile));
IconScreenshotDatabase_v2 JsonData = JsonSerializer.Deserialize<IconScreenshotDatabase_v2>(
await File.ReadAllTextAsync(IconsAndScreenshotsFile),
CoreData.SerializingOptions
);
if (JsonData.icons_and_screenshots != null)
{
IconDatabaseData = JsonData.icons_and_screenshots;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static Dictionary<string, string> GetDatabase()
private static void SaveDatabase()
{
// Serialize and save to disk
string rawContents = JsonSerializer.Serialize(IgnoredPackages, options: new(){ WriteIndented = true });
string rawContents = JsonSerializer.Serialize(IgnoredPackages, options: CoreData.SerializingOptions);
File.WriteAllText(CoreData.IgnoredUpdatesDatabaseFile, rawContents);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void SaveToDisk()

string fileContents = JsonSerializer.Serialize(
AsSerializable(),
new JsonSerializerOptions(){ WriteIndented = true }
CoreData.SerializingOptions
);
File.WriteAllText(optionsFile.FullName, fileContents);
}
Expand All @@ -219,7 +219,8 @@ public void LoadFromDisk()
}

using FileStream inputStream = optionsFile.OpenRead();
SerializableInstallationOptions_v1? options = JsonSerializer.Deserialize<SerializableInstallationOptions_v1>(inputStream);
SerializableInstallationOptions_v1? options = JsonSerializer.Deserialize<SerializableInstallationOptions_v1>(
inputStream, CoreData.SerializingOptions);

if (options == null)
{
Expand Down
8 changes: 6 additions & 2 deletions src/UniGetUI/SoftwarePages/PackageBundlesPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Documents;
using UniGetUI.Core.Data;
using UniGetUI.Core.Logging;
using UniGetUI.Core.Tools;
using UniGetUI.Interface.Enums;
Expand Down Expand Up @@ -565,7 +566,10 @@ public static async Task<string> CreateBundle(IEnumerable<IPackage> packages, Bu
string ExportableData;

if (formatType == BundleFormatType.JSON)
ExportableData = JsonSerializer.Serialize(exportable, new JsonSerializerOptions { WriteIndented = true });
ExportableData = JsonSerializer.Serialize(
exportable,
CoreData.SerializingOptions);

else if (formatType == BundleFormatType.YAML)
{
YamlDotNet.Serialization.ISerializer serializer = new YamlDotNet.Serialization.SerializerBuilder()
Expand Down Expand Up @@ -595,7 +599,7 @@ public async Task AddFromBundle(string content, BundleFormatType format)
SerializableBundle_v1? DeserializedData;
if (format is BundleFormatType.JSON)
{
DeserializedData = await Task.Run(() => JsonSerializer.Deserialize<SerializableBundle_v1>(content));
DeserializedData = await Task.Run(() => JsonSerializer.Deserialize<SerializableBundle_v1>(content, CoreData.SerializingOptions));
}
else if (format is BundleFormatType.YAML)
{
Expand Down
4 changes: 4 additions & 0 deletions src/UniGetUI/UniGetUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<WindowsAppSDKWinUI>true</WindowsAppSDKWinUI>
<WindowsPackageType>None</WindowsPackageType>
<WindowsSdkPackageVersion>10.0.22621.41</WindowsSdkPackageVersion>

<PublishTrimmed>true</PublishTrimmed>
<TrimMode>full</TrimMode>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit a5098ed

Please sign in to comment.