private AbcInstance EmbedResource(ResourceBundleContext context, Function func) { var embed = Embed.FromDirective(func); if (embed == null) { throw Errors.RBC.UnableToResolveEmbed.CreateException(func); } string type = embed.MimeType; string source = embed.Source; bool jpeg = false; if (MimeTypes.IsBitmap(type) || (jpeg = MimeTypes.IsJpeg(type))) { var image = ResolveImage(context, source); if (image == null) { throw Errors.RBC.UnableToResolveImage.CreateException(source); } var name = DefineAssetName(context, "embedded_image_"); var instance = _embedAssetInstances[name] as AbcInstance; if (instance != null) { return(instance); } var mn = DefineName(QName.PfxPublic(name)); instance = Generator.EmbeddedAssets.BuildBitmapAsset(mn, image, jpeg); _embedAssetInstances[name] = instance; return(instance); } //TODO: Support other mime-types throw Errors.RBC.NotSupportedMimeType.CreateException(embed.Source, embed.MimeType); }
public void ImportResourceBundle(string name, ResourceBundleContext context) { foreach (var locale in Locales) { ImportResourceBundle(locale, name, context); } }
private bool ImportResourceBundle(AbcFile abc, AbcMetaEntry e) { if (e.NameString != MetadataTags.ResourceBundle) { return(false); } string name = e.GetResourceBundleName(); if (string.IsNullOrEmpty(name)) { throw Errors.RBC.BadMetaEntry.CreateException(); } var swc = abc.Swc; if (swc != null) { swc.LoadResourceBundles(); } var context = new ResourceBundleContext { Swc = swc }; ImportResourceBundle(name, context); return(true); }
private static string DefineAssetName(ResourceBundleContext context, string prefix) { string name = prefix; if (context.Swc != null) { name += context.Swc.Name; name += "_"; } name += context.ResolvedSource; return(name.ToValidName()); }
private bool PushKeyValue(string line, AbcCode code, ResourceBundleContext context) { if (string.IsNullOrEmpty(line)) { return(false); } line = line.Trim(); if (string.IsNullOrEmpty(line)) { return(false); } if (line.IsResourceBundleComment()) { return(false); } int sep = line.IndexOf('='); if (sep >= 0) { //TODO: process standard escape sequences string key = line.Substring(0, sep).Trim(); string value = line.Substring(sep + 1).Trim(); code.PushString(key); if (value.StartsWith(PrefixEmbed)) { var res = EmbedResource(context, value); code.Getlex(res); return(true); } if (value.StartsWith(PrefixClassReference)) { var cr = ResolveClassRef(value); code.Getlex(cr); return(true); } code.PushString(value); return(true); } //TODO: Is it warning or error? return(false); }
private static Image ResolveImage(ResourceBundleContext context, string source) { try { var rb = context.ResourceBundle; if (context.Swc != null) { if (rb.IsZipped) { string dir = System.IO.Path.GetDirectoryName(rb.ZipEntry); string imagePath = System.IO.Path.Combine(dir, source); imagePath = imagePath.Replace('\\', '/'); imagePath = imagePath.ToFullPath(); context.ResolvedSource = imagePath; return(context.Swc.ResolveImage(imagePath)); } } return(null); } catch (Exception) { throw Errors.RBC.UnableToResolveImage.CreateException(source); } }
public void ImportResourceBundle(string locale, string name, ResourceBundleContext context) { if (context == null) { context = new ResourceBundleContext(); } context.Locale = locale; ResourceBundles.CopyFlexLocale(locale); string key = locale + "$" + name; if (ContainsResourceBundle(key)) { return; } var rb = ResourceBundles.Get(locale, name); //NOTE: null in case of Dynamic Resource Modules!!! if (rb == null) { return; } var superType = ResourceBundleSuper; var instance = new AbcInstance(true) { ResourceBundleName = name, Locale = locale }; _rbcache[key] = instance; //NOTE: naming is strongly determined in Flex Resource Manager. string fullname = locale + '$' + name + "_properties"; instance.Name = DefineName(QName.Global(fullname)); instance.Flags = AbcClassFlags.Sealed | AbcClassFlags.ProtectedNamespace; instance.ProtectedNamespace = DefineProtectedNamespace(fullname); instance.BaseInstance = superType; instance.BaseTypeName = superType.Name; AddInstance(instance); instance.Initializer = DefineMethod( Sig.@void(), code => { code.PushThisScope(); code.LoadThis(); code.PushString(locale); code.PushString(name); code.ConstructSuper(2); code.ReturnVoid(); }); instance.Class.Initializer = DefineEmptyMethod(); var mn = DefineQName(instance.ProtectedNamespace, "getContent"); instance.DefineMethod( Sig.@override(mn, AvmTypeCode.Object), code => { int n = 0; var lines = rb.Content; for (int i = 0; i < lines.Length; ++i) { string line = lines[i]; context.Line = i + 1; context.ResourceBundle = rb; if (PushKeyValue(line, code, context)) { ++n; } } code.Add(InstructionCode.Newobject, n); code.ReturnValue(); } ); DefineScript(instance); }
private AbcInstance EmbedResource(ResourceBundleContext context, string value) { var func = ParseDirective(value); return(EmbedResource(context, func)); }