mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 12:33:01 +08:00
Always write automated changes to skin metadata at the end of the file
Apart from being cleaner (and allowing removal at the point of export, if that is ever requires), this also gives us a better guarantee that the metadata is going to take effect. By writing the `[General]` section ourselves, we avoid any issues that may be present from a user constructing the file (incorrectly) themselves, such as multiple `Title:` entries or a malformed `[General]` marker. The main goal is to ensure that the name is updated to what we expect it to be.
This commit is contained in:
parent
ee6af1245c
commit
2e66ab453d
@ -198,48 +198,30 @@ namespace osu.Game.Skinning
|
||||
|
||||
if (existingFile != null)
|
||||
{
|
||||
List<string> outputLines = new List<string>();
|
||||
List<string> additionalLines = new List<string>();
|
||||
|
||||
bool addedName = false;
|
||||
bool addedAuthor = false;
|
||||
|
||||
using (var stream = Files.Storage.GetStream(existingFile.FileInfo.StoragePath))
|
||||
using (var sr = new StreamReader(stream))
|
||||
additionalLines.AddRange(new[]
|
||||
{
|
||||
string line;
|
||||
|
||||
while ((line = sr.ReadLine()) != null)
|
||||
{
|
||||
if (line.StartsWith(@"Name:", StringComparison.Ordinal))
|
||||
{
|
||||
outputLines.Add(nameLine);
|
||||
addedName = true;
|
||||
}
|
||||
else if (line.StartsWith(@"Author:", StringComparison.Ordinal))
|
||||
{
|
||||
outputLines.Add(authorLine);
|
||||
addedAuthor = true;
|
||||
}
|
||||
else
|
||||
outputLines.Add(line);
|
||||
}
|
||||
}
|
||||
|
||||
if (!addedName || !addedAuthor)
|
||||
{
|
||||
outputLines.AddRange(new[]
|
||||
{
|
||||
@"[General]",
|
||||
nameLine,
|
||||
authorLine,
|
||||
});
|
||||
}
|
||||
@"",
|
||||
@"// The following content was automatically added by osu! during import, based on filename / folder metadata.",
|
||||
@"[General]",
|
||||
nameLine,
|
||||
authorLine,
|
||||
});
|
||||
|
||||
using (Stream stream = new MemoryStream())
|
||||
{
|
||||
using (var sw = new StreamWriter(stream, Encoding.UTF8, 1024, true))
|
||||
{
|
||||
foreach (string line in outputLines)
|
||||
using (var existingStream = Files.Storage.GetStream(existingFile.FileInfo.StoragePath))
|
||||
using (var sr = new StreamReader(existingStream))
|
||||
{
|
||||
string line;
|
||||
while ((line = sr.ReadLine()) != null)
|
||||
sw.WriteLine(line);
|
||||
}
|
||||
|
||||
foreach (string line in additionalLines)
|
||||
sw.WriteLine(line);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user