diff --git a/src/Artemis.Core/JsonConverters/StreamConverter.cs b/src/Artemis.Core/JsonConverters/StreamConverter.cs deleted file mode 100644 index 8ea7b9abd..000000000 --- a/src/Artemis.Core/JsonConverters/StreamConverter.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.IO; -using System.Text.Json; -using System.Text.Json.Serialization; - -namespace Artemis.Core.JsonConverters -{ - internal class StreamConverter : JsonConverter - { - public override void Write(Utf8JsonWriter writer, Stream value, JsonSerializerOptions options) - { - using MemoryStream memoryStream = new(); - value.Position = 0; - value.CopyTo(memoryStream); - writer.WriteBase64StringValue(memoryStream.ToArray()); - } - - public override Stream Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - if (reader.TokenType != JsonTokenType.String) - throw new JsonException($"Expected a string token, but got {reader.TokenType}."); - - string base64 = reader.GetString() ?? string.Empty; - - if (typeToConvert == typeof(MemoryStream)) - return new MemoryStream(Convert.FromBase64String(base64)); - - throw new InvalidOperationException("StreamConverter only supports reading to MemoryStream"); - } - } -} \ No newline at end of file diff --git a/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfigurationExportModel.cs b/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfigurationExportModel.cs deleted file mode 100644 index 5febcbe25..000000000 --- a/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfigurationExportModel.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.IO; -using System.Text.Json.Serialization; -using Artemis.Core.JsonConverters; -using Artemis.Storage.Entities.Profile; - -namespace Artemis.Core; - -/// -/// A model that can be used to serialize a profile configuration, it's profile and it's icon -/// -public class ProfileConfigurationExportModel : IDisposable -{ - /// - /// Gets or sets the storage entity of the profile configuration - /// - public ProfileConfigurationEntity? ProfileConfigurationEntity { get; set; } - - /// - /// Gets or sets the storage entity of the profile - /// - [JsonRequired] - public ProfileEntity ProfileEntity { get; set; } = null!; - - /// - /// Gets or sets a stream containing the profile image - /// - [JsonConverter(typeof(StreamConverter))] - public Stream? ProfileImage { get; set; } - - /// - public void Dispose() - { - ProfileImage?.Dispose(); - } -} \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Sidebar/SidebarCategoryViewModel.cs b/src/Artemis.UI/Screens/Sidebar/SidebarCategoryViewModel.cs index 6120a814c..3892fee70 100644 --- a/src/Artemis.UI/Screens/Sidebar/SidebarCategoryViewModel.cs +++ b/src/Artemis.UI/Screens/Sidebar/SidebarCategoryViewModel.cs @@ -2,12 +2,10 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; -using System.IO.Compression; using System.Linq; using System.Reactive; using System.Reactive.Disposables; using System.Reactive.Linq; -using System.Text; using System.Threading.Tasks; using Artemis.Core; using Artemis.Core.Services; @@ -150,7 +148,7 @@ private async Task ExecuteAddProfile() private async Task ExecuteImportProfile() { string[]? result = await _windowService.CreateOpenFileDialog() - .HavingFilter(f => f.WithExtension("zip").WithExtension("json").WithName("Artemis profile")) + .HavingFilter(f => f.WithExtension("zip").WithName("Artemis profile")) .ShowAsync(); if (result == null) @@ -158,24 +156,8 @@ private async Task ExecuteImportProfile() try { - // Removing this at some point in the future - if (result[0].EndsWith("json")) - { - ProfileConfigurationExportModel? exportModel = CoreJson.Deserialize(await File.ReadAllTextAsync(result[0])); - if (exportModel == null) - { - await _windowService.ShowConfirmContentDialog("Import profile", "Failed to import this profile, make sure it is a valid Artemis profile.", "Confirm", null); - return; - } - - await using Stream convertedFileStream = await ConvertLegacyExport(exportModel); - await _profileService.ImportProfile(convertedFileStream, ProfileCategory, true, true); - } - else - { - await using FileStream fileStream = File.OpenRead(result[0]); - await _profileService.ImportProfile(fileStream, ProfileCategory, true, true); - } + await using FileStream fileStream = File.OpenRead(result[0]); + await _profileService.ImportProfile(fileStream, ProfileCategory, true, true); } catch (Exception e) { @@ -229,38 +211,4 @@ private void ApplyCategoryOrder(List categories) _profileService.SaveProfileCategory(categories[i]); } } - - private async Task ConvertLegacyExport(ProfileConfigurationExportModel exportModel) - { - MemoryStream archiveStream = new(); - - string configurationJson = CoreJson.Serialize(exportModel.ProfileConfigurationEntity); - string profileJson = CoreJson.Serialize(exportModel.ProfileEntity); - - // Create a ZIP archive - using (ZipArchive archive = new(archiveStream, ZipArchiveMode.Create, true)) - { - ZipArchiveEntry configurationEntry = archive.CreateEntry("configuration.json"); - await using (Stream entryStream = configurationEntry.Open()) - { - await entryStream.WriteAsync(Encoding.Default.GetBytes(configurationJson)); - } - - ZipArchiveEntry profileEntry = archive.CreateEntry("profile.json"); - await using (Stream entryStream = profileEntry.Open()) - { - await entryStream.WriteAsync(Encoding.Default.GetBytes(profileJson)); - } - - if (exportModel.ProfileImage != null) - { - ZipArchiveEntry iconEntry = archive.CreateEntry("icon.png"); - await using Stream entryStream = iconEntry.Open(); - await exportModel.ProfileImage.CopyToAsync(entryStream); - } - } - - archiveStream.Seek(0, SeekOrigin.Begin); - return archiveStream; - } } \ No newline at end of file