mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 17:33:02 +08:00
Expand available file operations in ArchiveModelManager
This commit is contained in:
parent
eff6af3111
commit
50ba320a51
@ -260,7 +260,7 @@ namespace osu.Game.Beatmaps
|
|||||||
fileInfo.Filename = beatmapInfo.Path;
|
fileInfo.Filename = beatmapInfo.Path;
|
||||||
|
|
||||||
stream.Seek(0, SeekOrigin.Begin);
|
stream.Seek(0, SeekOrigin.Begin);
|
||||||
UpdateFile(setInfo, fileInfo, stream);
|
ReplaceFile(setInfo, fileInfo, stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,29 +401,55 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Update an existing file, or create a new entry if not already part of the <paramref name="model"/>'s files.
|
/// Replace an existing file with a new version.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="model">The item to operate on.</param>
|
/// <param name="model">The item to operate on.</param>
|
||||||
/// <param name="file">The file model to be updated or added.</param>
|
/// <param name="file">The existing file to be replaced.</param>
|
||||||
/// <param name="contents">The new file contents.</param>
|
/// <param name="contents">The new file contents.</param>
|
||||||
public void UpdateFile(TModel model, TFileModel file, Stream contents)
|
/// <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)
|
||||||
|
{
|
||||||
|
using (ContextFactory.GetForWrite())
|
||||||
|
{
|
||||||
|
DeleteFile(model, file);
|
||||||
|
AddFile(model, contents, filename ?? file.Filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete new file.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">The item to operate on.</param>
|
||||||
|
/// <param name="file">The existing file to be deleted.</param>
|
||||||
|
public void DeleteFile(TModel model, TFileModel file)
|
||||||
{
|
{
|
||||||
using (var usage = ContextFactory.GetForWrite())
|
using (var usage = ContextFactory.GetForWrite())
|
||||||
{
|
{
|
||||||
// Dereference the existing file info, since the file model will be removed.
|
// Dereference the existing file info, since the file model will be removed.
|
||||||
if (file.FileInfo != null)
|
if (file.FileInfo != null)
|
||||||
{
|
|
||||||
Files.Dereference(file.FileInfo);
|
Files.Dereference(file.FileInfo);
|
||||||
|
|
||||||
// Remove the file model.
|
// This shouldn't be required, but here for safety in case the provided TModel is not being change tracked
|
||||||
|
// Definitely can be removed once we rework the database backend.
|
||||||
usage.Context.Set<TFileModel>().Remove(file);
|
usage.Context.Set<TFileModel>().Remove(file);
|
||||||
|
|
||||||
|
model.Files.Remove(file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the new file info and containing file model.
|
/// <summary>
|
||||||
model.Files.Remove(file);
|
/// Add a new file.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">The item to operate on.</param>
|
||||||
|
/// <param name="contents">The new file contents.</param>
|
||||||
|
/// <param name="filename">The filename for the new file.</param>
|
||||||
|
public void AddFile(TModel model, Stream contents, string filename)
|
||||||
|
{
|
||||||
|
using (ContextFactory.GetForWrite())
|
||||||
|
{
|
||||||
model.Files.Add(new TFileModel
|
model.Files.Add(new TFileModel
|
||||||
{
|
{
|
||||||
Filename = file.Filename,
|
Filename = filename,
|
||||||
FileInfo = Files.Add(contents)
|
FileInfo = Files.Add(contents)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user