From 3a6171726c8c29281baf6fdd2ed8a8c37a9d2156 Mon Sep 17 00:00:00 2001 From: Robert Date: Sun, 13 Aug 2023 10:41:12 +0200 Subject: [PATCH] Core - Removed OriginalFileName from icon since it's irrelevant --- .../ProfileConfigurationIcon.cs | 16 +--------------- .../Services/Storage/ProfileService.cs | 16 ++++++++-------- .../Profile/ProfileConfigurationEntity.cs | 1 - .../Repositories/ProfileCategoryRepository.cs | 2 +- 4 files changed, 10 insertions(+), 25 deletions(-) diff --git a/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfigurationIcon.cs b/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfigurationIcon.cs index 058e95687..10a500cba 100644 --- a/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfigurationIcon.cs +++ b/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfigurationIcon.cs @@ -15,7 +15,6 @@ public class ProfileConfigurationIcon : CorePropertyChanged, IStorageModel private string? _iconName; private Stream? _iconStream; private ProfileConfigurationIconType _iconType; - private string? _originalFileName; internal ProfileConfigurationIcon(ProfileConfigurationEntity entity) { @@ -40,15 +39,6 @@ public class ProfileConfigurationIcon : CorePropertyChanged, IStorageModel private set => SetAndNotify(ref _iconName, value); } - /// - /// Gets the original file name of the icon (if applicable) - /// - public string? OriginalFileName - { - get => _originalFileName; - private set => SetAndNotify(ref _originalFileName, value); - } - /// /// Gets or sets a boolean indicating whether or not this icon should be filled. /// @@ -69,7 +59,6 @@ public class ProfileConfigurationIcon : CorePropertyChanged, IStorageModel _iconStream?.Dispose(); IconName = iconName; - OriginalFileName = null; IconType = ProfileConfigurationIconType.MaterialIcon; OnIconUpdated(); @@ -78,11 +67,9 @@ public class ProfileConfigurationIcon : CorePropertyChanged, IStorageModel /// /// Updates the stream returned by to the provided stream /// - /// The original file name backing the stream, should include the extension /// The stream to copy - public void SetIconByStream(string originalFileName, Stream stream) + public void SetIconByStream(Stream stream) { - if (originalFileName == null) throw new ArgumentNullException(nameof(originalFileName)); if (stream == null) throw new ArgumentNullException(nameof(stream)); _iconStream?.Dispose(); @@ -92,7 +79,6 @@ public class ProfileConfigurationIcon : CorePropertyChanged, IStorageModel _iconStream.Seek(0, SeekOrigin.Begin); IconName = null; - OriginalFileName = originalFileName; IconType = ProfileConfigurationIconType.BitmapImage; OnIconUpdated(); } diff --git a/src/Artemis.Core/Services/Storage/ProfileService.cs b/src/Artemis.Core/Services/Storage/ProfileService.cs index 2ecf653f3..159e2ebf5 100644 --- a/src/Artemis.Core/Services/Storage/ProfileService.cs +++ b/src/Artemis.Core/Services/Storage/ProfileService.cs @@ -187,7 +187,7 @@ internal class ProfileService : IProfileService using Stream? stream = _profileCategoryRepository.GetProfileIconStream(profileConfiguration.Entity.FileIconId); if (stream != null) - profileConfiguration.Icon.SetIconByStream(profileConfiguration.Entity.IconOriginalFileName, stream); + profileConfiguration.Icon.SetIconByStream(stream); } /// @@ -197,11 +197,8 @@ internal class ProfileService : IProfileService return; using Stream? stream = profileConfiguration.Icon.GetIconStream(); - if (stream != null && profileConfiguration.Icon.OriginalFileName != null) - { - profileConfiguration.Entity.IconOriginalFileName = profileConfiguration.Icon.OriginalFileName; + if (stream != null) _profileCategoryRepository.SaveProfileIconStream(profileConfiguration.Entity, stream); - } } /// @@ -441,8 +438,11 @@ internal class ProfileService : IProfileService profileConfiguration = new ProfileConfiguration(category, profileEntity.Name, "Import"); } - if (exportModel.ProfileImage != null && exportModel.ProfileConfigurationEntity?.IconOriginalFileName != null) - profileConfiguration.Icon.SetIconByStream(exportModel.ProfileConfigurationEntity.IconOriginalFileName, exportModel.ProfileImage); + if (exportModel.ProfileImage != null) + { + profileConfiguration.Icon.SetIconByStream(exportModel.ProfileImage); + SaveProfileConfigurationIcon(profileConfiguration); + } profileConfiguration.Entity.ProfileId = profileEntity.Id; category.AddProfileConfiguration(profileConfiguration, 0); @@ -450,7 +450,7 @@ internal class ProfileService : IProfileService List modules = _pluginManagementService.GetFeaturesOfType(); profileConfiguration.LoadModules(modules); SaveProfileCategory(category); - + return profileConfiguration; } diff --git a/src/Artemis.Storage/Entities/Profile/ProfileConfigurationEntity.cs b/src/Artemis.Storage/Entities/Profile/ProfileConfigurationEntity.cs index e91ddcc96..276b6ec8d 100644 --- a/src/Artemis.Storage/Entities/Profile/ProfileConfigurationEntity.cs +++ b/src/Artemis.Storage/Entities/Profile/ProfileConfigurationEntity.cs @@ -7,7 +7,6 @@ public class ProfileConfigurationEntity { public string Name { get; set; } public string MaterialIcon { get; set; } - public string IconOriginalFileName { get; set; } public Guid FileIconId { get; set; } public int IconType { get; set; } public bool IconFill { get; set; } diff --git a/src/Artemis.Storage/Repositories/ProfileCategoryRepository.cs b/src/Artemis.Storage/Repositories/ProfileCategoryRepository.cs index 573b50a19..71517929f 100644 --- a/src/Artemis.Storage/Repositories/ProfileCategoryRepository.cs +++ b/src/Artemis.Storage/Repositories/ProfileCategoryRepository.cs @@ -70,6 +70,6 @@ internal class ProfileCategoryRepository : IProfileCategoryRepository if (stream == null && _profileIcons.Exists(profileConfigurationEntity.FileIconId)) _profileIcons.Delete(profileConfigurationEntity.FileIconId); - _profileIcons.Upload(profileConfigurationEntity.FileIconId, profileConfigurationEntity.IconOriginalFileName, stream); + _profileIcons.Upload(profileConfigurationEntity.FileIconId, profileConfigurationEntity.FileIconId + ".png", stream); } } \ No newline at end of file