Exemplo n.º 1
0
        public override bool LoadObject(string path, System.Text.Encoding Encoding, out UnifiedObject Object)
        {
            if (base.LoadObject(path, Encoding, out Object))
            {
                return(true);
            }

            if (System.IO.File.Exists(path) || System.IO.Directory.Exists(path))
            {
                Encoding = TextEncoding.GetSystemEncodingFromFile(path, Encoding);

                for (int i = 0; i < Program.CurrentHost.Plugins.Length; i++)
                {
                    if (Program.CurrentHost.Plugins[i].Object != null)
                    {
                        try {
                            if (Program.CurrentHost.Plugins[i].Object.CanLoadObject(path))
                            {
                                try
                                {
                                    UnifiedObject obj;
                                    if (Program.CurrentHost.Plugins[i].Object.LoadObject(path, Encoding, out obj))
                                    {
                                        obj.OptimizeObject(false, Interface.CurrentOptions.ObjectOptimizationBasicThreshold, Interface.CurrentOptions.ObjectOptimizationVertexCulling);
                                        Object = obj;

                                        StaticObject staticObject = Object as StaticObject;
                                        if (staticObject != null)
                                        {
                                            StaticObjectCache.Add(ValueTuple.Create(path, false), staticObject);
                                            return(true);
                                        }

                                        AnimatedObjectCollection aoc = Object as AnimatedObjectCollection;
                                        if (aoc != null)
                                        {
                                            AnimatedObjectCollectionCache.Add(path, aoc);
                                        }

                                        return(true);
                                    }
                                    Interface.AddMessage(MessageType.Error, false, "Plugin " + Program.CurrentHost.Plugins[i].Title + " returned unsuccessfully at LoadObject");
                                } catch (Exception ex) {
                                    Interface.AddMessage(MessageType.Error, false, "Plugin " + Program.CurrentHost.Plugins[i].Title + " raised the following exception at LoadObject:" + ex.Message);
                                }
                            }
                        } catch (Exception ex) {
                            Interface.AddMessage(MessageType.Error, false, "Plugin " + Program.CurrentHost.Plugins[i].Title + " raised the following exception at CanLoadObject:" + ex.Message);
                        }
                    }
                }
                Interface.AddMessage(MessageType.Error, false, "No plugin found that is capable of loading object " + path);
            }
            else
            {
                ReportProblem(OpenBveApi.Hosts.ProblemType.PathNotFound, path);
            }
            Object = null;
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>Loads an object</summary>
        /// <param name="Path">The absolute on-disk path to the object</param>
        /// <param name="Encoding">The detected text encoding</param>
        /// <param name="Object">The handle to the object</param>
        /// <returns>Whether loading the object was successful</returns>
        public virtual bool LoadObject(string Path, System.Text.Encoding Encoding, out UnifiedObject Object)
        {
            ValueTuple <string, bool> key = ValueTuple.Create(Path, false);

            if (StaticObjectCache.ContainsKey(key))
            {
                Object = StaticObjectCache[key].Clone();
                return(true);
            }

            if (AnimatedObjectCollectionCache.ContainsKey(Path))
            {
                Object = AnimatedObjectCollectionCache[Path].Clone();
                return(true);
            }

            Object = null;
            return(false);
        }