Пример #1
0
        internal string GetCertComponentsAsPEMString(byte[] pfxData, string pwd, ExportFlags flags)
        {
            // See also https://www.digicert.com/ssl-support/pem-ssl-creation.htm

            var cert  = new X509Certificate2(pfxData, pwd);
            var chain = new X509Chain();

            chain.Build(cert);

            using (var writer = new StringWriter())
            {
                var certParser = new X509CertificateParser();
                var pemWriter  = new PemWriter(writer);

                //output in order of private key, primary cert, intermediates, root

                if (flags.HasFlag(ExportFlags.PrivateKey))
                {
                    var key = GetCertKeyPem(pfxData, pwd);
                    writer.Write(key);
                }

                var i = 0;
                foreach (var c in chain.ChainElements)
                {
                    if (i == 0 && flags.HasFlag(ExportFlags.EndEntityCertificate))
                    {
                        // first cert is end entity cert (primary certificate)
                        var o = c.Certificate.Export(X509ContentType.Cert);
                        pemWriter.WriteObject(certParser.ReadCertificate(o));
                    }
                    else if (i == chain.ChainElements.Count - 1 && flags.HasFlag(ExportFlags.RootCertificate))
                    {
                        // last cert is root ca public cert
                        var o = c.Certificate.Export(X509ContentType.Cert);
                        pemWriter.WriteObject(certParser.ReadCertificate(o));
                    }
                    else if (i != 0 && (i != chain.ChainElements.Count - 1) && flags.HasFlag(ExportFlags.IntermediateCertificates))
                    {
                        // intermediate cert(s), if any, not including end entity and root
                        var o = c.Certificate.Export(X509ContentType.Cert);
                        pemWriter.WriteObject(certParser.ReadCertificate(o));
                    }
                    i++;
                }

                writer.Flush();

                return(writer.ToString());
            }
        }
Пример #2
0
        public void ExportAll(string dir, ExportFlags flags)
        {
            Console.WriteLine("Exporting to: " + dir);
            if (dir.Contains(" "))
            {
                Console.WriteLine("Warning, there are spaces in the path. This may affect material import.");
            }

            if (flags.HasFlag(ExportFlags.TexLow))
            {
                ExportTextures(Path.Combine(dir, "texLow"), Detail.Low);
            }
            if (flags.HasFlag(ExportFlags.MeshLow))
            {
                ExportMesh(dir, Detail.Low);
            }

            if (flags.HasFlag(ExportFlags.TexMed))
            {
                ExportTextures(Path.Combine(dir, "texMed"), Detail.Med);
            }
            if (flags.HasFlag(ExportFlags.MeshMed))
            {
                ExportMesh(dir, Detail.Med);
            }

            if (flags.HasFlag(ExportFlags.Models))
            {
                ExportModels(dir);
            }
            if (flags.HasFlag(ExportFlags.SkyBox))
            {
                ExportSkyBox(dir);
            }
        }
Пример #3
0
        public void Export(string path, ExportFlags flags)
        {
            Console.WriteLine($"Exporting to: {path}");

            if (path.Contains(" "))
                Console.WriteLine("Warning, the selected path contains space in its name.\r\nThis may affect material import in certain applications.\r\n");

            if (flags.HasFlag(ExportFlags.MeshLow)) ExportMesh(path, Detail.Low);
            if (flags.HasFlag(ExportFlags.TexLow)) ExportTextures(path, Detail.Low);

            Console.WriteLine("Low mesh: done.");

            if (flags.HasFlag(ExportFlags.MeshMed)) ExportMesh(path, Detail.Med);
            if (flags.HasFlag(ExportFlags.TexMed)) ExportTextures(path, Detail.Med);

            Console.WriteLine("Mid mesh: done.");

            //not implemented, should return subdivided mesh. not sure if needed.
            //if (flags.HasFlag(ExportFlags.MeshHigh)) ExportMesh(path, Detail.High);
            if (flags.HasFlag(ExportFlags.TexHigh)) ExportTextures(path, Detail.High);

            Console.WriteLine("High mesh: done.");

            if (flags.HasFlag(ExportFlags.Models)) ExportModels(path);
            if (flags.HasFlag(ExportFlags.TexModels)) ExportTextures(path, Detail.Models);
            if (flags.HasFlag(ExportFlags.SkyBox)) ExportSkyBox(path);

            Console.WriteLine("Additional models: done.");

            /*
            foreach (QuadBlock qb in quads)
            {
                string x = ".\\textures\\" + qb.id.ToString("X8") + "\\";

                Helpers.CheckFolder(x);

                ctrvram.GetTexture(qb.texlow).Save(x + "low_" + qb.texlow.Tag() + ".png");

                foreach (CtrTex ct in qb.tex)
                {
                    foreach (TextureLayout tl in ct.midlods)
                    {
                        try
                        {
                            ctrvram.GetTexture(tl).Save(x + "med_" + tl.Tag() + ".png");
                        }
                        catch
                        {
                            File.WriteAllText(x + "error.txt", $"error med: quad - {qb.pos.ToString("X8")}, texlayout: {tl.Position.ToString("X8")}\r\n");
                        }
                    }

                    int i = 0;

                    foreach (TextureLayout tl in ct.hi)
                    {
                        try
                        {
                            ctrvram.GetTexture(tl).Save(x + "hi_" + i + "_" + tl.Tag() + ".png");
                        }
                        catch
                        {
                            File.WriteAllText(x + "error.txt", $"error med: quad - {qb.pos.ToString("X8")}, texlayout: {tl.Position.ToString("X8")}\r\n");
                        }

                        i++;
                    }
                }  
            }
            */
        }
Пример #4
0
        public void Export()
        {
            string exportDirectoryLevels    = Path.Combine(this.exportPath, "Levels");
            string exportDirectoryAIModels  = Path.Combine(this.exportPath, "AIModels");
            string exportDirectoryMaterials = Path.Combine(this.exportPath, "Materials");
            string exportDirectoryFamilies  = Path.Combine(this.exportPath, "Families");
            string exportDirectoryGeneral   = Path.Combine(this.exportPath, "General");
            string exportDirectoryTextures  = Path.Combine(this.exportPath, "Resources", "Textures");

            if (flags.HasFlag(ExportFlags.Levels))
            {
                if (!Directory.Exists(exportDirectoryLevels))
                {
                    Directory.CreateDirectory(exportDirectoryLevels);
                }
            }

            if (flags.HasFlag(ExportFlags.AIModels))
            {
                if (!Directory.Exists(exportDirectoryAIModels))
                {
                    Directory.CreateDirectory(exportDirectoryAIModels);
                }
            }

            if (flags.HasFlag(ExportFlags.Materials))
            {
                if (!Directory.Exists(exportDirectoryMaterials))
                {
                    Directory.CreateDirectory(exportDirectoryMaterials);
                }
            }

            if (flags.HasFlag(ExportFlags.Textures))
            {
                if (!Directory.Exists(exportDirectoryTextures))
                {
                    Directory.CreateDirectory(exportDirectoryTextures);
                }
            }

            if (flags.HasFlag(ExportFlags.Families))
            {
                if (!Directory.Exists(exportDirectoryFamilies))
                {
                    Directory.CreateDirectory(exportDirectoryFamilies);
                }
            }

            // Always create general directory
            if (!Directory.Exists(exportDirectoryGeneral))
            {
                Directory.CreateDirectory(exportDirectoryGeneral);
            }

            if (flags.HasFlag(ExportFlags.Textures))
            {
                ExportTextures(exportDirectoryTextures);
            }

            if (flags.HasFlag(ExportFlags.Materials))
            {
                ExportMaterials(exportDirectoryMaterials);
            }

            if (flags.HasFlag(ExportFlags.Families))
            {
                ExportFamilies(exportDirectoryFamilies);
            }

            if (flags.HasFlag(ExportFlags.AIModels))
            {
                ExportAIModels(exportDirectoryAIModels);
            }

            if (flags.HasFlag(ExportFlags.EntryActions))
            {
                ExportEntryActions(exportDirectoryGeneral);
            }

            if (flags.HasFlag(ExportFlags.TextTable))
            {
                ExportTextTable(exportDirectoryGeneral);
            }

            if (flags.HasFlag(ExportFlags.Levels))
            {
                ExportScene(exportDirectoryLevels);
            }
        }
Пример #5
0
        public void Export(string path, ExportFlags flags)
        {
            Console.WriteLine($"Exporting to: {path}");

            if (path.Contains(" "))
            {
                Console.WriteLine("Warning, there are spaces in the path. This may affect material import.");
            }

            if (flags.HasFlag(ExportFlags.MeshLow))
            {
                ExportMesh(path, Detail.Low);
            }
            if (flags.HasFlag(ExportFlags.TexLow))
            {
                ExportTextures(Path.Combine(path, "texLow"), Detail.Low);
            }

            Console.WriteLine("Low mesh: done.");

            if (flags.HasFlag(ExportFlags.MeshMed))
            {
                ExportMesh(path, Detail.Med);
            }
            if (flags.HasFlag(ExportFlags.TexMed))
            {
                ExportTextures(Path.Combine(path, "texMed"), Detail.Med);
            }

            Console.WriteLine("Mid mesh: done.");

            //not implemented, should return subdivided mesh
            //if (flags.HasFlag(ExportFlags.MeshMed)) ExportMesh(dir, Detail.High);
            if (flags.HasFlag(ExportFlags.TexHigh))
            {
                ExportTextures(Path.Combine(path, "texHigh"), Detail.High);
            }

            Console.WriteLine("High mesh: done.");

            if (flags.HasFlag(ExportFlags.Models))
            {
                ExportModels(path);
            }
            if (flags.HasFlag(ExportFlags.SkyBox))
            {
                ExportSkyBox(path);
            }

            Console.WriteLine("Additional models: done.");

            /*
             * foreach (QuadBlock qb in quads)
             * {
             *  string x = ".\\textures\\" + qb.id.ToString("X8") + "\\";
             *
             *  Helpers.CheckFolder(x);
             *
             *  ctrvram.GetTexture(qb.texlow).Save(x + "low_" + qb.texlow.Tag() + ".png");
             *
             *  foreach (CtrTex ct in qb.tex)
             *  {
             *      foreach (TextureLayout tl in ct.midlods)
             *      {
             *          try
             *          {
             *              ctrvram.GetTexture(tl).Save(x + "med_" + tl.Tag() + ".png");
             *          }
             *          catch
             *          {
             *              File.WriteAllText(x + "error.txt", $"error med: quad - {qb.pos.ToString("X8")}, texlayout: {tl.Position.ToString("X8")}\r\n");
             *          }
             *      }
             *
             *      int i = 0;
             *
             *      foreach (TextureLayout tl in ct.hi)
             *      {
             *          try
             *          {
             *              ctrvram.GetTexture(tl).Save(x + "hi_" + i + "_" + tl.Tag() + ".png");
             *          }
             *          catch
             *          {
             *              File.WriteAllText(x + "error.txt", $"error med: quad - {qb.pos.ToString("X8")}, texlayout: {tl.Position.ToString("X8")}\r\n");
             *          }
             *
             *          i++;
             *      }
             *  }
             * }
             */
        }