Esempio n. 1
0
        private static void ExtractFile(NameSpaceFile nsf, DirectoryInfo currentOutputDirectory)
        {
            var  path    = Path.Combine(currentOutputDirectory.FullName, nsf.Name);
            bool useJson = !exportBson;


            var obj = nsf.Object as WzProperty;

            if (obj == null)
            {
                Console.WriteLine("Unable to export {0}, as its not a WzProperty", nsf.NodePath);
                return;
            }

            byte[] data;

            using (var exp = new Exporter(exportOptions, obj))
            {
                if (useJson)
                {
                    data = Encoding.ASCII.GetBytes(exp.ToJson());
                }
                else
                {
                    data = exp.ToBson();
                }


                if (exportOptions.HasFlag(Options.ExternalImageExport))
                {
                    // Generate image path of the first 4 characters of the name (if possible)
                    var imgDir = globalOutputDirectory.CreateSubdirectory("images");
                    var name   = obj.Name.Replace(".img", "");
                    if (name.Length > 0)
                    {
                        imgDir = imgDir.CreateSubdirectory("" + name[0]);
                    }
                    if (name.Length > 1)
                    {
                        imgDir = imgDir.CreateSubdirectory("" + name[1]);
                    }
                    if (name.Length > 2)
                    {
                        imgDir = imgDir.CreateSubdirectory("" + name[2]);
                    }
                    if (name.Length > 3)
                    {
                        imgDir = imgDir.CreateSubdirectory("" + name[3]);
                    }

                    ExtractImages(exp, imgDir);
                }
            }

            nsf.Checksum = (int)Crc32Algorithm.Compute(data);

            // This will replace .img with .hash.(json|bson)
            var outputFile = Path.ChangeExtension(path, $".{nsf.Checksum:X8}." + (useJson ? "json" : "bson"));

            if (File.Exists(outputFile))
            {
                return;
            }

            Console.WriteLine("Writing {0}", outputFile);

            File.WriteAllBytes(
                outputFile,
                data
                );
        }