mirror of
https://github.com/ppy/osu.git
synced 2026-06-02 23:41:00 +08:00
Add a toggle for checking overwriting
The GetFile method in AddFile has a huge overhead, given we're doing this in a loop. Since we clear the files in the skin, we already know there won't be any existing files, so we can skip all of that logic
This commit is contained in:
@@ -81,16 +81,19 @@ namespace osu.Game.Database
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a file from within an ongoing realm transaction. If the file already exists, it is overwritten.
|
||||
/// Add a file from within an ongoing realm transaction. If the file already exists, it is overwritten so long as <paramref name="overwrite"/> is true.
|
||||
/// </summary>
|
||||
public void AddFile(TModel item, Stream contents, string filename, Realm realm)
|
||||
public void AddFile(TModel item, Stream contents, string filename, Realm realm, bool overwrite = true)
|
||||
{
|
||||
var existing = item.GetFile(filename);
|
||||
|
||||
if (existing != null)
|
||||
if (overwrite)
|
||||
{
|
||||
ReplaceFile(existing, contents, realm);
|
||||
return;
|
||||
var existing = item.GetFile(filename);
|
||||
|
||||
if (existing != null)
|
||||
{
|
||||
ReplaceFile(existing, contents, realm);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var file = realmFileStore.Add(contents, realm);
|
||||
|
||||
@@ -59,6 +59,7 @@ namespace osu.Game.Skinning
|
||||
|
||||
skinInfoLive.PerformWrite(skinInfo =>
|
||||
{
|
||||
// Not sure if this deletes the files from the storage or just the database.
|
||||
skinInfo.Files.Clear();
|
||||
|
||||
string[] filesInMountedDirectory = Directory.EnumerateFiles(task.Path, "*.*", SearchOption.AllDirectories).Select(f => Path.GetRelativePath(task.Path, f)).ToArray();
|
||||
@@ -67,9 +68,7 @@ namespace osu.Game.Skinning
|
||||
{
|
||||
using var stream = File.OpenRead(Path.Combine(task.Path, file));
|
||||
|
||||
// The GetFile call in this method is *really* expensive, and we are certain that the file does not exist in the skin yet.
|
||||
// Consider adding a method to add a file without checking if it already exists. Or add the file directly to the skin.
|
||||
modelManager.AddFile(original, stream, file);
|
||||
modelManager.AddFile(original, stream, file, Realm.Realm, false);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user