1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-27 00:20:50 +08:00

Abstract out logic to SkinImporter

This commit is contained in:
smallketchup82
2024-09-23 09:47:33 -04:00
Unverified
parent 9de248f5d7
commit a20bd5cc3d
2 changed files with 29 additions and 29 deletions
+1 -27
View File
@@ -318,32 +318,7 @@ namespace osu.Game.Overlays.SkinEditor
mountMenuItem.Action.Disabled = true;
await Task.Run(() =>
{
currentSkin.Value.SkinInfo.PerformWrite(skinInfo =>
{
// Clear files in the skin
skinInfo.Files.Clear();
// Get all the files in the mounted directory and add them to the skin
string[] filesInMounted = Directory.EnumerateFiles(externalEditOperation.MountedPath, "*.*", SearchOption.AllDirectories).Select(f => Path.GetRelativePath(externalEditOperation.MountedPath, f)).ToArray();
foreach (string file in filesInMounted)
{
using var stream = File.OpenRead(Path.Combine(externalEditOperation.MountedPath, file));
// The GetFile call in this method is really expensive, and we are certain that the file does not exist in the skin yet.
// Consider adding a method to add a file without checking if it exists. Or add the file directly to the skin.
skins.AddFile(skinInfo, stream, file);
}
});
try
{
Directory.Delete(externalEditOperation.MountedPath, true);
}
catch { }
}).ConfigureAwait(false);
await externalEditOperation.Finish().ConfigureAwait(false);
Schedule(() =>
{
@@ -354,7 +329,6 @@ namespace osu.Game.Overlays.SkinEditor
// If there's a better way to reload the skin, this should be replaced with it.
currentSkin.Value = newSkinInfo.CreateInstance(skins);
// Dispose the old skin to ensure it's no longer used
oldskin.Dispose();
mountMenuItem.Action.Disabled = false;
+28 -2
View File
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -45,9 +46,34 @@ namespace osu.Game.Skinning
private const string unknown_creator_string = @"Unknown";
public override async Task<Live<SkinInfo>?> ImportAsUpdate(ProgressNotification notification, ImportTask task, SkinInfo original)
/// <summary>
/// Update an existing skin with the contents of a path
/// </summary>
/// <param name="notification">The progress notification</param>
/// <param name="task">The <see cref="ImportTask"/> to update the <paramref name="original"/> with</param>
/// <param name="original">The <see cref="SkinInfo"/> to update</param>
/// <returns></returns>
public override Task<Live<SkinInfo>?> ImportAsUpdate(ProgressNotification notification, ImportTask task, SkinInfo original)
{
throw new NotImplementedException();
var skinInfoLive = original.ToLive(Realm);
skinInfoLive.PerformWrite(skinInfo =>
{
skinInfo.Files.Clear();
string[] filesInMountedDirectory = Directory.EnumerateFiles(task.Path, "*.*", SearchOption.AllDirectories).Select(f => Path.GetRelativePath(task.Path, f)).ToArray();
foreach (string file in filesInMountedDirectory)
{
using var stream = File.OpenRead(Path.Combine(task.Path, file));
// The GetFile call in this method is *really* expensive, and we are certain that the file does not exist in the skin yet.
// Consider adding a method to add a file without checking if it already exists. Or add the file directly to the skin.
modelManager.AddFile(original, stream, file);
}
});
return Task.FromResult(skinInfoLive)!;
}
protected override void Populate(SkinInfo model, ArchiveReader? archive, Realm realm, CancellationToken cancellationToken = default)