Example #1
0
        public override Directive Run(RawSourceFile source)
        {
            if (!Consts.SupportedBSAs.Contains(Path.GetExtension(source.Path).ToLower()))
            {
                return(null);
            }

            var defaultInclude = false;

            if (source.Path.StartsWith("mods"))
            {
                if (_include_directly.Any(path => source.Path.StartsWith(path)))
                {
                    defaultInclude = true;
                }
            }

            var source_files = source.File.FileInArchive;

            var stack = defaultInclude ? _microstackWithInclude : _microstack;

            var id = Guid.NewGuid().ToString();

            var matches = source_files.PMap(e => Compiler.RunStack(stack, new RawSourceFile(e)
            {
                Path = Path.Combine(Consts.BSACreationDir, id, e.Paths.Last())
            }));


            foreach (var match in matches)
            {
                if (match is IgnoredDirectly)
                {
                    Utils.Error($"File required for BSA {source.Path} creation doesn't exist: {match.To}");
                }
                _compiler.ExtraFiles.Add(match);
            }

            CreateBSA directive;

            using (var bsa = BSADispatch.OpenRead(source.AbsolutePath))
            {
                directive = new CreateBSA
                {
                    To         = source.Path,
                    TempID     = id,
                    State      = bsa.State,
                    FileStates = bsa.Files.Select(f => f.State).ToList()
                };
            }

            return(directive);
        }
Example #2
0
        public override async ValueTask <Directive?> Run(RawSourceFile source)
        {
            if (!Consts.SupportedBSAs.Contains(source.Path.Extension))
            {
                return(null);
            }

            var defaultInclude = false;

            if (source.Path.RelativeTo(_mo2Compiler.MO2Folder).InFolder(_mo2Compiler.MO2Folder.Combine(Consts.MO2ModFolderName)))
            {
                if (_includeDirectly.Any(path => source.Path.StartsWith(path)))
                {
                    defaultInclude = true;
                }
            }

            var sourceFiles = source.File.Children;

            var stack = defaultInclude ? _microstackWithInclude(source.File) : _microstack(source.File);

            var id = Guid.NewGuid().ToString();

            var matches = await sourceFiles.PMap(_mo2Compiler.Queue, e => _mo2Compiler.RunStack(stack, new RawSourceFile(e, Consts.BSACreationDir.Combine((RelativePath)id, e.Name.FileName))));


            foreach (var match in matches)
            {
                if (match is IgnoredDirectly)
                {
                    Utils.ErrorThrow(new UnconvertedError($"File required for BSA {source.Path} creation doesn't exist: {match.To}"));
                }
                _mo2Compiler.ExtraFiles.Add(match);
            }

            CreateBSA directive;

            using (var bsa = BSADispatch.OpenRead(source.AbsolutePath))
            {
                directive = new CreateBSA(
                    state: bsa.State,
                    items: bsa.Files.Select(f => f.State).ToList())
                {
                    To     = source.Path,
                    TempID = (RelativePath)id,
                };
            }

            return(directive);
        }
Example #3
0
        public override async ValueTask <Directive?> Run(RawSourceFile source)
        {
            if (!Consts.SupportedBSAs.Contains(source.Path.Extension))
            {
                return(null);
            }

            var defaultInclude = false;

            if (source.Path.RelativeTo(_mo2Compiler.SourcePath).InFolder(_mo2Compiler.SourcePath.Combine(Consts.MO2ModFolderName)))
            {
                if (_includeDirectly.Any(path => source.Path.StartsWith(path)))
                {
                    defaultInclude = true;
                }
            }

            if (source.AbsolutePath.Size >= (long)2 << 31)
            {
                var bsaTest = await BSADispatch.OpenRead(source.AbsolutePath);

                if (bsaTest.State is BSAStateObject)
                {
                    Utils.Error(
                        $"BSA {source.AbsolutePath.FileName} is over 2GB in size, very few programs (Including Wabbajack) can create BSA files this large without causing CTD issues." +
                        $"Please re-compress this BSA into a more manageable size.");
                }
            }

            var sourceFiles = source.File.Children;

            var stack = defaultInclude ? _microstackWithInclude(source.File) : _microstack(source.File);

            var id = Guid.NewGuid().ToString();


            Func <Task>?_cleanup = null;

            if (defaultInclude)
            {
                //_cleanup = await source.File.Context.Stage(source.File.Children);
            }

            var matches = await sourceFiles.PMap(_mo2Compiler.Queue, e => _mo2Compiler.RunStack(stack, new RawSourceFile(e, Consts.BSACreationDir.Combine((RelativePath)id, (RelativePath)e.Name))));


            foreach (var match in matches)
            {
                if (match is IgnoredDirectly)
                {
                    Utils.ErrorThrow(new UnconvertedError($"File required for BSA {source.Path} creation doesn't exist: {match.To}"));
                }
                _mo2Compiler.ExtraFiles.Add(match);
            }

            CreateBSA directive;
            var       bsa = await BSADispatch.OpenRead(source.AbsolutePath);

            directive = new CreateBSA(
                state: bsa.State,
                items: bsa.Files.Select(f => f.State).ToList())
            {
                To     = source.Path,
                TempID = (RelativePath)id,
            };

            if (_cleanup != null)
            {
                await _cleanup();
            }
            return(directive);
        }