diff --git a/osu.Game/Graphics/ScreenshotManager.cs b/osu.Game/Graphics/ScreenshotManager.cs index 8e0c2cce50..f1477f6b6c 100644 --- a/osu.Game/Graphics/ScreenshotManager.cs +++ b/osu.Game/Graphics/ScreenshotManager.cs @@ -45,7 +45,7 @@ namespace osu.Game.Graphics { host.TakeScreenshot(screenshotBitmap => { - var stream = storage.GetStream($"{DateTime.Now:yyyyMMddTHHmmss}.{screenshotFormat.ToString().ToLower()}", FileAccess.Write); + var stream = getFileStream(); switch (screenshotFormat.Value) { @@ -60,5 +60,23 @@ namespace osu.Game.Graphics } }); } + + private Stream getFileStream() + { + var fileExt = screenshotFormat.ToString().ToLower(); + + var withoutIndex = $"Screenshot.{fileExt}"; + if (!storage.Exists(withoutIndex)) + return storage.GetStream(withoutIndex, FileAccess.Write); + + for (ulong i = 1; i < ulong.MaxValue; i++) + { + var indexedName = $"Screenshot-{i}.{fileExt}"; + if (!storage.Exists(indexedName)) + return storage.GetStream(indexedName, FileAccess.Write); + } + + throw new Exception($"Failed to get stream for saving {fileExt} file"); + } } }