mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-02-10 11:52:29 +00:00
Refactor
This commit is contained in:
@@ -41,23 +41,19 @@ public partial class DataDump
|
|||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
using var archive = ZipFile.OpenRead(zipFilePath);
|
await using var archive = await ZipFile.OpenReadAsync(zipFilePath, cancellationToken);
|
||||||
|
|
||||||
// Try to find the index file with case-insensitive search
|
// Use case-insensitive search to accommodate for different data dump versions
|
||||||
// Discord changed the structure from "messages/index.json" to "Messages/index.json"
|
|
||||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/1459
|
// https://github.com/Tyrrrz/DiscordChatExporter/issues/1459
|
||||||
var entry = archive.Entries.FirstOrDefault(e =>
|
var entry =
|
||||||
|
archive.Entries.FirstOrDefault(e =>
|
||||||
e.FullName.Equals("messages/index.json", StringComparison.OrdinalIgnoreCase)
|
e.FullName.Equals("messages/index.json", StringComparison.OrdinalIgnoreCase)
|
||||||
);
|
)
|
||||||
|
?? throw new InvalidOperationException(
|
||||||
if (entry is null)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException(
|
|
||||||
"Failed to locate the channel index inside the data package."
|
"Failed to locate the channel index inside the data package."
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
await using var stream = entry.Open();
|
await using var stream = await entry.OpenAsync(cancellationToken);
|
||||||
using var document = await JsonDocument.ParseAsync(stream, default, cancellationToken);
|
using var document = await JsonDocument.ParseAsync(stream, default, cancellationToken);
|
||||||
|
|
||||||
return Parse(document.RootElement);
|
return Parse(document.RootElement);
|
||||||
|
|||||||
Reference in New Issue
Block a user