Exemplo n.º 1
0
        private void ArchiveTaskInner(string path, string pattern, string regex, bool diff, bool list)
        {
            #region checks

            if (string.IsNullOrEmpty(path))
            {
                _loggerService.Warning("Please fill in an input path.");
                return;
            }

            var inputFileInfo = new FileInfo(path);
            var inputDirInfo  = new DirectoryInfo(path);

            if (!inputFileInfo.Exists && !inputDirInfo.Exists)
            {
                _loggerService.Warning("Input path does not exist.");
                return;
            }

            if (inputFileInfo.Exists && inputFileInfo.Extension != ".archive")
            {
                _loggerService.Warning("Input file is not an .archive.");
                return;
            }
            else if (inputDirInfo.Exists && inputDirInfo.GetFiles().All(_ => _.Extension != ".archive"))
            {
                _loggerService.Warning("No .archive file to process in the input directory");
                return;
            }

            var isDirectory = !inputFileInfo.Exists;
            var basedir     = inputFileInfo.Exists ? new FileInfo(path).Directory : inputDirInfo;

            #endregion checks

            List <FileInfo> archiveFileInfos;
            if (isDirectory)
            {
                _archiveManager.LoadFromFolder(basedir);
                // TODO: use the manager here?
                archiveFileInfos = _archiveManager.Archives.Items.Select(_ => new FileInfo(_.ArchiveAbsolutePath)).ToList();
            }
            else
            {
                archiveFileInfos = new List <FileInfo> {
                    inputFileInfo
                };
            }

            foreach (var processedarchive in archiveFileInfos)
            {
                // read archive
                var ar = Red4ParserServiceExtensions.ReadArchive(processedarchive.FullName, _hashService);

                // run

                // check search pattern then regex
                var finalmatches = ar.Files.Values.Cast <FileEntry>();
                if (!string.IsNullOrEmpty(pattern))
                {
                    finalmatches = ar.Files.Values.Cast <FileEntry>().MatchesWildcard(item => item.FileName, pattern);
                }

                if (!string.IsNullOrEmpty(regex))
                {
                    var searchTerm         = new System.Text.RegularExpressions.Regex($@"{regex}");
                    var queryMatchingFiles =
                        from file in finalmatches
                        let matches = searchTerm.Matches(file.FileName)
                                      where matches.Count > 0
                                      select file;

                    finalmatches = queryMatchingFiles;
                }

                // list files in archive
                if (list)
                {
                    foreach (var finalmatch in finalmatches)
                    {
                        Console.WriteLine(finalmatch.Name);
                    }
                }

                //
                if (diff)
                {
                    var json = JsonConvert.SerializeObject(ar, Formatting.Indented,
                                                           new JsonSerializerSettings()
                    {
                        ReferenceLoopHandling      = ReferenceLoopHandling.Ignore,
                        PreserveReferencesHandling = PreserveReferencesHandling.None,
                        TypeNameHandling           = TypeNameHandling.None
                    });
                    Console.Write(json);
                }
            }

            return;
        }
Exemplo n.º 2
0
        private void UnbundleTaskInner(string path, string outpath,
                                       string hash, string pattern, string regex, bool DEBUG_decompress = false)
        {
            #region checks

            if (string.IsNullOrEmpty(path))
            {
                _loggerService.Warning("Please fill in an input path.");
                return;
            }

            var inputFileInfo = new FileInfo(path);
            var inputDirInfo  = new DirectoryInfo(path);

            if (!inputFileInfo.Exists && !inputDirInfo.Exists)
            {
                _loggerService.Warning("Input path does not exist.");
                return;
            }

            if (inputFileInfo.Exists && inputFileInfo.Extension != ".archive")
            {
                _loggerService.Warning("Input file is not an .archive.");
                return;
            }
            else if (inputDirInfo.Exists && inputDirInfo.GetFiles().All(_ => _.Extension != ".archive"))
            {
                _loggerService.Warning("No .archive file to process in the input directory.");
                return;
            }

            var isDirectory = !inputFileInfo.Exists;
            var basedir     = inputFileInfo.Exists ? new FileInfo(path).Directory : inputDirInfo;

            #endregion checks

            List <FileInfo> archiveFileInfos;
            if (isDirectory)
            {
                _archiveManager.LoadFromFolder(basedir);
                // TODO: use the manager here?
                archiveFileInfos = _archiveManager.Archives.Items.Select(_ => new FileInfo(_.ArchiveAbsolutePath)).ToList();
            }
            else
            {
                archiveFileInfos = new List <FileInfo> {
                    inputFileInfo
                };
            }

            foreach (var fileInfo in archiveFileInfos)
            {
                // get outdirectory
                DirectoryInfo outDir;
                if (string.IsNullOrEmpty(outpath))
                {
                    outDir = new DirectoryInfo(Path.Combine(
                                                   basedir.FullName,
                                                   fileInfo.Name.Replace(".archive", "")));
                }
                else
                {
                    outDir = new DirectoryInfo(outpath);
                    if (!outDir.Exists)
                    {
                        outDir = new DirectoryInfo(outpath);
                    }

                    if (inputDirInfo.Exists)
                    {
                        outDir = new DirectoryInfo(Path.Combine(
                                                       outDir.FullName,
                                                       fileInfo.Name.Replace(".archive", "")));
                    }
                }

                // read archive
                var ar = Red4ParserServiceExtensions.ReadArchive(fileInfo.FullName, _hashService);

                var isHash = ulong.TryParse(hash, out var hashNumber);

                // run
                if (!isHash && File.Exists(hash))
                {
                    var hashlist = File.ReadAllLines(hash)
                                   .ToList().Select(_ => ulong.TryParse(_, out var res) ? res : 0);
                    _loggerService.Info($"Extracing all files from the hashlist ({hashlist.Count()}hashes) ...");
                    foreach (var hashNum in hashlist)
                    {
                        var r = ModTools.ExtractSingle(ar, hashNum, outDir, DEBUG_decompress);
                        if (r > 0)
                        {
                            _loggerService.Success($" {ar.ArchiveAbsolutePath}: Extracted one file: {hashNum}");
                        }
                        else
                        {
                            _loggerService.Info($" {ar.ArchiveAbsolutePath}: No file found with hash {hashNum}");
                        }
                    }

                    _loggerService.Success($"Bulk extraction from hashlist file completed.");
                }
                else if (isHash && hashNumber != 0)
                {
                    var r = ModTools.ExtractSingle(ar, hashNumber, outDir, DEBUG_decompress);
                    if (r > 0)
                    {
                        _loggerService.Success($" {ar.ArchiveAbsolutePath}: Extracted one file: {hashNumber}");
                    }
                    else
                    {
                        _loggerService.Info($" {ar.ArchiveAbsolutePath}: No file found with hash {hashNumber}");
                    }
                }
                else
                {
                    _modTools.ExtractAll(ar, outDir, pattern, regex, DEBUG_decompress);
                }
            }

            return;
        }
Exemplo n.º 3
0
        public int DumpTaskInner(string path, bool imports, bool missinghashes,
                                 bool texinfo, bool dump, bool list)
        {
            #region checks

            if (string.IsNullOrEmpty(path))
            {
                _loggerService.Warning("Please fill in an input path.");
                return(0);
            }

            var isDirectory   = false;
            var inputFileInfo = new FileInfo(path);
            var inputDirInfo  = new DirectoryInfo(path);
            if (!inputFileInfo.Exists)
            {
                if (!inputDirInfo.Exists)
                {
                    return(0);
                }
                else
                {
                    isDirectory = true;
                }
            }

            #endregion checks


            //fix to force loading all
            _hashService.GetAllHashes();

            var archives = new List <Archive>();

            var outputDir = isDirectory ? inputDirInfo.FullName : inputFileInfo.Directory.FullName;
            if (isDirectory)
            {
                archives.AddRange(inputDirInfo
                                  .GetFiles("*.archive", SearchOption.AllDirectories)
                                  .Select(_ => Red4ParserServiceExtensions.ReadArchive(_.FullName, _hashService)));
            }
            else
            {
                archives.Add(Red4ParserServiceExtensions.ReadArchive(inputFileInfo.FullName, _hashService));
            }

            if (missinghashes)
            {
                List <ulong> used    = new();
                List <ulong> missing = new();

                _loggerService.Info($"Parsing...");
                for (var i = 0; i < archives.Count; i++)
                {
                    var ar = archives[i];
                    foreach (var(hash, fileInfoEntry) in ar.Files)
                    {
                        if (fileInfoEntry is FileEntry fe && fe.NameOrHash == hash.ToString())
                        {
                            missing.Add(hash);
                        }
                        else
                        {
                            used.Add(hash);
                        }
                    }
Exemplo n.º 4
0
        private void UncookTaskInner(string path, string outpath, string rawOutDir,
                                     EUncookExtension?uext, bool?flip, ulong hash, string pattern, string regex, bool unbundle,
                                     ECookedFileFormat[] forcebuffers)
        {
            #region checks

            if (string.IsNullOrEmpty(path))
            {
                _loggerService.Warning("Please fill in an input path.");
                return;
            }

            var inputFileInfo = new FileInfo(path);
            var inputDirInfo  = new DirectoryInfo(path);

            if (!inputFileInfo.Exists && !inputDirInfo.Exists)
            {
                _loggerService.Warning("Input path does not exist.");
                return;
            }

            if (inputFileInfo.Exists && inputFileInfo.Extension != ".archive")
            {
                _loggerService.Warning("Input file is not an .archive.");
                return;
            }
            else if (inputDirInfo.Exists && inputDirInfo.GetFiles().All(_ => _.Extension != ".archive"))
            {
                _loggerService.Warning("No .archive file to process in the input directory");
                return;
            }

            var isDirectory = !inputFileInfo.Exists;
            var basedir     = inputFileInfo.Exists ? new FileInfo(path).Directory : inputDirInfo;

            #endregion checks

            var exportArgs = new GlobalExportArgs().Register(
                _xbmExportArgs.Value,
                _meshExportArgs.Value,
                _morphTargetExportArgs.Value,
                _mlmaskExportArgs.Value,
                _wemExportArgs.Value
                );
            if (flip != null)
            {
                exportArgs.Get <XbmExportArgs>().Flip = flip.Value;
            }
            if (uext != null)
            {
                exportArgs.Get <XbmExportArgs>().UncookExtension    = uext.Value;
                exportArgs.Get <MlmaskExportArgs>().UncookExtension = uext.Value;
            }

            var archiveDepot = exportArgs.Get <MeshExportArgs>().ArchiveDepot;
            if (!string.IsNullOrEmpty(archiveDepot) && Directory.Exists(archiveDepot))
            {
                _archiveManager.LoadFromFolder(new DirectoryInfo(archiveDepot));
                exportArgs.Get <MeshExportArgs>().Archives        = _archiveManager.Archives.Items.Cast <Archive>().ToList();
                exportArgs.Get <MorphTargetExportArgs>().Archives = _archiveManager.Archives.Items.Cast <Archive>().ToList();
                exportArgs.Get <AnimationExportArgs>().Archives   = _archiveManager.Archives.Items.Cast <Archive>().ToList();
            }
            else
            {
                archiveDepot = exportArgs.Get <MorphTargetExportArgs>().ArchiveDepot;
                if (!string.IsNullOrEmpty(archiveDepot) && Directory.Exists(archiveDepot))
                {
                    _archiveManager.LoadFromFolder(new DirectoryInfo(archiveDepot));
                    exportArgs.Get <MeshExportArgs>().Archives        = _archiveManager.Archives.Items.Cast <Archive>().ToList();
                    exportArgs.Get <MorphTargetExportArgs>().Archives = _archiveManager.Archives.Items.Cast <Archive>().ToList();
                    exportArgs.Get <AnimationExportArgs>().Archives   = _archiveManager.Archives.Items.Cast <Archive>().ToList();
                }
                else
                {
                    archiveDepot = exportArgs.Get <AnimationExportArgs>().ArchiveDepot;
                    if (!string.IsNullOrEmpty(archiveDepot) && Directory.Exists(archiveDepot))
                    {
                        _archiveManager.LoadFromFolder(new DirectoryInfo(archiveDepot));
                        exportArgs.Get <MeshExportArgs>().Archives        = _archiveManager.Archives.Items.Cast <Archive>().ToList();
                        exportArgs.Get <MorphTargetExportArgs>().Archives = _archiveManager.Archives.Items.Cast <Archive>().ToList();
                        exportArgs.Get <AnimationExportArgs>().Archives   = _archiveManager.Archives.Items.Cast <Archive>().ToList();
                    }
                }
            }

            List <FileInfo> archiveFileInfos;
            if (isDirectory)
            {
                _archiveManager.LoadFromFolder(basedir);
                archiveFileInfos = _archiveManager.Archives.Items.Select(_ => new FileInfo(_.ArchiveAbsolutePath)).ToList();
            }
            else
            {
                archiveFileInfos = new List <FileInfo> {
                    inputFileInfo
                };
            }

            foreach (var fileInfo in archiveFileInfos)
            {
                // get outdirectory
                DirectoryInfo outDir;
                if (string.IsNullOrEmpty(outpath))
                {
                    outDir = new DirectoryInfo(Path.Combine(
                                                   basedir.FullName,
                                                   fileInfo.Name.Replace(".archive", "")));
                }
                else
                {
                    outDir = new DirectoryInfo(outpath);
                    if (!outDir.Exists)
                    {
                        outDir = new DirectoryInfo(outpath);
                    }
                }

                DirectoryInfo rawOutDirInfo = null;
                if (string.IsNullOrEmpty(rawOutDir))
                {
                    rawOutDirInfo = outDir;
                }
                else
                {
                    rawOutDirInfo = new DirectoryInfo(rawOutDir);
                    if (!rawOutDirInfo.Exists)
                    {
                        rawOutDirInfo = new DirectoryInfo(rawOutDir);
                    }
                }

                // read archive
                var ar = Red4ParserServiceExtensions.ReadArchive(fileInfo.FullName, _hashService);

                // run
                if (hash != 0)
                {
                    _modTools.UncookSingle(ar, hash, outDir, exportArgs, rawOutDirInfo, forcebuffers);
                    _loggerService.Success($" {ar.ArchiveAbsolutePath}: Uncooked one file: {hash}");
                }
                else
                {
                    _modTools.UncookAll(ar, outDir, exportArgs, unbundle, pattern, regex, rawOutDirInfo, forcebuffers);
                }
            }

            return;
        }