mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 16:52:54 +08:00
Merge pull request #18777 from peppy/output-directory-on-import-failure
Silence exception and provide more log output when import fails due to empty `.osu` files
This commit is contained in:
commit
c402e90598
@ -276,6 +276,42 @@ namespace osu.Game.Tests.Database
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestImportDirectoryWithEmptyOsuFiles()
|
||||||
|
{
|
||||||
|
RunTestWithRealmAsync(async (realm, storage) =>
|
||||||
|
{
|
||||||
|
using var importer = new BeatmapImporter(storage, realm);
|
||||||
|
using var store = new RealmRulesetStore(realm, storage);
|
||||||
|
|
||||||
|
string? temp = TestResources.GetTestBeatmapForImport();
|
||||||
|
|
||||||
|
string extractedFolder = $"{temp}_extracted";
|
||||||
|
Directory.CreateDirectory(extractedFolder);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var zip = ZipArchive.Open(temp))
|
||||||
|
zip.WriteToDirectory(extractedFolder);
|
||||||
|
|
||||||
|
foreach (var file in new DirectoryInfo(extractedFolder).GetFiles("*.osu"))
|
||||||
|
{
|
||||||
|
using (file.Open(FileMode.Create))
|
||||||
|
{
|
||||||
|
// empty file.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var imported = await importer.Import(new ImportTask(extractedFolder));
|
||||||
|
Assert.IsNull(imported);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Directory.Delete(extractedFolder, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestImportThenImportWithReZip()
|
public void TestImportThenImportWithReZip()
|
||||||
{
|
{
|
||||||
|
@ -177,8 +177,17 @@ namespace osu.Game.Beatmaps
|
|||||||
}
|
}
|
||||||
|
|
||||||
Beatmap beatmap;
|
Beatmap beatmap;
|
||||||
|
|
||||||
using (var stream = new LineBufferedReader(reader.GetStream(mapName)))
|
using (var stream = new LineBufferedReader(reader.GetStream(mapName)))
|
||||||
|
{
|
||||||
|
if (stream.PeekLine() == null)
|
||||||
|
{
|
||||||
|
Logger.Log($"No content found in first .osu file of beatmap archive ({reader.Name} / {mapName})", LoggingTarget.Database);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
beatmap = Decoder.GetDecoder<Beatmap>(stream).Decode(stream);
|
beatmap = Decoder.GetDecoder<Beatmap>(stream).Decode(stream);
|
||||||
|
}
|
||||||
|
|
||||||
return new BeatmapSetInfo
|
return new BeatmapSetInfo
|
||||||
{
|
{
|
||||||
|
@ -74,7 +74,7 @@ namespace osu.Game.Beatmaps.Formats
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (line == null)
|
if (line == null)
|
||||||
throw new IOException("Unknown file format (null)");
|
throw new IOException("Unknown file format (no content)");
|
||||||
|
|
||||||
var decoder = typedDecoders.Where(d => line.StartsWith(d.Key, StringComparison.InvariantCulture)).Select(d => d.Value).FirstOrDefault();
|
var decoder = typedDecoders.Where(d => line.StartsWith(d.Key, StringComparison.InvariantCulture)).Select(d => d.Value).FirstOrDefault();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user