Пример #1
0
        public static void ConvertEmbeddedResources(Configuration configuration, string assemblyPath, TranslationResult result)
        {
            using (var domain = new TemporaryAppDomain("ConvertEmbeddedResources")) {
                var resourceExtractor = domain.CreateInstanceAndUnwrap <
                    ManifestResourceExtractor, IManifestResourceExtractor
                    >();

                var manifestResources = resourceExtractor.GetManifestResources(
                    assemblyPath, (fn) => fn.EndsWith(".resources")
                    );

                var encoding = new UTF8Encoding(false);

                foreach (var kvp in manifestResources)
                {
                    Console.WriteLine(kvp.Key);

                    string resourceJson;
                    using (var memoryStream = new MemoryStream(kvp.Value, false))
                        resourceJson = ConvertResources(memoryStream);

                    var bytes = encoding.GetBytes(resourceJson);

                    result.AddFile(
                        "Resources",
                        Path.GetFileNameWithoutExtension(kvp.Key) + ".resj",
                        new ArraySegment <byte>(bytes)
                        );
                }
            }
        }
Пример #2
0
        public static void ExtractFromAssembly(Configuration configuration, string assemblyPath, TranslationResult result)
        {
            using (var domain = new TemporaryAppDomain("ExtractFromAssembly")) {
                var resourceExtractor = domain.CreateInstanceAndUnwrap <
                    ManifestResourceExtractor, IManifestResourceExtractor
                    >();

                var manifestResources = resourceExtractor.GetManifestResources(
                    assemblyPath, (fn) => !fn.EndsWith(".resources")
                    );

                var encoding = new UTF8Encoding(false);

                foreach (var kvp in manifestResources)
                {
                    Console.WriteLine(kvp.Key);
                    var key = kvp.Key;

                    if (result.Files.ContainsKey(key))
                    {
                        if (result.Files[key].Size != kvp.Value.Length)
                        {
                            throw new InvalidOperationException("Found two conflicting manifest resources named '" + key + "'");
                        }
                    }
                    else
                    {
                        result.AddFile(
                            "ManifestResource", key,
                            new ArraySegment <byte>(kvp.Value),
                            properties: new Dictionary <string, object> {
                            { "assembly", Path.GetFileNameWithoutExtension(assemblyPath) }
                        }
                            );
                    }
                }
            }
        }
Пример #3
0
 protected override void PostProcessAllTranslatedAssemblies(Configuration configuration, string assemblyPath, TranslationResult result)
 {
     base.PostProcessAllTranslatedAssemblies(configuration, assemblyPath, result);
     result.AddFile("Script", "XNA.Colors.js", new ArraySegment <byte>(Encoding.UTF8.GetBytes(Common.MakeXNAColors())), 0);
 }
Пример #4
0
        public static void ConvertEmbeddedResources(Configuration configuration, string assemblyPath, TranslationResult result)
        {
            var asm = Assembly.ReflectionOnlyLoadFrom(assemblyPath);

            var resourceFiles = (from fn in asm.GetManifestResourceNames() where fn.EndsWith(".resources") select fn).ToArray();
            var encoding = new UTF8Encoding(false);

            foreach (var resourceName in resourceFiles) {
                if (!resourceName.EndsWith(".resources"))
                    continue;

                var resourceJson = ConvertEmbeddedResourceFile(configuration, assemblyPath, asm, resourceName);
                var bytes = encoding.GetBytes(resourceJson);

                result.AddFile(
                    "Resources",
                    Path.GetFileNameWithoutExtension(resourceName) + ".resj",
                    new ArraySegment<byte>(bytes)
                );
            }
        }
Пример #5
0
 protected override void PostProcessAllTranslatedAssemblies (Configuration configuration, string assemblyPath, TranslationResult result) {
     base.PostProcessAllTranslatedAssemblies(configuration, assemblyPath, result);
     result.AddFile("Script", "XNA.Colors.js", new ArraySegment<byte>(Encoding.UTF8.GetBytes(Common.MakeXNAColors())), 0);
 }