Merge branch 'safe-file-writes' into localisable-filter-items

This commit is contained in:
Dean Herbert 2022-05-20 23:51:24 +09:00
commit 2b3ec53fed
15 changed files with 33 additions and 13 deletions

View File

@ -507,7 +507,7 @@ namespace osu.Game.Tests.Database
using (var stream = storage.GetStream(firstFile.File.GetStoragePath()))
originalLength = stream.Length;
using (var stream = storage.GetStream(firstFile.File.GetStoragePath(), FileAccess.Write, FileMode.Create))
using (var stream = storage.CreateFileSafely(firstFile.File.GetStoragePath()))
stream.WriteByte(0);
var importedSecondTime = await LoadOszIntoStore(importer, realm.Realm);

View File

@ -1,7 +1,6 @@
// 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 System.Linq;
using System.Runtime.InteropServices;
using NUnit.Framework;
@ -25,7 +24,7 @@ namespace osu.Game.Tests.Visual.Navigation
if (isDisposing)
return;
using (var outStream = LocalStorage.GetStream(DatabaseContextFactory.DATABASE_NAME, FileAccess.Write, FileMode.Create))
using (var outStream = LocalStorage.CreateFileSafely(DatabaseContextFactory.DATABASE_NAME))
using (var stream = TestResources.OpenResource(DatabaseContextFactory.DATABASE_NAME))
stream.CopyTo(outStream);
}

View File

@ -28,7 +28,7 @@ namespace osu.Game.Tournament.Tests.NonVisual
// ReSharper disable once AccessToDisposedClosure
var storage = host.Storage.GetStorageForDirectory(Path.Combine("tournaments", "default"));
using (var stream = storage.GetStream("bracket.json", FileAccess.Write, FileMode.Create))
using (var stream = storage.CreateFileSafely("bracket.json"))
using (var writer = new StreamWriter(stream))
{
writer.Write(@"{

View File

@ -15,7 +15,7 @@ namespace osu.Game.Tournament.Tests.Screens
[BackgroundDependencyLoader]
private void load(Storage storage)
{
using (var stream = storage.GetStream("drawings.txt", FileAccess.Write))
using (var stream = storage.CreateFileSafely("drawings.txt"))
using (var writer = new StreamWriter(stream))
{
writer.WriteLine("KR : South Korea : KOR");

View File

@ -45,7 +45,7 @@ namespace osu.Game.Tournament.Models
public void SaveChanges()
{
using (var stream = configStorage.GetStream(config_path, FileAccess.Write, FileMode.Create))
using (var stream = configStorage.CreateFileSafely(config_path))
using (var sw = new StreamWriter(stream))
{
sw.Write(JsonConvert.SerializeObject(this,

View File

@ -205,7 +205,7 @@ namespace osu.Game.Tournament.Screens.Drawings
try
{
// Write to drawings_results
using (Stream stream = storage.GetStream(results_filename, FileAccess.Write, FileMode.Create))
using (Stream stream = storage.CreateFileSafely(results_filename))
using (StreamWriter sw = new StreamWriter(stream))
{
sw.Write(text);

View File

@ -321,7 +321,7 @@ namespace osu.Game.Tournament
Converters = new JsonConverter[] { new JsonPointConverter() }
});
using (var stream = storage.GetStream(BRACKET_FILENAME, FileAccess.Write, FileMode.Create))
using (var stream = storage.CreateFileSafely(BRACKET_FILENAME))
using (var sw = new StreamWriter(stream))
sw.Write(serialisedLadder);
}

View File

@ -37,7 +37,7 @@ namespace osu.Game.Database
{
string filename = $"{item.GetDisplayString().GetValidArchiveContentFilename()}{FileExtension}";
using (var stream = exportStorage.GetStream(filename, FileAccess.Write, FileMode.Create))
using (var stream = exportStorage.CreateFileSafely(filename))
ExportModelTo(item, stream);
exportStorage.PresentFileExternally(filename);

View File

@ -242,7 +242,7 @@ namespace osu.Game.Database
storage.Delete(Filename);
using (var inputStream = storage.GetStream(recoveryFilename))
using (var outputStream = storage.GetStream(Filename, FileAccess.Write, FileMode.Create))
using (var outputStream = storage.CreateFileSafely(Filename))
inputStream.CopyTo(outputStream);
storage.Delete(recoveryFilename);

View File

@ -118,7 +118,7 @@ namespace osu.Game.Graphics
if (filename == null) return;
using (var stream = storage.GetStream(filename, FileAccess.Write))
using (var stream = storage.CreateFileSafely(filename))
{
switch (screenshotFormat.Value)
{

View File

@ -67,9 +67,13 @@ namespace osu.Game.IO
public override IEnumerable<string> GetFiles(string path, string pattern = "*") =>
ToLocalRelative(UnderlyingStorage.GetFiles(MutatePath(path), pattern));
public override Stream CreateFileSafely(string path) => UnderlyingStorage.CreateFileSafely(path);
public override Stream GetStream(string path, FileAccess access = FileAccess.Read, FileMode mode = FileMode.OpenOrCreate) =>
UnderlyingStorage.GetStream(MutatePath(path), access, mode);
public override void Move(string from, string to) => UnderlyingStorage.Move(from, to);
public override bool OpenFileExternally(string filename) => UnderlyingStorage.OpenFileExternally(MutatePath(filename));
public override bool PresentFileExternally(string filename) => UnderlyingStorage.PresentFileExternally(MutatePath(filename));

View File

@ -1207,6 +1207,8 @@ namespace osu.Game
Current = newScreen?.GetType().ReadableName(),
Previous = current?.GetType().ReadableName(),
};
scope.SetTag(@"screen", newScreen?.GetType().ReadableName() ?? @"none");
});
switch (newScreen)

View File

@ -243,7 +243,7 @@ namespace osu.Game
{
if (source != null)
{
using (var destination = Storage.GetStream(Path.Combine(backup_folder, $"collection.{migration}.db"), FileAccess.Write, FileMode.CreateNew))
using (var destination = Storage.CreateFileSafely(Path.Combine(backup_folder, $"collection.{migration}.db")))
source.CopyTo(destination);
}
}

View File

@ -65,7 +65,7 @@ namespace osu.Game.Stores
{
data.Seek(0, SeekOrigin.Begin);
using (var output = Storage.GetStream(file.GetStoragePath(), FileAccess.Write))
using (var output = Storage.CreateFileSafely(file.GetStoragePath()))
data.CopyTo(output);
data.Seek(0, SeekOrigin.Begin);

View File

@ -18,6 +18,7 @@ using osu.Game.Database;
using osu.Game.Models;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays;
using osu.Game.Rulesets;
using osu.Game.Skinning;
using Sentry;
using Sentry.Protocol;
@ -109,6 +110,7 @@ namespace osu.Game.Utils
}, scope =>
{
var beatmap = game.Dependencies.Get<IBindable<WorkingBeatmap>>().Value.BeatmapInfo;
var ruleset = game.Dependencies.Get<IBindable<RulesetInfo>>().Value;
scope.Contexts[@"config"] = new
{
@ -125,6 +127,8 @@ namespace osu.Game.Utils
BeatmapSets = realm.All<BeatmapSetInfo>().Count(),
Beatmaps = realm.All<BeatmapInfo>().Count(),
Files = realm.All<RealmFile>().Count(),
Rulesets = realm.All<RulesetInfo>().Count(),
RulesetsAvailable = realm.All<RulesetInfo>().Count(r => r.Available),
Skins = realm.All<SkinInfo>().Count(),
}
};
@ -137,14 +141,25 @@ namespace osu.Game.Utils
scope.Contexts[@"beatmap"] = new
{
Name = beatmap.ToString(),
Ruleset = beatmap.Ruleset.InstantiationInfo,
beatmap.OnlineID,
};
scope.Contexts[@"ruleset"] = new
{
ruleset.ShortName,
ruleset.Name,
ruleset.InstantiationInfo,
ruleset.OnlineID
};
scope.Contexts[@"clocks"] = new
{
Audio = game.Dependencies.Get<MusicController>().CurrentTrack.CurrentTime,
Game = game.Clock.CurrentTime,
};
scope.SetTag(@"ruleset", ruleset.ShortName);
});
}
else