mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 16:59:53 +09:00
create NamingUtils.GetNextBestFilename()
This commit is contained in:
@ -1,7 +1,9 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace osu.Game.Utils
|
namespace osu.Game.Utils
|
||||||
@ -57,5 +59,19 @@ namespace osu.Game.Utils
|
|||||||
? desiredName
|
? desiredName
|
||||||
: $"{desiredName} ({bestNumber})";
|
: $"{desiredName} ({bestNumber})";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Given a set of <paramref name="existingFilenames"/> and a desired target <paramref name="desiredName"/>
|
||||||
|
/// finds a filename closest to <paramref name="desiredName"/> that is not in <paramref name="existingFilenames"/>
|
||||||
|
/// <remarks>
|
||||||
|
/// <paramref name="desiredName"/> SHOULD NOT CONTAIN the file extension.
|
||||||
|
/// </remarks>
|
||||||
|
/// </summary>
|
||||||
|
public static string GetNextBestFilename(IEnumerable<string> existingFilenames, string desiredName, string fileExtension)
|
||||||
|
{
|
||||||
|
var stripped = existingFilenames.Select(filename => filename.Substring(0, filename.Length - fileExtension.Length));
|
||||||
|
|
||||||
|
return $"{GetNextBestName(stripped, desiredName)}{fileExtension}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user