2019-01-24 16:43:03 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using System;
|
2019-06-26 16:10:22 +08:00
|
|
|
|
using System.IO;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using SharpCompress.Archives.Zip;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Utils
|
|
|
|
|
{
|
|
|
|
|
public static class ZipUtils
|
|
|
|
|
{
|
2021-11-12 18:16:22 +08:00
|
|
|
|
public static bool IsZipArchive(MemoryStream stream)
|
2021-11-12 15:39:17 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
stream.Seek(0, SeekOrigin.Begin);
|
|
|
|
|
|
|
|
|
|
using (var arc = ZipArchive.Open(stream))
|
|
|
|
|
{
|
|
|
|
|
foreach (var entry in arc.Entries)
|
|
|
|
|
{
|
|
|
|
|
using (entry.OpenEntryStream())
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
stream.Seek(0, SeekOrigin.Begin);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public static bool IsZipArchive(string path)
|
|
|
|
|
{
|
2019-06-26 16:10:22 +08:00
|
|
|
|
if (!File.Exists(path))
|
|
|
|
|
return false;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (var arc = ZipArchive.Open(path))
|
|
|
|
|
{
|
|
|
|
|
foreach (var entry in arc.Entries)
|
|
|
|
|
{
|
|
|
|
|
using (entry.OpenEntryStream())
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|