using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using System.Transactions; using ColdMint.scripts.database; using ColdMint.scripts.database.dataPackEntity; using ColdMint.scripts.dataPack.local; using ColdMint.scripts.debug; using ColdMint.scripts.inventory; using Microsoft.EntityFrameworkCore.Storage; using Array = System.Array; namespace ColdMint.scripts.dataPack; /// /// Packet manager /// 数据包管理器 /// public static class DataPackManager { /// /// When a packet is scanned /// 当一个数据包被扫描到时 /// public static Action? OnScanComplete; /// /// Load all packets in a directory /// 加载某个目录下的所有数据包 /// /// public static async Task ScanAllDataPack(string path) { if (!Directory.Exists(path)) { return Array.Empty(); } var dataPacks = new List(); var files = Directory.GetFiles(path); foreach (var file in files) { var dataPack = await ScanSingleDataPack(file); if (dataPack == null) { continue; } dataPacks.Add(dataPack); } return dataPacks.ToArray(); } /// /// Load a single packet /// 加载单个数据包 /// /// /// public async static Task ScanSingleDataPack(string path) { if (!File.Exists(path)) { return null; } var dataPack = new LocalDataPack(path); await dataPack.BuildIndex(); await dataPack.LoadManifest(); if (OnScanComplete != null) { OnScanComplete.Invoke(dataPack); } return dataPack; } }