示例#1
0
        private static IEnumerable <AbcFile> GetAbcFiles(string path)
        {
            string ext = Utils.GetExt(path);

            if (ext == "abc")
            {
                var abc  = new AbcFile(path);
                var list = new List <AbcFile> {
                    abc
                };
                return(list);
            }

            if (ext == "swf")
            {
                var swf  = new SwfMovie(path);
                var list = swf.GetAbcFiles();
                return(list);
            }

            if (ext == "swc")
            {
                var swc  = new SwcFile(path);
                var list = swc.GetAbcFiles();
                return(list);
            }

            return(Enumerable.Empty <AbcFile>());
        }
示例#2
0
        public static void LoadExclude(IDictionary filter, string path)
        {
            string ext = Utils.GetExt(path);

            switch (ext)
            {
            case "abc":
            {
                var abc = new AbcFile(path);
                AddExcludes(filter, abc);
            }
            break;

            case "swf":
            {
                var swf  = new SwfMovie(path);
                var list = swf.GetAbcFiles();
                foreach (var abc in list)
                {
                    AddExcludes(filter, abc);
                }
            }
            break;

            case "swc":
            {
                var swc = new SwcFile(path);
                foreach (var abc in swc.GetAbcFiles())
                {
                    AddExcludes(filter, abc);
                }
            }
            break;
            }
        }
示例#3
0
        private void ImportStyleMixins(AbcFile app, SwcFile swc, bool strict)
        {
            var mixins = new List <AbcInstance>(GetStyleMixins(swc, strict));

            foreach (var mixin in mixins)
            {
                string name = mixin.FullName;
                AddMixin(name);
                app.Import(mixin.Abc);
            }
        }
示例#4
0
        private void ImportEmbeddedStyleMixins(AbcFile app)
        {
            var swcResource = GetType().GetResourceStream("mixins.swc");

            if (swcResource == null)
            {
                throw new InvalidOperationException("Unable to load mixins");
            }

            var depsResource = GetType().GetResourceStream("mixins.dep");
            var deps         = new SwcDepFile(depsResource);

            var swc = new SwcFile(swcResource);

            swc.ResolveDependencies(new SimpleSwcLinker(_compiler.AppAssembly), deps);

            ImportStyleMixins(app, swc, false);
        }
示例#5
0
        static void DumpClassList(string path, bool sort)
        {
            string ext = Utils.GetExt(path);

            if (ext == "abc")
            {
                var abc  = new AbcFile(path);
                var list = new List <string>();
                GetClassList(list, abc);
                WriteClassList(path, "", list, sort);
                return;
            }

            if (ext == "swf")
            {
                var swf = new SwfMovie(path);
                var all = new List <string>();
                int i   = 1;
                foreach (var abc in swf.GetAbcFiles())
                {
                    GetClassList(all, abc);
                    var list = new List <string>();
                    GetClassList(list, abc);
                    WriteClassList(path, ".frame" + i, list, sort);
                    ++i;
                }
                WriteClassList(path, "", all, sort);
                return;
            }

            if (ext == "swc")
            {
                var swc  = new SwcFile(path);
                var list = new List <string>();
                foreach (var abc in swc.GetAbcFiles())
                {
                    GetClassList(list, abc);
                }
                WriteClassList(path, "", list, sort);
                return;
            }
        }
示例#6
0
        static void DumpAssets(string path)
        {
            string ext = Utils.GetExt(path);

            if (ext == "swf")
            {
                var swf = new SwfMovie(path);
                DumpAssetsCore(swf, path + ".assets");
                return;
            }

            if (ext == "swc")
            {
                var swc = new SwcFile(path);
                foreach (var swf in swc.ExtractSwfs())
                {
                    DumpAssetsCore(swf, path + "." + swf.Name + ".txt");
                }
                return;
            }
        }
示例#7
0
        private void ImportStyleMixins(AbcFile app)
        {
#if PERF
            int start = Environment.TickCount;
            Console.WriteLine("ImportStyleMixins");
#endif
            string styleMixins = _compiler.Options.StyleMixins;
            if (!string.IsNullOrEmpty(styleMixins) &&
                File.Exists(styleMixins))
            {
                var swc = new SwcFile(styleMixins);
                swc.ResolveDependencies(new SimpleSwcLinker(_compiler.AppAssembly), null);
                ImportStyleMixins(app, swc, true);
                return;
            }

            ImportEmbeddedStyleMixins(app);

#if PERF
            Console.WriteLine("ImportStyleMixins: {0}", Environment.TickCount - start);
#endif
        }
示例#8
0
        static void DumpInstances(CommandLine cl, string path)
        {
            string ext = Utils.GetExt(path);

            if (ext == "abc")
            {
                var abc = new AbcFile(path);
                DumpInstances(path, new[] { abc });
                return;
            }

            bool frames = cl.HasOption("frames");

            if (ext == "swf")
            {
                var swf  = new SwfMovie(path);
                var list = swf.GetAbcFiles();
                int n    = list.Count;
                for (int i = 0; i < n; ++i)
                {
                    var    abc = list[i];
                    string dir = path + ".instances";
                    if (frames)
                    {
                        dir += "\\" + i;
                    }
                    DumpInstancesTo(dir, abc);
                }
                return;
            }

            if (ext == "swc")
            {
                var swc = new SwcFile(path);
                DumpInstances(path, swc.GetAbcFiles());
                return;
            }
        }
示例#9
0
        public Linker(IAssembly assembly)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            var data = assembly.CustomData();

            if (data.Linker != null)
            {
                throw new InvalidOperationException();
            }

            data.Linker = this;

            Assembly = assembly;

            // we should always listen TypeLoaded event to fill AssemblyLinked
            if (Assembly.Loader != null)
            {
                Assembly.Loader.TypeLoaded += OnTypeLoaded;
            }

            var resource = Assembly.MainModule.Resources.FirstOrDefault(
                x => x.Name.EndsWith(".abc", StringComparison.OrdinalIgnoreCase) ||
                x.Name.EndsWith(".swc", StringComparison.OrdinalIgnoreCase));

            if (resource != null)
            {
                data.Flags |= InternalAssembyFlags.HasAbcImports;

                if (resource.Name.EndsWith(".abc", StringComparison.OrdinalIgnoreCase))
                {
                    _abc = new AbcFile(resource.Data)
                    {
                        Assembly = Assembly
                    };
                    data.Abc = _abc;
                    _cache   = new AbcCache();
                    _cache.Add(_abc);
                }
                else if (resource.Name.EndsWith(".swc", StringComparison.OrdinalIgnoreCase))
                {
                    string swcName = GetResFileName(resource.Name);

                    _swcDeps = LoadSwcDep(swcName);
                    _swc     = new SwcFile(resource.Data)
                    {
                        Assembly = Assembly,
                        Name     = swcName
                    };
                    _cache = _swc.AbcCache;

                    data.SWC = _swc;
                }
            }

            // create all linkers to subscribe on AssemblyLoader.TypeLoaded event before we start process
            assembly.ProcessReferences(true,
                                       asm =>
            {
                if (asm.CustomData().Linker == null)
                {
                    asm.CustomData().Linker = new Linker(asm);
                }
            });

            if (_swc != null)
            {
                _swc.ResolveDependencies(this, _swcDeps);
            }
        }
示例#10
0
 private static IEnumerable <AbcInstance> GetStyleMixins(SwcFile swc, bool strict)
 {
     return(swc.GetAbcFiles().SelectMany(abc => GetStyleMixins(abc, strict)));
 }