Merge pull request #15856 from peppy/simplify-replace-file

Remove the ability to specify a filename in `ReplaceFile`
This commit is contained in:
Dan Balasescu 2021-11-29 20:49:38 +09:00 committed by GitHub
commit 823552a5e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 14 deletions

View File

@ -288,9 +288,9 @@ public Task<ILive<BeatmapSetInfo>> Import(BeatmapSetInfo item, ArchiveReader arc
#region Implementation of IModelFileManager<in BeatmapSetInfo,in BeatmapSetFileInfo>
public void ReplaceFile(BeatmapSetInfo model, BeatmapSetFileInfo file, Stream contents, string filename = null)
public void ReplaceFile(BeatmapSetInfo model, BeatmapSetFileInfo file, Stream contents)
{
beatmapModelManager.ReplaceFile(model, file, contents, filename);
beatmapModelManager.ReplaceFile(model, file, contents);
}
public void DeleteFile(BeatmapSetInfo model, BeatmapSetFileInfo file)

View File

@ -453,13 +453,12 @@ void rollback()
/// <param name="model">The item to operate on.</param>
/// <param name="file">The existing file to be replaced.</param>
/// <param name="contents">The new file contents.</param>
/// <param name="filename">An optional filename for the new file. Will use the previous filename if not specified.</param>
public void ReplaceFile(TModel model, TFileModel file, Stream contents, string filename = null)
public void ReplaceFile(TModel model, TFileModel file, Stream contents)
{
using (ContextFactory.GetForWrite())
{
DeleteFile(model, file);
AddFile(model, contents, filename ?? file.Filename);
AddFile(model, contents, file.Filename);
}
}

View File

@ -15,8 +15,7 @@ public interface IModelFileManager<in TModel, in TFileModel>
/// <param name="model">The item to operate on.</param>
/// <param name="file">The existing file to be replaced.</param>
/// <param name="contents">The new file contents.</param>
/// <param name="filename">An optional filename for the new file. Will use the previous filename if not specified.</param>
void ReplaceFile(TModel model, TFileModel file, Stream contents, string filename = null);
void ReplaceFile(TModel model, TFileModel file, Stream contents);
/// <summary>
/// Delete an existing file.

View File

@ -78,9 +78,9 @@ public bool ChangeBackgroundImage(string path)
using (var stream = info.OpenRead())
{
if (oldFile != null)
beatmaps.ReplaceFile(set, oldFile, stream, info.Name);
else
beatmaps.AddFile(set, stream, info.Name);
beatmaps.DeleteFile(set, oldFile);
beatmaps.AddFile(set, stream, info.Name);
}
working.Value.Metadata.BackgroundFile = info.Name;
@ -105,9 +105,8 @@ public bool ChangeAudioTrack(string path)
using (var stream = info.OpenRead())
{
if (oldFile != null)
beatmaps.ReplaceFile(set, oldFile, stream, info.Name);
else
beatmaps.AddFile(set, stream, info.Name);
beatmaps.DeleteFile(set, oldFile);
beatmaps.AddFile(set, stream, info.Name);
}
working.Value.Metadata.AudioFile = info.Name;

View File

@ -171,7 +171,7 @@ public void Save(Skin skin)
var oldFile = skin.SkinInfo.Files.FirstOrDefault(f => f.Filename == filename);
if (oldFile != null)
skinModelManager.ReplaceFile(skin.SkinInfo, oldFile, streamContent, oldFile.Filename);
skinModelManager.ReplaceFile(skin.SkinInfo, oldFile, streamContent);
else
skinModelManager.AddFile(skin.SkinInfo, streamContent, filename);
}