mirror of
https://github.com/ppy/osu.git
synced 2025-01-07 22:16:10 +08:00
Centralise supported file extensions to one helper class
As proposed in https://github.com/ppy/osu-server-beatmap-submission/pull/5#discussion_r1861680837.
This commit is contained in:
parent
d0e80ce982
commit
110e4fbb30
@ -408,7 +408,7 @@ namespace osu.Game.Beatmaps
|
||||
// user requested abort
|
||||
return;
|
||||
|
||||
var video = b.Files.FirstOrDefault(f => OsuGameBase.VIDEO_EXTENSIONS.Any(ex => f.Filename.EndsWith(ex, StringComparison.OrdinalIgnoreCase)));
|
||||
var video = b.Files.FirstOrDefault(f => SupportedExtensions.VIDEO_EXTENSIONS.Any(ex => f.Filename.EndsWith(ex, StringComparison.OrdinalIgnoreCase)));
|
||||
|
||||
if (video != null)
|
||||
{
|
||||
|
@ -17,6 +17,7 @@ using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Objects.Legacy;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using osu.Game.Screens.Edit;
|
||||
using osu.Game.Utils;
|
||||
|
||||
namespace osu.Game.Beatmaps.Formats
|
||||
{
|
||||
@ -446,7 +447,7 @@ namespace osu.Game.Beatmaps.Formats
|
||||
// Some very old beatmaps had incorrect type specifications for their backgrounds (ie. using 1 for VIDEO
|
||||
// instead of 0 for BACKGROUND). To handle this gracefully, check the file extension against known supported
|
||||
// video extensions and handle similar to a background if it doesn't match.
|
||||
if (!OsuGameBase.VIDEO_EXTENSIONS.Contains(Path.GetExtension(filename).ToLowerInvariant()))
|
||||
if (!SupportedExtensions.VIDEO_EXTENSIONS.Contains(Path.GetExtension(filename).ToLowerInvariant()))
|
||||
{
|
||||
beatmap.BeatmapInfo.Metadata.BackgroundFile = filename;
|
||||
lineSupportedByEncoder = true;
|
||||
|
@ -10,6 +10,7 @@ using osu.Game.Beatmaps.Legacy;
|
||||
using osu.Game.IO;
|
||||
using osu.Game.Storyboards;
|
||||
using osu.Game.Storyboards.Commands;
|
||||
using osu.Game.Utils;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
@ -112,7 +113,7 @@ namespace osu.Game.Beatmaps.Formats
|
||||
//
|
||||
// This avoids potential weird crashes when ffmpeg attempts to parse an image file as a video
|
||||
// (see https://github.com/ppy/osu/issues/22829#issuecomment-1465552451).
|
||||
if (!OsuGameBase.VIDEO_EXTENSIONS.Contains(Path.GetExtension(path).ToLowerInvariant()))
|
||||
if (!SupportedExtensions.VIDEO_EXTENSIONS.Contains(Path.GetExtension(path).ToLowerInvariant()))
|
||||
break;
|
||||
|
||||
storyboard.GetLayer("Video").Add(storyboardSprite = new StoryboardVideo(path, offset));
|
||||
|
@ -13,6 +13,7 @@ using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterfaceV2.FileSelection;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Utils;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterfaceV2
|
||||
{
|
||||
@ -96,24 +97,18 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
{
|
||||
get
|
||||
{
|
||||
if (OsuGameBase.VIDEO_EXTENSIONS.Contains(File.Extension.ToLowerInvariant()))
|
||||
string extension = File.Extension.ToLowerInvariant();
|
||||
|
||||
if (SupportedExtensions.VIDEO_EXTENSIONS.Contains(extension))
|
||||
return FontAwesome.Regular.FileVideo;
|
||||
|
||||
switch (File.Extension)
|
||||
{
|
||||
case @".ogg":
|
||||
case @".mp3":
|
||||
case @".wav":
|
||||
return FontAwesome.Regular.FileAudio;
|
||||
if (SupportedExtensions.AUDIO_EXTENSIONS.Contains(extension))
|
||||
return FontAwesome.Regular.FileAudio;
|
||||
|
||||
case @".jpg":
|
||||
case @".jpeg":
|
||||
case @".png":
|
||||
return FontAwesome.Regular.FileImage;
|
||||
if (SupportedExtensions.IMAGE_EXTENSIONS.Contains(extension))
|
||||
return FontAwesome.Regular.FileImage;
|
||||
|
||||
default:
|
||||
return FontAwesome.Regular.File;
|
||||
}
|
||||
return FontAwesome.Regular.File;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,8 +73,6 @@ namespace osu.Game
|
||||
[Cached(typeof(OsuGameBase))]
|
||||
public partial class OsuGameBase : Framework.Game, ICanAcceptFiles, IBeatSyncProvider
|
||||
{
|
||||
public static readonly string[] VIDEO_EXTENSIONS = { ".mp4", ".mov", ".avi", ".flv", ".mpg", ".wmv", ".m4v" };
|
||||
|
||||
#if DEBUG
|
||||
public const string GAME_NAME = "osu! (development)";
|
||||
#else
|
||||
|
@ -35,6 +35,7 @@ using osu.Game.Screens.Edit.Components.Menus;
|
||||
using osu.Game.Skinning;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.Utils;
|
||||
|
||||
namespace osu.Game.Overlays.SkinEditor
|
||||
{
|
||||
@ -709,7 +710,7 @@ namespace osu.Game.Overlays.SkinEditor
|
||||
|
||||
Task ICanAcceptFiles.Import(ImportTask[] tasks, ImportParameters parameters) => throw new NotImplementedException();
|
||||
|
||||
public IEnumerable<string> HandledExtensions => new[] { ".jpg", ".jpeg", ".png" };
|
||||
public IEnumerable<string> HandledExtensions => SupportedExtensions.IMAGE_EXTENSIONS;
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -3,13 +3,12 @@
|
||||
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using osu.Game.Utils;
|
||||
|
||||
namespace osu.Game.Rulesets.Edit.Checks.Components
|
||||
{
|
||||
public static class AudioCheckUtils
|
||||
{
|
||||
public static readonly string[] AUDIO_EXTENSIONS = { "mp3", "ogg", "wav" };
|
||||
|
||||
public static bool HasAudioExtension(string filename) => AUDIO_EXTENSIONS.Any(Path.GetExtension(filename).ToLowerInvariant().EndsWith);
|
||||
public static bool HasAudioExtension(string filename) => SupportedExtensions.AUDIO_EXTENSIONS.Contains(Path.GetExtension(filename).ToLowerInvariant());
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics.UserInterfaceV2;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Localisation;
|
||||
using osu.Game.Utils;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Setup
|
||||
{
|
||||
@ -48,12 +49,14 @@ namespace osu.Game.Screens.Edit.Setup
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
backgroundChooser = new FormFileSelector(".jpg", ".jpeg", ".png")
|
||||
backgroundChooser = new FormFileSelector(SupportedExtensions.IMAGE_EXTENSIONS)
|
||||
{
|
||||
Caption = GameplaySettingsStrings.BackgroundHeader,
|
||||
PlaceholderText = EditorSetupStrings.ClickToSelectBackground,
|
||||
},
|
||||
audioTrackChooser = new FormFileSelector(".mp3", ".ogg")
|
||||
// `SupportedExtensions.AUDIO_EXTENSIONS` not used here specifically it includes `.wav` for samples, which is strictly disallowed by ranking criteria
|
||||
// (https://osu.ppy.sh/wiki/en/Ranking_criteria#audio)
|
||||
audioTrackChooser = new FormFileSelector(@".mp3", @".ogg")
|
||||
{
|
||||
Caption = EditorSetupStrings.AudioTrack,
|
||||
PlaceholderText = EditorSetupStrings.ClickToSelectTrack,
|
||||
|
@ -1,8 +1,8 @@
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
@ -14,6 +14,7 @@ using osu.Game.Configuration;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Localisation.SkinComponents;
|
||||
using osu.Game.Overlays.Settings;
|
||||
using osu.Game.Utils;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Skinning
|
||||
@ -93,10 +94,10 @@ namespace osu.Game.Skinning
|
||||
// but that requires further thought.
|
||||
var highestPrioritySkin = getHighestPriorityUserSkin(((SkinnableSprite)SettingSourceObject).source.AllSources) as Skin;
|
||||
|
||||
string[]? availableFiles = highestPrioritySkin?.SkinInfo.PerformRead(s => s.Files
|
||||
.Where(f => f.Filename.EndsWith(".png", StringComparison.Ordinal)
|
||||
|| f.Filename.EndsWith(".jpg", StringComparison.Ordinal))
|
||||
.Select(f => f.Filename).Distinct()).ToArray();
|
||||
string[]? availableFiles = highestPrioritySkin?.SkinInfo.PerformRead(
|
||||
s => s.Files
|
||||
.Where(f => SupportedExtensions.IMAGE_EXTENSIONS.Contains(Path.GetExtension(f.Filename).ToLowerInvariant()))
|
||||
.Select(f => f.Filename).Distinct()).ToArray();
|
||||
|
||||
if (availableFiles?.Length > 0)
|
||||
Items = availableFiles;
|
||||
|
@ -7,6 +7,7 @@ using System.Linq;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Storyboards.Drawables;
|
||||
using osu.Game.Utils;
|
||||
|
||||
namespace osu.Game.Storyboards
|
||||
{
|
||||
@ -96,8 +97,6 @@ namespace osu.Game.Storyboards
|
||||
public virtual DrawableStoryboard CreateDrawable(IReadOnlyList<Mod>? mods = null) =>
|
||||
new DrawableStoryboard(this, mods);
|
||||
|
||||
private static readonly string[] image_extensions = { @".png", @".jpg" };
|
||||
|
||||
public virtual string? GetStoragePathFromStoryboardPath(string path)
|
||||
{
|
||||
string? resolvedPath = null;
|
||||
@ -109,7 +108,7 @@ namespace osu.Game.Storyboards
|
||||
else
|
||||
{
|
||||
// Some old storyboards don't include a file extension, so let's best guess at one.
|
||||
foreach (string ext in image_extensions)
|
||||
foreach (string ext in SupportedExtensions.IMAGE_EXTENSIONS)
|
||||
{
|
||||
if ((resolvedPath = BeatmapInfo.BeatmapSet?.GetPathForFile($"{path}{ext}")) != null)
|
||||
break;
|
||||
|
19
osu.Game/Utils/SupportedExtensions.cs
Normal file
19
osu.Game/Utils/SupportedExtensions.cs
Normal file
@ -0,0 +1,19 @@
|
||||
// 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.
|
||||
|
||||
namespace osu.Game.Utils
|
||||
{
|
||||
public static class SupportedExtensions
|
||||
{
|
||||
public static readonly string[] VIDEO_EXTENSIONS = [@".mp4", @".mov", @".avi", @".flv", @".mpg", @".wmv", @".m4v"];
|
||||
public static readonly string[] AUDIO_EXTENSIONS = [@".mp3", @".ogg", @".wav"];
|
||||
public static readonly string[] IMAGE_EXTENSIONS = [@".jpg", @".jpeg", @".png"];
|
||||
|
||||
public static readonly string[] ALL_EXTENSIONS =
|
||||
[
|
||||
..VIDEO_EXTENSIONS,
|
||||
..AUDIO_EXTENSIONS,
|
||||
..IMAGE_EXTENSIONS
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user