public PackReader(IPackCollection packCollection, IPackResourceManager packResourceManager, PackReaderSettings settings = null) { _packCollection = packCollection; _packResourceManager = packResourceManager; this.PackReaderSettings = settings ?? PackReaderSettings.DefaultPackReaderSettings; }
public async Task <IPackCollection> LoadMapAsync(int mapId, IPackCollection packCollection = null, PackReaderSettings packReaderSettings = null) { if (this.ManifestedPack) { return(await LoadMapFromOptimizedMarkerPackAsync(mapId, packCollection, packReaderSettings)); } else { return(await LoadMapFromNonOptimizedMarkerPackAsync(mapId, packCollection, packReaderSettings)); } }
public async Task <Stream> GetArchiveStreamAsync(Pack pack, IPackCollection packCollection) { var archiveStream = new MemoryStream(); using (var outputZip = new ZipArchive(archiveStream, ZipArchiveMode.Create, true)) { await foreach (var file in GetFileStreams(pack, packCollection)) { using (var fileEntryStream = outputZip.CreateEntry(file.filename).Open()) { await file.stream.CopyToAsync(fileEntryStream); } } } archiveStream.Seek(0, SeekOrigin.Begin); return(archiveStream); }
public async Task <IPackCollection> LoadAllAsync(IPackCollection packCollection = null, PackReaderSettings packReaderSettings = null) { var collection = packCollection ?? new PackCollection(); var reader = new PackReader(collection, this.ResourceManager, packReaderSettings); var candidates = new List <(Stream fileStream, IDataReader dataReader)>(); await _dataReader.LoadOnFileTypeAsync((fileStream, dataReader) => { candidates.Add((fileStream, dataReader)); return(Task.CompletedTask); }, ".xml"); foreach (var candidate in candidates) { await reader.PopulatePackFromStream(candidate.fileStream); } return(collection); }
private Stream WriteMarkerCategories(IPackCollection pack) { var markerCategoryStream = new MemoryStream(); var categoryWriter = XmlWriter.Create(markerCategoryStream); categoryWriter.WriteStartDocument(); categoryWriter.WriteStartElement(PackConstImpl.XML_ELEMENT_OVERLAYDATA); foreach (var category in pack.Categories) { WriteMarkerCategory(categoryWriter, category); } categoryWriter.WriteEndElement(); categoryWriter.WriteEndDocument(); categoryWriter.Close(); markerCategoryStream.Seek(0, SeekOrigin.Begin); return(markerCategoryStream); }
public async Task WriteAsync(Pack pack, IPackCollection packCollection, string directoryPath, string packName) { if (!Directory.Exists(directoryPath)) { throw new DirectoryNotFoundException($"Directory path '{directoryPath}' does not exist."); } switch (this.PackWriterSettings.PackOutputMethod) { case PackWriterSettings.OutputMethod.Archive: var archive = await GetArchiveStreamAsync(pack, packCollection); string packPath = Path.Combine(directoryPath, packName); using (var fileOut = new FileStream(packPath, FileMode.Create)) { await archive.CopyToAsync(fileOut); } break; case PackWriterSettings.OutputMethod.Directory: string rootPath = Path.Combine(directoryPath, packName); Directory.CreateDirectory(rootPath); await foreach (var file in GetFileStreams(pack, packCollection)) { string filePath = Path.Combine(rootPath, file.filename); string fileDir = Path.GetDirectoryName(filePath); Directory.CreateDirectory(fileDir); using (var fileOut = new FileStream(filePath, FileMode.Create)) { await file.stream.CopyToAsync(fileOut); } } break; } }
private async IAsyncEnumerable <(string filename, Stream stream)> GetReferencedResources(Pack pack, IPackCollection packCollection, string resourceAttribute) { IEnumerable <string> resources = packCollection.PointsOfInterest .Where(p => !ShouldIgnorePathableType(p)) .Select(p => p.GetAggregatedAttributeValue(resourceAttribute)) .Distinct() .Where(s => s != null && pack.ResourceManager.ResourceExists(s)); // seems cursed foreach (string resourcePath in resources) { yield return(resourcePath.ToLowerInvariant(), new MemoryStream(await pack.ResourceManager.LoadResourceAsync(resourcePath))); } }
private async IAsyncEnumerable <(string filename, Stream stream)> GetFileStreams(Pack pack, IPackCollection packCollection) { // Export categories yield return(PackConstImpl.FILE_OPTIMIZED_MARKERCATEGORIES, WriteMarkerCategories(packCollection)); // Get pathables by map ID var groupedPathables = packCollection.PointsOfInterest .Where(poi => poi.ParentPathingCategory != null && !ShouldIgnorePathableType(poi)) .OrderBy(poi => poi.ParentPathingCategory.Namespace) .GroupBy(poi => poi.MapId); // Export each set of pathables per map foreach (var pathablesGroup in groupedPathables) { yield return(string.Format(PackConstImpl.FILE_OPTIMIZED_MAPPATHABLES, pathablesGroup.Key), WriteMapPois(pathablesGroup.Key, pathablesGroup)); } // Export resources (textures, icons, and trl files) - dirty foreach (string resourceAttribute in new[] { PackConstImpl.XML_KNOWNATTRIBUTE_TEXTURE, PackConstImpl.XML_KNOWNATTRIBUTE_ICONFILE, PackConstImpl.XML_KNOWNATTRIBUTE_TRAILDATA }) { await foreach (var resource in GetReferencedResources(pack, packCollection, resourceAttribute)) { yield return(resource); } } }
public static async Task WritePackAsync(Pack pack, IPackCollection packCollection, string directoryPath, string packName, PackWriterSettings settings = null) { await new PackWriter(settings).WriteAsync(pack, packCollection, directoryPath, packName); }
public static async Task <Stream> GetPackArchiveStreamAsync(Pack pack, IPackCollection packCollection, PackWriterSettings settings = null) { return(await new PackWriter(settings).GetArchiveStreamAsync(pack, packCollection)); }
private async Task <IPackCollection> LoadMapFromNonOptimizedMarkerPackAsync(int mapId, IPackCollection packCollection, PackReaderSettings packReaderSettings = null) { await LoadAllAsync(packCollection == null ?null : new FilteredPackCollection(packCollection, poi => poi.MapId == mapId), packReaderSettings); return(packCollection); }
private async Task <IPackCollection> LoadMapFromOptimizedMarkerPackAsync(int mapId, IPackCollection packCollection, PackReaderSettings packReaderSettings = null) { var collection = packCollection ?? new PackCollection(); var reader = new PackReader(collection, this.ResourceManager, packReaderSettings); await reader.PopulatePackFromStream(await _dataReader.GetFileStreamAsync(PackConstImpl.FILE_OPTIMIZED_MARKERCATEGORIES)); if (_dataReader.FileExists(string.Format(PackConstImpl.FILE_OPTIMIZED_MAPPATHABLES, mapId))) { await reader.PopulatePackFromStream(await _dataReader.GetFileStreamAsync(string.Format(PackConstImpl.FILE_OPTIMIZED_MAPPATHABLES, mapId))); } return(collection); }