mirror of
https://github.com/ppy/osu.git
synced 2025-01-29 02:03:22 +08:00
Merge pull request #6853 from peppy/dedupe-same-hash
Disallow .osu files with the same file content from being imported when in the same set
This commit is contained in:
commit
7b062b4de4
@ -411,6 +411,48 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task TestImportWithDuplicateHashes()
|
||||||
|
{
|
||||||
|
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(TestImportNestedStructure)))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var osu = loadOsu(host);
|
||||||
|
|
||||||
|
var temp = TestResources.GetTestBeatmapForImport();
|
||||||
|
|
||||||
|
string extractedFolder = $"{temp}_extracted";
|
||||||
|
Directory.CreateDirectory(extractedFolder);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var zip = ZipArchive.Open(temp))
|
||||||
|
zip.WriteToDirectory(extractedFolder);
|
||||||
|
|
||||||
|
using (var zip = ZipArchive.Create())
|
||||||
|
{
|
||||||
|
zip.AddAllFromDirectory(extractedFolder);
|
||||||
|
zip.AddEntry("duplicate.osu", Directory.GetFiles(extractedFolder, "*.osu").First());
|
||||||
|
zip.SaveTo(temp, new ZipWriterOptions(CompressionType.Deflate));
|
||||||
|
}
|
||||||
|
|
||||||
|
await osu.Dependencies.Get<BeatmapManager>().Import(temp);
|
||||||
|
|
||||||
|
ensureLoaded(osu);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Directory.Delete(extractedFolder, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
host.Exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task TestImportNestedStructure()
|
public async Task TestImportNestedStructure()
|
||||||
{
|
{
|
||||||
|
@ -296,8 +296,13 @@ namespace osu.Game.Beatmaps
|
|||||||
var decoder = Decoder.GetDecoder<Beatmap>(sr);
|
var decoder = Decoder.GetDecoder<Beatmap>(sr);
|
||||||
IBeatmap beatmap = decoder.Decode(sr);
|
IBeatmap beatmap = decoder.Decode(sr);
|
||||||
|
|
||||||
|
string hash = ms.ComputeSHA2Hash();
|
||||||
|
|
||||||
|
if (beatmapInfos.Any(b => b.Hash == hash))
|
||||||
|
continue;
|
||||||
|
|
||||||
beatmap.BeatmapInfo.Path = file.Filename;
|
beatmap.BeatmapInfo.Path = file.Filename;
|
||||||
beatmap.BeatmapInfo.Hash = ms.ComputeSHA2Hash();
|
beatmap.BeatmapInfo.Hash = hash;
|
||||||
beatmap.BeatmapInfo.MD5Hash = ms.ComputeMD5Hash();
|
beatmap.BeatmapInfo.MD5Hash = ms.ComputeMD5Hash();
|
||||||
|
|
||||||
var ruleset = rulesets.GetRuleset(beatmap.BeatmapInfo.RulesetID);
|
var ruleset = rulesets.GetRuleset(beatmap.BeatmapInfo.RulesetID);
|
||||||
|
Loading…
Reference in New Issue
Block a user