mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 12:17:26 +08:00
Move archive filename helper method to extension method
This commit is contained in:
parent
a0fa030f55
commit
416ee2447a
@ -212,7 +212,7 @@ namespace osu.Game.Beatmaps
|
|||||||
var fileInfo = setInfo.Files.SingleOrDefault(f => string.Equals(f.Filename, beatmapInfo.Path, StringComparison.OrdinalIgnoreCase)) ?? new BeatmapSetFileInfo();
|
var fileInfo = setInfo.Files.SingleOrDefault(f => string.Equals(f.Filename, beatmapInfo.Path, StringComparison.OrdinalIgnoreCase)) ?? new BeatmapSetFileInfo();
|
||||||
|
|
||||||
// metadata may have changed; update the path with the standard format.
|
// metadata may have changed; update the path with the standard format.
|
||||||
beatmapInfo.Path = GetValidFilename($"{metadata.Artist} - {metadata.Title} ({metadata.Author}) [{beatmapInfo.DifficultyName}].osu");
|
beatmapInfo.Path = $"{metadata.Artist} - {metadata.Title} ({metadata.Author}) [{beatmapInfo.DifficultyName}].osu".GetValidArchiveContentFilename();
|
||||||
|
|
||||||
beatmapInfo.MD5Hash = stream.ComputeMD5Hash();
|
beatmapInfo.MD5Hash = stream.ComputeMD5Hash();
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.IO;
|
using osu.Game.IO;
|
||||||
@ -124,5 +125,21 @@ namespace osu.Game.Extensions
|
|||||||
|
|
||||||
return instance.OnlineID.Equals(other.OnlineID);
|
return instance.OnlineID.Equals(other.OnlineID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static readonly char[] invalid_filename_characters = Path.GetInvalidFileNameChars()
|
||||||
|
// Backslash is added to avoid issues when exporting to zip.
|
||||||
|
// See SharpCompress filename normalisation https://github.com/adamhathcock/sharpcompress/blob/a1e7c0068db814c9aa78d86a94ccd1c761af74bd/src/SharpCompress/Writers/Zip/ZipWriter.cs#L143.
|
||||||
|
.Append('\\')
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get a valid filename for use inside a zip file. Avoids backslashes being incorrectly converted to directories.
|
||||||
|
/// </summary>
|
||||||
|
public static string GetValidArchiveContentFilename(this string filename)
|
||||||
|
{
|
||||||
|
foreach (char c in invalid_filename_characters)
|
||||||
|
filename = filename.Replace(c, '_');
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user