mirror of
https://github.com/ppy/osu
synced 2025-01-08 23:29:43 +00:00
Use temporary storage for exported files on iOS
This commit is contained in:
parent
1b8d9370aa
commit
0c0dcb1e15
@ -3,12 +3,14 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Extensions;
|
||||
using osu.Game.IO;
|
||||
using osu.Game.Overlays.Notifications;
|
||||
using osu.Game.Utils;
|
||||
using Realms;
|
||||
@ -40,13 +42,15 @@ namespace osu.Game.Database
|
||||
protected abstract string FileExtension { get; }
|
||||
|
||||
protected readonly Storage UserFileStorage;
|
||||
private readonly Storage exportStorage;
|
||||
private readonly Storage? exportStorage;
|
||||
|
||||
public Action<Notification>? PostNotification { get; set; }
|
||||
|
||||
protected LegacyExporter(Storage storage)
|
||||
{
|
||||
exportStorage = storage.GetStorageForDirectory(@"exports");
|
||||
if (storage is OsuStorage osuStorage)
|
||||
exportStorage = osuStorage.GetExportStorage();
|
||||
|
||||
UserFileStorage = storage.GetStorageForDirectory(@"files");
|
||||
}
|
||||
|
||||
@ -68,6 +72,8 @@ namespace osu.Game.Database
|
||||
/// <param name="cancellationToken">A cancellation token.</param>
|
||||
public async Task ExportAsync(Live<TModel> model, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Debug.Assert(exportStorage != null);
|
||||
|
||||
string itemFilename = model.PerformRead(s => GetFilename(s).GetValidFilename());
|
||||
|
||||
if (itemFilename.Length > MAX_FILENAME_LENGTH - FileExtension.Length)
|
||||
|
@ -61,6 +61,11 @@ namespace osu.Game.IO
|
||||
TryChangeToCustomStorage(out Error);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Storage"/> used for storing exported files.
|
||||
/// </summary>
|
||||
public virtual Storage GetExportStorage() => GetStorageForDirectory(@"exports");
|
||||
|
||||
/// <summary>
|
||||
/// Resets the custom storage path, changing the target storage to the default location.
|
||||
/// </summary>
|
||||
|
@ -5,6 +5,8 @@ using System;
|
||||
using Foundation;
|
||||
using Microsoft.Maui.Devices;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.iOS;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game;
|
||||
using osu.Game.Updater;
|
||||
using osu.Game.Utils;
|
||||
@ -19,6 +21,8 @@ namespace osu.iOS
|
||||
|
||||
protected override BatteryInfo CreateBatteryInfo() => new IOSBatteryInfo();
|
||||
|
||||
protected override Storage CreateStorage(GameHost host, Storage defaultStorage) => new OsuStorageIOS((IOSGameHost)host, defaultStorage);
|
||||
|
||||
protected override Edges SafeAreaOverrideEdges =>
|
||||
// iOS shows a home indicator at the bottom, and adds a safe area to account for this.
|
||||
// Because we have the home indicator (mostly) hidden we don't really care about drawing in this region.
|
||||
|
23
osu.iOS/OsuStorageIOS.cs
Normal file
23
osu.iOS/OsuStorageIOS.cs
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.IO;
|
||||
using osu.Framework.iOS;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.IO;
|
||||
|
||||
namespace osu.iOS
|
||||
{
|
||||
public class OsuStorageIOS : OsuStorage
|
||||
{
|
||||
private readonly IOSGameHost host;
|
||||
|
||||
public OsuStorageIOS(IOSGameHost host, Storage defaultStorage)
|
||||
: base(host, defaultStorage)
|
||||
{
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public override Storage GetExportStorage() => new IOSStorage(Path.GetTempPath(), host);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user