Example #1
0
        private static void ExtractEntry(PackageEntry entry, ref string outputDirectory)
        {
            if (Program.Closing)
            {
                Environment.Exit(0);
            }

            // save raw
            var filePathWithoutExtension = _options.SingleDir
                ? Path.Combine(outputDirectory, entry.Name)
                : Path.Combine(outputDirectory, entry.DirectoryPath, entry.Name);

            var filePath = filePathWithoutExtension + entry.Extension;

            Directory.CreateDirectory(Path.GetDirectoryName(filePathWithoutExtension));

            if (!_options.Overwrite && File.Exists(filePath))
            {
                Console.WriteLine($"* Skipping, already exists: {filePath}");
            }
            else
            {
                Console.WriteLine($"* Extracting: {entry.FullPath}");

                File.WriteAllBytes(filePath, entry.Bytes);
            }

            // decompile and save
            if (_options.NoTexDecompile || entry.Type != EntryType.Tex)
            {
                return;
            }


            var tex = LoadTex(entry.Bytes, entry.FullPath);

            if (tex == null)
            {
                return;
            }

            try
            {
                TexPreviewWriter.WriteTexture(tex, filePathWithoutExtension, _options.Overwrite);
                var jsonInfo = _texJsonInfoGenerator.GenerateInfo(tex);
                File.WriteAllText($"{filePathWithoutExtension}.tex-json", jsonInfo);
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to write texture");
                Console.WriteLine(e);
            }
        }
        protected void Test(string name, bool validateBytes = true, Action <Tex, byte[]> validateTex = null)
        {
            var texture = _reader.ReadFromStream(LoadTestFile(name));

            var firstMipmap = texture.FirstMipmap;
            var bytes       = firstMipmap.Bytes;

            validateTex?.Invoke(texture, bytes);

            if (validateBytes)
            {
                ValidateBytes(bytes, name);
            }
            else
            {
                SaveValidatedBytes(bytes, name);
                TexPreviewWriter.WriteTexture(texture, $"{BasePath}\\{OutputDirectoryName}\\{name}");
            }
        }
Example #3
0
        private static void ExtractTexDirectory(DirectoryInfo directoryInfo)
        {
            var flags = SearchOption.TopDirectoryOnly;

            if (_options.Recursive)
            {
                flags = SearchOption.AllDirectories;
            }

            Directory.CreateDirectory(_options.OutputDirectory);

            foreach (var fileInfo in directoryInfo.EnumerateFiles("*.tex", flags))
            {
                if (!fileInfo.Extension.Equals(".tex", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                try
                {
                    var tex = LoadTex(File.ReadAllBytes(fileInfo.FullName), fileInfo.FullName);

                    if (tex == null)
                    {
                        continue;
                    }

                    var filePath = Path.Combine(_options.OutputDirectory,
                                                Path.GetFileNameWithoutExtension(fileInfo.Name));

                    TexPreviewWriter.WriteTexture(tex, filePath, _options.Overwrite);
                    var jsonInfo = _texJsonInfoGenerator.GenerateInfo(tex);
                    File.WriteAllText($"{filePath}.tex-json", jsonInfo);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to write texture");
                    Console.WriteLine(e);
                }
            }
        }
Example #4
0
        private static void ExtractFile(FileInfo fileInfo)
        {
            Directory.CreateDirectory(_options.OutputDirectory);

            if (fileInfo.Extension.Equals(".pkg", StringComparison.OrdinalIgnoreCase))
            {
                ExtractPkg(fileInfo);
            }
            else if (fileInfo.Extension.Equals(".tex", StringComparison.OrdinalIgnoreCase))
            {
                var tex = LoadTex(File.ReadAllBytes(fileInfo.FullName), fileInfo.FullName);

                if (tex == null)
                {
                    return;
                }

                try
                {
                    var filePath = Path.Combine(_options.OutputDirectory,
                                                Path.GetFileNameWithoutExtension(fileInfo.Name));

                    TexPreviewWriter.WriteTexture(tex, filePath, _options.Overwrite);
                    var jsonInfo = _texJsonInfoGenerator.GenerateInfo(tex);
                    File.WriteAllText($"{filePath}.tex-json", jsonInfo);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"");
                    Console.WriteLine(e);
                }
            }
            else
            {
                Console.WriteLine($"Unrecognized file extension: {fileInfo.Extension}");
            }
        }