mirror of
https://github.com/ppy/osu.git
synced 2025-03-28 10:17:19 +08:00
Disallow archive imports with no hashable files
This commit is contained in:
parent
fa542f2547
commit
439e90fce3
@ -317,14 +317,18 @@ namespace osu.Game.Database
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
protected virtual string ComputeHash(TModel item, ArchiveReader reader = null)
|
protected virtual string ComputeHash(TModel item, ArchiveReader reader = null)
|
||||||
{
|
{
|
||||||
if (reader != null)
|
var hashableFiles = item.Files
|
||||||
// fast hashing for cases where the item's files may not be populated.
|
.Where(f => HashableFileTypes.Any(ext => f.Filename.EndsWith(ext, StringComparison.OrdinalIgnoreCase)))
|
||||||
return computeHashFast(reader);
|
.OrderBy(f => f.Filename)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
if (hashableFiles.Length == 0)
|
||||||
|
throw new InvalidOperationException("Attempted to hash an archive with no files");
|
||||||
|
|
||||||
// for now, concatenate all hashable files in the set to create a unique hash.
|
// for now, concatenate all hashable files in the set to create a unique hash.
|
||||||
MemoryStream hashable = new MemoryStream();
|
MemoryStream hashable = new MemoryStream();
|
||||||
|
|
||||||
foreach (TFileModel file in item.Files.Where(f => HashableFileTypes.Any(ext => f.Filename.EndsWith(ext, StringComparison.OrdinalIgnoreCase))).OrderBy(f => f.Filename))
|
foreach (TFileModel file in hashableFiles)
|
||||||
{
|
{
|
||||||
using (Stream s = Files.Store.GetStream(file.FileInfo.StoragePath))
|
using (Stream s = Files.Store.GetStream(file.FileInfo.StoragePath))
|
||||||
s.CopyTo(hashable);
|
s.CopyTo(hashable);
|
||||||
@ -700,10 +704,10 @@ namespace osu.Game.Database
|
|||||||
s.CopyTo(hashable);
|
s.CopyTo(hashable);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hashable.Length > 0)
|
if (hashable.Length == 0)
|
||||||
return hashable.ComputeSHA2Hash();
|
throw new InvalidOperationException("Attempted to hash an archive with no files");
|
||||||
|
|
||||||
return reader.Name.ComputeSHA2Hash();
|
return hashable.ComputeSHA2Hash();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user