Ejemplo n.º 1
0
        public bool Run()
        {
            var manifests = new List <string>();

            foreach (string manifest in GetType().Assembly.GetManifestResourceNames())
            {
                if (manifest.StartsWith("SilverSim.Tests.Resources.Objects.") && manifest.EndsWith(".xml"))
                {
                    manifests.Add(manifest);
                }
            }

            foreach (string manifest in manifests)
            {
                m_Log.InfoFormat("Testing decoder with asset {0}", manifest);
                Stream resource = GetType().Assembly.GetManifestResourceStream(manifest);
                try
                {
                    ObjectXML.FromXml(resource, UGUI.Unknown, XmlDeserializationOptions.ReadKeyframeMotion);
                }
                catch (Exception e)
                {
                    m_Log.InfoFormat("Failed to parse asset {0}: {1}\n{2}", e.GetType().FullName, e.StackTrace, e.StackTrace.ToString());
                    return(false);
                }

                var reflist = new List <UUID>();
                resource = GetType().Assembly.GetManifestResourceStream(manifest);
                ObjectReferenceDecoder.GetReferences(resource, "", reflist);
                m_Log.InfoFormat("Found {0} references", reflist.Count);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public bool Run()
        {
            bool success    = true;
            int  count      = 0;
            int  successcnt = 0;

            foreach (KeyValuePair <UUID, string> file in Assets)
            {
                ++count;
                var tr = new TestRunner.TestResult
                {
                    Name    = "Asset " + file.Key + "(" + file.Value + ")",
                    Result  = false,
                    Message = string.Empty
                };
                int startTime = Environment.TickCount;
                m_Log.InfoFormat("Testing deserialization of {1} ({0})", file.Key, file.Value);

                try
                {
                    using (Stream s = new HttpClient.Get(file.Value).ExecuteStreamRequest())
                    {
                        ObjectXML.FromXml(s, UGUI.Unknown, XmlDeserializationOptions.ReadKeyframeMotion);
                    }
                    m_Log.InfoFormat("Deserialization of {1} ({0}) successful", file.Key, file.Value);
                    ++successcnt;
                    tr.Result = true;
                }
                catch (Exception e)
                {
                    m_Log.ErrorFormat("Compilation of {1} ({0}) failed: {2}", file.Key, file.Value, e.Message);
                    m_Log.WarnFormat("Stack Trace:\n{0}", e.StackTrace);
                    tr.Message = e.Message + "\n" + e.StackTrace;
                    success    = false;
                }
                tr.RunTime = Environment.TickCount - startTime;
                m_Runner.TestResults.Add(tr);
            }
            m_Log.InfoFormat("{0} of {1} compilations successful", successcnt, count);
            return(success);
        }
Ejemplo n.º 3
0
        public int CheckAssetFormat(ScriptInstance instance, LSLKey assetid)
        {
            lock (instance)
            {
                AssetServiceInterface assetService = instance.Part.ObjectGroup.AssetService;
                AssetData             asset;
                if (!assetService.TryGetValue(assetid.AsUUID, out asset))
                {
                    return(0);
                }

                switch (asset.Type)
                {
                case AssetType.Bodypart:
                case AssetType.Clothing:
                    try
                    {
                        new Wearable(asset);
                        return(1);
                    }
                    catch
                    {
                        return(0);
                    }

                case AssetType.Gesture:
                    try
                    {
                        new Gesture(asset);
                        return(1);
                    }
                    catch
                    {
                        return(0);
                    }

                case AssetType.Landmark:
                    try
                    {
                        new Landmark(asset);
                        return(1);
                    }
                    catch
                    {
                        return(0);
                    }

                case AssetType.Mesh:
                    try
                    {
                        new LLMesh(asset);
                        return(1);
                    }
                    catch
                    {
                        return(0);
                    }

                case AssetType.Notecard:
                    try
                    {
                        new Notecard(asset);
                        return(1);
                    }
                    catch
                    {
                        return(0);
                    }

                case AssetType.Object:
                    try
                    {
                        ObjectXML.FromXml(asset.InputStream, instance.Part.Owner);
                        return(1);
                    }
                    catch
                    {
                        return(0);
                    }

                case AssetType.Texture:
                    try
                    {
                        using (J2kImage.FromStream(asset.InputStream))
                        {
                        }
                        return(1);
                    }
                    catch
                    {
                        return(0);
                    }

                default:
                    m_Log.WarnFormat("Testing asset type {0} not supported", asset.Type.ToString());
                    return(0);
                }
            }
        }
        public static void Load(
            SceneList scenes,
            SceneInterface scene,
            LoadOptions options,
            Stream inputFile,
            TTY io = null)
        {
            var currentLoadState = CurrentOarLoadState.Unknown;

            using (var gzipStream = new GZipStream(inputFile, CompressionMode.Decompress))
            {
                using (var reader = new TarArchiveReader(gzipStream))
                {
                    var baseLoc = new GridVector(0, 0);
                    if (scene != null)
                    {
                        baseLoc = scene.GridPosition;
                    }

                    var  regionSize     = new GridVector(256, 256);
                    var  regionMapping  = new Dictionary <string, ArchiveXmlLoader.RegionInfo>();
                    var  regionInfos    = new List <ArchiveXmlLoader.RegionInfo>();
                    bool parcelsCleared = false;
                    var  load_sogs      = new List <ObjectGroup>();

                    for (; ;)
                    {
                        TarArchiveReader.Header header;
                        try
                        {
                            header = reader.ReadHeader();
                        }
                        catch (TarArchiveReader.EndOfTarException)
                        {
                            if ((options & LoadOptions.Merge) == 0 && scene != null)
                            {
                                scene.ClearObjects();
                            }

                            AddObjects(scene, load_sogs, options);
                            return;
                        }

                        if (header.FileType == TarFileType.File)
                        {
                            if (header.FileName == "archive.xml")
                            {
                                ArchiveXmlLoader.RegionInfo rinfo = ArchiveXmlLoader.LoadArchiveXml(new ObjectXmlStreamFilter(reader), regionInfos);

                                regionSize = rinfo.RegionSize;
                                foreach (ArchiveXmlLoader.RegionInfo reginfo in regionInfos)
                                {
                                    regionMapping.Add(reginfo.Path, reginfo);
                                }
                                if (regionInfos.Count != 0 && scene != null)
                                {
                                    throw new MultiRegionOARLoadingTriedOnRegionException();
                                }
                                else if (regionInfos.Count == 0 && scene == null)
                                {
                                    throw new OARLoadingTriedWithoutSelectedRegionException();
                                }
                            }
                            else if (header.FileName.StartsWith("assets/"))
                            {
                                if ((options & LoadOptions.NoAssets) == 0)
                                {
                                    ShowOarLoadState(ref currentLoadState, CurrentOarLoadState.Assets, io);
                                    /* Load asset */
                                    AssetData ad = reader.LoadAsset(header, scene.Owner);
                                    if (!scene.AssetService.Exists(ad.ID))
                                    {
                                        scene.AssetService.Store(ad);
                                    }
                                }
                            }
                            else
                            {
                                if (header.FileName.StartsWith("regions/"))
                                {
                                    ShowOarLoadState(ref currentLoadState, CurrentOarLoadState.Region, io);
                                    if ((options & LoadOptions.Merge) == 0 && scene != null)
                                    {
                                        scene.ClearObjects();
                                    }

                                    if (scene != null)
                                    {
                                        AddObjects(scene, load_sogs, options);
                                    }

                                    string[] pcomps = header.FileName.Split(new char[] { '/' }, 3);
                                    if (pcomps.Length < 3)
                                    {
                                        throw new OARFormatException();
                                    }
                                    string regionname = pcomps[1];
                                    header.FileName = pcomps[2];
                                    regionSize      = regionMapping[regionname].RegionSize;
                                    scene           = scenes[regionMapping[regionname].ID];
                                    parcelsCleared  = false;
                                }

                                if (header.FileName.StartsWith("objects/"))
                                {
                                    ShowOarLoadState(ref currentLoadState, CurrentOarLoadState.Objects, io);
                                    /* Load objects */
                                    List <ObjectGroup>        sogs;
                                    XmlDeserializationOptions xmloptions = XmlDeserializationOptions.ReadKeyframeMotion;
                                    if ((options & LoadOptions.PersistUuids) != 0)
                                    {
                                        xmloptions |= XmlDeserializationOptions.RestoreIDs;
                                    }
                                    try
                                    {
                                        sogs = ObjectXML.FromXml(reader, scene.Owner, xmloptions);
                                    }
                                    catch (Exception e)
                                    {
                                        throw new OARLoadingErrorException("Failed to load sog " + header.FileName, e);
                                    }

                                    foreach (ObjectGroup sog in sogs)
                                    {
                                        if (sog.Owner.ID == UUID.Zero)
                                        {
                                            sog.Owner = scene.Owner;
                                        }
                                    }
                                    load_sogs.AddRange(sogs);
                                }
                                else if (header.FileName.StartsWith("terrains/"))
                                {
                                    ShowOarLoadState(ref currentLoadState, CurrentOarLoadState.Terrain, io);
                                    /* Load terrains */
                                    if ((options & LoadOptions.Merge) == 0)
                                    {
                                        scene.Terrain.AllPatches = TerrainLoader.LoadStream(reader, (int)regionSize.X, (int)regionSize.Y);
                                        scene.StoreTerrainAsDefault();
                                    }
                                }
                                else if (header.FileName.StartsWith("landdata/"))
                                {
                                    ShowOarLoadState(ref currentLoadState, CurrentOarLoadState.Parcels, io);
                                    /* Load landdata */
                                    if ((options & LoadOptions.Merge) == 0)
                                    {
                                        if (!parcelsCleared)
                                        {
                                            scene.ClearParcels();
                                            parcelsCleared = true;
                                        }
                                        var        whiteList = new List <ParcelAccessEntry>();
                                        var        blackList = new List <ParcelAccessEntry>();
                                        ParcelInfo pinfo     = ParcelLoader.GetParcelInfo(new ObjectXmlStreamFilter(reader), regionSize, whiteList, blackList);
                                        if (pinfo.Owner.ID == UUID.Zero)
                                        {
                                            pinfo.Owner = scene.Owner;
                                        }
                                        if ((options & LoadOptions.PersistUuids) == LoadOptions.PersistUuids)
                                        {
                                            ParcelInfo check;
                                            if (scene.Parcels.TryGetValue(pinfo.ID, out check))
                                            {
                                                pinfo.ID = UUID.Random;
                                            }
                                        }
                                        else
                                        {
                                            pinfo.ID = UUID.Random;
                                        }
                                        scene.AddParcel(pinfo);
                                        scene.Parcels.WhiteList.Remove(scene.ID, pinfo.ID);
                                        scene.Parcels.BlackList.Remove(scene.ID, pinfo.ID);
                                        foreach (ParcelAccessEntry pae in whiteList)
                                        {
                                            scene.Parcels.WhiteList.Store(pae);
                                        }
                                        foreach (ParcelAccessEntry pae in blackList)
                                        {
                                            scene.Parcels.BlackList.Store(pae);
                                        }
                                    }
                                }
                                else if (header.FileName.StartsWith("settings/") && ((options & LoadOptions.Merge) == 0))
                                {
                                    ShowOarLoadState(ref currentLoadState, CurrentOarLoadState.Parcels, io);
                                    /* Load settings */
                                    RegionSettingsLoader.LoadRegionSettings(new ObjectXmlStreamFilter(reader), scene);
                                }
                            }
                        }
                    }
                }
            }
        }