mirror of
https://github.com/osukey/osukey.git
synced 2025-05-30 01:47:30 +09:00
Rename and add documentation to function
This commit is contained in:
parent
6901ed997d
commit
66ed77ac91
@ -340,7 +340,7 @@ namespace osu.Game.Beatmaps
|
|||||||
static string createBeatmapFilenameFromMetadata(BeatmapInfo beatmapInfo)
|
static string createBeatmapFilenameFromMetadata(BeatmapInfo beatmapInfo)
|
||||||
{
|
{
|
||||||
var metadata = beatmapInfo.Metadata;
|
var metadata = beatmapInfo.Metadata;
|
||||||
return $"{metadata.Artist} - {metadata.Title} ({metadata.Author.Username}) [{beatmapInfo.DifficultyName}].osu".GetValidArchiveContentFilename();
|
return $"{metadata.Artist} - {metadata.Title} ({metadata.Author.Username}) [{beatmapInfo.DifficultyName}].osu".GetValidFilename();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ namespace osu.Game.Database
|
|||||||
/// <param name="item">The item to export.</param>
|
/// <param name="item">The item to export.</param>
|
||||||
public void Export(TModel item)
|
public void Export(TModel item)
|
||||||
{
|
{
|
||||||
string filename = $"{item.GetDisplayString().GetValidArchiveContentFilename()}{FileExtension}";
|
string filename = $"{item.GetDisplayString().GetValidFilename()}{FileExtension}";
|
||||||
|
|
||||||
using (var stream = exportStorage.CreateFileSafely(filename))
|
using (var stream = exportStorage.CreateFileSafely(filename))
|
||||||
ExportModelTo(item, stream);
|
ExportModelTo(item, stream);
|
||||||
|
@ -15,6 +15,8 @@ namespace osu.Game.Extensions
|
|||||||
{
|
{
|
||||||
public static class ModelExtensions
|
public static class ModelExtensions
|
||||||
{
|
{
|
||||||
|
private static readonly Regex invalid_filename_chars = new Regex(@"(?!$)[^A-Za-z0-9_()[\]. \-]", RegexOptions.Compiled);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the relative path in osu! storage for this file.
|
/// Get the relative path in osu! storage for this file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -137,14 +139,14 @@ namespace osu.Game.Extensions
|
|||||||
return instance.OnlineID.Equals(other.OnlineID);
|
return instance.OnlineID.Equals(other.OnlineID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly Regex invalid_filename_chars = new Regex(@"(?!$)[^A-Za-z0-9_()[\]. \-]", RegexOptions.Compiled);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a valid filename for use inside a zip file. Avoids backslashes being incorrectly converted to directories.
|
/// Create a valid filename which should work across all platforms.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string GetValidArchiveContentFilename(this string filename)
|
/// <remarks>
|
||||||
{
|
/// This function replaces all characters not included in a very pessimistic list which should be compatible
|
||||||
return invalid_filename_chars.Replace(filename, "_");
|
/// across all operating systems. We are using this in place of <see cref="Path.GetInvalidFileNameChars"/> as
|
||||||
}
|
/// that function does not have per-platform considerations (and is only made to work on windows).
|
||||||
|
/// </remarks>
|
||||||
|
public static string GetValidFilename(this string filename) => invalid_filename_chars.Replace(filename, "_");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user