Skip to content

Commit 87f788e

Browse files
committed
Disable the creation of XML and YAML bundles. XML and YAML bundles will still be importable
1 parent 5e0f8a8 commit 87f788e

File tree

10 files changed

+34
-49
lines changed

10 files changed

+34
-49
lines changed

src/UniGetUI.PackageEngine.Serializable/InstallOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ this.CustomParameters_Uninstall.Count is 0 &&
148148
this.OverridesNextLevelOpts = data[nameof(OverridesNextLevelOpts)]?.GetValue<bool>() ?? DiffersFromDefault();
149149
}
150150

151-
public override JsonNode AsJsonNode()
151+
public override JsonObject AsJsonNode()
152152
{
153153
JsonObject obj = new();
154154

src/UniGetUI.PackageEngine.Serializable/SerializableBundle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public override void LoadFromJson(JsonNode data)
5858
}
5959
}
6060

61-
public override JsonNode AsJsonNode()
61+
public override JsonObject AsJsonNode()
6262
{
6363
JsonObject obj = new();
6464
obj.Add(nameof(export_version), export_version);

src/UniGetUI.PackageEngine.Serializable/SerializableComponent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public string AsJsonString()
3131
/// Serializes this object into a JsonNode object
3232
/// </summary>
3333
/// <returns>A pretty-formatted JSON string representing the current data</returns>
34-
public abstract JsonNode AsJsonNode();
34+
public abstract JsonObject AsJsonNode();
3535

3636
/// <summary>
3737
/// Creates an instance of this object with the default data

src/UniGetUI.PackageEngine.Serializable/SerializableIncompatiblePackage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public override void LoadFromJson(JsonNode data)
2727
this.Source = data[nameof(Source)]?.GetVal<string>() ?? "";
2828
}
2929

30-
public override JsonNode AsJsonNode()
30+
public override JsonObject AsJsonNode()
3131
{
3232
JsonObject obj = new();
3333
obj.Add(nameof(Id), Id);

src/UniGetUI.PackageEngine.Serializable/SerializablePackage.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,27 @@ public override void LoadFromJson(JsonNode data)
4141
this.Updates = new(data[nameof(Updates)] ?? new JsonObject());
4242
}
4343

44-
public override JsonNode AsJsonNode()
44+
public override JsonObject AsJsonNode()
4545
{
4646
JsonObject obj = new();
4747
obj.Add(nameof(Id), Id);
4848
obj.Add(nameof(Name), Name);
4949
obj.Add(nameof(Version), Version);
5050
obj.Add(nameof(Source), Source);
5151
obj.Add(nameof(ManagerName), ManagerName);
52-
obj.Add(nameof(InstallationOptions), InstallationOptions.AsJsonNode());
53-
obj.Add(nameof(Updates), Updates.AsJsonNode());
52+
53+
var ioNode = InstallationOptions.AsJsonNode();
54+
if (ioNode.Count > 0)
55+
{
56+
obj.Add(nameof(InstallationOptions), InstallationOptions.AsJsonNode());
57+
}
58+
59+
var updNode = Updates.AsJsonNode();
60+
if (updNode.Count > 0)
61+
{
62+
obj.Add(nameof(Updates), updNode);
63+
}
64+
5465
return obj;
5566
}
5667

src/UniGetUI.PackageEngine.Serializable/SerializableUpdatesOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public override void LoadFromJson(JsonNode data)
2020
this.IgnoredVersion = data[nameof(IgnoredVersion)]?.GetVal<string>() ?? "";
2121
}
2222

23-
public override JsonNode AsJsonNode()
23+
public override JsonObject AsJsonNode()
2424
{
2525
JsonObject obj = new();
2626
if(UpdatesIgnored is not false) obj.Add(nameof(UpdatesIgnored), UpdatesIgnored);

src/UniGetUI/Pages/SettingsPages/GeneralPages/Internet.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ namespace UniGetUI.Pages.SettingsPages.GeneralPages
1717
/// </summary>
1818
public sealed partial class Internet : Page, ISettingsPage
1919
{
20-
20+
2121

2222
public Internet()
2323
{
2424
this.InitializeComponent();
25-
25+
2626

2727
UsernameBox.PlaceholderText = CoreTools.Translate("Username");
2828
PasswordBox.PlaceholderText = CoreTools.Translate("Password");
@@ -85,7 +85,7 @@ public Internet()
8585
});
8686

8787
}
88-
88+
8989
}
9090

9191
public bool CanGoBack => true;

src/UniGetUI/Pages/SoftwarePages/AbstractPackagesPage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,7 @@ private void ABSTRACT_PAGE_SizeChanged(object sender, SizeChangedEventArgs e)
13421342
{
13431343
_titleHidden = true;
13441344
MainSubtitle.Visibility = Visibility.Visible;
1345-
1345+
13461346
}
13471347
}
13481348

src/UniGetUI/Pages/SoftwarePages/InstalledPackagesPage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ public static Task<string> GenerateBackupContents()
377377
packagesToExport.Add(package);
378378
}
379379

380-
return PackageBundlesPage.CreateBundle(packagesToExport.ToArray(), BundleFormatType.UBUNDLE);
380+
return PackageBundlesPage.CreateBundle(packagesToExport.ToArray());
381381
}
382382

383383
public static async Task BackupPackages_CLOUD()

src/UniGetUI/Pages/SoftwarePages/PackageBundlesPage.cs

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ public async Task SaveFile()
518518
{
519519
// Get file
520520
string defaultName = CoreTools.Translate("Package bundle") + ".ubundle";
521-
string file = (new FileSavePicker(MainApp.Instance.MainWindow.GetWindowHandle())).Show(["*.ubundle", "*.json", "*.yaml", "*.xml"], defaultName);
521+
string file = (new FileSavePicker(MainApp.Instance.MainWindow.GetWindowHandle())).Show(["*.ubundle", "*.json"], defaultName);
522522
if (file != String.Empty)
523523
{
524524
// Loading dialog
@@ -527,19 +527,15 @@ public async Task SaveFile()
527527
// Select appropriate format
528528
BundleFormatType formatType;
529529
string EXT = file.Split('.')[^1].ToLower();
530-
if (EXT == "yaml")
531-
formatType = BundleFormatType.YAML;
532-
else if (EXT == "xml")
533-
formatType = BundleFormatType.XML;
534-
else if (EXT == "json")
530+
if (EXT == "json")
535531
formatType = BundleFormatType.JSON;
536532
else if (EXT == "ubundle")
537533
formatType = BundleFormatType.UBUNDLE;
538534
else
539535
formatType = BundleFormatType.UBUNDLE;
540536

541537
// Save serialized data
542-
await File.WriteAllTextAsync(file, await CreateBundle(Loader.Packages, formatType));
538+
await File.WriteAllTextAsync(file, await CreateBundle(Loader.Packages));
543539
TelemetryHandler.ExportBundle(formatType);
544540

545541
DialogHelper.HideLoadingDialog();
@@ -574,9 +570,9 @@ public async Task SaveFile()
574570
}
575571
}
576572

577-
public static async Task<string> CreateBundle(IReadOnlyList<IPackage> unsorted_packages, BundleFormatType formatType = BundleFormatType.UBUNDLE)
573+
public static async Task<string> CreateBundle(IReadOnlyList<IPackage> unsorted_packages)
578574
{
579-
SerializableBundle exportable = new();
575+
SerializableBundle exportableData = new();
580576

581577
List<IPackage> packages = unsorted_packages.ToList();
582578
packages.Sort(Comparison);
@@ -591,37 +587,15 @@ static int Comparison(IPackage x, IPackage y)
591587
foreach (IPackage package in packages)
592588
{
593589
if (package is Package && !package.Source.IsVirtualManager)
594-
exportable.packages.Add(await package.AsSerializableAsync());
590+
exportableData.packages.Add(await package.AsSerializableAsync());
595591
else
596-
exportable.incompatible_packages.Add(package.AsSerializable_Incompatible());
597-
}
598-
599-
Logger.Debug("Finished loading serializable objects. Serializing with format " + formatType);
600-
string ExportableData;
601-
602-
if (formatType is BundleFormatType.JSON or BundleFormatType.UBUNDLE)
603-
ExportableData = exportable.AsJsonString();
604-
605-
else if (formatType is BundleFormatType.YAML)
606-
{
607-
ISerializer serializer = new SerializerBuilder()
608-
.Build();
609-
ExportableData = serializer.Serialize(exportable);
610-
}
611-
else
612-
{
613-
string tempfile = Path.GetTempFileName();
614-
StreamWriter writer = new(tempfile);
615-
XmlSerializer serializer = new(typeof(SerializableBundle));
616-
serializer.Serialize(writer, exportable);
617-
writer.Close();
618-
ExportableData = await File.ReadAllTextAsync(tempfile);
619-
File.Delete(tempfile);
592+
exportableData.incompatible_packages.Add(package.AsSerializable_Incompatible());
620593
}
621594

595+
Logger.Debug("Finished loading serializable objects.");
596+
string exportablePayload = exportableData.AsJsonString();
622597
Logger.Debug("Serialization finished successfully");
623-
624-
return ExportableData;
598+
return exportablePayload;
625599
}
626600

627601
public async Task<double> AddFromBundle(string content, BundleFormatType format)

0 commit comments

Comments
 (0)