Exemple #1
0
        public static void SaveWithPreArchiveData(this MpqArchiveBuilder mpqArchiveBuilder, Stream stream, bool leaveOpen = false)
        {
            var mpqFiles         = mpqArchiveBuilder.ToArray();
            var campaignInfoFile = mpqFiles.SingleOrDefault(file => file.Name == CampaignInfoHashedFileName);

            if (campaignInfoFile is not null)
            {
                using var reader = new BinaryReader(campaignInfoFile.MpqStream, new UTF8Encoding(false, true), true);
                var campaignInfo = reader.ReadCampaignInfo();
                campaignInfoFile.MpqStream.Position = 0;
                mpqArchiveBuilder.SaveWithPreArchiveData(stream, campaignInfo, leaveOpen);
            }
            else
            {
                var mapInfoFile = mpqFiles.SingleOrDefault(file => file.Name == MapInfoHashedFileName);
                if (mapInfoFile is not null)
                {
                    using var reader = new BinaryReader(mapInfoFile.MpqStream, new UTF8Encoding(false, true), true);
                    var mapInfo = reader.ReadMapInfo();
                    mapInfoFile.MpqStream.Position = 0;
                    mpqArchiveBuilder.SaveWithPreArchiveData(stream, mapInfo, leaveOpen);
                }
                else
                {
                    throw new FileNotFoundException($"Unable to find {CampaignInfo.FileName} or {MapInfo.FileName} file to use as source for pre-archive data.");
                }
            }
        }
        public static void SaveWithPreArchiveData(this MpqArchiveBuilder mpqArchiveBuilder, string fileName, MpqArchiveCreateOptions createOptions)
        {
            var mpqFiles         = mpqArchiveBuilder.ToArray();
            var campaignInfoFile = mpqFiles.SingleOrDefault(file => file.Name == CampaignInfoHashedFileName);

            if (campaignInfoFile is not null)
            {
                using var reader = new BinaryReader(campaignInfoFile.MpqStream, _defaultEncoding, true);
                var campaignInfo = reader.ReadCampaignInfo();
                campaignInfoFile.MpqStream.Position = 0;

                var campaignTriggerStringsFile = mpqFiles.SingleOrDefault(file => file.Name == CampaignTriggerStringsHashedFileName);
                if (campaignTriggerStringsFile is not null)
                {
                    using var triggerStringsReader = new StreamReader(campaignTriggerStringsFile.MpqStream, _defaultEncoding, leaveOpen: true);
                    var campaignTriggerStrings = triggerStringsReader.ReadCampaignTriggerStrings();
                    campaignTriggerStringsFile.MpqStream.Position = 0;

                    mpqArchiveBuilder.SaveCampaignWithPreArchiveData(fileName, createOptions, campaignInfo, campaignTriggerStrings);
                }
                else
                {
                    mpqArchiveBuilder.SaveCampaignWithPreArchiveData(fileName, createOptions, campaignInfo);
                }
            }
            else
            {
                var mapInfoFile = mpqFiles.SingleOrDefault(file => file.Name == MapInfoHashedFileName);
                if (mapInfoFile is not null)
                {
                    using var reader = new BinaryReader(mapInfoFile.MpqStream, _defaultEncoding, true);
                    var mapInfo = reader.ReadMapInfo();
                    mapInfoFile.MpqStream.Position = 0;

                    var mapTriggerStringsFile = mpqFiles.SingleOrDefault(file => file.Name == MapTriggerStringsHashedFileName);
                    if (mapTriggerStringsFile is not null)
                    {
                        using var triggerStringsReader = new StreamReader(mapTriggerStringsFile.MpqStream, _defaultEncoding, leaveOpen: true);
                        var mapTriggerStrings = triggerStringsReader.ReadMapTriggerStrings();
                        mapTriggerStringsFile.MpqStream.Position = 0;

                        mpqArchiveBuilder.SaveMapWithPreArchiveData(fileName, createOptions, mapInfo, mapTriggerStrings);
                    }
                    else
                    {
                        mpqArchiveBuilder.SaveMapWithPreArchiveData(fileName, createOptions, mapInfo);
                    }
                }
                else
                {
                    throw new FileNotFoundException($"Unable to find {CampaignInfo.FileName} or {MapInfo.FileName} file to use as source for pre-archive data.");
                }
            }
        }