Skip to content

Commit

Permalink
Remove legacy profile import
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertBeekman committed Feb 27, 2024
1 parent 110dee1 commit 1db2888
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 122 deletions.
31 changes: 0 additions & 31 deletions src/Artemis.Core/JsonConverters/StreamConverter.cs

This file was deleted.

This file was deleted.

58 changes: 3 additions & 55 deletions src/Artemis.UI/Screens/Sidebar/SidebarCategoryViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -150,32 +148,16 @@ 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)
return;

try
{
// Removing this at some point in the future
if (result[0].EndsWith("json"))
{
ProfileConfigurationExportModel? exportModel = CoreJson.Deserialize<ProfileConfigurationExportModel>(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)
{
Expand Down Expand Up @@ -229,38 +211,4 @@ private void ApplyCategoryOrder(List<ProfileCategory> categories)
_profileService.SaveProfileCategory(categories[i]);
}
}

private async Task<Stream> 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;
}
}

0 comments on commit 1db2888

Please sign in to comment.