private bool ParseFoundFiles()
        {
            bool writeCache = false;

            // parse files
            int n = foundFiles.Count;
            NotifyProgress(String.Format(TextHelper.GetString("Info.Parsing"), n), 0, n);
            FileModel aFile = null;
            string basePath = "";
            string packagePath = "";
            int cpt = 0;
            string filename;
            for (int i = 0; i < n; i++)
            {
                if (stopExploration) return writeCache;
                // parse
                filename = foundFiles[i] as string;
                if (!File.Exists(filename))
                    continue;
                if (pathModel.HasFile(filename))
                {
                    FileModel cachedModel = pathModel.GetFile(filename);
                    if (cachedModel.OutOfDate)
                    {
                        cachedModel.Check();
                        writeCache = true;
                    }
                    continue;
                }
                else writeCache = true;

                aFile = GetFileModel(filename); //ASContext.Panel.Invoke(new GetFileModelHandler(GetFileModel), new object[] { filename }) as FileModel;

                if (aFile == null || pathModel.HasFile(filename)) continue;
                // store model
                basePath = Path.GetDirectoryName(filename);
                if (aFile.Package != "")
                {
                    packagePath = '\\' + aFile.Package.Replace('.', '\\');
                    if (basePath.EndsWith(packagePath))
                        basePath = basePath.Substring(0, basePath.Length - packagePath.Length);
                }
                basePath += "\\";
                lock (pathModel.Files) { pathModel.Files[aFile.FileName.ToUpper()] = aFile; }
                aFile = null;
                cpt++;
                // update status
                if (stopExploration) return writeCache;
                if (i % 10 == 0) NotifyProgress(String.Format(TextHelper.GetString("Info.Parsing"), n), i, n);
                Thread.Sleep(1);
            }
            return writeCache;
        }
Example #2
0
        private bool ParseFoundFiles()
        {
            bool writeCache = false;

            // parse files
            int n = foundFiles.Count;

            NotifyProgress(String.Format(TextHelper.GetString("Info.Parsing"), n), 0, n);
            FileModel aFile = null;
            int       cpt   = 0;
            string    filename;

            for (int i = 0; i < n; i++)
            {
                if (stopExploration)
                {
                    return(writeCache);
                }
                // parse
                filename = foundFiles[i];
                if (!File.Exists(filename))
                {
                    continue;
                }
                if (pathModel.HasFile(filename))
                {
                    FileModel cachedModel = pathModel.GetFile(filename);
                    if (cachedModel.OutOfDate)
                    {
                        cachedModel.Check();
                        writeCache = true;
                    }
                    continue;
                }
                else
                {
                    writeCache = true;
                }

                aFile = GetFileModel(filename);

                if (aFile == null || pathModel.HasFile(filename))
                {
                    continue;
                }
                // store model
                if (aFile.Context.IsModelValid(aFile, pathModel))
                {
                    pathModel.AddFile(aFile);
                }
                aFile = null;
                cpt++;
                // update status
                if (stopExploration)
                {
                    return(writeCache);
                }
                if (i % 10 == 0)
                {
                    NotifyProgress(String.Format(TextHelper.GetString("Info.Parsing"), n), i, n);
                }
                Thread.Sleep(1);
            }
            return(writeCache);
        }
Example #3
0
 private ClassModel LocateClassFile(PathModel aPath, string fileName)
 {
     if (!aPath.IsValid) return null;
     try
     {
         string path = Path.Combine(aPath.Path, fileName);
         // cached file
         if (aPath.HasFile(path))
         {
             FileModel nFile = aPath.GetFile(path);
             if (nFile.Context != this)
             {
                 // not associated with this context -> refresh
                 nFile.OutOfDate = true;
                 nFile.Context = this;
             }
             return nFile.GetPublicClass();
         }
         // non-cached existing file
         else if (File.Exists(path))
         {
             FileModel nFile = GetFileModel(path);
             if (nFile != null)
             {
                 aPath.AddFile(nFile);
                 return nFile.GetPublicClass();
             }
         }
     }
     catch (Exception ex)
     {
         aPath.IsValid = false;
         ErrorManager.ShowError(ex);
     }
     return null;
 }
Example #4
0
        private bool OpenVirtualFileModel(string virtualPath)
        {
            int p = virtualPath.IndexOf("::");
            if (p < 0) return false;

            string container = virtualPath.Substring(0, p);
            string ext = Path.GetExtension(container).ToLower();
            if (ext != ".swc" && ext != ".swf")
                return false;
            if (!File.Exists(container))
                return false;

            string fileName = Path.Combine(container, 
                virtualPath.Substring(p + 2).Replace('.', Path.DirectorySeparatorChar));
            PathModel path = new PathModel(container, contextInstance);
            SwfOp.ContentParser parser = new SwfOp.ContentParser(path.Path);
            parser.Run();
            AbcConverter.Convert(parser, path, contextInstance);
            
            if (path.HasFile(fileName))
            {
                FileModel model = path.GetFile(fileName);
                ASComplete.OpenVirtualFile(model);
            }
            return false;
        }
Example #5
0
        private bool OpenVirtualFileModel(string virtualPath)
        {
            int p = virtualPath.IndexOf("::");
            if (p < 0) return false;

            string container = virtualPath.Substring(0, p);
            string ext = Path.GetExtension(container).ToLower();
            if (ext != ".loomlib") return false;
            if (!File.Exists(container)) return false;

            string fileName = Path.Combine(container, virtualPath.Substring(p + 2).Replace('.', Path.DirectorySeparatorChar));
            PathModel path = new PathModel(container, contextInstance);

            if (path.HasFile(fileName))
            {
                FileModel model = path.GetFile(fileName);
                ASComplete.OpenVirtualFile(model);
                return true;
            }
            return false;
        }
Example #6
0
        /// <summary>
        /// Create virtual FileModel objects from Abc bytecode
        /// </summary>
        /// <param name="abcs"></param>
        /// <param name="path"></param>
        /// <param name="context"></param>
        public static void Convert(ContentParser parser, PathModel path, IASContext context)
        {
            path.Files.Clear();
            inSWF = Path.GetExtension(path.Path).ToLower() == ".swf";

            // extract documentation
            ParseDocumentation(parser);

            // extract models
            FileModel privateClasses = new FileModel(Path.Combine(path.Path, "__Private.as"));
            privateClasses.Version = 3;
            privateClasses.Package = "private";
            genericTypes = new Dictionary<string, FileModel>();
            imports = new Dictionary<string, string>();

            foreach (Abc abc in parser.Abcs)
            {
                // types
                foreach (Traits trait in abc.classes)
                {
                    Traits instance = trait.itraits;
                    if (instance == null)
                        continue;
                    imports.Clear();

                    FileModel model = new FileModel("");
                    model.Context = context;
                    model.Package = reSafeChars.Replace(instance.name.uri, "_");
                    model.HasPackage = true;
                    string filename = reSafeChars.Replace(trait.name.ToString(), "_").TrimEnd('$');
                    filename = Path.Combine(model.Package.Replace('.', Path.DirectorySeparatorChar), filename);
                    model.FileName = Path.Combine(path.Path, filename);
                    model.Version = 3;

                    ClassModel type = new ClassModel();
                    model.Classes = new List<ClassModel>();
                    model.Classes.Add(type);
                    type.InFile = model;

                    type.Type = instance.name.ToTypeString();
                    type.Name = instance.name.localName;

                    thisDocs = GetDocs(model.Package);
                    if (thisDocs != null)
                    {
                        docPath = (model.Package.Length > 0 ? model.Package + ":" : "globalClassifier:") + type.Name;
                        if (thisDocs.ContainsKey(docPath))
                        {
                            DocItem doc = thisDocs[docPath];
                            setDoc(doc, type);
                            if (doc.Meta != null) model.MetaDatas = doc.Meta;
                        }
                        if (model.Package.Length == 0) docPath = type.Name;
                    }

                    if (instance.baseName.uri == model.Package)
                        type.ExtendsType = ImportType(instance.baseName.localName);
                    else type.ExtendsType = ImportType(instance.baseName);

                    if (instance.interfaces != null && instance.interfaces.Length > 0)
                    {
                        type.Implements = new List<string>();
                        foreach (QName name in instance.interfaces)
                            type.Implements.Add(ImportType(name));
                    }

                    if (model.Package == "private")
                    {
                        model.Package = "";
                        type.Access = Visibility.Private;
                        type.Namespace = "private";
                    }
                    else if (model.Package == "__AS3__.vec")
                    {
                        model.Package = "";
                        type.Access = Visibility.Private;
                        type.Namespace = "private";
                        string genType = type.Name;
                        if (type.Name.IndexOf("$") > 0)
                        {
                            string[] itype = type.Name.Split('$');
                            genType = itype[0];
                            type.Name = itype[0] + "$" + itype[1];
                            type.IndexType = itype[1];
                        }
                        if (genericTypes.ContainsKey(genType))
                        {
                            model.Classes.Clear();
                            type.InFile = genericTypes[genType];
                            genericTypes[genType].Classes.Add(type);
                        }
                        else genericTypes[genType] = model;
                    }
                    else if (type.Name.StartsWith("_"))
                    {
                        type.Access = Visibility.Private;
                        type.Namespace = "private";
                    }
                    else
                    {
                        type.Access = Visibility.Public;
                        type.Namespace = "public";
                    }

                    type.Flags = FlagType.Class;
                    if (instance.flags == TraitMember.Function) type.Flags |= FlagType.Interface;

                    type.Members = GetMembers(trait.members, FlagType.Static, instance.name);
                    type.Members.Add(GetMembers(instance.members, FlagType.Dynamic, instance.name));

                    if ((type.Flags & FlagType.Interface) > 0)
                    {
                        // TODO properly support interface multiple inheritance
                        type.ExtendsType = null;
                        if (type.Implements != null && type.Implements.Count > 0)
                        {
                            type.ExtendsType = type.Implements[0];
                            type.Implements.RemoveAt(0);
                            if (type.Implements.Count == 0) type.Implements = null;
                        }

                        foreach (MemberModel member in type.Members)
                        {
                            member.Access = Visibility.Public;
                            member.Namespace = "";
                        }
                    }

                    // constructor
                    if (instance.init != null && (type.Flags & FlagType.Interface) == 0)
                    {
                        List<MemberInfo> temp = new List<MemberInfo>(new MemberInfo[] { instance.init });
                        MemberList result = GetMembers(temp, 0, instance.name);
                        if (result.Count > 0)
                        {
                            MemberModel ctor = result[0];
                            ctor.Flags |= FlagType.Constructor;
                            ctor.Access = Visibility.Public;
                            ctor.Type = type.Type;
                            ctor.Namespace = "public";
                            type.Members.Merge(result);
                            type.Constructor = ctor.Name;
                        }
                        result = null;
                        temp = null;
                    }
                    else type.Constructor = type.Name;

                    if (type.Access == Visibility.Private)
                    {
                        model = privateClasses;
                        type.InFile = model;
                    }

                    if (model.Classes.Count > 0 || model.Members.Count > 0)
                    {
                        AddImports(model, imports);
                        path.AddFile(model);
                    }
                }

                // packages
                if (abc.scripts == null)
                    continue;
                foreach (Traits trait in abc.scripts)
                {
                    FileModel model = null;
                    foreach (MemberInfo info in trait.members)
                    {
                        if (info.kind == TraitMember.Class)
                            continue;

                        MemberModel member = GetMember(info, 0);
                        if (member == null) continue;

                        if (model == null || model.Package != info.name.uri)
                        {
                            AddImports(model, imports);

                            string package = info.name.uri ?? "";
                            string filename = package.Length > 0 ? "package.as" : "toplevel.as";
                            filename = Path.Combine(package.Replace('.', Path.DirectorySeparatorChar), filename);
                            filename = Path.Combine(path.Path, filename);
                            if (path.HasFile(filename))
                                model = path.GetFile(filename);
                            else
                            {
                                model = new FileModel("");
                                model.Context = context;
                                model.Package = package;
                                model.HasPackage = true;
                                model.FileName = filename;
                                model.Version = 3;
                                path.AddFile(model);
                            }
                        }

                        thisDocs = GetDocs(model.Package);
                        if (thisDocs != null)
                        {
                            docPath = "globalOperation:" + (model.Package.Length > 0 ? model.Package + ":" : "")
                                + member.Name;
                            if (member.Access == Visibility.Public && !String.IsNullOrEmpty(member.Namespace)
                                && member.Namespace != "public")
                                docPath += member.Namespace + ":";
                            if ((member.Flags & FlagType.Setter) > 0) docPath += ":set";
                            else if ((member.Flags & FlagType.Getter) > 0) docPath += ":get";

                            if (thisDocs.ContainsKey(docPath)) setDoc(thisDocs[docPath], member);
                        }

                        member.InFile = model;
                        member.IsPackageLevel = true;
                        model.Members.Add(member);
                    }

                    AddImports(model, imports);
                }
            }

            if (privateClasses.Classes.Count > 0) path.AddFile(privateClasses);

            // some SWCs need manual fixes
            CustomFixes(path);

            // fake SWC (like 'playerglobal_rb.swc', only provides documentation)
            if (path.Files.Count == 1)
            {
                foreach (FileModel model in path.Files.Values)
                    if (model.GetPublicClass().QualifiedName == "Empty")
                    {
                        path.Files.Clear();
                        break;
                    }
            }
        }
Example #7
0
 private static void CustomFixes(PathModel path)
 {
     string file = Path.GetFileName(path.Path);
     if (file == "playerglobal.swc" || file == "airglobal.swc")
     {
         string mathPath = Path.Combine(path.Path, "Math").ToUpper();
         if (path.HasFile(mathPath))
         {
             ClassModel mathModel = path.GetFile(mathPath).GetPublicClass();
             foreach (MemberModel member in mathModel.Members)
             {
                 if (member.Parameters != null && member.Parameters.Count > 0 && member.Parameters[0].Name == "x")
                 {
                     string n = member.Name;
                     if (member.Parameters.Count > 1)
                     {
                         if (n == "atan2") member.Parameters.Reverse();
                         else if (n == "min" || n == "max") { member.Parameters[0].Name = "val1"; member.Parameters[1].Name = "val2"; }
                         else if (n == "pow") { member.Parameters[0].Name = "base"; member.Parameters[1].Name = "pow"; }
                     }
                     else if (n == "sin" || n == "cos" || n == "tan") member.Parameters[0].Name = "angleRadians";
                     else member.Parameters[0].Name = "val";
                 }
             }
         }
         string objPath = Path.Combine(path.Path, "Object").ToUpper();
         if (path.HasFile(objPath))
         {
             ClassModel objModel = path.GetFile(objPath).GetPublicClass();
             if (objModel.Members.Search("prototype", 0, 0) == null)
             {
                 MemberModel proto = new MemberModel("prototype", "Object", FlagType.Dynamic | FlagType.Variable, Visibility.Public);
                 objModel.Members.Add(proto);
             }
         }
     }
 }
Example #8
0
        private bool OpenVirtualFileModel(string virtualPath)
        {
            int p = virtualPath.IndexOfOrdinal("::");
            if (p < 0) return false;

            string container = virtualPath.Substring(0, p);
            string ext = Path.GetExtension(container).ToLower();
            if (ext != ".swf" && ext != ".swc" && ext != ".ane") return false;
            if (!File.Exists(container)) return false;

            string fileName = Path.Combine(container, virtualPath.Substring(p + 2).Replace('.', Path.DirectorySeparatorChar));
            PathModel path = new PathModel(container, contextInstance);
            ContentParser parser = new ContentParser(path.Path);
            parser.Run();
            AbcConverter.Convert(parser, path, contextInstance);

            if (path.HasFile(fileName))
            {
                FileModel model = path.GetFile(fileName);
                ASComplete.OpenVirtualFile(model);
                return true;
            }
            int split = fileName.LastIndexOf(Path.DirectorySeparatorChar) + 1;
            fileName = fileName.Substring(0, split) + "package.as";
            if (path.HasFile(fileName))
            {
                FileModel model = path.GetFile(fileName);
                ASComplete.OpenVirtualFile(model);
                return true;
            }
            fileName = fileName.Substring(0, split) + "toplevel.as";
            if (path.HasFile(fileName))
            {
                FileModel model = path.GetFile(fileName);
                ASComplete.OpenVirtualFile(model);
                return true;
            }
            return false;
        }